Add a0malloc(), a0calloc(), and a0free().
Add a0malloc(), a0calloc(), and a0free(), which are used by FreeBSD's libc to allocate/deallocate TLS in static binaries.
This commit is contained in:
@@ -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);
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
Reference in New Issue
Block a user