summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2012-04-03 16:28:00 (GMT)
committerJason Evans <jasone@canonware.com>2012-04-04 02:25:48 (GMT)
commit01b3fe55ff3ac8e4aa689f09fcb0729da8037638 (patch)
tree259b126e311fb6c6526443cc813d619953d1bad7 /src
parent633aaff96787db82c06d35baf012de197a1a1902 (diff)
downloadjemalloc-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')
-rw-r--r--src/arena.c6
-rw-r--r--src/ctl.c2
-rw-r--r--src/jemalloc.c53
3 files changed, 56 insertions, 5 deletions
diff --git a/src/arena.c b/src/arena.c
index b7e1422..6444099 100644
--- a/src/arena.c
+++ b/src/arena.c
@@ -1888,7 +1888,7 @@ arena_ralloc_no_move(void *ptr, size_t oldsize, size_t size, size_t extra,
void *
arena_ralloc(void *ptr, size_t oldsize, size_t size, size_t extra,
- size_t alignment, bool zero)
+ size_t alignment, bool zero, bool try_tcache)
{
void *ret;
size_t copysize;
@@ -1909,7 +1909,7 @@ arena_ralloc(void *ptr, size_t oldsize, size_t size, size_t extra,
return (NULL);
ret = ipalloc(usize, alignment, zero);
} else
- ret = arena_malloc(size + extra, zero);
+ ret = arena_malloc(NULL, size + extra, zero, try_tcache);
if (ret == NULL) {
if (extra == 0)
@@ -1921,7 +1921,7 @@ arena_ralloc(void *ptr, size_t oldsize, size_t size, size_t extra,
return (NULL);
ret = ipalloc(usize, alignment, zero);
} else
- ret = arena_malloc(size, zero);
+ ret = arena_malloc(NULL, size, zero, try_tcache);
if (ret == NULL)
return (NULL);
diff --git a/src/ctl.c b/src/ctl.c
index 2afca51..6777688 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -1016,7 +1016,7 @@ thread_arena_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
int ret;
unsigned newind, oldind;
- newind = oldind = choose_arena()->ind;
+ newind = oldind = choose_arena(NULL)->ind;
WRITE(newind, unsigned);
READ(oldind, unsigned);
if (newind != oldind) {
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);
+}
+
+/******************************************************************************/