aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
Commit message (Collapse)AuthorAgeFilesLines
* jemalloc: don't error out on initializer warning in gccWarner Losh11 days1-0/+2
| | | | | | | | gcc doesn't like something about the initializer that comes with jemalloc. Since it's vendor code, make this warning not an error for -Werror purposes. Sponsored by: Netflix
* jemalloc: Merge from jemalloc 5.3.0 vendor branchWarner Losh13 days8-128/+648
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This brings in a merge from jemalloc 5.3.0. It's almost fully scripted, except: Three conflicts resolved by hand: include/jemalloc/internal/test_hooks.h Use the new name src/extent.c Use the new code src/jemalloc.c Use the new code since je_realloc has moved The script is recorded in FREEBSD-upgrade. The old script did svn commands that were basically a rebase of our changes. This update has a series of diff reduction changes before this. Note: I'd planned on fixing the above three conflicts with commits, but ran out of time when I did this work in January. I got discouraged when jemalloc was EOL'd and didn't pick this back up. I did the above by hand to get this into FreeBSD 15.0 This work is a repeat of the work by Minsoo Choo who did all these changes and created a pull request. Given the importance of jemalloc, I audited these changes by redoing them in this series of commits (and with the script that was checked in). I did this to confince myself and anybody else in doubt that there was no supply chain attack. The diffs between this series of commits and Minsoo's work are minor (though the version skew makes adds some noise). Interested parties can independent audit each step, I hope. I've listed Minsoo as a co-author since without his pull request to test again, this wouldn't have been possible. Thanks to brooks@ for help with getting the jemalloc 3 ABI compat symbols right. Co-authored-by: Minsoo Choo <minsoochoo0122@proton.me> Pull Request: https://github.com/freebsd/freebsd-src/pull/1337 Sponsored by: Netflix
* libc: Drop incorrect qsort optimizationDag-Erling Smørgrav13 days1-13/+0
| | | | | | | | | | | | | | | | As pointed out in the PR and the article linked below, the switch to insertion sort in the BSD qsort code is based on a misunderstanding of Knuth's TAOCP and is actually a pessimization. As demonstrated by the added test, it is trivially easy to construct pathological input which results in quadratic runtime. Without that misguided optimization, the same input runs in nearly linearithmic time. https://www.raygard.net/2022/02/26/Re-engineering-a-qsort-part-3 PR: 287089 MFC after: 1 week Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D51907
* getopt_long.3: Use "optstring" consistentlyEd Maste2025-04-291-2/+2
| | | | | | | The SYNOPSIS uses "optstring" as the argument name but the body text used a mixture of "optstr" and "optstring." Sponsored by: The FreeBSD Foundation
* alloca.3: move to share/man/man3Brooks Davis2025-04-292-86/+1
| | | | | | | The alloca() API is a compiler builtin and not generally part of libc. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D50055
* libc: Add getenv_r() function.Dag-Erling Smørgrav2025-04-273-3/+75
| | | | | | | | | | This is a calque of the NetBSD function of the same name. MFC after: never Relontes: yes Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D49979
* issetugid() is a system call and belongs in section 2 (not 3).Jens Schweikhardt2025-04-171-2/+2
|
* libc: allow __cxa_atexit handlers to be added during __cxa_finalizeAurélien Croc de Suray2025-04-051-25/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | science/dlib-cpp reveals an interesting scenario that works fine on other platforms but not on FreeBSD; notably, it ends up creating a new global object from some destructor which is called during __cxa_finalize. This breaks when libdlib is dlopen()ed and then subsequently dlclose()ed, as we never end up invoking the created object's dtor until program exit when the shlib is already unmapped. Fix it by noting when we're in the middle of __cxa_finalize for a dso, and then restarting the search if __cxa_atexit() was called in the middle somewhere. We wait until we've processed the initial set before starting over and processing the newly added handlers as if it were a complete set of handlers added during runtime. The alternative is calling them as they're added to maintain a LIFO in terms of total ordering, but in theory a constructor could add another global object that also needs to be destroyed, and that object needs to be destroyed after the one that constructed it to avoid creating unexpected lifetime issues. This manifests in the pdlib PHP extension for dlib crashing, see [0]. [0] https://github.com/goodspb/pdlib/issues/39 PR: 285870 Reviewed by: kevans (also supplied commit message) MFC after: 1 week
* libc: use __sys___realpathat directly in realpathBrooks Davis2025-02-191-9/+3
| | | | | | | | | | | | We don't need to use an interposable symbol for this purpose and it's simpler to just call the syscall in libsys. This resolves a bug where we were incorrectly using __realpathat in libc not libsys. While here, drop support for running on a FreeBSD 12 kernel and simplify includes. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D49048
* jemalloc: Move generated files into lib/libc treeWarner Losh2024-12-139-1/+1738
| | | | | | | | | | | | | | | Make it easire to update jemalloc by moving the FreeBSD specific files and the generated files into lib/libc. This allows us to regenerate them more easily, and emphasizes a bit that we may have to regenerate stuff from upstream. This is necessary to also unthin the import from the vendor branch as well (which will be needed to simplify the imports in the future since we are trying to use contrib/jemalloc for two different things). No functional change. Sponsored by: Netflix
* jemalloc: Move generated jemalloc.3 into lib/libc treeWarner Losh2024-12-132-4/+2563
| | | | | | | | | | | The more generated things that are in contrib/jemalloc tree, the more chances for interference goes way up. So, move this file into our lib/libc tree. I didn't add a 'generated file' line / info, but this is funky enough I don't think we need that. We do add things to the man page, and that should be tracked in the contrib/jemalloc tree to allow better importing experience. Sponsored by: Netflix
* libc: indicate existing functions that are POSIX 2024Ed Maste2024-11-152-1/+6
| | | | | | Reviewed by: brooks, imp Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D47581
* Revise qsort(3 reflect POSIX.1-2024 update.Xin LI2024-10-251-23/+24
| | | | | | Reviewed by: emaste, trasz MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D47262
* manuals: Fix "unusual .Xr" warnings with a scriptGraham Percival2024-10-151-1/+1
| | | | | | | | | | | | | These were reported by `mandoc -T lint ...` as warnings: - unusual Xr order - unusual Xr punctuation Fixes made by script in https://github.com/Tarsnap/freebsd-doc-scripts Signed-off-by: Graham Percival <gperciva@tarsnap.com> Reviewed by: mhorne, Alexander Ziaee <concussious.bugzilla@runbox.com> Sponsored by: Tarsnap Backup Inc. Pull Request: https://github.com/freebsd/freebsd-src/pull/1464
* jemalloc: set LG_VADDR to 64 on amd64Konstantin Belousov2024-09-261-0/+3
| | | | | | | | | | | and allow to revert it back to 48 with WITHOUT_JEMALLOC_LG_VADDR_WIDE build option. Reviewed by: andrew, emaste Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D46686
* realpath(3): Minor style issues.Dag-Erling Smørgrav2024-09-181-9/+10
| | | | | | Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D46695
* jemalloc: don't expose 3.0 compat symbolsBrooks Davis2024-08-221-10/+0
| | | | | | | | | | | | Don't provide default linkage for jemalloc 3.0 compatability symbols. We stopped declaring these interfaces with the introduction of jemalloc 4.0 prior to FreeBSD 11.0. Any code using them would have had to declare them manually so stop declaring them and export the symbols directly for compatability. Arguably they should be x86 only as they were never declared on other Tier-1 architectures. Reviewed by: imp, kib Differential Revision: https://reviews.freebsd.org/D46407
* exit(3): clarify how to obtain full exit status of the exited processKonstantin Belousov2024-07-291-0/+14
| | | | | Sponsored by: The FreeBSD Foundation MFC after: 3 days
* exit(3): make it thread-safeKonstantin Belousov2024-07-292-1/+39
| | | | | | | | | | | It was explained by Rich Felker <dalias@libc.org> on libc-coord. See https://austingroupbugs.net/view.php?id=1845. Reviewed by: imp, markj Tested by: antoine (exp-run) Sponsored by: The FreeBSD Foundation MFC after: 1 month Differential revision: https://reviews.freebsd.org/D46108
* Remove residual blank line at start of MakefileWarner Losh2024-07-151-1/+0
| | | | | | | This is a residual of the $FreeBSD$ removal. MFC After: 3 days (though I'll just run the command on the branches) Sponsored by: Netflix
* include: ssp: fortify <stdlib.h>Kyle Evans2024-07-131-1/+2
| | | | | | | | | | | The immediately obvious and attractive targets from <stdlib.h> are arc4random_buf(3) and realpath(3) -- scraping the header didn't reveal much else of interest. Reviewed by: markj Sponsored by: Klara, Inc. Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D45681
* __cxa_thread_call_dtors(3): fix dtor pointer validity checkKonstantin Belousov2024-05-031-1/+1
| | | | | | | | | | | | | | When checking for the destructor pointer belonging to some still loaded dso, do not limit the possible dso to the one instantiated the destructor. For instance, dso could set up the dtr pointer to a function from libcxx. PR: 278701 Reported by: vd Reviewed by: dim, emaste, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D45074
* libc: Remove support for pre-C99 C standardsMinsoo Choo2024-04-124-47/+4
| | | | | Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D43254
* exit.3: add the comma after an empty spacerilysh2024-04-101-1/+1
| | | | | | | | | | exit(3) man page shows __cxa_atexit(3,) instead of __cxa_atexit(3), in a particular section. It seems the comma gets inside the parenthesis and with an extra space, it can be viewed as expected. Signed-off-by: rilysh <nightquick@proton.me> Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1006
* bsearch_b: fix compilation with gccBrooks Davis2024-03-061-1/+2
| | | | | Reported by: rscheff Differential Revision: https://reviews.freebsd.org/D44256
* libc: actually build bsearch_bBrooks Davis2024-03-051-1/+1
| | | | | | | Fixes: 46cdc14062f7 Add support for some block functions ... Reviewed by: theraven Differential Revision: https://reviews.freebsd.org/D44189
* system(3): fix typo santized -> sanitizedSteve Kargl2024-01-121-2/+2
| | | | | PR: 276262 Reviewed by: imp
* strfmon.c: Use the restrict keyword directlyKonstantin Belousov2023-12-101-3/+3
| | | | | | | | libc sources assume C99 or even C11 compiler already, unlike headers. There is no reason to obfuscate the basic C constructs. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* strfmon: style fixesJose Luis Duran2023-12-101-98/+99
| | | | | | | Check style(9) with checkstyle9.pl and clang-format. No functional change intended. MFC after: 1 week
* strfmon: Silence scan-build warningJose Luis Duran2023-12-091-1/+0
| | | | | | | The value stored to 'value' is never read. Reported by: Jenkins (scan-build) MFC after: 1 week
* strfmon.3: Cleanup example codeJose Luis Duran2023-12-091-3/+5
| | | | | | | | | - xlocale.h would have been required if using strfmon_l(). Here, setlocale() just requires locale.h. - ANSIfy function declaration. - Add a final return(). MFC after: 1 week
* lib: Automated cleanup of cdefs and other formattingWarner Losh2023-11-272-5/+0
| | | | | | | | | | | | | | | | Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
* lib: Remove ancient SCCS tags.Warner Losh2023-11-2759-147/+0
| | | | | | | | Remove ancient SCCS tags from the tree, automated scripting, with two minor fixup to keep things compiling. All the common forms in the tree were removed with a perl script. Sponsored by: Netflix
* libc: Remove empty comments in Symbol.mapBrooks Davis2023-11-152-6/+0
| | | | | | | These were left over from $FreeBSD$ removal. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D42612
* libc: Purge unneeded cdefs.hWarner Losh2023-11-0154-54/+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: Fix missing or misspelled MLINKS.Dag-Erling Smørgrav2023-10-181-13/+37
| | | | Differential Revision: https://reviews.freebsd.org/D42192
* memory(3): Mention more functions.Dag-Erling Smørgrav2023-10-181-14/+43
| | | | Differential Revision: https://reviews.freebsd.org/D42191
* ptsname.3: accommodate upcoming POSIX Issue 8 ptsname_rEd Maste2023-10-141-2/+15
| | | | | | | | | | | | | | POSIX has accepted a proposal[1] to add glibc-compatible ptsname_r. It indicates an error by returning the error number, rather than returning -1 and setting errno. Update RETURN VALUES in ptsname_r's man page now to encourage folks to test that the return value != 0 rather than == -1. [1] https://www.austingroupbugs.net/bug_view_page.php?bug_id=508 Reported by: Collin Funk Reviewed by: kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D42204
* libc: Rewrite quick_exit() and at_quick_exit() using C11 atomics.Dag-Erling Smørgrav2023-09-261-24/+16
| | | | | | | | | | | | | Compiler memory barriers do not prevent the CPU from executing the code out of order. Switch to C11 atomics. This also lets us get rid of the mutex; instead, loop until the compare_exchange succeeds. While here, change the return value of at_quick_exit() on failure to the more traditional -1, matching atexit(). Sponsored by: Klara, Inc. Reviewed by: Olivier Certner, kevans, kib Differential Revision: https://reviews.freebsd.org/D41936
* libc: add LIBC_MALLOC optionBrooks Davis2023-09-011-1/+1
| | | | | | | | | | This will enable alternative mallocs to be included in the tree and selected by setting LIBC_MALLOC. As there is only one today (jemalloc) this option does nothing, but we expect to add other implementations in the future. This will also reduce diffs to CheriBSD. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D41660
* libc: Document support for binary integers.Dag-Erling Smørgrav2023-08-282-2/+6
| | | | | Reviewed by: debdrup, emaste Differential Revision: https://reviews.freebsd.org/D41522
* libc: Implement N2630.Dag-Erling Smørgrav2023-08-286-2/+45
| | | | | | | This adds formatted input/output of binary integer numbers to the printf(), scanf(), and strtol() families, including their wide-character counterparts. Reviewed by: imp, emaste Differential Revision: https://reviews.freebsd.org/D41511
* libc: regoranize malloc buildBrooks Davis2023-08-164-3/+4
| | | | | | | | | | | | | Create a stdlib/malloc to hold the definition of the malloc interface (e.g., the Symbol.map file) and make jemalloc a subdirectory. This will make it easier to integrate alternative allocators such as snmalloc while making it clear that the current jemalloc symbols are the FreeBSD API/ABI (for better or worse). Suggested by: jrtc27 Reviewed by: jrtc27, emaste Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D41457
* jemalloc: drop unused .PATHBrooks Davis2023-08-161-3/+0
| | | | | | | | | All jemalloc sources are in contrib so don't look for them in the jemalloc subdirectory. Reviewed by: jrtc27, emaste Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D41481
* libc: include malloc via stdlib/Makefile.incBrooks Davis2023-08-161-0/+2
| | | | | | | | | | There's a hierarchy here and we should use it. Improves: cbeacb7c46f3a3650e5dbefa9a1a18bc9943a8cc Reviewed by: jrtc27, jhb, emaste Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D41456
* Remove $FreeBSD$: one-line nroff patternWarner Losh2023-08-1629-29/+0
| | | | Remove /^\.\\"\s*\$FreeBSD\$$\n/
* Remove $FreeBSD$: two-line nroff patternWarner Losh2023-08-1614-28/+0
| | | | Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-162-2/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-1658-116/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Remove $FreeBSD$: one-line .h patternWarner Losh2023-08-163-3/+0
| | | | Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/