Home | History | Annotate | Download | only in stdlib
History log of /src/lib/libc/stdlib/malloc.c
RevisionDateAuthorComments
 1.60  15-May-2020  joerg Hook up proper fork lock handling for malloc:
- lock all relevant mutexes just before fork
- unlock all mutexes just after fork in the parent
- full reinit non-spinlocks in the child
This is not using the normal pthread_atfork interface to ensure order of
operation, malloc is used as implementation detail too often.
 1.59  13-Jan-2017  christos use getpagesize(3).
 1.58  12-Jan-2017  christos Avoid sysconf: __sysconf -> sysctlgetmibinfo -> strtoimax -> locale, etc.
 1.57  12-Jan-2017  christos make this smaller.
 1.56  18-Sep-2014  christos branches: 1.56.2;
make more descriptors that we open as close-on-exec
 1.55  30-Dec-2012  dholland typo in comment, from Abhinav Upadhyay in PR 47385
 1.54  18-May-2011  christos branches: 1.54.4; 1.54.10;
cleanup saving and restoring errno, and make it similar.
 1.53  13-May-2011  christos don't let readlink trash errno.;
 1.52  03-Feb-2008  christos fix posix_memalign; we are not going to support alignments > pagesize in
this implementation.
 1.51  12-Dec-2007  macallan make this compile again
 1.50  04-Dec-2007  christos move decls for _malloc_{pre,post}fork() to extern.h
 1.49  28-Nov-2007  christos Sync phk malloc.c with the latest one from FreeBSD. This gives us the
same api as jemalloc by:

- adding posix_memalign()
- moving calloc in the same file
- renaming malloc_options -> _malloc_options
 1.48  24-Nov-2006  christos branches: 1.48.8;
fix spelling of accidentally; from Zapher
 1.47  08-Oct-2006  elad PR/34602: sushant: Bug in malloc implementation contains dead code in
free_pages()

Applied patch from Mindaugas <unex at linija org> (in #NetBSD-code), thanks
 1.46  24-Dec-2005  perry __inline__ -> inline
 1.45  29-Nov-2005  christos WARNS=4
 1.44  12-Jun-2005  lukem Add missing __RCSID()
 1.43  05-Oct-2003  junyoung Style fixes to reduce diff size against the FreeBSD version, notably:
- Use NULL where appropriate.
- No need to pull in stdint.h.
- Get rid of "register" keywords in the hope that the compiler will
do a better job for us. :-)
- Every message ends with a period.
- MMAP() macro is supposed to return MAP_FAILED rather than -1 if it
fails.
- De-__P.
 1.42  23-Jul-2003  itojun call malloc_init() on first call to free/realloc, to make malloc.conf to
take effect. in response to PR 22223
 1.41  18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.40  09-Dec-2002  chris Add a couple of missing THREAD_UNLOCK's, for the error exit path.

No functional change on Mainline, however SA branch probably needs this.
 1.39  11-Nov-2002  thorpej Fix signed/unsigned comparison warnings.
 1.38  06-May-2001  christos More fixes:

1. use uintptr_t instead of u_long
2. check for overflow in map_pages and malloc_pages
3. bring in fixes from FreeBSD [int -> size_t, and a missing THREAD_UNLOCK]
4. rewrite map_pages to use sbrk() only to grow memory (avoids extra syscall
and elides bug in brk(2) that ross is fixing)
5. restore the break point to its original value if the mmap(2) for the page
directory or the alignment sbrk breaks.

reviewed by: chuq and ross
tested by: make build and reboot
Now memtest nearly works; unfortunately there is no way currently to lower
the break point as we free, so memtest keeps trying to reduce memory when
mlock() fails and that does not work.
 1.37  03-May-2001  christos PR/12810: Chris ?: malloc core-dumps when given large number as the argument.
This is because integer overflow occurs in the computation of the size of
the page directory array. We now detect that, and return ENOMEM.
 1.36  19-Feb-2001  cgd branches: 1.36.2;
convert from __progname to getprogname()
 1.35  05-Jan-2001  jdolecek we now have utrace, support it here
 1.34  20-Dec-2000  christos fix sbrk casts
 1.33  06-Jul-2000  christos avoid losing precision warnings
 1.32  20-May-2000  simonb Disable malloc's hints to the kernel - now that the madvise() syscall
actually does something, this can be expensive. From discussion on
current-users.

Note that the man page is already correct - we imported malloc.c from
FreeBSD before they made the same change but malloc.3 after...
 1.31  07-Apr-2000  enami Fix the bug introduced in rev 1.28 and actually caused failure on alpha;
In the function malloc_make_chunks, don't define the local variable ``l'',
which is used to hold the actual size of pginfo, as size_t. Define it as
a signed integer as before. We expect it to become zero or negative value,
and we know that it is much smaller than pagesize and it is small enough to
fit in signed interger.
 1.30  07-Apr-2000  enami Backout the previous backing out.
 1.29  31-Jan-2000  thorpej Back out the previous 2 revs. The delint'ing of this file caused
something to break horribly on the Alpha.
 1.28  23-Jan-2000  mycroft Delint.
 1.27  23-Jan-2000  mycroft Partially delint, and a few microoptimizations.
 1.26  10-Sep-1999  kleink Restore the behaviour of not setting errno to ENOMEM when allocating 0
units of storage and returning a null pointer in System V mode; this was
broken by the `fix' in rev. 1.24. Also, as it is stated in ISO C that
such operation does not constitute an allocation failure, do not abort()
even if the `X' option is set.

Amusingly enough the SVID, Fourth Edition, specifies the `unique pointer'
return behaviour for this kind of allocation, so this is kind of mis-named.
 1.25  22-Aug-1999  kleink Need "namespace.h".
 1.24  08-Jul-1999  thorpej Make sure errno is set to ENOMEM if we return NULL.
 1.23  05-Jul-1999  thorpej index -> ldx (and similar in some related variable names). Avoids a lint
warning.
 1.22  05-Jul-1999  thorpej Oops, back out 1.21. Christos and I apparently stepped on each other.
 1.21  05-Jul-1999  christos s/index/idx/
s/EXTRA_SANITY/MALLOC_EXTRA_SANITY/
const poisoning
use sysconf to get the pagesize
 1.20  05-Jul-1999  thorpej Compute page size related parameters at run-time.
 1.19  05-Jul-1999  thorpej EXTRA_SANITY -> MALLOC_EXTRA_SANITY, consistently.
 1.18  04-Jul-1999  thorpej Only define MADV_FREE do MADV_DONTNEED if it's not already defined
by <sys/mman.h>.
 1.17  26-Jun-1999  tls The 'new malloc' (phk's malloc, from FreeBSD) is now our only malloc.
 1.16  29-Jan-1999  kleink Protect access of state with a mutex. Miscellaneous notes:
* still needs an implementation-independent ("reentrant.h") method for
disabling cancellation,
* break a leg to leave realloc() `storage compaction' as was for non-reentrant
code,
* use of stdio in assertion code is unsafe.
 1.15  15-Nov-1998  christos delint
 1.14  26-Aug-1998  perry make memcpy into memmove in some cases
 1.13  10-Aug-1998  perry bzero->memset, bcopy->memcpy, bcmp->memcmp
 1.12  03-Feb-1998  perry remove obsolete register declarations
 1.11  30-Jan-1998  perry update to lite-2
 1.10  21-Jul-1997  jtc If port provides __weak_alias(), provide an Standard C and POSIX pure
identifier namespace by renaming non standard functions and variables
such that they have a leading underscore. The library will use those
names internally. Weak aliases are used to provide the original names
to the API.

This is only the first part of this change. It is most of the functions
which are implemented in C for all NetBSD ports. Subsequent changes are
to add the same support to the remaining C files, to assembly files, and
to the automagically generated assembly source used for system calls.
When all of the above is done, ports with weak alias support should add
a definition for __weak_alias to <sys/cdefs.h>.
 1.9  13-Jul-1997  christos Add local.h for local prototypes.
Fix namespace issues for strtoq and strtouq
Fix gcc warnings.
Fix RCSID's
 1.8  07-Apr-1997  christos PR/3448: Bill Sommerfeld: Change "p" to __STRING(p)
 1.7  20-Dec-1996  cgd don't confuse long and int; pointed out by lint
 1.6  17-Jan-1996  jtc branches: 1.6.2;
The C standard says (about realloc) that "If size is zero and ptr is
not a null pointer, the object it points to is freed." Reported by
Peter Seebach in PR #1806.
 1.5  28-Dec-1995  thorpej New-style RCS ids.
 1.4  19-Oct-1994  cgd branches: 1.4.2;
casting types.
 1.3  26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.2  01-Aug-1993  mycroft Add RCS identifiers.
 1.1  21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2  30-Jan-1998  perry import lite-2
 1.1.1.1  21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.2.1  02-May-1995  jtc #include "namespace.h"
 1.6.2.1  20-Sep-1996  jtc snapshot namespace cleanup: net, etc.
 1.36.2.6  10-Dec-2002  thorpej Sync with HEAD.
 1.36.2.5  25-Mar-2002  nathanw Bind libc's pthread desires to _libc_pthread_*, rather than pthread_*, to
prevent accidental use of pthread libraries that aren't actually integrated
with libc.
 1.36.2.4  11-Mar-2002  nathanw Use an ordinary mutex for malloc now that internal spinlocks aren't exported.
 1.36.2.3  01-Jan-2002  wdk pt_spin_t has been renamed to pthread_spin_t
 1.36.2.2  08-Oct-2001  nathanw Catch up to -current.
 1.36.2.1  08-Aug-2001  nathanw Add THREAD_LOCK stubs that use the library's spinlocks.
(XXX why spinlocks instead of a normal mutex?)
 1.48.8.2  23-Mar-2008  matt sync with HEAD
 1.48.8.1  09-Jan-2008  matt sync with HEAD
 1.54.10.1  25-Feb-2013  tls resync with head
 1.54.4.1  23-Jan-2013  yamt sync with head
 1.56.2.1  20-Mar-2017  pgoyette Sync with HEAD

RSS XML Feed