aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/include
Commit message (Collapse)AuthorAgeFilesLines
* libc,libthr: Remove __pthread_distribute_static_tlsJessica Clarke2025-07-101-3/+1
| | | | | | | This private API is no longer used by rtld-elf so can be removed. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D50921
* libc: Allow more complex expressions for CALL_BLOCK first argumentJessica Clarke2025-06-031-1/+1
| | | | | | | | | For the case where the compiler supports blocks we only allow the first expression to have an operator if it has as high precedence as a function call, which for blocks effectively means member access and subscripting only, not even a dereference nor a cast. Parenthesise this, as is the case for the missing compiler support case, so that it's more general.
* Provide user interface to retrieve reported extended errorsKonstantin Belousov2025-05-311-0/+5
| | | | | | | Reviewed by: brooks Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D50483
* libc: treat execvpe as a week symbolSHENGYI HONG2025-04-221-0/+1
| | | | | | | | | | | | | | Some program intercepts the execvpe call in runtime. At the same time, the implementation of posix_spwan use execvpe. If execvpe is intercepted and then calls posix_spawn when intercepted. It wil create a infinite loop because the intercepted execvpe will spawn a posix_spwan call and will be intercepted again. See https://github.com/rizsotto/Bear/issues/557 for reference. Reviewed by: brooks, kib, emaste Sponsored by: FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D49733
* libc, libthr: coordinate stubs for pthread_{suspend,resume}_all_npKyle Evans2024-11-141-0/+2
| | | | | | | | | If libthr isn't linked into the process, then we don't have any pthreads to worry about and our stubs can just return success -- there are none to suspend/resume. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D47350
* libthr: avoid gcc -Wcast-function-typeRyan Libby2024-07-031-2/+2
| | | | | | | | | | The actual types of pthread_func_t and interpos_func_t are not used. Declare them as the generic void (*)(void) which suppresses warnings. https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wcast-function-type Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D45830
* libc: make strerror_rl() usable for libcKonstantin Belousov2024-04-231-0/+2
| | | | | | | Reviewed by: imp Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D44916
* libc: INTERPOS_SYS macro for interposed syscallsBrooks Davis2024-04-161-0/+6
| | | | | | | | This macro makes uses the __sys_<foo>_t typedefs from libsys.h to greatly simplify calling functions in the interposing table. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D44389
* lib{c,rt}: use libsys.h for __sys_* declerationsBrooks Davis2024-04-161-77/+2
| | | | | | | Use the genreated source of truth for system call declerations. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D44388
* syscalls.master: make __sys_fcntl take an intptr_tBrooks Davis2024-03-191-1/+1
| | | | | | | | | | | | | The (optional) third argument of fcntl is sometimes a pointer so change the type to intptr_t. Update the libc-internal defintion (actually used by libthr) to take a fixed intptr_t argument rather than pretending it's a variadic function. (That worked because all supported architectures pass variadic arguments as though the function was declared with those types. In CheriBSD that changes because variadic arguments are passed via a bounded array.) Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D44381
* libsys: make __libsys_interposing staticBrooks Davis2024-03-131-1/+0
| | | | | | | | Access __libsys_interposing with __libc_interposing_slot() in all cases to support a move of these wrappers back to libc. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D44239
* libsys: don't expose sigwait wrapperBrooks Davis2024-03-131-2/+1
| | | | | | | | | | | Long ago (e129c18a83ef) __sys_sigwait was wrapped to prevent sigwait() from returning with EINTR. Through a series of changes this wrapper become __libc_sigwait which was internal to libc and used solely in the interposing table. To support a move of sigwait back to libc, move this wrapper into libsys and rename it with an __libsys_ prefix. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D44238
* libc: remove remnants of __fcntl_compatBrooks Davis2024-03-132-3/+0
| | | | | | Reviewed by: kib Fixes: 60b2e2d3ee82 libc: stop exposing __fcntl_compat Differential Revision: https://reviews.freebsd.org/D44326
* libc: split libc and syscall interposing (1/2)Brooks Davis2024-02-051-0/+2
| | | | | | | | | | | | | | System calls or their wrappers are now interposed by __libsys_interposing with purely libc entries remaining in __libc_interposing. Use __libsys_interposing_slot in libthr to update __libsys_interposing, but also make __libc_interposing_slot fall back to __libsys_interposing_slot so an out of date libc has a chance of working during updates. Reviewed by: kib, emaste, imp Pull Request: https://github.com/freebsd/freebsd-src/pull/908
* libc: expose execvpe for Linux compatBrooks Davis2023-12-111-3/+0
| | | | | | | | | | | | | | We already implemented execvpe internally with an _ prefix in libc so go ahead and expose it for compatibility with Linux. This reverts c605eea952146348e5e1ad5cab6c127d7a1bd164. Bump __FreeBSD_version for the addition and add definitions to supress compat shims in libzfs (zfs changes were merged from upstream). PR: 275370 (request and exp-run (thanks antoine!)) Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D42846
* libc: Purge unneeded cdefs.hWarner Losh2023-11-012-2/+0
| | | | | | | | | 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
* libc: export pthread_getname_np stubMinsoo Choo2023-08-201-0/+1
| | | | | | | | | | | | | | | pthread_getname_np needs to be provided by libc in order to import jemalloc 5.3.0. A stub implementation for libc pthread_getname_np() is added for _pthread_stubs.c, which always reports empty name for the main thread. Internal _pthread_getname_np() is not exported, but provided for libc own use. Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D41461
* Remove $FreeBSD$: one-line .c comment patternWarner Losh2023-08-164-4/+0
| | | | Remove /^/[*/]\s*\$FreeBSD\$.*\n/
* Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-1612-24/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-129-9/+9
| | | | | | | | | 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
* libc: move declaration of 'char **environ' to common private headerKonstantin Belousov2023-03-111-0/+2
| | | | | | | | | Suggested by: imp Reviewed by: markj Tested by: markj (aarch64) Sponsored by: The FreeBSD Foundation MFC after: 3 weeks Differential revision: https://reviews.freebsd.org/D37220
* csu: move common code to libcKonstantin Belousov2023-03-111-0/+6
| | | | | | | | | | | | | | | | | | | | | | Why? Most trivial point, it shaves around 600 bytes from the dynamic binaries on amd64. Less trivial, the removed code is no longer part of the ABI, and we can ship updates to it with libc updates. Right now most of the csu is linked into the binaries and require us to do somewhat tricky ABI compat when it needs to change. For instance, the init_array change would be much simpler and does not require note tagging if we have init calling code in libc. This could be improved more, by splitting dynamic and static initialization. For instance, &_DYNAMIC tests can be removed then. Such change, nonetheless, would require building libc three times. I left this for later, after this change stabilizes, if ever. Reviewed by: markj Discussed with: jrtc27 (some objections, see the review), imp Tested by: markj (aarch64) Sponsored by: The FreeBSD Foundation MFC after: 3 weeks Differential revision: https://reviews.freebsd.org/D37220
* cpuset: Add compat shim to the sched_affinity functionsDmitry Chagin2023-02-151-0/+6
| | | | | | | | | | | To allow to run a newer world on a pre-1400079 kernel a compat shims to the sched_affinity functions has beed added. Reported by: antoine Tested by: antoine Reviewed by: kib Differential revision: https://reviews.freebsd.org/D38555 MFC after: 3 days
* libc: Remove _get_tp() and _set_tp().John Baldwin2021-12-091-6/+0
| | | | | | | | | 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
* swapoff: add one more variant of the syscallKonstantin Belousov2021-12-091-0/+2
| | | | | | | Requested and reviewed by: brooks Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D33343
* Add sched_getcpu()Konstantin Belousov2021-11-101-0/+1
| | | | | | | | | for compatibility with Linux. Reviewed by: jhb Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D32901
* StyleKonstantin Belousov2021-08-031-2/+2
| | | | | | | Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D31378
* libc: add _get_tp() private functionKonstantin Belousov2021-04-091-1/+2
| | | | | | | | which returns pointer to tcb Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D29623
* libthr: wrap pdfork(2), same as fork(2).Konstantin Belousov2021-01-111-0/+2
| | | | | | | | | | Without wrapping, rtld services and malloc(3) are not guaranteed to operate correctly in the forked child. Reviewed by: markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D28088
* Add eventfd(3) wrappers to libc.Konstantin Belousov2020-12-271-0/+1
| | | | | | | | | eventfd_read/write one-liners are from musl libc. Submitted by: greg@unrelenting.technology Reviewed by: markj (previous version) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D26668
* Implement strerror_l().Konstantin Belousov2020-12-161-0/+5
| | | | | | | | | | | | | | Only for the arches that provide user-mode TLS. PR: 251651 Requested by: yuri Discussed with: emaste, jilles, tijl Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D27495 MFC after: 2 weeks Notes: svn path=/head/; revision=368692
* libc: Add pthread_attr_get_np(3) stub, reporting ESRCH.Konstantin Belousov2020-11-281-0/+1
| | | | | | | | | | | | | | | This seems to be required by recent clang asan. I do not see other way than put the symbol under FBSD_1.0 version. PR: 251112 Reported by: Andrew Stitcher <astitcher@apache.org> Reviewed by: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D27389 Notes: svn path=/head/; revision=368125
* Add pthread_getname_np() and pthread_setname_np() aliases forKonstantin Belousov2020-06-102-0/+4
| | | | | | | | | | | | | | | pthread_get_name_np() and pthread_set_name_np(). This re-applies r361770 after compatibility fixes. Reviewed by: antoine, jkim, markj Tested by: antoine (exp-run) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D25117 Notes: svn path=/head/; revision=362032
* Mark closefrom(2) COMPAT12, reimplement in libc to wrap close_rangeKyle Evans2020-04-141-0/+1
| | | | | | | | | | | Include a temporarily compatibility shim as well for kernels predating close_range, since closefrom is used in some critical areas. Reviewed by: markj (previous version), kib Differential Revision: https://reviews.freebsd.org/D24399 Notes: svn path=/head/; revision=359930
* Add linux-compatible memfd_createKyle Evans2019-09-251-0/+1
| | | | | | | | | | | | | | | | | memfd_create is effectively a SHM_ANON shm_open(2) mapping with optional CLOEXEC and file sealing support. This is used by some mesa parts, some linux libs, and qemu can also take advantage of it and uses the sealing to prevent resizing the region. This reimplements shm_open in terms of shm_open2(2) at the same time. shm_open(2) will be moved to COMPAT12 shortly. Reviewed by: markj, kib Differential Revision: https://reviews.freebsd.org/D21393 Notes: svn path=/head/; revision=352703
* Add libc stub for pthread_getthreadid_np(3).Konstantin Belousov2019-06-231-0/+1
| | | | | | | | | | Requested by: jbeich PR: 238650 Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=349299
* Fix initial exec TLS mode for dynamically loaded shared objects.Konstantin Belousov2019-03-291-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=345703
* Bump sys_errlist size to keep ABI backward-compatible for some time.Konstantin Belousov2018-12-271-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Addition of the new errno values requires adding new elements to sys_errlist array, which is actually ABI-incompatible, since ELF records the object size. Expand array in advance to 150 elements so that we have our users to go over the issue only once, at least until more than 53 new errors are added. I did not bumped the symbol version, same as it was not done for previous increases of the array size. Runtime linker only copies as much data into binary object on copy relocation as the binary'object specifies. This is not fixable for binaries which access sys_errlist directly. While there, correct comment and calculation of the temporary buffer size for the message printed for unknown error. The on-stack buffer is used only for the number and delimiter since r108603. Requested by: mckusick Reviewed by: mckusick, yuripv MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D18656 Notes: svn path=/head/; revision=342551
* Update userland arc4random() with OpenBSD's Chacha20 based arc4random().Xin LI2018-08-191-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ObsoleteFiles.inc: Remove manual pages for arc4random_addrandom(3) and arc4random_stir(3). contrib/ntp/lib/isc/random.c: contrib/ntp/sntp/libevent/evutil_rand.c: Eliminate in-tree usage of arc4random_addrandom(). crypto/heimdal/lib/roken/rand.c: crypto/openssh/config.h: Eliminate in-tree usage of arc4random_stir(). include/stdlib.h: Remove arc4random_stir() and arc4random_addrandom() prototypes, provide temporary shims for transistion period. lib/libc/gen/Makefile.inc: Hook arc4random-compat.c to build, add hint for Chacha20 source for kernel, and remove arc4random_addrandom(3) and arc4random_stir(3) links. lib/libc/gen/arc4random.c: Adopt OpenBSD arc4random.c,v 1.54 with bare minimum changes, use the sys/crypto/chacha20 implementation of keystream. lib/libc/gen/Symbol.map: Remove arc4random_stir and arc4random_addrandom interfaces. lib/libc/gen/arc4random.h: Adopt OpenBSD arc4random.h,v 1.4 but provide _ARC4_LOCK of our own. lib/libc/gen/arc4random.3: Adopt OpenBSD arc4random.3,v 1.35 but keep FreeBSD r114444 and r118247. lib/libc/gen/arc4random-compat.c: Compatibility shims for arc4random_stir and arc4random_addrandom functions to preserve ABI. Log once when called but do nothing otherwise. lib/libc/gen/getentropy.c: lib/libc/include/libc_private.h: Fold __arc4_sysctl into getentropy.c (renamed to arnd_sysctl). Remove from libc_private.h as a result. sys/crypto/chacha20/chacha.c: sys/crypto/chacha20/chacha.h: Make it possible to use the kernel implementation in libc. PR: 182610 Reviewed by: cem, markm Obtained from: OpenBSD Relnotes: yes Differential Revision: https://reviews.freebsd.org/D16760 Notes: svn path=/head/; revision=338059
* Add pthread_get_name_np(3).Konstantin Belousov2018-08-172-0/+2
| | | | | | | | | | | | | | | | The function retrieves the thread name previously set by pthread_set_name_np(3). The name is cached in the process memory. Requested by: Willem Jan Withagen <wjw@digiware.nl> Man page update: Yuri Pankov <yuripv@yuripv.net> Reviewed by: ian (previous version) Discussed with: arichardson, bjk (man page) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D16702 Notes: svn path=/head/; revision=337983
* getentropy(3): Fallback to kern.arandom sysctl on older kernelsConrad Meyer2018-03-211-0/+2
| | | | | | | | | | | | | | | | | | | On older kernels, when userspace program disables SIGSYS, catch ENOSYS and emulate getrandom(2) syscall with the kern.arandom sysctl (via existing arc4_sysctl wrapper). Special care is taken to faithfully emulate EFAULT on NULL pointers, because sysctl(3) as used by kern.arandom ignores NULL oldp. (This was caught by getentropy(3) ATF tests.) Reported by: kib Reviewed by: kib Discussed with: delphij Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D14785 Notes: svn path=/head/; revision=331334
* lib: Fix several typos and minor errorsEitan Adler2017-12-271-1/+1
| | | | | | | | | | | - duplicate words - typos - references to old versions of FreeBSD Reviewed by: imp, benno Notes: svn path=/head/; revision=327232
* SPDX: license IDs for some ISC-related files.Pedro F. Giffuni2017-12-083-3/+9
| | | | Notes: svn path=/head/; revision=326695
* Add include guard to fpmath.hEitan Adler2017-12-021-0/+5
| | | | | | | Submitted by: kargl Notes: svn path=/head/; revision=326479
* libc: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-259-2/+20
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using mis-identified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326193
* General further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-202-2/+6
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326025
* In the stdio cleanup push and pop wrappers, always call libc stubs forKonstantin Belousov2017-06-301-0/+5
| | | | | | | | | | | | | | | | | | __pthread_cleanup_push/pop_imp instead of symbols also exported from libthr. This prevents calls into libthr if libthr is not yet initialized. The situation occurs e.g. when an LD_PRELOADed object is not linked against libthr, but the main binary is. Reported and tested by: jbeich PR: 220381 Discussed with: vangyzen Sponsored by: The FreeBSD Foundation MFC after: 13 days Notes: svn path=/head/; revision=320509
* Forward compatibility for ino64.Warner Losh2017-06-231-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add forward compatibility so that new binaries can run on old kernels. If the new system call from ino64 isn't available on your system, then the old one will be used and the results translated. The stat and statfs families of functions are fully emulated. While not required by policy, in this case it is helpful to our users to provide this compatibility. In this case, it allows rollback of the kernel after installing a new userland should a problem be discovered. It also prevents foot-shooting if a user does an install before rebooting with the new kernel. Finally, it allows the use case where one needs to run new binaries on an old kernel as part of an upgrade process. The getdirentries family uses tricks that may not work on remote filesystems. Specifically, it uses a buffer 1/4 the size requested to get the data from he old syscall. The code carefully uses direct syscalls for old system calls to avoid referencing freebsd11_* symbols, which contaminate ld-elf.so.1's export table due to its use of stat functions, which causes errno to be incorrect in client programs due to the wrong *stat* function being resolved in some cases. This code should removed sometime after 12 is branched. Tested on: 12-current binaries on a 10.3-beta kernel run and return consistent results. 12-current kernel and userland with packages from before ino64 was committed also work. Differential Revision: https://reviews.freebsd.org/D11185 Reviewed by: kib@, emaste@ Notes: svn path=/head/; revision=320278
* Add abstime kqueue(2) timers and expand struct kevent members.Konstantin Belousov2017-06-171-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This change implements NOTE_ABSTIME flag for EVFILT_TIMER, which specifies that the data field contains absolute time to fire the event. To make this useful, data member of the struct kevent must be extended to 64bit. Using the opportunity, I also added ext members. This changes struct kevent almost to Apple struct kevent64, except I did not changed type of ident and udata, the later would cause serious API incompatibilities. The type of ident was kept uintptr_t since EVFILT_AIO returns a pointer in this field, and e.g. CHERI is sensitive to the type (discussed with brooks, jhb). Unlike Apple kevent64, symbol versioning allows us to claim ABI compatibility and still name the new syscall kevent(2). Compat shims are provided for both host native and compat32. Requested by: bapt Reviewed by: bapt, brooks, ngie (previous version) Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D11025 Notes: svn path=/head/; revision=320043
* libthr: fix warnings from GCC when WARNS=6Eric van Gyzen2017-05-231-0/+3
| | | | | | | | | | | | | | | | | | | Fix warnings about: - redundant declarations - a local variable shadowing a global function (dlinfo) - an old-style function definition (with an empty parameter list) - a variable that is possibly used uninitialized "make tinderbox" passes this time, except for a few unrelated kernel failures. Reviewed by: kib MFC after: 3 days Sponsored by: Dell EMC Differential Revision: https://reviews.freebsd.org/D10870 Notes: svn path=/head/; revision=318749