aboutsummaryrefslogtreecommitdiff
path: root/lib/libc
Commit message (Collapse)AuthorAgeFilesLines
...
* kern: Make dup3() support O_CLOFORKRicardo Branco2025-07-061-4/+5
| | | | | | Reviewed by: kib MFC after: 1 month Pull Request: https://github.com/freebsd/freebsd-src/pull/1698
* libc: Add inotify supportMark Johnston2025-07-043-0/+52
| | | | | | | | | | inotify_init() and inotify_init1() are implemented using __specialfd(2). inotify_add_watch() is implemented in terms of inotify_add_watch_at(2). Reviewed by: kib MFC after: 3 months Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D50315
* opendir: Simplify is_unionstack().Dag-Erling Smørgrav2025-07-021-9/+7
| | | | | | Sponsored by: Klara, Inc. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D51118
* fts: Add test cases for unreadable directories.Dag-Erling Smørgrav2025-07-024-72/+180
| | | | | | Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D51098
* fts: Clarify what FTS_DNR is used for.Dag-Erling Smørgrav2025-07-021-1/+7
| | | | | | Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D51097
* scandir: Code cleanup.Dag-Erling Smørgrav2025-06-261-11/+13
| | | | | | Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D51050
* scandir: Propagate errors from readdir().Dag-Erling Smørgrav2025-06-263-3/+104
| | | | | | | | | | | | | | Currently, if `readdir()` fails, `scandir()` simply returns a partial result (or a null result if it fails before any entries were selected). There is no way within the current API design to return both a partial result and an error indicator, so err on the side of caution: if an error occurs, discard any partial result and return the error instead. MFC after: 1 week Reported by: Maxim Suhanov <dfirblog@gmail.com> Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D51046
* csu: C standard requires errno on main() entryKonstantin Belousov2025-06-241-0/+9
| | | | | | | | | Reported by: Greg Becker <greg.becker@klarasystems.com> Reviewed by: emaste, kevans, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Also see: https://reviews.freebsd.org/D50998 Differential revision: https://reviews.freebsd.org/D50997
* libc: Rename fscandir{,_b}() to fdscandir{,_b}().Dag-Erling Smørgrav2025-06-236-32/+40
| | | | | | | | | | | | | This seems to fit the pattern better (e.g. fdopendir()). I've added weak references to ease the transition, but since it's only been a few days, we can remove them (and the ObsoleteFiles entries for the manual pages) before we branch stable/15. Fixes: deeebfdecab5 Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D50980
* glob: Delete trailing whitespace in 'struct glob_limit' definitionBojan Novković2025-06-231-2/+2
| | | | Sponsored by: Klara, Inc.
* glob.3: Fix punctuation mistakesBojan Novković2025-06-231-3/+3
| | | | | Fixes: 1e0743f54d2d Sponsored by: Klara, Inc.
* glob: Improve callback tests.Dag-Erling Smørgrav2025-06-232-35/+63
| | | | | | | | | | | Most importantly, they need to run without privileges, since root is allowed to read a directory regardless of its permission bits. PR: 287694 Fixes: 4d7c31bca252 Sponsored by: Klara, Inc. Reviewed by: bnovkov Differential Revision: https://reviews.freebsd.org/D50965
* libc/rpc/svc_nl: plg a memory leakGleb Smirnoff2025-06-201-1/+2
| | | | CID: 1591126
* scandir: Fix behavior when no entries match.Dag-Erling Smørgrav2025-06-203-3/+30
| | | | | | | | | | | | In the previous commit, I removed the initial initialization of the `names` array, not realizing that `scandir()` is expected to return a non-null (but empty) array of entries if no entries matched. Restore the historical behavior, document it, and add a test. Fixes: deeebfdecab5 Sponsored by: Klara, Inc. Reviewed by: kevans, allanjude, markj Differential Revision: https://reviews.freebsd.org/D50949
* libc: Add fscandir(), fscandir_b(), scandirat_b().Dag-Erling Smørgrav2025-06-207-42/+397
| | | | | | | | | While here, clean up scandir() a bit and improve the documentation. MFC after: never Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D50935
* exec(3): add missing execvpe(3) to MLINKSSergey A. Osokin2025-06-181-1/+2
| | | | Reviewed by: glebius
* manuals: Align our tree with upstream C23 macroAlexander Ziaee2025-06-122-2/+2
| | | | | | | Switch all instances of the -isoC-2024 macro to -isoC-2023 selected by upstream. Keep -isoC-2024 defined, but deprecated, for backwards compat. MFC after: 3 days (I will resolve merge conflicts with cdefs)
* include: ssp: fortify <signal.h>Ricardo Branco2025-06-114-1/+331
| | | | | | | | sig2str(3) Reviewed by: imp, kib, des, jilles Pull Request: https://github.com/freebsd/freebsd-src/pull/1696 Closes: https://github.com/freebsd/freebsd-src/pull/1696
* Add tests for sig2str() / str2sig()Ricardo Branco2025-06-112-0/+214
| | | | | Reviewed by: imp, kib, des, jilles Pull Request: https://github.com/freebsd/freebsd-src/pull/1696
* Add the POSIX sig2str(3) & str2sig(3) callsRicardo Branco2025-06-114-2/+171
| | | | | | Signed-off-by: Ricardo Branco <rbranco@suse.de> Reviewed by: imp, kib, des, jilles Pull Request: https://github.com/freebsd/freebsd-src/pull/1696
* Add POSIX NSIG_MAX & _SC_NSIGRicardo Branco2025-06-111-0/+2
| | | | | | | Signed-off-by: Ricardo Branco <rbranco@suse.de> Reviewed by: imp, kib Pull Request: https://github.com/freebsd/freebsd-src/pull/1710 Closes: https://github.com/freebsd/freebsd-src/pull/1710
* closefrom: always use close_range(2)Brooks Davis2025-06-061-9/+1
| | | | | | | | close_range(2) was added prior to 13.0. There is no need to support a new userspace on such an old kernel. Reviewed by: kevans, imp Differential Revision: https://reviews.freebsd.org/D50730
* C runtime: add kernel version guards on exterrctlBrooks Davis2025-06-041-2/+6
| | | | | | | | | | | | This allows userspace to run on a (somewhat) out of date kernel. Avoid a __FreeBSD_version bump and use the bump from a02180cf60a6 which has occured since exterrctl was added. Reviewed by: kevans Fixes: b9c8a07d4dd9 ("C runtime: enable extended error reporting from kernel") Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D50687
* libc: Fix glob.c build with GCCJessica Clarke2025-06-031-1/+2
| | | | | | | | | | We don't expose the dummy struct pointer in the header file, so gl_errblk is just a void * when lacking compiler support for blocks and we need to cast to the former for CALL_BLOCK to work. If blocks support is present this should be a redundant cast to the type that gl_errblk already is. Fixes: 1e0743f54d2d ("glob: Add blocks support")
* 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.
* glob2_test: Add tests for error callback functions and blocksBojan Novković2025-06-023-2/+112
| | | | | | | | | This change adds tests that check basic callback functionality for blocks and function pointers. The tests also make sure that GLOB_ERR overrides the callback's return value. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D50486
* glob: Add blocks supportBojan Novković2025-06-024-24/+114
| | | | | | | | | | This change introduces the `glob_b` function which takes a block instead of a function pointer. Relnotes: yes Sponsored by: Klara, Inc. Inspired by: https://github.com/apple-oss-distributions/Libc Differential Revision: https://reviews.freebsd.org/D50485
* Provide user interface to retrieve reported extended errorsKonstantin Belousov2025-05-316-0/+64
| | | | | | | Reviewed by: brooks Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D50483
* sysconf(3): add _SC_UEXTERR_LEN, the max length of the extended error stringKonstantin Belousov2025-05-311-0/+3
| | | | | | | Reviewed by: brooks Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D50483
* C runtime: enable extended error reporting from kernelKonstantin Belousov2025-05-312-0/+16
| | | | | | | Reviewed by: brooks Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D50483
* libc, libthr: Ditch MD __pthread_distribute_static_tls helpersJessica Clarke2025-05-298-316/+12
| | | | | | | | | | | | | | | | | | _libc_get_static_tls_base() is just _tcb_get() followed by adding (for Variant I) or subtracting (for Variant II) the offset, so just inline that as the implementation (like we do in rtld-elf) rather than having another copy (or equivalent) of _tcb_get()'s assembly. _get_static_tls_base() doesn't even have any MD assembly as it's reading thr->tcb, the only difference is whether to add or subtract, so again just inline that. Whilst here add some missing blank lines to comply with style(9) for elf_utils.c's includes, and use a pointer type rather than uintptr_t to reduce the need to cast, as is done in rtld-elf. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D50592
* Revert "Mark several getaddrinfo tests as XFAIL"Enji Cooper2025-05-281-6/+0
| | | | | | This change was unreviewed and should not have been committed to :main. This reverts commit 9b37d84c87e69dabc69d818aa4d2fea718bd8b74.
* Mark several getaddrinfo tests as XFAILEnji Cooper2025-05-281-0/+6
| | | | | | | | | | | | | | | | | These tests were recently enabled on main and have failed consistently since they were enabled. - lib.libc.net.getaddrinfo.getaddrinfo.basic - lib.libc.net.getaddrinfo.getaddrinfo.nofamily - lib.libc.net.getaddrinfo.getaddrinfo_test.basic - lib.libc.net.getaddrinfo.getaddrinfo_test.empty_servname - lib.libc.net.getaddrinfo.getaddrinfo_test.sock_raw Mark them as expected failures so they no longer count as failures in Jenkins CI. PR: 285826 MFC with: 5313457780, 0b773a94ab
* libc/riscv: Fix initial exec TLS mode for dynamically loaded shared objectsJessica Clarke2025-05-281-1/+3
| | | | | | | | | | | | | | | | | | | | | | | The offset here is relative to the TCB, not whatever the thread pointer points to, so as with powerpc and powerpc64 we need to account for that. However, rather than using hard-coded offsets as they did, due to predating machine/tls.h, we can just re-use _tcb_get(). Note that if libthr is used, and its initialiser has been called, it will take a different path that uses _get_static_tls_base, which works just fine on riscv (adding the offset to thr->tcb). This only affects programs that aren't linked against libthr (or that are but manage to dlopen before the initialiser is called, if that's even possible). In future this code should be made MI by just reusing _tcb_get() and checking the TLS variant (since the offset here is positive even for variant II, where it should be subtracted), but this is a targeted fix that makes it clear what's changing. Reviewed by: kib Fixes: 5d00c5a6571c ("Fix initial exec TLS mode for dynamically loaded shared objects.") MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D50564
* libc: set close-on-exec for temp socket used to detect IPv6 supportKonstantin Belousov2025-05-241-1/+1
| | | | | | | Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D50509
* Remove vestiges of keyserv(8)Lexi Winter2025-05-231-2/+1
| | | | | | | | This daemon has been removed; also remove things which reference it. Reviewed by: manu, des, emaste Approved by: des (mentor) Differential Revision: https://reviews.freebsd.org/D50441
* SPDX: Tag BSD-4.3TAHOEAlexander Ziaee2025-05-211-0/+2
| | | | | | | | | | | | | | TIL traceroute.8 has one of the oldest liceses, predating BSD-4-Clause! The SPDX tag was not even on Wikipedia. These are all the files I could find in the tree with git grep that look like the license reported on the SPDX website, including one that was misfiled. Ref: https://spdx.org/licenses/BSD-4.3TAHOE.html MFC after: 3 days Reported by: brooks Reviewed by: brooks, carlavilla, imp, ivy Approved by: carlavilla (mentor) Differential Revision: https://reviews.freebsd.org/D50362
* libc: Give __thr_jtable protected visibilityMark Johnston2025-05-191-0/+1
| | | | | | | | | | | | | | | | | | | | This function pointer table is overwritten by libthr when it's loaded. libc's pthread stubs are implemented by looking up an entry in this table and invoking the function pointer contained in the entry. pthread calls are fairly expensive even when libthr is not loaded: each call involves indirection through the PLT, then through the GOT to look up __thr_jtable, then the function pointer itself. We can however eliminate one level of indirection by disallowing preemption of the __thr_jtable symbol, and since the existence table is an internal implementation detail, disabling preemption is unlikely to break anything. This gives a modest improvement in some microbenchmarks which call libc's pthread stubs. Reviewed by: kib MFC after: 1 month Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D50354
* libc: Improve scanfloat test.Dag-Erling Smørgrav2025-05-161-68/+68
|
* link_addr: be more strict about address formatsLexi Winter2025-05-153-81/+303
| | | | | | | | | | | | | | | | | | | | | | instead of accepting any character as a delimiter, only accept ':', '.' and '-', and only permit a single delimiter in an address. this prevents accepting bizarre addresses like: ifconfig epair2a link 10.1.2.200/28 ... which is particularly problematic on an INET6-only system, in which case ifconfig defaults to the 'link' family, meaning that: ifconfig epair2a 10.1.2.200/28 ... changes the Ethernet address of the interface. bump __FreeBSD_version so link_addr() consumers can detect the change. Reviewed by: kp, des Approved by: des (mentor) Differential Revision: https://reviews.freebsd.org/D49936
* fts: Fix misindented line.Dag-Erling Smørgrav2025-05-081-2/+2
| | | | | Fixes: da2025a0e894 Sponsored by: Klara, Inc.
* fts: Rename fts_options to fts_options_testDag-Erling Smørgrav2025-05-082-1/+1
| | | | Sponsored by: Klara, Inc.
* fts: Give the blocks test a description.Dag-Erling Smørgrav2025-05-081-1/+6
| | | | | | Sponsored by: Klara, Inc. Reviewed by: kevans, imp Differential Revision: https://reviews.freebsd.org/D50235
* fts: Add tests for most FTS options.Dag-Erling Smørgrav2025-05-082-0/+455
| | | | | | Sponsored by: Klara, Inc. Reviewed by: kevans, imp Differential Revision: https://reviews.freebsd.org/D50234
* fts: Add FTS_COMFOLLOWDIR and FTS_NOSTAT_TYPE.Dag-Erling Smørgrav2025-05-082-8/+59
| | | | | | | | MFC after: never Relnotes: yes Sponsored by: Klara, Inc. Reviewed by: kevans, imp Differential Revision: https://reviews.freebsd.org/D50233
* fts: Drop obsolete conditionals.Dag-Erling Smørgrav2025-05-081-14/+2
| | | | | | | | We've never not had DT_DIR or FTS_WHITEOUT. Sponsored by: Klara, Inc. Reviewed by: kevans, imp Differential Revision: https://reviews.freebsd.org/D50218
* tls: Introduce struct dtv and struct dtv_slotJessica Clarke2025-05-071-16/+18
| | | | | | | | | | | | | | Rather than treating the DTV as a raw array of uintptr_t, use proper struct types and gain the benefit of having different types for different members. In particular, the module slots now have real pointer types so less casting is generally needed. Note that, whilst struct dtv_slot may seem a little unnecessary, this will help downstream in CheriBSD where we wish to be able to easily alter the layout of a module's slot, which this helps abstract. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D50231
* libc: Use struct tcb * rather than uintptr_t ** for the tcbJessica Clarke2025-05-071-12/+12
| | | | | | | | This lets us access via named struct members rather than magic hard-coded indices. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D50228
* libc: Use variables more consistent with Variant I for Variant II TLSJessica Clarke2025-05-071-22/+18
| | | | | | | | | | | | | | | | | | | | | | Firstly, the first argument to __libc_allocate_tls is the old TCB (versus oldtls, which has less of a clear meaning), so rename it to oldtcb like Variant I. Secondly, segbase and oldsegbase are oriented towards what ends up in the segment registers, but that's not the main concern here, and those don't convey what they actually point to. Instead, rename segbase to tcb and change it to a uintptr_t **, and remove oldsegbase as it's always equal to oldtcb, again both matching Variant I. Finally, rename tls to tls_block, and add back a (different) tls variable rather than constantly recomputing tcb - libc_tls_static_space, again both matching Variant I. Whilst here, similarly fix the oldtls argument to be oldtcb in the PIC __libc_allocate_tls stub. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D50227
* libc: Consistently use uintptr_t for TLS implementationJessica Clarke2025-05-071-22/+23
| | | | | | | | | | | | | | | | | | | | Elf_Addr is the format of addresses in the ELF file with the current ABI's default class. This is normally the same as the format of an address at run time, though technically exceptions do exist outside of FreeBSD's currently-supported architectures (for example, IA-64's LP64 supports both ELFCLASS32 and ELFCLASS64 file formats; LP64 vs ILP32 is an orthogonal EF_IA_64_ABI64 flag). On traditional architectures, including all currently-supported FreeBSD architectures, addresses and pointers are synonymous, but on CHERI they are not, as pointers are capabilities that contain metadata alongside the address. In the cases here, the quantities are run-time pointers, not addresses (and definitely not ELF file addresses), so we should use pointer-ish types. Note that we already use uintptr_t in struct tcb (both Variant I and Variant II) but still use Elf_Addr in various places here. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D50225