summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/malloc.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Revert addtion of assertions in revision 1.99. These assertions causeJason Evans2006-01-191-7/+0
| | | | | | | | | problems in cases where regions are faked up for the purposes of red-black tree searches, since those faked region headers reside on the stack, rather than in a malloc chunk. Notes: svn path=/head/; revision=154557
* Add assertions that detect some forms of region separator corruption.Jason Evans2006-01-191-0/+7
| | | | Notes: svn path=/head/; revision=154556
* Remove loops in arena_coalesce(). They are no longer necessary, now thatJason Evans2006-01-191-4/+5
| | | | | | | | internal allocation does not rely on recursive arena use (base_arena was removed in revision 1.95). Notes: svn path=/head/; revision=154555
* Make all internal variables and functions static.Jason Evans2006-01-191-12/+15
| | | | | | | Reported by: ache Notes: svn path=/head/; revision=154549
* Return NULL if there is an OOM error during initialization, rather thanJason Evans2006-01-191-35/+50
| | | | | | | | | | | allowing the error to be fatal. Move a label in order to make sure to properly handle errors in malloc(0). Reported by: Alastair D'Silva, Saneto Takanori Notes: svn path=/head/; revision=154546
* Add a separate simple internal base allocator and remove base_arena, so thatJason Evans2006-01-161-151/+175
| | | | | | | | | | | | | there is never any need to recursively call the main allocation functions. Remove recursive spinlock support, since it is no longer needed. Allow chunks to be as small as the page size. Correctly propagate OOM errors from arena_new(). Notes: svn path=/head/; revision=154421
* Define NO_TLS on ia64. The dynamic TLS implementation on ia64 isMarcel Moolenaar2006-01-161-0/+1
| | | | | | | | | | | | broken for non-threaded shared processes in that __tls_get_addr() assumes the thread pointer is always initialized. This is not the case. When arenas_map is referenced in choose_arena() and it is defined as a thread-local variable, it will result in a SIGSEGV. PR: ia64/91846 (describes the TLS/ia64 bug). Notes: svn path=/head/; revision=154415
* Replace malloc(), calloc(), posix_memalign(), realloc(), and free() withJason Evans2006-01-131-927/+4481
| | | | | | | | | | a scalable concurrent allocator implementation. Reviewed by: current@ Approved by: phk, markm (mentor) Notes: svn path=/head/; revision=154306
* Fix a bitwise logic error in posix_memalign().Jason Evans2006-01-121-2/+2
| | | | | | | Reported by: glebius Notes: svn path=/head/; revision=154263
* In preparation for a new malloc implementation:Jason Evans2006-01-121-0/+64
| | | | | | | | | | | | | | | | * Add posix_memalign(). * Move calloc() from calloc.c to malloc.c. Add a calloc() implementation in rtld-elf in order to make the loader happy (even though calloc() isn't used in rtld-elf). * Add _malloc_prefork() and _malloc_postfork(), and use them instead of directly manipulating __malloc_lock. Approved by: phk, markm (mentor) Notes: svn path=/head/; revision=154248
* Remove the check about whether MALLOC_EXTRA_SANITY is defined,Xin LI2005-02-271-2/+0
| | | | | | | | | | | | surrounding the undef'ing it. It does not seem necessary to undef some symbol that is not exist, and gcc does not complain about whether a symbol is exist before #undef'ing it out. Spotted by: mingyanguo via ChinaUnix.net forum Reviewed by: phk Notes: svn path=/head/; revision=142668
* Consistently use __inline instead of __inline__ as the former is an empty macroStefan Farfeleder2004-07-041-3/+3
| | | | | | | in <sys/cdefs.h> for compilers without support for inline. Notes: svn path=/head/; revision=131575
* Define malloc_pageshift and malloc_minsize for arm.Olivier Houchard2004-05-141-0/+4
| | | | Notes: svn path=/head/; revision=129200
* Rearrange (centralize) initialization of mallocs internals to always bePoul-Henning Kamp2004-03-071-19/+13
| | | | | | | | | done before the first call, even if this is a malloc(0) call. PR: 62859 Notes: svn path=/head/; revision=126727
* Remove the triplicity in the public functions by vectoring them allPoul-Henning Kamp2004-02-211-70/+49
| | | | | | | | | | | | | through a realloc like function. Make the malloc_active variable a local static to this new function. Don't warn about recursion more than once per base call. constify malloc_func. Notes: svn path=/head/; revision=126061
* Move the check for sensitive processes to the point where the exceptionPoul-Henning Kamp2004-02-211-14/+7
| | | | | | | | | | | | has been hit, this makes it cover more cases. Call the message function directly rather than fiddle with flag-saving when we find an unknown character in our options. The 'A' flag should not trigger on legal out of memory conditions. Notes: svn path=/head/; revision=126060
* Do not adjust to the pagesize at runtime. Besides for the one-timeMarcel Moolenaar2003-11-281-8/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | initialization overhead, there's a problem in that we never call imalloc() and thus malloc_init() for zero-sized allocations. As a result, malloc(0) returns NULL when it's the first or only malloc in the program. Any non-zero allocation will initialize the malloc code with the side-effect that subsequent zero-sized allocations return a non-NULL pointer. This is because the pointer we return for zero- sized allocations is calculated from malloc_pageshift, which needs to be initialized at runtime on ia64. The result of the inconsistent behaviour described above is that configure scripts failed the test for a GNU compatible malloc. This resulted in a lot of broken ports. Other, even simpler, solutions were possible as well: 1. initialize malloc_pageshift with some non-zero value (say 13 for 8KB pages) and keep the runtime adjustment. 2. Stop using malloc_pageshift to calculate ZEROSIZEPTR. Removal of the runtime adjustment was chosen because then ia64 is the same as any other platform. It is not to say that using a page size obtained at runtime is bad per se. It's that there's currently a high level of gratuity for its existence and the moment it causes problems is the moment you need to get rid of it. Hence, it's not unthinkable that this commit is (partially) reverted some time in the future when we do have a good reason for it and a good way to achieve it. Approved by: re@ (rwatson) Reported by: kris (portmgr@) -- may the ports be with you Notes: svn path=/head/; revision=123031
* Externalize malloc's spinlock so that a thread library can takeDaniel Eischen2003-11-041-0/+1
| | | | | | | | | | | | | | it around an application's fork() call. Our new thread libraries (libthr, libpthread) can now have threads running while another thread calls fork(). In this case, it is possible for malloc to be left in an inconsistent state in the child. Our thread libraries, libpthread in particular, need to use malloc internally after a fork (in the child). Reviewed by: davidxu Notes: svn path=/head/; revision=122069
* Remove incomplete support for running FreeBSD userland on old NetBSD kernelsTim J. Robbins2003-10-291-3/+1
| | | | | | | lacking the issetugid() and utrace() syscalls. Notes: svn path=/head/; revision=121667
* Consistently cast to (u_char *) when filling with junk.Poul-Henning Kamp2003-10-251-3/+3
| | | | Notes: svn path=/head/; revision=121518
* Style changes. Inching closer to convergence with OpenBSD.Poul-Henning Kamp2003-10-251-61/+60
| | | | Notes: svn path=/head/; revision=121500
* More style fixes to improve diffability with OpenBSD.Poul-Henning Kamp2003-09-271-46/+54
| | | | | | | Pull 'A' evilness for realloc(3) from OpenBSD. Notes: svn path=/head/; revision=120524
* Style changes to improve diffability against OpenBSD version.Poul-Henning Kamp2003-09-271-91/+91
| | | | Notes: svn path=/head/; revision=120520
* Minor constification.Poul-Henning Kamp2003-07-291-2/+2
| | | | Notes: svn path=/head/; revision=118153
* Clarify the code a bit.Poul-Henning Kamp2003-06-011-1/+2
| | | | | | | Submitted by: Nadav Eiron <nadav@TheEirons.org> Notes: svn path=/head/; revision=115610
* Tell malloc.c that AMD64 uses the same pagesize as i386.Peter Wemm2003-04-301-0/+4
| | | | Notes: svn path=/head/; revision=114321
* Catch some cases where asking for ridiculously large allocations couldPoul-Henning Kamp2003-01-301-0/+4
| | | | | | | result in a segfault. Instead just return NULL. Notes: svn path=/head/; revision=110103
* For "sensitive" processes, we always set the 'A' flag which causes abort()Poul-Henning Kamp2003-01-231-0/+7
| | | | | | | | | | | | | | | | to be called on first sight of trouble. "sensitive" is somewhat arbitrarily defined as "setuid, setgid, uid == root or gid == wheel". The 'A' option carries no performance penalty. It is not possible to override this setting: fix the program instead. Absentmindedly nodded OK to by: various Notes: svn path=/head/; revision=109754
* s/EDOFUS/EDOOFUS/Poul-Henning Kamp2002-08-211-3/+3
| | | | | | | Persuaded by: Google Notes: svn path=/head/; revision=102229
* Make sure we set errno sensibly in case of failure.Poul-Henning Kamp2002-08-091-0/+7
| | | | | | | Spotted by: ache Notes: svn path=/head/; revision=101568
* Const poison.Poul-Henning Kamp2002-05-301-3/+5
| | | | | | | Partially submitted by: wollman Notes: svn path=/head/; revision=97639
* Avoid casting a different sized integer to a pointer on LP64 systems.Peter Wemm2002-05-101-1/+1
| | | | Notes: svn path=/head/; revision=96350
* Constify _malloc_options.Poul-Henning Kamp2002-04-241-1/+1
| | | | Notes: svn path=/head/; revision=95377
* Do not use __progname directly (except in [gs]etprogname(3)).Mark Murray2002-03-291-4/+2
| | | | | | | | | Also, make an internal _getprogname() that is used only inside libc. For libc, getprogname(3) is a weak symbol in case a function of the same name is defined in userland. Notes: svn path=/head/; revision=93399
* Fix the style of the SCM ID's.David E. O'Brien2002-03-221-2/+3
| | | | | | | I believe have made all of libc .c's as consistent as possible. Notes: svn path=/head/; revision=92986
* Remove __P() usage.David E. O'Brien2002-03-211-1/+1
| | | | Notes: svn path=/head/; revision=92905
* Remove 'register' keyword.David E. O'Brien2002-03-211-1/+1
| | | | Notes: svn path=/head/; revision=92889
* Add ifdefs for sparc64.Jake Burkholder2002-02-231-0/+4
| | | | Notes: svn path=/head/; revision=91161
* If 'VX' is given, realloc(foo,0) will bail, it shouldn't.Poul-Henning Kamp2001-11-171-2/+5
| | | | | | | | PR: 29376 Submitted by: Farooq Mela <fmela0@sm.socccd.cc.ca.us> Notes: svn path=/head/; revision=86488
* Correctly call THREAD_UNLOCK() if the recursive call trap is sprung.Poul-Henning Kamp2001-11-161-0/+2
| | | | | | | Pointed out by: knu Notes: svn path=/head/; revision=86466
* phkmalloc->evilchecks++;Poul-Henning Kamp2001-11-021-3/+13
| | | | | | | | | | | If zero bytes are allocated, return pointer to the middle of page-zero (which is protected) so that the program will crash if it dereferences this illgotten pointer. Inspired & Urged by: Theo de Raadt <deraadt@cvs.openbsd.org> Notes: svn path=/head/; revision=85869
* Port to ia64, taking into account the fact that pagesizes may be variable.Doug Rabson2001-09-071-0/+11
| | | | Notes: svn path=/head/; revision=83202
* Fixed style bugs (dot `.' at the end of error and warning messages).Ruslan Ermilov2001-08-101-22/+22
| | | | | | | Noticed by: bde Notes: svn path=/head/; revision=81447
* Remove a sizeof(void *) == sizeof(int) assumption.Poul-Henning Kamp2001-02-041-7/+7
| | | | | | | Submitted by: Loren James Rittle <rittle@latour.rsch.comm.mot.com> Notes: svn path=/head/; revision=71987
* Remove _THREAD_SAFE and make libc thread-safe by default byDaniel Eischen2001-01-241-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | adding (weak definitions to) stubs for some of the pthread functions. If the threads library is linked in, the real pthread functions will pulled in. Use the following convention for system calls wrapped by the threads library: __sys_foo - actual system call _foo - weak definition to __sys_foo foo - weak definition to __sys_foo Change all libc uses of system calls wrapped by the threads library from foo to _foo. In order to define the prototypes for _foo(), we introduce namespace.h and un-namespace.h (suggested by bde). All files that need to reference these system calls, should include namespace.h before any standard includes, then include un-namespace.h after the standard includes and before any local includes. <db.h> is an exception and shouldn't be included in between namespace.h and un-namespace.h namespace.h will define foo to _foo, and un-namespace.h will undefine foo. Try to eliminate some of the recursive calls to MT-safe functions in libc/stdio in preparation for adding a mutex to FILE. We have recursive mutexes, but would like to avoid using them if possible. Remove uneeded includes of <errno.h> from a few files. Add $FreeBSD$ to a few files in order to pass commitprep. Approved by: -arch Notes: svn path=/head/; revision=71579
* Add `_PATH_DEVZERO'.David E. O'Brien2000-12-091-1/+2
| | | | | | | Use _PATH_* where where possible. Notes: svn path=/head/; revision=69793
* Make it possible to override the function which writes messages toPoul-Henning Kamp2000-11-261-12/+18
| | | | | | | | | | stderr in case of warnings and errors. Rename malloc_options to have a leading underscore, I belive I have been told that is more correct namespace wise. Notes: svn path=/head/; revision=69201
* Oops, un-spam this file - the last commit was an accident.Brian Somers2000-09-201-1/+0
| | | | | | | Pointed out by: phk Notes: svn path=/head/; revision=66105
* Only realloc() environ if we're sure that we know where it came from.Brian Somers2000-09-201-0/+1
| | | | | | | | | The recent problems with sshd were due to sshd reassigning `environ' when setenv() thinks it owns it. setenv() subsequently realloc()s the new version of environ and *boom* Notes: svn path=/head/; revision=66101
* Turn malloc options "AJ" on by default.Poul-Henning Kamp2000-07-091-2/+2
| | | | | | | | | | | These will be turned off again as we approach 5.0-RELEASE. If you benchmark things, make sure to ln -sf j /etc/malloc.conf to see "true" performance. Notes: svn path=/head/; revision=62847