summaryrefslogtreecommitdiff
path: root/src/lib/libc (follow)
Commit message (Collapse)AuthorAgeFilesLines
* This thread-aware profiling support diff comes from Yuichiro NAITO.deraadt2025-07-161-1/+5
| | | | | | | | | | | | At runtime, profiling data is stored per-thread. Upon termination, the per-thread profiling data pools are merged into a into a single record, which is then written out (using the new kernel-assisted system). I think the original gmon merging parts may have come from or been inspired by someone at NetBSD. This has been delayed because there were concerns about adding a TLS object which would require other library cranks, so this rides all the major cranks today. ok kettenis tb claudio sthen etc etc etc
* add libc specific __cmtx and __rcmtx locks for internal use.dlg2025-07-121-1/+55
| | | | | | | | | | | | | | | | | | | | | | | __cmtx provides mutual exclusion using futex(2) and cas on archs that support it, or _spinlocks on the rest. __rcmtx is a recursive mutex built on top of __cmtx, so it inherits the use of futex and cas/spinlock from __cmtx. until now the options we had for locking between threads in libc were spinlocks or pthread mutexes. spinlocks use sched_yield to relax if they have to spin on a contended lock, which we are trying to minimise the use of as much as possible. pthread_mutex is relatively large in memory and offers a lot of complicated features which are unecessary for most of libc. the non cas/futex version of pthread_mutexes currently relies on __thrsleep and __thrwakeup, which we also want to deprecate. having a small futex based lock available everywhere will help us move away from overuse of spinlocks, and deprecate __thrsleep and __thrwakeup. ok kettenis@ jca@ provided his eyes too.
* make the argument to ether_ntoa const.dlg2025-06-292-5/+5
| | | | | | | | this drives me nuts when i want to print something out of what's already const. casting it works, but feels gross. ok guenther@ tb@ deraadt@ enh says this is already in bionic/glibc/musl
* The mdoc(7) .Ft macro does not need quoting of its arguments, but aboutschwarze2025-06-138-35/+35
| | | | | | | 10% of our manual pages using this macro employed useless quoting anyway. Remove these quotes such that they do not incite fear, uncertainty, and doubt in developers who happen to look at these pages. jmc@ and tb@ agree with the direction.
* <uvm/uvmexp.h> is clearly only for VM_MALLOC_CONF, but <sys/sysctl.h> takesderaadt2025-06-121-2/+1
| | | | care of doing that include.
* Revert 1.144 of lib/libc/stdlib/malloc.3. It was changed by accidentyasuoka2025-06-041-12/+3
| | | | by my previous commit.
* Again. Make exit(), fclose(), fflush(), and freopen() comply withyasuoka2025-06-032-9/+17
| | | | | | | | | | | | | POSIX-2008 requirements for setting the underlying file position when flushing read-mode streams, and make an fseek()-after-fflush() not change the underlying file position. This commit fixes some minor problems of the previous. previous diff from guenther Much testing, review, assistence form tb@ ok tb@ millert@ for the previous ok asou
* Delete bad advice about abusing malloc_options = "X" as a productionschwarze2025-05-271-12/+3
| | | | | | | | | | | | | | | | feature to terminate the program when out of memory. Application code should always handle failure of library functions properly. So if you want your program to terminate, write something like | p = malloc(...); | if (p == NULL) | err(1, NULL); and don't abuse malloc_options. Direction suggested by otto@ after anton@ pointed out that this very old text still used an outdated data type for malloc_options and potentially failed to define its value at compile time. OK otto@
* explain more precisely how to initialize malloc_options;schwarze2025-05-241-4/+12
| | | | OK deraadt@
* When commons were deprecated, noone noticed that malloc_options in staticderaadt2025-05-232-7/+10
| | | | | | | | binaries had become unlinkable. Change the libc definition to weak to solve that, and to "const char * const" so that noone will try to set it late. It must be stable before the first malloc() call, which could be before main()... discussion with otto, kettenis, tedu
* When describing v3 crypt, be specific as to which machine was simulated.jsg2025-01-091-3/+3
| | | | feedback jmc@ ok deraadt@ schwarze@
* appeared in 4.3BSD before 4.3BSD-Tahoejsg2024-12-1111-33/+33
| | | | ok millert@ schwarze@
* remove unneeded semicolons; checked by millert@jsg2024-09-201-2/+2
|
* typo in comment; Effectivly -> Effectively; ok gilles@op2024-09-031-2/+2
|
* wild white spacederaadt2024-09-031-2/+2
|
* Revert commitid KcCtsA53F9UQzc0t:guenther2024-08-301-5/+6
| | | | | | | | | | | | "Make exit(), fclose(), fflush(), and freopen() comply with POSIX-2008 requirements for setting the underlying file position when flushing read-mode streams, and make an fseek()-after-fflush() not change the underlying file position." Something isn't correct about it and it breaks at least initdb from the postgresql-server package. discussed with tb@, semarie@, and deraadt@
* Use struct __sFILE instead of FILE in thread locking callbackguenther2024-08-181-5/+6
| | | | | | | declarations to reduce <stdio.h> pollution. Declare __isthreaded in thread_private.h where it's really needed. ok deraadt@
* Make exit(), fclose(), fflush(), and freopen() comply with POSIX-2008guenther2024-08-121-6/+5
| | | | | | | | | requirements for setting the underlying file position when flushing read-mode streams, and make an fseek()-after-fflush() not change the underlying file position. Much testing, review, and assistance from tb@ ok tb@ millert@
* wcslcpy() and wcslcat() are in POSIX-2024. Update #include visibilityguenther2024-08-071-4/+11
| | | | | | and manpages and add restrict qualifiers. ok millert@
* A dozen interfaces in <endian.h> were standardized in POSIX-2024 as expectedguenther2024-08-031-6/+4
|
* The improbable occurred: strlcpy(3) and strlcat(3) are in POSIX-2024.guenther2024-08-032-7/+16
| | | | | | | memmem(3) was also added. Update #include visibility and manpages and add restrict qualifiers. "never thought I'd see this day" millert@
* mkostemp(3) and reallocarray(3) are in POSIX-2024:guenther2024-08-031-2/+6
| | | | | | adjust #include visibility and update the reallocarray(3) manpage ok millert@
* Add wcsnlen(3), wcslen(3) with a max len argumentjca2024-07-143-7/+84
| | | | Missing function hit by fcambus@ some time ago. ok millert@
* Zap warning against __findenv usage, it is not exported by libcjca2024-07-101-3/+1
| | | | | The comment probably made sense before guenther restricted the symbols exported by libc in 2015.
* strmode takes a mode_t, not an int; prompted by Collin Funk.otto2024-06-231-4/+2
| | | | ok kettenis@ deraadt@ tb@
* drop htonl(), htons(), ntohl(), ntohs() MD functions from libcnaddy2024-04-155-50/+21
| | | | | | | | | | | Userland code compiled in a normal fashion picks up the htonl(), htons(), ntohl(), ntohs() macros implemented by endian.h. The functions in libc are effectively unused. Keep the MI functions in case something looks for the symbols in libc or plays games with #undef, but change them to wrap the implementation from endian.h. tweaks suggested by claudio@, ok miod@
* In _malloc_init(), round up the region being mprotected RW to the mallocmiod2024-03-301-11/+11
| | | | | | | | | | page size, rather than relying upon mprotect to round up to the actual mmu page size. This repairs malloc operation on systems where the malloc page size (1 << _MAX_PAGE_SHIFT) is larger than the mmu page size. ok otto@
* POSIX defines inet_ntoa, not inet_aton.bentley2024-03-061-3/+3
| | | | ok deraadt@ jmc@
* Add mkdtemps(3), like mkdtemp(3) but with a suffix.millert2024-03-012-8/+32
| | | | OK deraadt@ tb@
* make login.conf(5) and crypt_newhash(3) and the underlying codederaadt2024-01-221-2/+2
| | | | | | | | consistant regarding bcrypt,a instead of blowfish,a. "blowfish" is a historical alias which we don't need to document as firmly as "bcrypt". report about difficult manual page discovery from ataraxia937 ok millert
* Make our mktemp(3) callback-driven and split into multiple files.millert2024-01-195-130/+195
| | | | | | Previously, calling any of the mktemp(3) family would pull in lstat(2), open(2) and mkdir(2). Now, only the necessary system calls will be reachable from the binary. OK deraadt@ guenther@
* Move mktemp.c to stdlib where it belongs.millert2024-01-193-4/+582
| | | | OK deraadt@
* A small cleanup of malloc_bytes(), getting rid of a goto and a tinyotto2023-12-191-29/+27
| | | | bit of optimization; ok tb@ asou@
* zap trailing whitespacetb2023-12-041-2/+2
|
* Save backtraces to show in leak dump. Depth of backtrace set byotto2023-12-042-87/+184
| | | | | malloc option D (aka 1), 2, 3 or 4. No performance impact if not used. ok asou@
* KNF plus fixed a few signed vs unsigned compares (that we actuallyotto2023-11-041-22/+33
| | | | not real problems)
* Enable ISO C11 APIs when building libc, even with an older compiler.millert2023-10-291-1/+9
| | | | | Otherwise, the prototypes for timespec_get() and aligned_alloc() are not visible. OK guenther@
* A few micro-optimizations; ok asou@otto2023-10-261-20/+15
|
* correct Va in previous;jmc2023-10-221-2/+3
|
* When option D is active, store callers for all chunks; this avoidsotto2023-10-222-86/+178
| | | | | | | the 0x0 call sites for leak reports. Also display more info on detected write of free chunks: print the info about where the chunk was allocated, and for the preceding chunk as well. ok asou@
* Print waring message when not allocated memory in putleakinfo().asou2023-09-091-2/+20
| | | | ok otto.
* Document that small allocations are initially junked with 0xdf nowotto2023-07-011-3/+3
|
* Recommit "Allow to ask for deeper callers for leak reports usingotto2023-06-302-12/+71
| | | | | | | malloc options" Now only enabled for platforms where it's know to work and written as a inline functions instead of a macro.
* Revert previous, not all platforms allow compilingotto2023-06-232-37/+4
| | | | __builtin_return_address(a) with a != 0.
* Allow to ask for deeper callers for leak reports using malloc options.otto2023-06-222-4/+37
| | | | ok deraadt@
* Add portable version and m88k-specific version lb() function, becauseaoyama2023-06-071-1/+21
| | | | | | unfortunately gcc3 does not have __builtin_clz(). ok miod@ otto@
* More thorough write-afetr-free checks.otto2023-06-042-19/+33
| | | | | | | | | | | | | | | | | | | On free, chunks (the pieces of a pages used for smaller allocations) are junked and then validated after they leave the delayed free list. So after free, a chunk always contains junk bytes. This means that if we start with the right contents for a new page of chunks, we can *validate* instead of *write* junk bytes when (re)-using a chunk. With this, we can detect write-after-free when a chunk is recycled, not justy when a chunk is in the delayed free list. We do a little bit more work on initial allocation of a page of chunks and when re-using (as we validate now even on junk level 1). Also: some extra consistency checks for recallocaray(3) and fixes in error messages to make them more consistent, with man page bits. Plus regress additions.
* Remove malloc interposition, a workaround that was once needed for emacsotto2023-05-271-7/+7
| | | | ok guenther@
* Add PROTO_NORMAL() declarations for the remaining syscalls, to avoidguenther2023-05-181-4/+1
| | | | | | | | future, inadvertant PLT entries. Move the __getcwd and __realpath declarations to hidden/{stdlib,unistd}.h to consolidate and remove duplication. ok tb@ otto@ deraadt@
* As mmap(2) is no longer a LOCK syscall, do away with the extraotto2023-05-101-23/+1
| | | | | unlock-lock dance it serves no real purpose any more. Confirmed by a small performance increase in tests. ok @tb