diff options
author | jasone <jasone@FreeBSD.org> | 2012-04-17 07:22:14 +0000 |
---|---|---|
committer | jasone <jasone@FreeBSD.org> | 2012-04-17 07:22:14 +0000 |
commit | cbeacb7c46f3a3650e5dbefa9a1a18bc9943a8cc (patch) | |
tree | 24efdb5b31d087479e78f72f3b772bd5b02e470c /lib/libc/gen/tls.c | |
parent | 1bc364bf7eebf6139e4f968987974484d35c5cb4 (diff) | |
download | FreeBSD-src-cbeacb7c46f3a3650e5dbefa9a1a18bc9943a8cc.zip FreeBSD-src-cbeacb7c46f3a3650e5dbefa9a1a18bc9943a8cc.tar.gz |
Import jemalloc 9ef7f5dc34ff02f50d401e41c8d9a4a928e7c2aa (dev branch,
prior to 3.0.0 release) as contrib/jemalloc, and integrate it into libc.
The code being imported by this commit diverged from
lib/libc/stdlib/malloc.c in March 2010, which means that a portion of
the jemalloc 1.0.0 ChangeLog entries are relevant, as are the entries
for all subsequent releases.
Diffstat (limited to 'lib/libc/gen/tls.c')
-rw-r--r-- | lib/libc/gen/tls.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/libc/gen/tls.c b/lib/libc/gen/tls.c index abae57a..84b7ba5 100644 --- a/lib/libc/gen/tls.c +++ b/lib/libc/gen/tls.c @@ -39,6 +39,11 @@ #include "libc_private.h" +/* Provided by jemalloc to avoid bootstrapping issues. */ +void *a0malloc(size_t size); +void *a0calloc(size_t num, size_t size); +void a0free(void *ptr); + __weak_reference(__libc_allocate_tls, _rtld_allocate_tls); __weak_reference(__libc_free_tls, _rtld_free_tls); @@ -120,8 +125,8 @@ __libc_free_tls(void *tcb, size_t tcbsize, size_t tcbalign __unused) tls = (Elf_Addr **)((Elf_Addr)tcb + tcbsize - TLS_TCB_SIZE); dtv = tls[0]; - free(dtv); - free(tcb); + a0free(dtv); + a0free(tcb); } /* @@ -137,18 +142,18 @@ __libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign __unused) if (oldtcb != NULL && tcbsize == TLS_TCB_SIZE) return (oldtcb); - tcb = calloc(1, tls_static_space + tcbsize - TLS_TCB_SIZE); + tcb = a0calloc(1, tls_static_space + tcbsize - TLS_TCB_SIZE); tls = (Elf_Addr **)(tcb + tcbsize - TLS_TCB_SIZE); if (oldtcb != NULL) { memcpy(tls, oldtcb, tls_static_space); - free(oldtcb); + a0free(oldtcb); /* Adjust the DTV. */ dtv = tls[0]; dtv[2] = (Elf_Addr)tls + TLS_TCB_SIZE; } else { - dtv = malloc(3 * sizeof(Elf_Addr)); + dtv = a0malloc(3 * sizeof(Elf_Addr)); tls[0] = dtv; dtv[0] = 1; dtv[1] = 1; @@ -189,8 +194,8 @@ __libc_free_tls(void *tcb, size_t tcbsize __unused, size_t tcbalign) dtv = ((Elf_Addr**)tcb)[1]; tlsend = (Elf_Addr) tcb; tlsstart = tlsend - size; - free((void*) tlsstart); - free(dtv); + a0free((void*) tlsstart); + a0free(dtv); } /* @@ -208,8 +213,8 @@ __libc_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign) if (tcbsize < 2 * sizeof(Elf_Addr)) tcbsize = 2 * sizeof(Elf_Addr); - tls = calloc(1, size + tcbsize); - dtv = malloc(3 * sizeof(Elf_Addr)); + tls = a0calloc(1, size + tcbsize); + dtv = a0malloc(3 * sizeof(Elf_Addr)); segbase = (Elf_Addr)(tls + size); ((Elf_Addr*)segbase)[0] = segbase; |