aboutsummaryrefslogtreecommitdiff
path: root/lib/libc
Commit message (Collapse)AuthorAgeFilesLines
...
* Regen for the fork and exit/wait exterror category additionKonstantin Belousov2026-01-251-0/+2
|
* lib/libsys, lib/libc: export pdwaitKonstantin Belousov2026-01-253-0/+25
| | | | | | | | | | Make pdwait(2) cancellable, same as all other wait*(2) syscalls wrappers. Reviewed by: asomers, markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54592
* xdr_string: don't leak strings with xdr_freeBrooks Davis2026-01-231-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | Historically (and in a small amount of older software such as OpenAFS), developers would attempt to free XDR strings with xdr_free((xdrproc_t)xdr_string, &string) This resulted in xdr_free calling xdr_string with only two intentional arguments and whatever was left in the third argument register. If the register held a sufficently small number, xdr_string would return FALSE and not free the string (no one checks the return values). Software should instead free strings with: xdr_free((xdrproc_t)xdr_wrapstring, &string) Because buggy software exists in the wild, act as though xdr_wrapstring was used in the XDR_FREE case and plug these leaks. Reviewed by: kib MFC after: 3 days Effort: CHERI upstreaming Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D54825
* rpc/xdr.h: make xdrproc_t always take two argumentsBrooks Davis2026-01-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The type of xdrproc_t is clearly defined in the comments as a function with two arguments, an XDR * and a void * (sometimes spelled caddr_t). It was initialy defined as: typedef bool_t (*xdrproc_t)(); At some point people started giving it a non-empty argument list. Unfortunatly, there has been widespread disagreement about how arguments are passed. There seems to have been a widespread view that it should be allowed to pass three argument function pointer to xdrproc_t. Most notable is xdr_string which takes a maximum length parameter. This lead to all sorts of prototypes (all of which have been present in the FreeBSD source tree): FreeBSD userspace (nominally from tirpc, but seemingly local): typedef bool_t (*xdrproc_t)(XDR *, ...); FreeBSD kernel, glibc: typedef bool_t (*xdrproc_t)(XDR *, void *, ...); rcp/xdr.h with _KERNEL defined (not used?): typedef bool_t (*xdrproc_t)(XDR *, void *, u_int); gssrpc (in krb5) and Linux kernel: typedef bool_t (*xdrproc_t)(XDR *, void *); For two argument functions on current ABIs, these all equivalent as these arguments are passed in registers regardless of decleration and definition, but we end up with two problems: - xdr_free((xdrproc_t)xdr_string, ...) calls xdr_string with no third argument and (at least on FreeBSD) may fail to free memory if the string is shorter than the value lying around in the third argument register. There are no instance of this in tree, but I found some with Debian code search, in particular in OpenAFS. - Under CheriABI, variadic arguments are passed in a separate, bounded array so theses prototypes aren't equilvalent to the non-variadic calling convention of the functions. The reality is that that xdr_string should not be cast to xdrproc_t and xdr_wrapstring should be used instead so we do not need to support this case. Instances of the former behavior are now extremely rare. With this change we bring FreeBSD in line with gssrpc and the Linux Kernel. Warnings about casts should now be correct and should be fixed. Bump __FreeBSD_version as some software required adaptation if it is declaring functions to cast to xdrproc_t. Update OpenZFS's workaround of this historic mess accordingly. Effort: CHERI upstreaming Sponsored by: Innovate UK Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D54824
* jail(3): fix common usage after mac.label supportKyle Evans2026-01-202-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Nobody else's mac.conf(5) has any entries for jails, so they get a trivial ENOENT and we fail before we can fetch any jail parameters. Most notably, this breaks `jls -s` / `jls -n` if you do not have any loaded policy that applies jail labels. Add an entry that works for everyone, and hardcode that as an ENOENT fallback in libjail to provide a smoother transition. This is probably not harmful to leave in long-term, since mac.conf(5) will override it. This unearthed one additional issue, in that mac_get_prison() in the MAC framework handled the no-label-policies bit wrong. We don't want to break jail utilities enumerating jail parameters automatically, so we must ingest the label in all cases -- we can still use it as a small optimization to avoid trying to copy out any label. We will break things if a non-optional element is specified in the copied in label, but that's expected. The APIs dedicated to jaildescs remain unphased, since they won't be used in the same way. Fixes: db3b39f063d9f05 ("libjail: extend struct handlers [...]") Fixes: bd55cbb50c58876 ("kern: add a mac.label jail parameter") Reported by: jlduran (on behalf of Jenkins) Reviewed by: jlduran Differential Revision: https://reviews.freebsd.org/D54786
* libc: drop NO_FP_LIBC supportXin LI2026-01-1710-75/+0
| | | | | | | | | | | NO_FP_LIBC was added in 2004 to save space by disabling FP support in *printf()/*scanf(). The size benefit is negligible on modern systems and conflicts with assumptions made by current base utilities. Remove the option and always build libc with floating-point support. Reported by: Oskar Holmlund <eovholmlund at gmail com> MFC after: 2 weeks
* tdestroy: don't visit one-child node twiceDoug Moore2026-01-161-34/+32
| | | | | | | | | Change tdestroy() to immediately free a node with no right child as soon as it is encountered. Currently, such nodes are visited twice before deletion. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D54699
* exterr: Regenerate exterr_cat_filenames.hMark Johnston2026-01-161-1/+1
|
* libc/stdlib: Port strtonumx() from IllumosHans Rosenfeld2026-01-154-23/+80
| | | | | | | | | | | Add strtonumx(), a companion to strtonum(3) that preserves its safety and error-reporting semantics while allowing the caller to specify a conversion base, similar to the strtol(3) family of functions. Reviewed by: emaste, kib, ziaee Obtained from: https://www.illumos.org/issues/15365 Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D54270
* swab: Correctly treat the data as misalignedJohn Baldwin2026-01-141-3/+10
| | | | | | | | | | | | | | | | | | | | | The __aligned attribute in the previous version applied to the location of the pointers, not the data the pointers pointed to. While this could be fixed by applying the attribute to a local typedef of uint16_t, just using memcpy() for the unaligned access is simpler and ISO C. This fixes the build on CHERI architectures which do not support misaligned pointers and were thus failing with: lib/libc/string/swab.c:12:18: error: alignment (1) of 'const uint16_t *' (aka 'const unsigned short *') is less than the required capability alignment (16) [-Werror,-Wcheri-capability-misuse] 12 | const uint16_t *f __aligned(1) = from; | Co-authored by: Jessica Clarke <jrtc27@FreeBSD.org> Fixes: 02ebbc781f08 ("swab: Fix implementation to support overlapping copies") Sponsored by: AFRL, DARPA Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D54399
* libc/aarch64: Use MOPS implementations of memcpy/memmove/memset where availbleSarah Walker2026-01-136-6/+139
| | | | | | Reviewed by: andrew Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D54560
* libc/csu: Pass HWCAP flags to ifunc resolver functionsSarah Walker2026-01-131-3/+28
| | | | | | | | | | Function arguments are based on Section 9.4.1 "GNU C Library IFUNC interface" from "System V ABI for the Arm 64-bit Architecture (AArch64)", 2025Q1. (https://github.com/ARM-software/abi-aa/releases/download/2025Q1/sysvabi64.pdf) Reviewed by: andrew Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D54599
* getopt(3): be more explicit about :: extensionSimon Wollwage2026-01-091-15/+34
| | | | | | | | | | | | Make it possible to search for literal two colons (::) and actually find something. Make the "x"/"x:"/"x::" examples more explicit and more visibile. Signed-off-by: Simon Wollwage <rootnode+freebsd@wollwage.com> Obtained from: NetBSD, nbuwe <uwe@stderr.spb.ru>, 856d5b6 PR: 291374 Reviewed by: imp, jlduran Pull Request: https://github.com/freebsd/freebsd-src/pull/1923
* lib: remove powerpcspeMinsoo Choo2026-01-0917-1244/+0
| | | | | | | Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me> Reviewed by: emaste Pull Request: https://github.com/freebsd/freebsd-src/pull/1914 (cherry picked from commit 907cf3e4378f9d114af41d05a59ef4a075d3efb0)
* libc/amd64: fix stpncpy.S againRobert Clausecker2026-01-041-6/+3
| | | | | | | | | | | | | | | | | | The previous fix introduced a regression on machines without the BMI1 instruction set extension. The TZCNT instruction used in this function behaves different on old machines when the source operand is zero, but the code was originally designed to never trigger this case. The bug fix caused this case to be possible, leading to a regression on sufficiently old hardware. Fix the code by messing with things such that the source operand is never zero. PR: 291720 Fixes: 66eb78377bf109af1d9e25626bf254b4369436ec Tested by: cy Approved by: markj (mentor) Differential Revision: https://reviews.freebsd.org/D54303
* tdestroy(3): add testsKonstantin Belousov2025-12-291-0/+65
| | | | | | | Reviewed by: alc, emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54365
* tdestroy(3) man pageKonstantin Belousov2025-12-292-3/+25
| | | | | | | Reviewed by: alc, emaste, ziaee Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54365
* libc: add glibc-compatible tdestroy(3)Konstantin Belousov2025-12-293-0/+70
| | | | | | | | | | | The function clears the whole tree. Relnotes: yes Reviewed by: alc, emaste Discussed with: dougm Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54365
* libc/stdlib/Makefile: one line for each source file nameKonstantin Belousov2025-12-291-13/+69
| | | | | | | Reviewed by: alc, emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54365
* man pages: provide some description for extended errorsKonstantin Belousov2025-12-291-0/+16
| | | | | | | | | , related functions, and the EXTERROR_VERBOSE environment variable. Reviewed by: emaste, mckusick Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54380
* exterr: in verbose mode, print the source file nameKonstantin Belousov2025-12-291-4/+17
| | | | | | | Reviewed by: emaste, mckusick Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54380
* Add automatically generated file libc/gen/exterr_cat_filenames.hKonstantin Belousov2025-12-291-0/+17
| | | | MFC after: 1 week
* exterror: Add EXTERROR_VERBOSE env variable to control verbosityKonstantin Belousov2025-12-291-5/+48
| | | | | | | | | | | | If the variable is set and the process is not suid, __uexterr_format(), used by err(3), prints errno/category/source line/pX always, not only when there is no kernel message provided. Requested by: mckusick Reviewed by: emaste, mckusick Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54380
* exterror: add support for the format specifiers in the extended error msgKonstantin Belousov2025-12-291-1/+2
| | | | | | | | | | Note that we trust kernel code to only request the printout of integer types, and use the 'j' modifier always. Reviewed by: emaste, mckusick Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54380
* libc/gen/err.c: remove 'extended error' herald from extended error outputKonstantin Belousov2025-12-291-1/+1
| | | | | | | Reviewed by: emaste, mckusick Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54380
* libc/amd64: Disable baseline version of stpncpy()Dag-Erling Smørgrav2025-12-161-0/+2
| | | | | | | | | This implementation appears to be broken on some CPUs. Disable it until the issue can be investigated and fixed. PR: 291720 Fixes: 66eb78377bf1 ("libc/amd64: fix overread conditions in stpncpy()") Fixes: 90253d49db09 ("lib/libc/amd64/string: add stpncpy scalar, baseline implementation")
* libc/test: fix typoRobert Clausecker2025-12-141-1/+1
| | | | | | | I misapplied ngie's recommended correction. Fixes: 123c086200491819595abc271d360e605288fd18 Differential Revision: https://reviews.freebsd.org/D54169
* libc/amd64: fix overread conditions in stpncpy()Robert Clausecker2025-12-141-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Due to incorrect unit test design, two overread conditions went undetected in the amd64 baseline stpncpy() implementation. For buffers of 1--16 and 32 bytes that do not contain nul bytes and end exactly at a page boundary, the code would incorrectly read 16 bytes from the next page, possibly crossing into an unmapped page and crashing the program. If the next page was mapped, the code would then proceed with the expected behaviour of the stpncpy() function. Three changes were made to fix the bug: - an off-by-one error is fixed in the code deciding whether to enter the runt case or not, entering it for 0<n<=32 bytes instead of 0<n<32 bytes as it was before. - in the runt case, the logic to skip reading a second 16-byte chunk if the buffer ends in the first chunk was fixed to account for buffers that end at a 16-byte boundary but do not hold a nul byte. - in the runt case, the logic to transform the location of the end of the input buffer into a bit mask was fixed to allow the case of n==32, which was previously impossible due to the incorrect logic for entering said case. The performance impact should be minimal. PR: 291359 See also: D54169 Reported by: Collin Funk <collin.funk1@gmail.com> Reviewed by: getz Approved by: markj (mentor) MFC after: 1 week Fixes: 90253d49db09a9b1490c448d05314f3e4bbfa468 (D42519) Differential Revision: https://reviews.freebsd.org/D54170
* libc/tests/string: improve stpncpy() "bounds" unit testRobert Clausecker2025-12-141-16/+39
| | | | | | | | | | | | | | | | The test is extended the same way I previously extended the memccpy() test to fix what is probably the same kind of bug. PR: 291359 Reported by: Collin Funk <collin.funk1@gmail.com> Reviewed by: ngie Approved by: markj (mentor) Fixes: 6fa9e7d8737548ef93c573387ce62402c368d486 (D42519) See also: 61ed5748e4e9c7397fcb2638b442f46ac5c9e7c5 (D46051) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D54169 lib/libc/tests/string/stpncpy_test.c: apply ngie's fixes
* get*ent: be consistant about _ALIGN(p) - pBrooks Davis2025-12-107-13/+21
| | | | | | | | | | | | | Add an nscache specific inline function to calculate the misalignment rather than adding and subtracting _ALIGN(p) and p which can take the buffer far out of bound (undefined behavior in C and unsupported on CHERI). Reviewed by: kib Effort: CHERI upstreaming Obtained from: CheriBSD Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D53945
* libc/string: add strdupa(3) and strndupa(3)Konstantin Belousov2025-12-082-2/+36
| | | | | | | Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54066
* libc/string: put source files list one item per lineKonstantin Belousov2025-12-081-23/+121
| | | | | | | Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54066
* libc/limits_test: add no-op testcase to satisfy kyuaSiva Mahadevan2025-12-051-1/+4
| | | | | | | | | | | | | This test suite is purely tested with compile-time assertions, so it needs a dummy runtime test to ensure that kyua reports the file as passing. Pull Request: https://github.com/freebsd/freebsd-src/pull/1915 Sponsored by: The FreeBSD Foundation Reviewed by: fuz Approved by: markj (mentor) MFC after: 1 month Signed-off-by: Siva Mahadevan <me@svmhdvn.name>
* libc/stdc_has_single_bit.c: fix gcc warning (-Wparentheses)Robert Clausecker2025-12-031-5/+5
| | | | | | | | | | | | gcc14 is concerned that the operator precedence between - and & might be confusing. Throw in some redundant parentheses to make it shut up. The LLVM build was fine before this change. Reported by: Martin Filla <freebsd@sysctl.cz> Approved by: markj (mentor) MFC after: 1 month Fixes: 6296500a85c8474e3ff3fe2f8e4a9d56dd0acd64 Differential Revision: https://reviews.freebsd.org/D54057
* libc: Fix TESTSDIR for new stdbit testsJessica Clarke2025-12-011-0/+2
| | | | | | | | | | Otherwise the directory created by etc/mtree/BSD.tests.dist, which is where these belong, and referred to by the generated Kyuafile for /usr/tests/lib/libc (via stdbit's existence in TESTS_SUBDIRS), ends up empty with no Kyuafile, which is an error for kyua. Reported by: kp Fixes: 2fb8cbc6ef1b ("libc/tests: add stdbit test framework and unit tests")
* man/man3: add cross references to stdbit(3)Robert Clausecker2025-11-301-0/+2
| | | | | | | | Add cross references to relevant stdbit man pages Approved by: markj (mentor) MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D53661
* libc/tests: add stdbit test framework and unit testsRobert Clausecker2025-11-3018-0/+511
| | | | | | | | | | | | This adds unit tests for all 70 functions in <stdbit.h>. I'm sorry for the test framework, but it makes it so I don't have to write 70 unit tests by hand. Reviewed by: adrian, des Approved by: markj (mentor) MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D53660
* libc/stdbit: add man pages for stdbit functionsRobert Clausecker2025-11-3015-0/+1283
| | | | | | | | | | | | This adds man pages for each group of functions in <stdbit.h>. The man pages have cross references to one-another. Cross references from external man pages to these will be added in a later commit. Reviewed by: pauamma@gundo.com, kib Approved by: markj (mentor) MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D53659
* libc: implement C23 <stdbit.h> functionsRobert Clausecker2025-11-3017-0/+847
| | | | | | | | | | | | | | This new header complies with ISO/IEC 9899:2024 (C23). Contrary to glibc, we do not provide inline definitions in <stdbit.h> as we expect our system compiler to soon recognise these as builtins anyway. Relnotes: yes MFC after: 1 month Reviewed by: adrian Approved by: markj (mentor) Differential Revision: https://reviews.freebsd.org/D53657
* libc/tests: add test for *_MAX, *_MIN, and *_WIDTHRobert Clausecker2025-11-302-0/+102
| | | | | | | | | | This file checks the correctness of the various _MAX, _MIN, and _WIDTH macros defined for the libc types. It assumes that none of the types have padding bits. Approved by: markj (mentor) MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D53831
* libc: remove ARMv5/6 from man pageMinsoo Choo2025-11-291-4/+1
| | | | | | Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me> Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1903
* strfmon: Fix negative sign handling for C localeJose Luis Duran2025-11-262-4/+4
| | | | | | | | | | | | | | | | | | | If the locale's positive_sign and negative_sign values would both be returned by localeconv() as empty strings, strfmon() shall behave as if the negative_sign value was the string "-". This occurs with the C locale. The implementation previously assigned "0" to sign_posn (parentheses around the entire string); now it assigns it to "1" (sign before the string) when it is undefined (CHAR_MAX). Austin Group Defect 1199[1] is applied, changing the requirements for the '+' and '(' flags. [1]: https://www.austingroupbugs.net/view.php?id=1199 Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D53913
* strfmon: EINVAL if the '+' flag and both signs are emptyJose Luis Duran2025-11-263-6/+18
| | | | | | | | | | | | | | | | According to the Open Group Base Specifications Issue 8[1], strfmon(3) should return EINVAL when the '+' flag was included in a conversion specification and the locale's positive_sign and negative_sign values would both be returned by localeconv(3) as empty strings. Austin Group Defect 1199[2] is applied, adding the [EINVAL] error. [1]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/strfmon.html [2]: https://www.austingroupbugs.net/view.php?id=1199 Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D53912
* strfmon: Add tests for Austin Group Defect 1199Jose Luis Duran2025-11-261-23/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Add tests for The Open Group Base Specifications Issue 8[1], Austin Group Defect 1199[2]. Items marked with XXX represent an invalid output. These items will be fixed in subsequent commits. Notice that an existing test is now considered invalid. Our locale definitions do not include int_p_sep_by_space nor int_n_sep_by_space[3]. Those will be addressed in a subsequent commit. However, the CLDR project defines them as "0", which causes the output to appear as "USD123.45". If our locale definitions were to set the international {n,p}_sep_by_space to "1", the output would display as the expected "USD 123.45". While here, use the SPDX license identifier and add my name to the file. [1]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/strfmon.html [2]: https://www.austingroupbugs.net/view.php?id=1199 [3]: https://unicode-org.atlassian.net/browse/CLDR-237 Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D53911
* libc: Simplify __get_locale()Dag-Erling Smørgrav2025-11-261-4/+2
| | | | | | | MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: fuz Differential Revision: https://reviews.freebsd.org/D53908
* strfmon: Fix typo s/poistion/position/Jose Luis Duran2025-11-261-1/+1
| | | | MFC after: 1 week
* jemalloc: apply freebsd changes to jemalloc 5.3.0 man pageMinsoo Choo2025-11-251-1/+31
| | | | | Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1890
* jemalloc: import jemalloc 5.3.0 man pageMinsoo Choo2025-11-251-52/+180
| | | | | Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1890
* exit.3: Fix a typo in the manual pageGordon Bergling2025-11-191-1/+1
| | | | | | - s/avaliable/available/ MFC after: 3 days
* mpool(3): Fix a typo in statistical messageGordon Bergling2025-11-191-1/+1
| | | | | | - s/cacheing/caching/ MFC after: 5 days