mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-05-14 00:46:21 +03:00
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:
parent
633aaff967
commit
01b3fe55ff
6 changed files with 89 additions and 29 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue