summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib
Commit message (Collapse)AuthorAgeFilesLines
* Don't forget to free() currency_symbol and asciivalue when multipleru2008-04-191-0/+4
| | | | | | | | conversion specifiers for them are present. Submitted by: Maxim Dounin <mdounin@mdounin.ru> Obtained from: NetBSD (partially) MFC after: 3 days
* Better strfmon(3) conversion specifiers sanity checking.ru2008-04-191-1/+8
| | | | | | | | | | There were no checks for left and right precisions at all, and a check for field width had integer overflow bug. Reported by: Maksymilian Arciemowicz Security: http://securityreason.com/achievement_securityalert/53 Submitted by: Maxim Dounin <mdounin@mdounin.ru> MFC after: 3 days
* Use calloc() instaed of zeroing memory ourselves.delphij2008-04-131-2/+1
|
* Remove stale #include <machine/atomic.h>, which as needed by lazyjasone2008-03-071-4/+4
| | | | deallocation.
* Replace the use of warnx() with direct output to stderr using _write().scf2008-02-281-12/+36
| | | | | | | | | | | | | | | | This reduces the size of a statically-linked binary by approximately 100KB in a trivial "return (0)" test application. readelf -S was used to verify that the .text section was reduced and that using strlen() saved a few more bytes over using sizeof(). Since the section of code is only called when environ is corrupt (program bug), I went with fewer bytes over fewer cycles. I made minor edits to the submitted patch to make the output resemble warnx(). Submitted by: kib bz Approved by: wes (mentor) MFC after: 5 days
* Fix a race condition in arena_ralloc() for shrinking in-place largejasone2008-02-171-25/+41
| | | | | | | | reallocation, when junk filling is enabled. Junk filling must occur prior to shrinking, since any deallocated trailing pages are immediately available for use by other threads. Reported by: Mats Palmgren <mats.palmgren@bredband.net>
* Remove support for lazy deallocation. Benchmarks across a wide range ofjasone2008-02-172-221/+4
| | | | | | | | allocation patterns, number of CPUs, and MALLOC_OPTIONS settings indicate that lazy deallocation has the potential to worsen throughput dramatically. Performance degradation occurs when multiple threads try to clear the lazy free cache simultaneously. Various experiments to avoid this bottleneck failed to completely solve this problem, while adding yet more complexity.
* Fix a bug in lazy deallocation that was introduced whenjasone2008-02-081-7/+10
| | | | | | | | arena_dalloc_lazy_hard() was split out of arena_dalloc_lazy() in revision 1.162. Reduce thundering herd problems in lazy deallocation by randomly varying how many probes a thread does before taking the slow path.
* Clean up manipulation of chunk page map elements to remove some tenuousjasone2008-02-081-362/+357
| | | | | | | | | | | assumptions about whether bits are set at various times. This makes adding other flags safe. Reorganize functions in order to inline i{m,c,p,s,re}alloc(). This allows the entire fast-path call chains for malloc() and free() to be inlined. [1] Suggested by: [1] Stuart Parmenter <stuart@mozilla.com>
* Track dirty unused pages so that they can be purged if they exceed ajasone2008-02-062-679/+973
| | | | | | | | | | | | | | | | | | | | | | | | | threshold, according to the 'F' MALLOC_OPTIONS flag. This obsoletes the 'H' flag. Try to realloc() large objects in place. This substantially speeds up incremental large reallocations in the common case. Fix a bug in arena_ralloc() that caused relocation of sub-page objects even if the old and new sizes were in the same size class. Maintain trees of runs and simplify the per-chunk page map. This allows logarithmic-time searching for sufficiently large runs in arena_run_alloc(), whereas the previous algorithm required linear time in the worst case. Break various large functions into smaller sub-functions, and inline only the functions that are in the fast path for small object allocation/deallocation. Remove an unnecessary check in base_pages_alloc_mmap(). Avoid integer division in choose_arena() for the NO_TLS case on single-CPU systems.
* Remove some now-unused macros.jhb2008-01-151-3/+1
| | | | MFC after: 1 week
* Put back the openpty(3) and ptsname(3) fixes but don't disable ptsname(3)jhb2008-01-151-46/+31
| | | | | on pts(4) devices this time. This fixes the issues while leaving pts(4) enabled on HEAD.
* Back out last commit, since it accidentally broke pts.cperciva2008-01-151-37/+48
| | | | | The security fix will be re-committed soon, hopefully without breaking anything.
* Fix issues which allow snooping on ptys. [08:01]cperciva2008-01-141-48/+37
| | | | | | | Fix an off-by-one error in inet_network(3). [08:02] Security: FreeBSD-SA-08:01.pty Security: FreeBSD-SA-08:02.libc
* Changing 'r' to a size_t in the previous commit turned quicksortdas2008-01-141-4/+5
| | | | | | | into slowsort for some sequences because different parts of the code used 'r' to store two different things, one of which was signed. Clean things up by splitting 'r' into two variables, and use a more meaningful name.
* Use size_t to avoid overflow when sorting arrays larger than 2 GB.das2008-01-132-2/+3
| | | | | PR: 111085 MFC after: 2 weeks
* Enable both sbrk(2)- and mmap(2)-based memory acquisition methods byjasone2008-01-032-19/+20
| | | | | | | | | default. This has the disadvantage of rendering the datasize resource limit irrelevant, but without this change, legitimate uses of more memory than will fit in the data segment are thwarted by default. Fix chunk_alloc_mmap() to work correctly if initial mapping is not chunk-aligned and mapping extension fails.
* Fix a major chunk-related memory leak in chunk_dealloc_dss_record(). [1]jasone2007-12-311-65/+56
| | | | | | | | Clean up DSS-related locking and protect all pertinent variables with dss_mtx (remove dss_chunks_mtx). This fixes race conditions that could cause chunk leaks. Reported by: [1] kris
* Fix a bug related to sbrk() calls that could cause address space leaks.jasone2007-12-311-186/+268
| | | | | | | | | | | | | | | | | | | | | | | | | This is a long-standing bug, but until recent changes it was difficult to trigger, and even then its impact was non-catastrophic, with the exception of revision 1.157. Optimize chunk_alloc_mmap() to avoid the need for unmapping pages in the common case. Thanks go to Kris Kennaway for a patch that inspired this change. Do not maintain a record of previously mmap'ed chunk address ranges. The original intent was to avoid the extra system call overhead in chunk_alloc_mmap(), which is no longer a concern. This also allows some simplifications for the tree of unused DSS chunks. Introduce huge_mtx and dss_chunks_mtx to replace chunks_mtx. There was no compelling reason to use the same mutex for these disjoint purposes. Avoid memset() for huge allocations when possible. Maintain two trees instead of one for tracking unused DSS address ranges. This allows scalable allocation of multi-chunk huge objects in the DSS. Previously, multi-chunk huge allocation requests failed if the DSS could not be extended.
* Back out premature commit of previous version.jasone2007-12-281-183/+113
|
* Maintain two trees instead of one (old_chunks --> old_chunks_{ad,szad}) injasone2007-12-281-113/+183
| | | | | | | | | order to support re-use of multi-chunk unused regions within the DSS for huge allocations. This generalization is important to correct function when mmap-based allocation is disabled. Avoid zeroing re-used memory in the DSS unless it really needs to be zeroed.
* Release chunks_mtx for all paths through chunk_dealloc().jasone2007-12-281-1/+4
| | | | Reported by: kris
* Add the 'D' and 'M' run time options, and use them to control whetherjasone2007-12-272-315/+492
| | | | | | | | | | | | | | | | | | memory is acquired from the system via sbrk(2) and/or mmap(2). By default, use sbrk(2) only, in order to support traditional use of resource limits. Additionally, when both options are enabled, prefer the data segment to anonymous mappings, in order to coexist better with large file mappings in applications on 32-bit platforms. This change has the potential to increase memory fragmentation due to the linear nature of the data segment, but from a performance perspective this is mitigated by the use of madvise(2). [1] Add the ability to interpret integer prefixes in MALLOC_OPTIONS processing. For example, MALLOC_OPTIONS=lllllllll can now be specified as MALLOC_OPTIONS=9l. Reported by: [1] rwatson Design review: [1] alc, peter, rwatson
* Clean up some of the pts(4) vs pty(4) stuff in grantpt(3) and friends:jhb2007-12-211-22/+23
| | | | | | | | | | - Use PTY* for all pty(4) related constants. - Use PTMX* for all pts(4) related constants. - Consistently use _PATH_DEV PTMX rather than "/dev/ptmx". - Revert 1.7 and properly fix it by using the correct prefix string for pts(4) masters. MFC after: 3 days
* Use fixed point integer math instead of floating point math whenjasone2007-12-181-42/+47
| | | | | | | | | | calculating run sizes. Use of the floating point unit was a potential pessimization to context switching for applications that do not otherwise use floating point math. [1] Reformat cpp macro-related comments to improve consistency. Submitted by: das
* Refactor features a bit in order to make it possible to disable lazyjasone2007-12-171-52/+127
| | | | | | | | | deallocation and dynamic load balancing via the MALLOC_LAZY_FREE and MALLOC_BALANCE knobs. This is a non-functional change, since these features are still enabled when possible. Clean up a few things that more pedantic compiler settings would cause complaints over.
* Implement and document nan(), nanf(), and nanl(). This commitdas2007-12-161-4/+23
| | | | | | | adds two new directories in msun: ld80 and ld128. These are for long double functions specific to the 80-bit long double format used on x86-derived architectures, and the 128-bit format used on sparc64, respectively.
* Update posix_openpt(3) to handle 512 ptys. This was missed in the earlierjhb2007-12-131-2/+2
| | | | | | pty(4) changes. MFC after: 3 days
* Fix typo in the commentache2007-12-111-1/+1
|
* Only zero large allocations when necessary (for calloc()).jasone2007-11-281-1/+1
|
* Document the B and L MALLOC_OPTIONS.jasone2007-11-271-1/+26
|
* Implement dynamic load balancing of thread-->arena mapping, based on lockjasone2007-11-271-58/+297
| | | | | | | | | | | | | | | | | contention. The intent is to dynamically adjust to load imbalances, which can cause severe contention. Use pthread mutexes where possible instead of libc "spinlocks" (they aren't actually spin locks). Conceptually, this change is meant only to support the dynamic load balancing code by enabling the use of spin locks, but it has the added apparent benefit of substantially improving performance due to reduced context switches when there is moderate arena lock contention. Proper tuning parameter configuration for this change is a finicky business, and it is very much machine-dependent. One seemingly promising solution would be to run a tuning program during operating system installation that computes appropriate settings for load balancing. (The pthreads adaptive spin locks should probably be similarly tuned.)
* Implement lazy deallocation of small objects. For each arena, maintain ajasone2007-11-271-0/+218
| | | | | | | | | | | vector of slots for lazily freed objects. For each deallocation, before doing the hard work of locking the arena and deallocating, try several times to randomly insert the object into the vector using atomic operations. This approach is particularly effective at reducing contention for multi-threaded applications that use the producer-consumer model, wherein one producer thread allocates objects, then multiple consumer threads deallocate those objects.
* Avoid re-zeroing memory in calloc() when possible.jasone2007-11-271-143/+218
|
* Fix stats printing of the amount of memory currently consumed by hugejasone2007-11-271-36/+37
| | | | | | | | | | | allocations. [1] Fix calculation of the number of arenas when 'n' is specified via MALLOC_OPTIONS. Clean up various style inconsistencies. Obtained from: [1] NetBSD
* Remove out of date notes, the atoi code is thread-safe and async-canceldavidxu2007-10-191-4/+0
| | | | | | safe. Discussed with: desichen
* The precision for a string argument in a call to warnx() needs to be castscf2007-09-221-1/+2
| | | | | | | | | to an int to remove the warning from using a size_t variable on 64-bit platforms. Submitted by: Xin LI <delphij@FreeBSD.org> Approved by: wes Approved by: re (kensmith)
* Skip rebuilding environ in setenv() only upon reuse of an active variable;scf2007-09-151-2/+2
| | | | | | | | | | | inactive variables should cause a rebuild of environ, otherwise, exec()'d processes will be missing a variable in environ that has been unset then set. Submitted by: Taku Yamamoto <taku@tackymt.homeip.net> Reviewed by: ache Approved by: wes (mentor) Approved by: re (kensmith)
* Added environ-replacement detection. For programs that "clean" (i.e., su)scf2007-07-201-78/+163
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | or replace (i.e., zdump) the environment after a call to setenv(), putenv() or unsetenv() has been made, a few changes were made. - getenv() will return the value from the new environ array. - setenv() was split into two functions: __setenv() which is most of the previous setenv() without checks on the name and setenv() which contains the checks before calling __setenv(). - setenv(), putenv() and unsetenv() will unset all previous values and call __setenv() on all entries in the new environ array which in turn adds them to the end of the envVars array. Calling __setenv() instead of setenv() is done to avoid the temporary replacement of the '=' in a string with a NUL byte. Some strings may be read-only data. Added more regression checks for clearing the environment array. Replaced gettimeofday() with getrusage() in timing regression check for better accuracy. Fixed an off-by-one bug in __remove_putenv() in the use of memmove(). This went unnoticed due to the allocation of double the number of environ entries when building envVars. Fixed a few spelling mistakes in the comments. Reviewed by: ache Approved by: wes Approved by: re (kensmith)
* Significantly reduce the memory leak as noted in BUGS section forscf2007-07-045-259/+622
| | | | | | | | | | | | | | | | | | | | | | | | | | setenv(3) by tracking the size of the memory allocated instead of using strlen() on the current value. Convert all calls to POSIX from historic BSD API: - unsetenv returns an int. - putenv takes a char * instead of const char *. - putenv no longer makes a copy of the input string. - errno is set appropriately for POSIX. Exceptions involve bad environ variable and internal initialization code. These both set errno to EFAULT. Several patches to base utilities to handle the POSIX changes from Andrey Chernov's previous commit. A few I re-wrote to use setenv() instead of putenv(). New regression module for tools/regression/environ to test these functions. It also can be used to test the performance. Bump __FreeBSD_version to 700050 due to API change. PR: kern/99826 Approved by: wes Approved by: re (kensmith)
* Add information about the implications of using mmap(2) instead of sbrk(2).jasone2007-06-151-1/+19
| | | | Submitted by: bmah, jhb
* Fix junk/zero filling for realloc(). Junk filling was missing in one case,jasone2007-06-151-36/+48
| | | | | | and zero filling was broken in a way that could cause memory corruption. Update comments.
* Backout 1.5 as requested by deischenjon2007-05-221-1/+0
|
* __cleanup() is needed for ports/devel/valgrind, export it.jon2007-05-221-0/+1
|
* Back out all POSIXified *env() changes.ache2007-05-014-96/+41
| | | | | | | | | Not because I admit they are technically wrong and not because of bug reports (I receive nothing). But because I surprisingly meets so strong opposition and resistance so lost any desire to continue that. Anyone who interested in POSIX can dig out what changes and how through cvs diffs.
* Bump .Ddache2007-04-301-1/+1
| | | | Suggested by: Henrik Brix Andersen <henrik@brixandersen.dk>
* Add phraseache2007-04-301-1/+2
| | | | | "so altering the argument shall change the environment." into putenv description.
* Make putenv() fully conforms to Open Group specs Issue 6ache2007-04-304-26/+58
| | | | | | | | | | | (also IEEE Std 1003.1-2001) The specs explicitly says that altering passed string should change the environment, i.e. putenv() directly puts its arg into environment (unlike setenv() which just copies it there). It means that putenv() can't be implemented via setenv() (like we have before) at all. Putenv() value lives (allows modifying) up to the next putenv() or setenv() call.
* Remove special case skipping initial '=' of the setenv() value "forache2007-04-302-7/+0
| | | | | | | | | compatibility with the different environment conventions" (man page). With the standards, we don't have them different anymore and IEEE Std 1003.1-2001 says that "The values that the environment variables may be assigned are not restricted except that they are considered to end with a null byte"
* Make setenv, putenv, getenv and unsetenv conforming to Open Group specsache2007-04-304-19/+48
| | | | | | | | | Issue 6 (also IEEE Std 1003.1-2001) in following areas: args, return, errors. Putenv still needs rewriting because specs explicitly says that altering passed string later should change the environment (currently we copy the string so can't provide that).
OpenPOWER on IntegriCloud