diff options
author | Jason Evans <jasone@canonware.com> | 2012-04-03 16:28:00 (GMT) |
---|---|---|
committer | Jason Evans <jasone@canonware.com> | 2012-04-04 02:25:48 (GMT) |
commit | 01b3fe55ff3ac8e4aa689f09fcb0729da8037638 (patch) | |
tree | 259b126e311fb6c6526443cc813d619953d1bad7 /src/jemalloc.c | |
parent | 633aaff96787db82c06d35baf012de197a1a1902 (diff) | |
download | jemalloc-01b3fe55ff3ac8e4aa689f09fcb0729da8037638.zip jemalloc-01b3fe55ff3ac8e4aa689f09fcb0729da8037638.tar.gz jemalloc-01b3fe55ff3ac8e4aa689f09fcb0729da8037638.tar.bz2 |
Add a0malloc(), a0calloc(), and a0free().
Add a0malloc(), a0calloc(), and a0free(), which are used by FreeBSD's
libc to allocate/deallocate TLS in static binaries.
Diffstat (limited to 'src/jemalloc.c')
-rw-r--r-- | src/jemalloc.c | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/src/jemalloc.c b/src/jemalloc.c index a6d2df5..690cf08 100644 --- a/src/jemalloc.c +++ b/src/jemalloc.c @@ -1487,7 +1487,6 @@ je_nallocm(size_t *rsize, size_t size, int flags) * End experimental functions. */ /******************************************************************************/ - /* * The following functions are used by threading libraries for protection of * malloc during fork(). @@ -1552,3 +1551,55 @@ jemalloc_postfork_child(void) } /******************************************************************************/ +/* + * The following functions are used for TLS allocation/deallocation in static + * binaries on FreeBSD. The primary difference between these and i[mcd]alloc() + * is that these avoid accessing TLS variables. + */ + +static void * +a0alloc(size_t size, bool zero) +{ + + if (malloc_init()) + return (NULL); + + if (size == 0) + size = 1; + + if (size <= arena_maxclass) + return (arena_malloc(arenas[0], size, zero, false)); + else + return (huge_malloc(size, zero)); +} + +void * +a0malloc(size_t size) +{ + + return (a0alloc(size, false)); +} + +void * +a0calloc(size_t num, size_t size) +{ + + return (a0alloc(num * size, true)); +} + +void +a0free(void *ptr) +{ + arena_chunk_t *chunk; + + if (ptr == NULL) + return; + + chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr); + if (chunk != ptr) + arena_dalloc(chunk->arena, chunk, ptr, false); + else + huge_dalloc(ptr, true); +} + +/******************************************************************************/ |