aboutsummaryrefslogtreecommitdiff
path: root/lib/libc
Commit message (Collapse)AuthorAgeFilesLines
* libc: Fix dtor order in __cxa_thread_atexitShengYi Hung3 days1-2/+2
| | | | | | | | | | | | | | | The thread_local variable may creates another thread_local variable inside its dtor. This new object is immediately be registered in __cxa_thread_atexit() and need to be freed before processing another variable. This fixes the libcxx test thread_local_destruction_order.pass.cpp. Reported by: kib Approved by: lwhsu (mentor) MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D55826
* build: Stop testing LINKER_FEATURES for ifunc and build-idEd Maste6 days1-6/+0
| | | | | | | | | | These features are available in all supported linkers, and we can expect that they'll be supported by any GNU-compatible linker that we'd use to link FreeBSD. Reviewed by: imp, kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D55676
* system(3): Fix brain glitch in previous commitDag-Erling Smørgrav7 days1-7/+7
| | | | | | | | | | | | We were saving SIGINT twice instead of SIGINT and SIGQUIT. Also restore original order of operations (SIGINT then SIGQUIT), which matches the order in which they're discussed in the POSIX description of system(3). MFC after: 1 week Sponsored by: Klara, Inc. Fixes: 48368f702423 ("system(3): Address test robustness issue")
* system(3): Address test robustness issueDag-Erling Smørgrav7 days1-11/+27
| | | | | | | | | | | Don't assume that SIGINT and SIGQUIT are set to SIG_DFL at the start of the test. Instead, retrieve their current dispositions and verify that they are restored at the end of the test. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55709
* libc/riscv64: temporarily disable strnlen() implementation until a fix is ↵Strahinja Stanišić9 days1-1/+0
| | | | | | | | | | | | developed strnlen() doesn't seem to cope well with a length argument such that string pointer plus length overflows past the end of the address space. Reviewed by: fuz MFC after: 1 week PR: 293353, 293296 Differential Revision: https://reviews.freebsd.org/D55714
* libc/quad: fix missing closing #endif in Symbol.mapXin LI11 days1-0/+1
| | | | | Without this lib32 libc.so.7 would be missing critical symbols, including malloc / free and all syscall wrappers.
* libc/quad: Switch to per-arch lists of symbolsJohn Baldwin12 days1-24/+19
| | | | | | | | This more closely mirrors libc/quad/Makefile.inc and is easier to read. Reviewed by: brooks Differential Revision: https://reviews.freebsd.org/D55658
* libc/quad: narrow list of symbols exposed for 32-bit armJohn Baldwin12 days1-0/+14
| | | | | | | lld doesn't notice, but ld.bfd complains. Reviewed by: brooks Differential Revision: https://reviews.freebsd.org/D55657
* libc/armv7: remove default version for allocaBrooks Davis12 days2-1/+3
| | | | | | | | | | | | The alloca() interface has been a macro expanding to __builtin_alloca() since 2003 (commit 79806b4cdce0, included in FreeBSD 5.2). Even before that virtually every compiler version I was able to test replaced alloca() with compiler generated code when targeting C. Hide it to prevent future (mis)use. Reviewed by: imp, kib Differential Revision: https://reviews.freebsd.org/D51858
* getnetconfig: make nc_error a thread local variableBrooks Davis12 days1-38/+1
| | | | | | | | | Remove a bunch of complexity at the cost of 4 bytes of storage per thread. Reviewed by: jhb Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D55310
* system(3): Unwrap execve()Dag-Erling Smørgrav13 days1-1/+3
| | | | | | | | | | | There is no need to call execl(), which will allocate an array and copy our arguments into it, when we can use a static array and call execve() directly. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55648
* Refinements to the output when the EXTERROR_VERBOSE environment is setKirk McKusick2026-02-262-9/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When kernel external errors are available they are included in the err(3) library function messages. In addition to the extended error itself, the kernel also tracks the kernel file and line number at which the error was generated. This additional information is not included in the err(3) messages unless the EXTERROR_VERBOSE environment variable is present. Currently, when EXTERROR_VERBOSE is present, all the internal extended error information associated with the error is printed most of which is redundant with the formatted error message printed by err(3). This change will add only the kernel file and line number to the err(3) message when EXTERROR_VERBOSE is present and set to "brief". Sample output with bad protection bits to mmap: guest_16 % ./Example bigfile Example: mmap bigfile: Invalid argument (unknown PROT bits 0x8) guest_16 % setenv EXTERROR_VERBOSE guest_16 % ./Example bigfile Example: mmap bigfile: Invalid argument (unknown PROT bits 0x8 errno 22 category 1 (src sys/vm/vm_mmap.c:200) p1 0x8 p2 0) guest_16 % setenv EXTERROR_VERBOSE brief guest_16 % ./Example bigfile Example: mmap bigfile: Invalid argument (unknown PROT bits 0x8 (src sys/vm/vm_mmap.c:200)) Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D55494 MFC-after: 1 week Sponsored-by: Netflix
* system(3): Fix null caseDag-Erling Smørgrav2026-02-252-1/+11
| | | | | | | | | | | | | | | | | | | | | Our manual page states that if given a null pointer, system() returns non-zero if the shell is available and zero if it is not. This is consistent with the C standard's description of system(), but it is not what we actually do. What we actually do is always return non-zero, as required by POSIX. As the POSIX rationale explains, implementing the logic required by the C standard does not violate POSIX, since a conforming system always has a shell, therefore the logic will always return non-zero. Since our libc is commonly used in non-conforming situations such as chroots or thin jails, we should implement the full logic required by the C standard. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: obiwac, bnovkov, kevans Differential Revision: https://reviews.freebsd.org/D55484
* system(3): Clarify return valuesDag-Erling Smørgrav2026-02-251-3/+5
| | | | | | | | | | | | Our manual page currently states that system() will return 127 if it fails to execute the shell. The actual return value is, to quote POSIX, “as if the command language interpreter had terminated using exit(127) or _exit(127)”. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: bnovkov, kevans Differential Revision: https://reviews.freebsd.org/D55483
* system(3): Write our own testsDag-Erling Smørgrav2026-02-252-1/+166
| | | | | | | | | Replace the somewhat perfunctory NetBSD tests with our own. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: bnovkov, kevans Differential Revision: https://reviews.freebsd.org/D55482
* system(3): Improve signal handlingDag-Erling Smørgrav2026-02-251-43/+73
| | | | | | | | | | | | | | | | Ignore SIGINT and SIGQUIT and block SIGCHLD, as POSIX requires. To deal with the concurrency problem described in POSIX, we keep track of the count of concurrent invocations. We ignore and block signals only when the counter was zero before we incremented it, and restore them only when the counter reaches zero after we decrement it. Note that this does not address the issue of thread cancellation. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: bnovkov, sef, kevans Differential Revision: https://reviews.freebsd.org/D55471
* mpool/mpool_get.c: Avoid clobbering 'errno' when handling 'pread' errorsBojan Novković2026-02-251-0/+4
| | | | | | | | | | | | | | POSIX.1-2024 states that the 'free' function "shall not modify errno if ptr is a null pointer or a pointer previously returned as if by malloc() and not yet deallocated". However this is a fairly recent addition and non-compliant allocators might still clobber 'errno', causing 'mpool_get' to return the wrong error code. Fix this by saving and restoring 'errno' after calling 'free'. Sponsored by: Klara, Inc. Reviewed by: obiwac Differential Revision: https://reviews.freebsd.org/D55463 MFC after: 1 week
* libc: Roll {l,ll,imax}abs(3) manpages into just abs(3)Aymeric Wibo2026-02-219-216/+61
| | | | | | | | | | | | No need to have 4 separate manpages for these functions. Use opportunity to change parameter names in the source from j -> i to reflect the name used in POSIX. (The ISO C standard uses j but i is a better name anyway.) Reviewed by: des, rpokala Approved by: rpokala Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D55361
* libc: Roll {l,ll,imax}div(3) manpages into just div(3)Aymeric Wibo2026-02-215-242/+67
| | | | | | | | | No need to have 4 separate manpages for these functions. Reviewed by: ziaee, rpokala, des Approved by: rpokala, des Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D55360
* vmm: Start using exterrorMark Johnston2026-02-191-0/+1
| | | | | | | | | | | For now, just describe the error where an unprivileged user attempts to run a VM without DESTROY_ON_CLOSE semantics, i.e., monitor mode. Reviewed by: bnovkov MFC after: 2 months Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D54743
* libc: improve include usage for exterror sourcesKonstantin Belousov2026-02-181-0/+1
| | | | | | | | | | | Include sys/types.h by exterr.h, since size_t is used. Drop include of sys/exterr_cat.h, it is useless for the only prototype provided. Reviewed by: mckusick Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D55337
* libc: add man page for uexterr_gettext(3)Konstantin Belousov2026-02-182-0/+72
| | | | | | | Reviewed by: mckusick Sponsored by: The FreeBSD Foundation MFC after: 3 days Differential revision: https://reviews.freebsd.org/D55336
* libc: print extended errors from warn(3) and vwarn(3)Konstantin Belousov2026-02-171-2/+2
| | | | | | | Noted and reviewed by: mckusick Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D55327
* libc/arm: use __builtin_trap() instead of abort() in aeabi_unwind stubsRobert Clausecker2026-02-131-6/+6
| | | | | | | | | | This avoids a dependency on the abort symbol in libsys. PR: 292539 Reviewed by: mmel Approved by: markj (mentor) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D55255
* Summary: *.3: misc man page fixesRobert Clausecker2026-02-131-1/+1
| | | | | | Approved by: markj (mentor) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D55249
* libc: Improve {,l,ll,imax}div(3) manpagesAymeric Wibo2026-02-126-24/+28
| | | | | | | | | | Mainly rename numerator parameter of div(3) and ldiv(3) from num to numer, and explicitly specify what "numer", "denom", and "rem" mean in the manpages. MFC after: 3 days Obtained from: https://github.com/apple-oss-distributions/libc (partially) Sponsored by: Klara, Inc.
* libc: Remove leftover commentsAymeric Wibo2026-02-123-4/+0
| | | | | | | These comments refer to a comment in div.c which doesn't exist anymore. Fixes: 7c7299df76e2 ("libc: Remove support for pre-C99 C standards") Sponsored by: Klara, Inc.
* lib/libc/net/sockatmark.3: fix groff mdoc warningKonstantin Belousov2026-02-121-1/+1
| | | | | | PR: 293072 Sponsored by: The FreeBSD Foundation MFC after: 3 days
* STACKALIGN: Reimplement in terms of __align_downJohn Baldwin2026-02-062-2/+4
| | | | | | | | | | This changes STACKALIGN to be type-preserving when operating on pointers. Reviewed by: brooks, kib Effort: CHERI upstreaming Sponsored by: AFRL, DARPA Differential Revision: https://reviews.freebsd.org/D54920
* libc/aarch64: Add memset for a 64 byte dc zvaAndrew Turner2026-02-033-1/+20
| | | | | | | | | | | | | | | | On arm64 we can use the "dc zva" instruction to zero memory. The CPU tells software if the instruction is implemented, and if so the size and alignment it will use. When the size is 64-bytes the Arm Optimized Routines implementation of memset can use dc zva to zero memory, and has a build flag to skip checking. Use this flag to build a version of memset that will be used when this assumption is true. Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D54776
* libc/aarch64: Split out the MOPS functionsAndrew Turner2026-02-033-3/+14
| | | | | | | | | This allows static binaries to only include the functions they reference. Reviewed by: imp Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D54775
* libc/aarch64: Add a Makefile.inc dependencyAndrew Turner2026-02-031-2/+2
| | | | | | | | | If we update Makefile.inc it may be to change the contents of these files. Reviewed by: imp Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D54774
* libc/tests: Clean up *dir() testsDag-Erling Smørgrav2026-02-031-15/+13
| | | | | | | | | Mainly, avoid reusing the name of one of the functions we should be testing (but aren't) for local variables. Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D55054
* rpc: correct resultproc_t's typeBrooks Davis2026-02-021-3/+5
| | | | | | | | | | | | It takes exactly three arguments of known type. Tweak the types of various resultproc_t functions to match the type (mostly added const to struct pointers) allowing us to drop casts. Effort: CHERI upstreaming Reviewed by: vangyzen, glebius Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D54941
* clnt_broadcast(3): fix eachresult argument typeBrooks Davis2026-02-021-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | The `eachresult` argument is documented to take a function pointer of type: bool_t (*)(caddr_t, struct sockaddr_in *) It was declared to take a resultproc_t which has historically been declared to be: bool_t (*resultproc_t)(caddr_t, ...); This overlapped well enough for currently supported ABIs where variadic arguments are passed in registers, but this declaration is misaligned with the documentation (resultproc_t takes three arguments) and will be fixed in a followup commit. Fix the type to be non-variadic, matching callbacks, and define a convenience type of as most callbacks take something other than a char * as their first argument and need to be cast. Effort: CHERI upstreaming Reviewed by: ngie, glebius, jhb Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D54940
* clnt_broadcast(3): don't free function pointersBrooks Davis2026-02-021-25/+10
| | | | | | | | | | | | | | | | | Replace use of thr_getspecific/thr_setspecific to stash the function pointer we're smuggling between clnt_broadcast and rpc_wrap_bcast with a simple thread local variable. Clear it after use so the reference doesn't linger. In the relatively unlikely event clnt_broadcast was called from threads that exited prior to program termination, the previous code called free on a function pointer, which is undefined and might corrupted allocator state. Effort: CHERI upstreaming Reviewed by: glebius, jhb Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D54939
* libc: Fix missing includeDag-Erling Smørgrav2026-02-021-0/+1
| | | | | | | Although not needed on FreeBSD due to namespace pollution, we should technically #include <stddef.h> to secure a definition of NULL. Fixes: 5074d5c9845e ("libc: Improve POSIX conformance of dirfd()")
* libc: Improve POSIX conformance of dirfd()Dag-Erling Smørgrav2026-02-022-1/+18
| | | | | | | | | | | | POSIX states that dirfd() should set errno to EINVAL and return -1 if dirp does not refer to a valid directory stream. Our interpretation is that this applies if dirp is null or the file descriptor associated with it is negative. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D55025
* libc: Clean up *dir() codeDag-Erling Smørgrav2026-02-029-49/+43
| | | | | | | | | Fix style nits (mostly whitespace issues) and clean up the manual page. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D55024
* bcmp(3): update manpage to following the Posix StandardPouria Mousavizadeh Tehrani2026-02-021-1/+9
| | | | | | Reviewed by: glebius Approved by: glebius (mentor) Differential Revision: https://reviews.freebsd.org/D52980
* libc/resolv: Switch default to loopback addressDag-Erling Smørgrav2026-01-311-41/+26
| | | | | | | | | | | | | | | | | If no resolver configuration was found, we would fall back to INADDR_ANY and IN6ADDR_ANY. This made sense when it was first written thirty or forty years ago but not today, especially since connecting to INADDR_ANY or IN6ADDR_ANY is no longer supported. Switch to the loopback address and simplify the code. Note that (as the pre-existing comment in the code states) running without a resolver configuration is not really supported. Still, if we're going to have a hardcoded fallback, it might as well work. PR: 291790 MFC after: 1 week Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55011
* posix_spawn: use rfork_thread on all archesKonstantin Belousov2026-01-281-21/+18
| | | | | | | | | Do not allocate or switch to the custom stack on non-x86. Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54898
* libc: Don't use uninitialised string for getnetbyaddr[_r](0) DNS lookupJessica Clarke2026-01-271-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | If net is all-zero, the loop to extract all leading non-zero octets will iterate zero times and leave nn with the value 4, which the following switch statement to initialise qbuf does not handle. As a result, _dns_getnetbyaddr will look up the PTR record for this uninitialised string, which will leak the pre-existing contents of that stack memory to the DNS resolver and, if remote and not otherwise protected, network. Note that _dns_getnetbyaddr is only used if nsswitch.conf is configured to enable the "dns" source for the "networks" database, which is not the default configuration in FreeBSD. For glibc this same bug, in code also derived from BIND's, was issued CVE-2026-0915. This commit adopts the same behaviour as glibc's fix, which is to regard a net of 0 as being for 0.0.0.0. Apparently NetBSD will return NS_UNAVAIL instead, which may or may not make more sense, but in general glibc compatibility tends to cause less friction when there's not a good reason to avoid it. Reviewed by: markj (secteam) Fixes: 1363f04ce1b8 ("get* rework and new bind code") MFC after: 1 day Security: Same bug as glibc's CVE-2026-0915
* btree/bt_seq.c: Fix two NULL pointer dereferencesBojan Novković2026-01-271-4/+4
| | | | | | | | | | | | | | | | This change fixes two NULL pointer dereferences caused by the __bt_first function. The first was caused by returning 0 (i.e., RET_SUCCESS) when a key was not found, causing the caller to dereference an uninitalized or NULL pointer. The second one was caused by an if statment clobbering a local variable with a function call result that might be NULL. Reported by: clang-tidy Sponsored by: Klara, Inc. Reviewed by: markj Obtained from: https://github.com/apple-oss-distributions/libc (partially) Differential Revision: https://reviews.freebsd.org/D54905
* btree/bt_split.c: Fix a misaligned if statementBojan Novković2026-01-271-1/+1
| | | | Sponsored by: Klara, Inc.
* libc: document posix_spawnattr_{get,set}procdescp_np(3)Konstantin Belousov2026-01-263-0/+98
| | | | | | | Reviewed by: asomers Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54899
* METALOG: Order keyword entriesJose Luis Duran2026-01-261-3/+3
| | | | | | | | | | | To facilitate comparison with mtree -C generated output, keep the keywords ordered. No functional change intended. Reviewed by: imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D54872
* posix_spawnattr_getexecfd_np.3: add closing .FcKonstantin Belousov2026-01-261-0/+1
| | | | | | Fixes: 9bf69c37f43e96292e97e41bf942d7aca4101362 Sponsored by: The FreeBSD Foundation MFC after: 1 week
* libc: add posix_spawnattr_{get,set}procdescp_npKonstantin Belousov2026-01-262-5/+51
| | | | | | | Reviewed by: asomers Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54879
* libc: document posix_spawnattr_getexecfd_np(3)Konstantin Belousov2026-01-253-0/+90
| | | | | | | Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54862