aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
Commit message (Collapse)AuthorAgeFilesLines
...
* In reallocf(3), free the memory only when size != 0. Otherwise, when theJaakko Heinonen2010-03-031-1/+8
| | | | | | | | | | | System V compatibility option (malloc "V" flag) is in effect a zero sized reallocf() could cause a double free. PR: bin/141753 Submitted by: Dan Lukes Notes: svn path=/head/; revision=204636
* Rewrite red-black trees to do lazy balance fixup. This improvesJason Evans2010-02-282-772/+837
| | | | | | | insert/remove speed by ~30%. Notes: svn path=/head/; revision=204493
* Define TLS_MODEL for PowerPC as well. Since PowerPC uses variant I,Marcel Moolenaar2010-02-161-0/+1
| | | | | | | like ia64, leave it empty (default model). Notes: svn path=/head/; revision=203969
* Unbreak ia64: tls_model("initial-exec") is invalid, because it assumesMarcel Moolenaar2010-02-161-11/+9
| | | | | | | | | the static TLS model, which is fundamentally different from the dynamic TLS model. The consequence was data corruption. Limit the attribute to i386 and amd64. Notes: svn path=/head/; revision=203950
* Fix PRMartin Cracauer2010-02-101-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/143350 Empty string test gone wrong. Testing this requires that you have a locale that has the sign string unset but has int_n_sign_posn set (the default locale falls through to use "()" around negative numbers which is probably another bug). I created that setup by hand and indeed without this fix negative numbers are put out as positive numbers (doesn't fall through to use "-" as default indicator). Unfixed example in nl_NL.ISO8859-1 with lc->negative_sign set to empty string: strfmon(buf, sizeof(buf), "%-8i", -42.0); ==> example2: 'EUR 42,00' 'Eu 42,00' Fixed: example2: 'EUR 42,00-' 'Eu 42,00-' This file and suggested fix are identical in at least freebsd-8. Backport might be appropriate but some expert on locales should probably have a look at us defaulting to negative numbers in parenthesis when LC_* is default. That doesn't look right and is not what other OSes are doing. PR: 143350 Submitted by: Corinna Vinschen Reviewed by: bug reporter submitted, tested by me Notes: svn path=/head/; revision=203734
* Fix bugs:Jason Evans2010-01-314-1352/+2256
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Fix a race in chunk_dealloc_dss(). * Check for allocation failure before zeroing memory in base_calloc(). Merge enhancements from a divergent version of jemalloc: * Convert thread-specific caching from magazines to an algorithm that is more tunable, and implement incremental GC. * Add support for medium size classes, [4KiB..32KiB], 2KiB apart by default. * Add dirty page tracking for pages within active small/medium object runs. This allows malloc to track precisely which pages are in active use, which makes dirty page purging more effective. * Base maximum dirty page count on proportion of active memory. * Use optional zeroing in arena_chunk_alloc() to avoid needless zeroing of chunks. This is useful in the context of DSS allocation, since a long-lived application may commonly recycle chunks. * Increase the default chunk size from 1MiB to 4MiB. Remove feature: * Remove the dynamic rebalancing code, since thread caching reduces its utility. Notes: svn path=/head/; revision=203329
* Add missing return, in a rare case where we can't allocate memory inEd Maste2010-01-271-0/+1
| | | | | | | | | | deallocate. Submitted by: Ryan Stone (rysto32 at gmail dot com) Approved by: jasone Notes: svn path=/head/; revision=203077
* Simplify arena_run_reg_dalloc(), and remove a bug that was due to incorrectJason Evans2009-12-101-89/+28
| | | | | | | initialization of ssize_invs. Notes: svn path=/head/; revision=200345
* Fix the posix_memalign() changes in r196861 to actually return a NULL pointerJason Evans2009-12-101-0/+1
| | | | | | | | | as intended. PR: standards/138307 Notes: svn path=/head/; revision=200340
* Revert behavior change to setenv(), unsetenv() and putenv() until a moreSean Farley2009-12-071-3/+6
| | | | | | | thorough security review has been completed. Notes: svn path=/head/; revision=200198
* Update the getenv(3) man page to reflect the recent change to the behaviorSean Farley2009-12-061-9/+9
| | | | | | | | | | of setenv(), putenv() and unsetenv() when dealing with corrupt entries in environ. They now output a warning and complete their task without error. MFC after: 1 week Notes: svn path=/head/; revision=200195
* Change the behavior of setenv(), putenv() and unsetenv() to continue parsingSean Farley2009-12-061-6/+3
| | | | | | | | | | | | | | | instead of returning an error if a corrupt (not a "name=value" string) entry in the environ array is detected when (re)-building the internal environment. This should prevent applications or libraries from experiencing issues arising from the expectation that these calls will complete even with corrupt entries. The behavior is now as it was prior to 7.0. Reviewed by: jilles MFC after: 1 week Notes: svn path=/head/; revision=200191
* Improve the comment within getenv() explaining the search order it takes toSean Farley2009-12-061-8/+9
| | | | | | | | | | | | | find a variable. Include a note that it must not cause the internal environment to be generated since malloc() depends upon getenv(). To call malloc() would create a circular dependency. Recommended by: green Approved by: jilles MFC after: 1 week Notes: svn path=/head/; revision=200190
* Fix many "function declaration isn't a prototype" warnings in libc.Ed Schouten2009-12-051-2/+1
| | | | | | | | I've only fixed code that seems to be written by `us'. There are still many warnings like this present in resolv/, rpc/, stdtime/ and yp/. Notes: svn path=/head/; revision=200150
* Temporarily revert the previous change because the linker has beenBrian Feldman2009-12-011-36/+28
| | | | | | | modified so that it will abort when the environment is bad. Notes: svn path=/head/; revision=199987
* Do not gratuitously fail *env(3) operations due to corrupt ('='-less)Brian Feldman2009-12-011-28/+36
| | | | | | | | | | | | | | | | **environ entries. This puts non-getenv(3) operations in line with getenv(3) in that bad environ entries do not cause all operations to fail. There is still some inconsistency in that getenv(3) in the absence of any environment-modifying operation does not emit corrupt environ entry warnings. I also fixed another inconsistency in getenv(3) where updating the global environ pointer would not be reflected in the return values. It would have taken an intermediary setenv(3)/putenv(3)/unsetenv(3) in order to see the change. Notes: svn path=/head/; revision=199983
* Change the utrace log entry for malloc_init from (0, 0, 0) to (-1, 0, 0)Colin Percival2009-11-141-1/+1
| | | | | | | | | in order to distinguish it from free(NULL), which is logged as (0, 0, 0). Reviewed by: jhb Notes: svn path=/head/; revision=199264
* Make malloc(3) superpage aware. Specifically, if getpagesizes(3) returnsAlan Cox2009-09-262-2/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | a large page size that is greater than malloc(3)'s default chunk size but less than or equal to 4 MB, then increase the chunk size to match the large page size. Most often, using a chunk size that is less than the large page size is not a problem. However, consider a long-running application that allocates and frees significant amounts of memory. In particular, it frees enough memory at times that some of that memory is munmap()ed. Up until the first munmap(), a 1MB chunk size is just fine; it's not a problem for the virtual memory system. Two adjacent 1MB chunks that are aligned on a 2MB boundary will be promoted automatically to a superpage even though they were allocated at different times. The trouble begins with the munmap(), releasing a 1MB chunk will trigger the demotion of the containing superpage, leaving behind a half-used 2MB reservation. Now comes the real problem. Unfortunately, when the application needs to allocate more memory, and it recycles the previously munmap()ed address range, the implementation of mmap() won't be able to reuse the reservation. Basically, the coalescing rules in the virtual memory system don't allow this new range to combine with its neighbor. The effect being that superpage promotion will not reoccur for this range of addresses until both 1MB chunks are freed at some point in the future. Reviewed by: jasone MFC after: 3 weeks Notes: svn path=/head/; revision=197524
* Handle zero size for posix_memalign. Return NULL or unique addressKonstantin Belousov2009-09-051-0/+9
| | | | | | | | | | according to the 'V' option. PR: standards/138307 MFC after: 1 week Notes: svn path=/head/; revision=196861
* Our implementation of granpt(3) could be valid in the future.Ed Schouten2009-08-241-15/+11
| | | | | | | | | | | | | | | | | | | | | | | | When I wrote the pseudo-terminal driver for the MPSAFE TTY code, Robert Watson and I agreed the best way to implement this, would be to let posix_openpt() create a pseudo-terminal with proper permissions in place and let grantpt() and unlockpt() be no-ops. This isn't valid behaviour when looking at the spec. Because I thought it was an elegant solution, I filed a bug report at the Austin Group about this. In their last teleconference, they agreed on this subject. This means that future revisions of POSIX may allow grantpt() and unlockpt() to be no-ops if an open() on /dev/ptmx (if the implementation has such a device) and posix_openpt() already do the right thing. I'd rather put this in the manpage, because simply mentioning we don't comply to any standard makes it look worse than it is. Right now we don't, but at least we took care of it. Approved by: re (kib) MFC after: 3 days Notes: svn path=/head/; revision=196508
* Simplify. We can just use .sinclude here.Ed Schouten2009-06-231-3/+1
| | | | | | | Submitted by: Christoph Mallon Notes: svn path=/head/; revision=194703
* Our grantpt(3) and unlockpt(3) don't comply with POSIX.Ed Schouten2009-05-041-3/+7
| | | | Notes: svn path=/head/; revision=191789
* "-isoC-99" should be spelled without 'c'.Xin LI2009-03-011-1/+1
| | | | Notes: svn path=/head/; revision=189207
* Add two new routines: fdevname() and fdevname_r().Ed Schouten2009-02-111-5/+3
| | | | | | | | | | | | | | | | | A more elegant way of obtaining a name of a character device by its file descriptor on FreeBSD, is to use the FIODGNAME ioctl. Because a valid file descriptor implies a file descriptor is visible in /dev, it will always resolve a valid device name. I'm adding a more friendly wrapper for this ioctl, called fdevname(). It is a lot easier to use than devname() and also has better error handling. When a device name cannot be resolved, it will just return NULL instead of a generated device name that makes no sense. Discussed with: kib Notes: svn path=/head/; revision=188497
* Fix language on atol(3) manpage. Add a COMPATIBILITY sectionGiorgos Keramidas2009-02-081-3/+32
| | | | | | | | | | | | | stating that in FreeBSD the atol() and atoll() functions affect errno in the same way as strtol() and stroll(). PR: docs/126487 Submitted by: edwin Reviewed by: trhodes, gabor MFC after: 1 week Notes: svn path=/head/; revision=188305
* Fix a lock order reversal bug that could cause deadlock during fork(2).Jason Evans2008-12-011-11/+37
| | | | | | | Reported by: kib Notes: svn path=/head/; revision=185514
* Adjust an assertion to handle the case where a lock is contested, butJason Evans2008-11-301-1/+1
| | | | | | | | | spinning is avoided due to running on a single-CPU system. Reported by: stefanf Notes: svn path=/head/; revision=185483
* Do not spin when trying to lock on a single-CPU system.Jason Evans2008-11-301-11/+13
| | | | | | | Reported by: davidxu Notes: svn path=/head/; revision=185468
* Revert to preferring mmap(2) over sbrk(2) when mapping memory, due toJason Evans2008-11-032-13/+18
| | | | | | | | | | potential extreme contention in the kernel for multi-threaded applications on SMP systems. Reported by: kris Notes: svn path=/head/; revision=184602
* MTC r183949:Alexander Leidinger2008-10-171-0/+5
| | | | | | | | | | Allow to define MALLOC_PRODUCTION with a make variable instead of polluting the global CFLAGS. Reviewed by: jasone Notes: svn path=/head/; revision=183969
* Use PAGE_{SIZE,MASK,SHIFT} from machine/param.h rather than hard-codingJason Evans2008-09-101-120/+88
| | | | | | | | | page size and using sysconf(3). Suggested by: marcel Notes: svn path=/head/; revision=182906
* Unbreak ia64: pges are 8KB.Marcel Moolenaar2008-09-061-1/+1
| | | | Notes: svn path=/head/; revision=182809
* Add thread-specific caching for small size classes, based on magazines.Jason Evans2008-08-273-256/+1133
| | | | | | | | | | | | | | | | | | | | | | | | | | | This caching allows for completely lock-free allocation/deallocation in the steady state, at the expense of likely increased memory use and fragmentation. Reduce the default number of arenas to 2*ncpus, since thread-specific caching typically reduces arena contention. Modify size class spacing to include ranges of 2^n-spaced, quantum-spaced, cacheline-spaced, and subpage-spaced size classes. The advantages are: fewer size classes, reduced false cacheline sharing, and reduced internal fragmentation for allocations that are slightly over 512, 1024, etc. Increase RUN_MAX_SMALL, in order to limit fragmentation for the subpage-spaced size classes. Add a size-->bin lookup table for small sizes to simplify translating sizes to size classes. Include a hard-coded constant table that is used unless custom size class spacing is specified at run time. Add the ability to disable tiny size classes at compile time via MALLOC_TINY. Notes: svn path=/head/; revision=182225
* Remove grantpt.c, which should have been deleted in the MPSAFE TTY commit.Ed Schouten2008-08-201-286/+0
| | | | | | | | | The routines in grantpt.c have been moved to ptsname.c in the MPSAFE TTY layer, because grantpt() is now effectively a no-op. I forgot to remove the corresponding source file from libc. Notes: svn path=/head/; revision=181915
* Integrate the new MPSAFE TTY layer to the FreeBSD operating system.Ed Schouten2008-08-204-100/+129
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The last half year I've been working on a replacement TTY layer for the FreeBSD kernel. The new TTY layer was designed to improve the following: - Improved driver model: The old TTY layer has a driver model that is not abstract enough to make it friendly to use. A good example is the output path, where the device drivers directly access the output buffers. This means that an in-kernel PPP implementation must always convert network buffers into TTY buffers. If a PPP implementation would be built on top of the new TTY layer (still needs a hooks layer, though), it would allow the PPP implementation to directly hand the data to the TTY driver. - Improved hotplugging: With the old TTY layer, it isn't entirely safe to destroy TTY's from the system. This implementation has a two-step destructing design, where the driver first abandons the TTY. After all threads have left the TTY, the TTY layer calls a routine in the driver, which can be used to free resources (unit numbers, etc). The pts(4) driver also implements this feature, which means posix_openpt() will now return PTY's that are created on the fly. - Improved performance: One of the major improvements is the per-TTY mutex, which is expected to improve scalability when compared to the old Giant locking. Another change is the unbuffered copying to userspace, which is both used on TTY device nodes and PTY masters. Upgrading should be quite straightforward. Unlike previous versions, existing kernel configuration files do not need to be changed, except when they reference device drivers that are listed in UPDATING. Obtained from: //depot/projects/mpsafetty/... Approved by: philip (ex-mentor) Discussed: on the lists, at BSDCan, at the DevSummit Sponsored by: Snow B.V., the Netherlands dcons(4) fixed by: kan Notes: svn path=/head/; revision=181905
* Move CPU_SPINWAIT into the innermost spin loop, in order to allow fasterJason Evans2008-08-141-2/+3
| | | | | | | | | preemption while busy-waiting. Submitted by: Mike Schuster <schuster@adobe.com> Notes: svn path=/head/; revision=181733
* Re-order the terms of an expression in arena_run_reg_dalloc() to correctlyJason Evans2008-08-141-2/+2
| | | | | | | | | detect whether the integer division table is large enough to handle the divisor. Before this change, the last two table elements were never used, thus causing the slow path to be used for those divisors. Notes: svn path=/head/; revision=181732
* Remove variables which are assigned values and never used thereafter.Colin Percival2008-08-081-5/+1
| | | | | | | | Found by: LLVM/Clang Static Checker Approved by: jasone Notes: svn path=/head/; revision=181438
* Restructure and use different variables in the tests that involveSean Farley2008-08-031-13/+15
| | | | | | | | | | | | environ[0] to be more obvious that environ is not NULL before environ[0] is tested. Although I believe the previous code worked, this change improves code maintainability. Reviewed by: ache MFC after: 3 days Notes: svn path=/head/; revision=181266
* Detect if the application has cleared the environ variable by settingSean Farley2008-08-021-7/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | the first value (environ[0]) to NULL. This is in addition to the current detection of environ being replaced, which includes being set to NULL. Without this fix, the environment is not truly wiped, but appears to be by getenv() until an *env() call is made to alter the enviroment. This change is necessary to support those applications that use this method for clearing environ such as Dovecot and Postfix. Applications such as Sendmail and the base system's env replace environ (already detected). While neither of these methods are defined by SUSv3, it is best to support them due to historic reasons and in lieu of a clean, defined method. Add extra units tests for clearing environ using four different methods: 1. Set environ to NULL pointer. 2. Set environ[0] to NULL pointer. 3. Set environ to calloc()'d NULL-terminated array. 4. Set environ to static NULL-terminated array. Noticed by: Timo Sirainen MFC after: 3 days Notes: svn path=/head/; revision=181150
* Enhance arena_chunk_map_t to directly support run coalescing, and useJason Evans2008-07-181-394/+338
| | | | | | | | | | the chunk map instead of red-black trees where possible. Remove the red-black trees and node objects that are obsoleted by this change. The net result is a ~1-2% memory savings, and a substantial allocation speed improvement. Notes: svn path=/head/; revision=180599
* - This code was intially obtained from NetBSD, but it's missing licenceDaniel Gerzo2008-07-061-1/+29
| | | | | | | | | | | | statement. Add the one from the current NetBSD version. - Also bump a date to reflect my content changes I have done in previous revision Approved by: imp MFC after: 3 days Notes: svn path=/head/; revision=180329
* - Add description about a missing return valueDaniel Gerzo2008-07-061-2/+6
| | | | | | | | | PR: docs/75995 Submitted by: Tarc <tarc@po.cs.msu.su> MFC after: 3 days Notes: svn path=/head/; revision=180325
* - remove superfluous wordDaniel Gerzo2008-07-061-3/+3
| | | | | | | | | - remove contractions MFC after: 3 days Notes: svn path=/head/; revision=180323
* Mark the section describing return values with an appropriate section flag.Daniel Gerzo2008-06-261-1/+1
| | | | | | | | PR: docs/122818 MFC after: 3 days Notes: svn path=/head/; revision=180024
* Don't export the unused __use_pts() routine.Ed Schouten2008-06-172-2/+1
| | | | | | | | | | | | | The __use_pts() routine was once probably used by libutil to determine if we are using BSD or UNIX98 style PTY device names. It doesn't seem to be used outside grantpt.c, which means we can make it static and remove it from the Symbol.map. Reviewed by: cognet, kib Approved by: philip (mentor) Notes: svn path=/head/; revision=179846
* In the error path through base_alloc(), release base_mtx [1].Jason Evans2008-06-101-3/+7
| | | | | | | | | Fix bit vector initialization for run headers. Submitted by: [1] Mike Schuster <schuster@adobe.com> Notes: svn path=/head/; revision=179704
* Clean up cpp logic and comments.Jason Evans2008-05-141-8/+21
| | | | Notes: svn path=/head/; revision=178995
* Fix a comment.Jason Evans2008-05-031-1/+1
| | | | Notes: svn path=/head/; revision=178744
* Add a separate tree to track arena chunks that contain dirty pages.Jason Evans2008-05-011-157/+133
| | | | | | | | | | This substantially improves worst case allocation performance, since O(lg n) tree search can be used instead of O(n) tree iteration. Use rb_wrap() instead of directly calling rb_*() macros. Notes: svn path=/head/; revision=178709