Commit graph

67 commits

Author SHA1 Message Date
Andrew Turner 5202ca77aa libc/aarch64: Add a non-trivial getcontextx
Add support for extra registers to the arm64 getcontextx. As no
registers are defined this just adds the extra register list and an end
context.

Reviewed by:	kib
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D44255
2024-03-21 10:13:24 +00:00
Andrew Turner fd6b1cc34e libc/aarch64: Copy the trivial getcontextx
This will be used as the base of a non-trivial implementation.

Reviewed by:	kib
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D44254
2024-03-21 10:13:24 +00:00
Brooks Davis 31a46e2cc8 libc: Move per-arch sys/Makefile.inc to libsys
libc/<arch>/sys/Makefile.inc -> libsys/<arch>/Makefile.sys.

Require that libsys/<arch>/Makefile.sys exist.  At least for current
archtiectures, it's not possible for an architecture to not have and MD
syscall bits.

powerpcspe/Makefile.sys's structure means it had to be modified when moved
so rename detection won't work, but it has trivial contents so the
history is unimportant.

Reviewed by:	kib, emaste, imp
Pull Request:	https://github.com/freebsd/freebsd-src/pull/908
2024-02-05 20:34:55 +00:00
Brooks Davis 0d6cc87b18 libc: libc/<arch>/sys/__vdso_gettc -> libsys/<arch>/
Reviewed by:	kib, emaste, imp
Pull Request:	https://github.com/freebsd/freebsd-src/pull/908
2024-02-05 20:34:55 +00:00
Brooks Davis 8269e7673c libsys: relocate implementations and manpages
Remove core system call implementations and documentation to lib/libsys
and lib/libsys/<arch> from lib/libc/sys and lib/libc/<arch>/<sys>.
Update paths to allow libc to find them in their new home.

Reviewed by:	kib, emaste, imp
Pull Request:	https://github.com/freebsd/freebsd-src/pull/908
2024-02-05 20:34:55 +00:00
Brooks Davis 0e867a4911 aarch/SYS.h: implement _SYSCALL_BODY() macro
Add _SYSCALL_BODY() macro which invokes the syscall via _SYCALL() and
calls cerror as required.  Use to implement PSEUDO() and RSYSCALL().

Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D43058
2024-02-02 17:08:55 +00:00
Brooks Davis 9aaf4e3be6 libc/*/SYS.h: remove SYCALL macro
This has not been a univerally available interface since it was removed
from amd64 by commit efbef97de9 in 2004.
I removed the last consumers in 2016 when I replaced pipe(2) with
pipe2(2) in commit b60998c633.

Reviewed by:	imp, jhibbits
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D42996
2023-12-12 22:52:41 +00:00
Brooks Davis ec27c0bb3e libc: don't needlessly add vfork.o to NOASM
For architectures where vfork.S was named Ovfork.S this was needed, but
it was always pointless here as an entry in either MDASM or NOASM is
equivalent.

Reviewed by:	kib
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D42914
2023-12-06 20:49:08 +00:00
Brooks Davis 7893419d49 Remove never implemented sbrk and sstk syscalls
Both system calls were stubs returning EOPNOTSUPP and libc did not
provide _ or __sys_ prefixed symbols.  The actual implementation of
sbrk(2) is on top of the undocumented break(2) system call.

Technically this is a change in ABI, but no non-contrived program ever
called these syscalls.

Reviewed by:	kib, emaste
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D42872
2023-12-04 20:36:08 +00:00
Andrew Turner fd5aaf2ea0 libc: Teach libc about the BTI elf note
Add the Branch Target Identification (BTI) note to libc assembly
sources. As all obect files need the note for the library to have it
we need to insert it in all asm files.

Reviewed by:	emaste, markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42228
2023-11-21 10:02:51 +00:00
Brooks Davis c704518681 libc: centralize a few numeric symbols
fabs, __infinity, and __nan are universally implemented so declare them
in gen/Symbol.map.

We would also include __flt_rounds, but  it's under FBSD_1.3 on arm so
until that's gone we're stuck with it.  Likewise, everyone but i386
implements fp[gs]etmask.

Reviewed by:	imp, kib, emaste
Differential Revision:	https://reviews.freebsd.org/D42618
2023-11-15 23:42:37 +00:00
Brooks Davis 5d79b5445e libc: centralize makecontext symbols
Declare makecontext() and __makecontext() symbols centrally as they are
always implemented.

Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D42617
2023-11-15 23:42:18 +00:00
Brooks Davis 1c656143be libc: centralize {_,sig,}{set,long}jmp symbols
These symbols are universally exposed and documented so declare them
centrally.  Double- and triple-underscore versions exist on some
platforms, but leave those alone for now.

Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D42616
2023-11-15 23:41:35 +00:00
Brooks Davis ff3a9d8e29 libc: centralize ntoh symbols
These are implemented by net/ntoh.c via headers and compiler intrinsics
so declare them in net/Symbol.map.

Reviewed by:	imp, kib, emaste
Differential Revision:	https://reviews.freebsd.org/D42615
2023-11-15 23:40:54 +00:00
Brooks Davis e4a1800f06 libc: further centralize syscall symbols
All architectures necessarily implement _exit(2) and vfork(2) so
declare them in sys/Symbol.map.

Reviewed by:	imp, kib, emaste
Differential Revision:	https://reviews.freebsd.org/D42614
2023-11-15 23:40:33 +00:00
Brooks Davis 1ca63a8219 libc: Remove empty comments in Symbol.map
These were left over from $FreeBSD$ removal.

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D42612
2023-11-15 17:51:03 +00:00
Brooks Davis b73eace889 libc/<arch>/sys/Makefile.inc: remove cruft
Remove stray blank lines left over from $FreeBSD$ removal as well as
some CVS-era (perhaps pre-repocopy) version comments.

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D42611
2023-11-15 17:50:53 +00:00
Warner Losh 559a218c9b libc: Purge unneeded cdefs.h
These sys/cdefs.h are not needed. Purge them. They are mostly left-over
from the $FreeBSD$ removal. A few in libc are still required for macros
that cdefs.h defines. Keep those.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D42385
2023-11-01 16:44:30 -06:00
Jessica Clarke 1c1f229e91 libc: Strip plentiful trailing whitespace from aarch64+arm makecontext.c 2023-10-28 02:45:06 +01:00
Warner Losh d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh 1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh 42b388439b Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:23 -06:00
Warner Losh b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06:00
Warner Losh 4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Jessica Clarke 9fb118bebc libc: Fix longjmp/_longjmp(buf, 0) for AArch64 and RISC-V
These architectures fail to handle this special case, and will cause the
corresponding setjmp/_setjmp to return 0 rather than 1. Fix this and add
regression tests (also committed upstream).

PR:		268684
Reviewed by:	arichardson, jhb
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D29363
2023-01-09 18:34:43 +00:00
Andrew Turner 101480e926 Remove "All rights reserved" where I can in libc
These all have my copyright so can be removed. Some also have FreeBSD
Foundation copyright so drop from there as has been done for previous
files.

Sponsored by:	The FreeBSD Foundation
2022-08-05 15:11:39 +01:00
Ed Maste 560e22c8fe Remove "All Rights Reserved" from FreeBSD Foundation libc copyrights
As per the updated FreeBSD copyright template.  These were unambiguous
cases where the Foundation was the only listed copyright holder.

Sponsored by:	The FreeBSD Foundation
2022-07-21 09:53:31 -04:00
Andrew Turner 16d5f9a164 Add an implementation of .mcount on arm64
To support cc -pg on arm64 we need to implement .mcount. As clang and
gcc think it is function like it just needs to load the arguments
to _mcount and call it.

On gcc the first argument is passed in x0, however this is missing on
clang so we need to load it from the stack. As it's the caller return
address this will be at a known location.

PR:		262709
Reviewed by:	emaste (earlier version)
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34634
2022-03-23 15:16:59 +00:00
John Baldwin ae67737a4c libc: Remove _get_tp() and _set_tp().
Their uses have been replaced by _tcb_get() and _tcb_set() from
<machine/tls.h>.

Reviewed by:	kib, jrtc27
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D33354
2021-12-09 13:23:26 -08:00
Andrew Turner 2e8ff4d1d5 Switch to Arm Optimized Routines for mem* & str*
These are the updated version of the older Cortex Strings Library we
previously used. The Arm Optimized Routines also support CPU features
that are currently in development on FreeBSD, e.g. Branch Target
Identification (BTI). Rather than add BTI support to the old code it's
easier to just use the maintained version.

Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D32774
2021-11-19 11:40:46 +00:00
Konstantin Belousov 77b2c2f814 Add sched_getcpu()
for compatibility with Linux.

Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D32901
2021-11-10 21:18:54 +02:00
Konstantin Belousov 06d8a116bd libc: add _get_tp() private function
which returns pointer to tcb

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D29623
2021-04-09 23:46:24 +03:00
Konstantin Belousov 5d00c5a657 Fix initial exec TLS mode for dynamically loaded shared objects.
If dso uses initial exec TLS mode, rtld tries to allocate TLS in
static space. If there is no space left, the dlopen(3) fails. If space
if allocated, initial content from PT_TLS segment is distributed to
all threads' pcbs, which was missed and caused un-initialized TLS
segment for such dso after dlopen(3).

The mode is auto-detected either due to the relocation used, or if the
DF_STATIC_TLS dynamic flag is set.  In the later case, the TLS segment
is tried to allocate earlier, which increases chance of the dlopen(3)
to succeed.  LLD was recently fixed to properly emit the flag, ld.bdf
did it always.

Initial test by:	dumbbell
Tested by:	emaste (amd64), ian (arm)
Tested by:	Gerald Aryeetey <aryeeteygerald_rogers.com> (arm64)
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D19072
2019-03-29 17:52:57 +00:00
Mark Johnston 2e7680c6bf Don't export _end on arm64 and riscv.
These platforms don't support brk() and sbrk(), which are the reason
for exporting _end in the first place.

MFC after:	1 week
2018-06-01 23:42:10 +00:00
Brooks Davis 97e5d68bb0 Remove architecture specific shmat.S files.
These files are identical to the generated system calls.
In the case of MIPS, the file was already disconnected from the build.

Submitted by:	Ali Mashtizadeh <ali@mashtizadeh.com>
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D14976
2018-04-05 18:17:46 +00:00
Brooks Davis 7dd87e9a82 Remove architecture specific sigreturn.S files.
All of these files are identical (modulo license blocks and VCS IDs) to
the files generated by lib/libc/sys/Makefile.inc and serve no purpose.

Reported by:	Ali Mashtizadeh <ali@mashtizadeh.com>
Reviewed by:	kib
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D14953
2018-04-04 22:45:08 +00:00
Jason Evans e46bcb7d38 Decrease relative branch brittleness.
Replace conditional branches with trampolines to unconditional branches when
jumping to labels within other compilation units.  This increases the offset
range from +-1 MiB to +-128 MiB.
2017-06-20 07:25:38 +00:00
Alexander Kabaev 07b49497db Do not use b.cs instruction to jump to cerror.
The conditional jump can only be performed to targets up to 1MB in
either direction and does not work too well when linker places cerror
further that that from the caller. In that case linker will complain
about relocation overflows.

Reviewed by: emaste, andrew
Differential Revision:  https://reviews.freebsd.org/D10305
2017-04-07 22:58:20 +00:00
Brooks Davis 13f2393362 Correct an misunderstanding of MDSRCS.
MDSRCS it intended to allow assembly versions of funtions with C
implementations listed in MISRCS. The selection of the correct
machdep_ldis?.c for a given architecture does not follow this pattern
and the file should be added to SRCS directly.

Reviewed by:	emaste, imp, jhb
MFC after:	1 week
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D9841
2017-03-02 17:07:28 +00:00
Brooks Davis 9fe44df287 Correct MDSRCS use in <arch>/string/Makefile.inc.
- Remove .c files which duplicate entries in MISRCS.
- Use the same, less merge conflict prone style in all cases.
- Use MDSRCS for mips (.c and .S files both ended up in SRCS).
- Remove pointless sparc64 Makefile.inc.
- Remove uninformative foreign VCS ID entries.

Reviewed by:	emaste, imp, jhb
MFC after:	1 week
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D9841
2017-03-02 17:05:52 +00:00
Andrew Turner 5b50ed8043 Fix the comment showing the meaning of the first argument to sigprocmask.
Sponsored by:	ABT Systems Ltd
2017-02-03 11:51:06 +00:00
Andrew Turner d15ac668f0 Fix the error value we write in cerror. __error returns an int *, however
we were writing a 64 bit value meaning the 32 bits after this would be
trashed.

MFC after:	3 days
Sponsored by:	DARPA, AFRL
2017-01-24 18:56:09 +00:00
Enji Cooper d0fd0203fb Replace dot-dot relative pathing with SRCTOP-relative paths where possible
This reduces build output, need for recalculating paths, and makes it clearer
which paths are relative to what areas in the source tree. The change in
performance over a locally mounted UFS filesystem was negligible in my testing,
but this may more positively impact other filesystems like NFS.

LIBC_SRCTOP was left alone so Juniper (and other users) can continue to
manipulate lib/libc/Makefile (and other Makefile.inc's under lib/libc) as
include Makefiles with custom options.

Discussed with:	marcel, sjg
MFC after:	1 week
Reviewed by:	emaste
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D9207
2017-01-20 03:23:24 +00:00
Andrew Turner 5a3a700931 Attach the cortex strings library to the build. Only a subset of functions
have been added as some don't seem to be improvements over the libc C
implementation.

Obtained from:	ABT Systems Ltd
Sponsored by:	The FreeBSD Foundation
2016-09-19 15:08:03 +00:00
Brooks Davis aec2fba60f Reduce duplicate NOASM and PSEUDO definitions
The initial value of NOASM is nearly the same in all cases and the
initial value of PSEUDO is the same in all cases so reduce duplication
(and hopefully, future merge conflicts) by machine independent defaults.

Also document the PSEUDO variable.

Reviewed by:	jhb, kib
Obtained from:	CheriBSD
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D7820
2016-09-08 22:38:20 +00:00
Konstantin Belousov f6fea94e5d Remove commented out mention of ptrace.S.
After r305012 the asm wrapper is not needed.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2016-08-29 18:53:51 +00:00
George V. Neville-Neil 5cba398b0c Remove unusedd and obsolete openbsd_poll system call. (Phase 1)
Reported by:	brooks
Reviewed by:	brooks,jhb
Differential Revision:	https://reviews.freebsd.org/D7548
2016-08-18 10:50:40 +00:00
Konstantin Belousov 1680854946 Implement userspace gettimeofday(2) with HPET timecounter.
Right now, userspace (fast) gettimeofday(2) on x86 only works for
RDTSC.  For older machines, like Core2, where RDTSC is not C2/C3
invariant, and which fall to HPET hardware, this means that the call
has both the penalty of the syscall and of the uncached hw behind the
QPI or PCIe connection to the sought bridge.  Nothing can me done
against the access latency, but the syscall overhead can be removed.
System already provides mappable /dev/hpetX devices, which gives
straight access to the HPET registers page.

Add yet another algorithm to the x86 'vdso' timehands. Libc is updated
to handle both RDTSC and HPET.  For HPET, the index of the hpet device
to mmap is passed from kernel to userspace, index might be changed and
libc invalidates its mapping as needed.

Remove cpu_fill_vdso_timehands() KPI, instead require that
timecounters which can be used from userspace, to provide
tc_fill_vdso_timehands{,32}() methods.  Merge i386 and amd64
libc/<arch>/sys/__vdso_gettc.c into one source file in the new
libc/x86/sys location.  __vdso_gettc() internal interface is changed
to move timecounter algorithm detection into the MD code.

Measurements show that RDTSC even with the syscall overhead is faster
than userspace HPET access.  But still, userspace HPET is three-four
times faster than syscall HPET on several Core2 and SandyBridge
machines.

Tested by:	Howard Su <howard0su@gmail.com>
Sponsored by:	The FreeBSD Foundation
MFC after:	1 month
Differential revision:	https://reviews.freebsd.org/D7473
2016-08-17 09:52:09 +00:00
Brooks Davis b60998c633 Replace use of the pipe(2) system call with pipe2(2) with a zero flags
value.

This eliminates the need for machine dependant assembly wrappers for
pipe(2).

It also make passing an invalid address to pipe(2) return EFAULT rather
than triggering a segfault.  Document this behavior (which was already
true for pipe2(2), but undocumented).

Reviewed by:	andrew
Approved by:	re (gjb)
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D6815
2016-06-22 21:11:27 +00:00
Andrew Turner 94098ab7c3 Remove brk and sbrk from arm64. They were defined in The Single UNIX
Specification, Version 2, but marked as legacy, and have been removed from
later specifications. After 12 years it is time to remove them from new
architectures when the main use for sbrk is an invalid method to attempt
to find how much memory has been allocated from malloc.

There are a few places in the tree that still call sbrk, however they are
not used on arm64. They will need to be fixed to cross build from arm64,
but these will be fixed in a follow up commit.

Old copies of binutils from ports called into sbrk, however this has been
fixed around 6 weeks ago. It is advised to update binutils on arm64 before
installing a world that includes this change.

Reviewed by:	brooks, emaste
Obtained from:	brooks
Relnotes:	yes
Sponsored by:	ABT Systems Ltd
Differential Revision:	https://reviews.freebsd.org/D6464
2016-05-20 15:04:48 +00:00