#include "dlmalloc.h"
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/param.h>
Data Structures | |
struct | malloc_chunk |
struct | malloc_params |
struct | malloc_segment |
struct | malloc_state |
struct | malloc_tree_chunk |
Macros | |
#define | ACQUIRE_MAGIC_INIT_LOCK() |
#define | ACQUIRE_MORECORE_LOCK() |
#define | align_as_chunk(A) (mchunkptr)((A) + align_offset(chunk2mem(A))) |
#define | align_offset(A) |
#define | assert(x) |
#define | bit_for_tree_index(i) (i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2) |
#define | CALL_MMAP(s) mmap(0, (s), MMAP_PROT, MMAP_FLAGS, -1, 0) |
#define | CALL_MORECORE(S) MORECORE(S) |
#define | CALL_MREMAP(addr, osz, nsz, mv) MFAIL |
#define | CALL_MUNMAP(a, s) munmap((a), (s)) |
#define | calloc_must_clear(p) (!is_mmapped(p)) |
#define | check_free_chunk(M, P) |
#define | check_inuse_chunk(M, P) |
#define | check_malloc_state(M) |
#define | check_malloced_chunk(M, P, N) |
#define | check_mmapped_chunk(M, P) |
#define | check_top_chunk(M, P) |
#define | chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES)) |
#define | CHUNK_ALIGN_MASK (MALLOC_ALIGNMENT - SIZE_T_ONE) |
#define | chunk_minus_offset(p, s) ((mchunkptr)(((char*)(p)) - (s))) |
#define | CHUNK_OVERHEAD (SIZE_T_SIZE) |
#define | chunk_plus_offset(p, s) ((mchunkptr)(((char*)(p)) + (s))) |
#define | chunksize(p) ((p)->head & ~(INUSE_BITS)) |
#define | cinuse(p) ((p)->head & CINUSE_BIT) |
#define | CINUSE_BIT (SIZE_T_TWO) |
#define | clear_cinuse(p) ((p)->head &= ~CINUSE_BIT) |
#define | clear_pinuse(p) ((p)->head &= ~PINUSE_BIT) |
#define | clear_smallmap(M, i) ((M)->smallmap &= ~idx2bit(i)) |
#define | clear_treemap(M, i) ((M)->treemap &= ~idx2bit(i)) |
#define | CMFAIL ((char*)(MFAIL)) /* defined for convenience */ |
#define | compute_bit2idx(X, I) |
#define | compute_tree_index(S, I) |
#define | CORRUPTION_ERROR_ACTION(m) ABORT |
#define | DIRECT_MMAP(s) CALL_MMAP(s) |
#define | disable_contiguous(M) ((M)->mflags |= USE_NONCONTIGUOUS_BIT) |
#define | disable_lock(M) ((M)->mflags &= ~USE_LOCK_BIT) |
#define | disable_mmap(M) ((M)->mflags &= ~USE_MMAP_BIT) |
#define | enable_lock(M) ((M)->mflags |= USE_LOCK_BIT) |
#define | enable_mmap(M) ((M)->mflags |= USE_MMAP_BIT) |
#define | EXTERN_BIT (8U) |
#define | FENCEPOST_HEAD (INUSE_BITS|SIZE_T_SIZE) |
#define | fm gm |
#define | FOUR_SIZE_T_SIZES (SIZE_T_SIZE<<2) |
#define | get_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_foot) |
#define | gm (&_gm_) |
#define | granularity_align(S) (((S) + (mparams.granularity)) & ~(mparams.granularity - SIZE_T_ONE)) |
#define | HALF_MAX_SIZE_T (MAX_SIZE_T / 2U) |
#define | idx2bit(i) ((binmap_t)(1) << (i)) |
#define | INITIAL_LOCK(l) |
#define | insert_chunk(M, P, S) |
#define | insert_large_chunk(M, X, S) |
#define | insert_small_chunk(M, P, S) |
#define | internal_free(m, mem) dlfree(mem) |
#define | internal_malloc(m, b) dlmalloc(b) |
#define | INUSE_BITS (PINUSE_BIT|CINUSE_BIT) |
#define | is_aligned(A) (((size_t)((A)) & (CHUNK_ALIGN_MASK)) == 0) |
#define | is_extern_segment(S) ((S)->sflags & EXTERN_BIT) |
#define | is_global(M) ((M) == &_gm_) |
#define | is_granularity_aligned(S) (((size_t)(S) & (mparams.granularity - SIZE_T_ONE)) == 0) |
#define | is_initialized(M) ((M)->top != 0) |
#define | is_mmapped(p) (!((p)->head & PINUSE_BIT) && ((p)->prev_foot & IS_MMAPPED_BIT)) |
#define | IS_MMAPPED_BIT (SIZE_T_ONE) |
#define | is_mmapped_segment(S) ((S)->sflags & IS_MMAPPED_BIT) |
#define | is_page_aligned(S) (((size_t)(S) & (mparams.page_size - SIZE_T_ONE)) == 0) |
#define | is_small(s) (((s) >> SMALLBIN_SHIFT) < NSMALLBINS) |
#define | least_bit(x) ((x) & -(x)) |
#define | left_bits(x) ((x<<1) | -(x<<1)) |
#define | leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1]) |
#define | leftshift_for_tree_index(i) |
#define | malloc_getpagesize ((size_t)4096U) |
#define | mark_inuse_foot(M, p, s) |
#define | mark_smallmap(M, i) ((M)->smallmap |= idx2bit(i)) |
#define | mark_treemap(M, i) ((M)->treemap |= idx2bit(i)) |
#define | MAX_REQUEST ((-MIN_CHUNK_SIZE) << 2) |
#define | MAX_SMALL_REQUEST (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD) |
#define | MAX_SMALL_SIZE (MIN_LARGE_SIZE - SIZE_T_ONE) |
#define | MCHUNK_SIZE (sizeof(mchunk)) |
#define | mem2chunk(mem) ((mchunkptr)((char*)(mem) - TWO_SIZE_T_SIZES)) |
#define | MFAIL ((void*)(MAX_SIZE_T)) |
#define | MIN_CHUNK_SIZE ((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) |
#define | MIN_LARGE_SIZE (SIZE_T_ONE << TREEBIN_SHIFT) |
#define | MIN_REQUEST (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE) |
#define | MIN_SMALL_INDEX (small_index(MIN_CHUNK_SIZE)) |
#define | minsize_for_tree_index(i) |
#define | MMAP_CHUNK_OVERHEAD (TWO_SIZE_T_SIZES) |
#define | MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS) |
#define | MMAP_FOOT_PAD (FOUR_SIZE_T_SIZES) |
#define | MMAP_PROT (PROT_READ|PROT_WRITE) |
#define | next_chunk(p) ((mchunkptr)( ((char*)(p)) + ((p)->head & ~INUSE_BITS))) |
#define | next_pinuse(p) ((next_chunk(p)->head) & PINUSE_BIT) |
#define | NSMALLBINS (32U) |
#define | NTREEBINS (32U) |
#define | ok_address(M, a) ((char*)(a) >= (M)->least_addr) |
#define | ok_cinuse(p) cinuse(p) |
#define | ok_magic(M) (1) |
#define | ok_next(p, n) ((char*)(p) < (char*)(n)) |
#define | ok_pinuse(p) pinuse(p) |
#define | overhead_for(p) (is_mmapped(p)? MMAP_CHUNK_OVERHEAD : CHUNK_OVERHEAD) |
#define | pad_request(req) (((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) |
#define | page_align(S) (((S) + (mparams.page_size)) & ~(mparams.page_size - SIZE_T_ONE)) |
#define | pinuse(p) ((p)->head & PINUSE_BIT) |
#define | PINUSE_BIT (SIZE_T_ONE) |
#define | POSTACTION(M) |
#define | PREACTION(M) (0) |
#define | prev_chunk(p) ((mchunkptr)( ((char*)(p)) - ((p)->prev_foot) )) |
#define | RELEASE_MAGIC_INIT_LOCK() |
#define | RELEASE_MORECORE_LOCK() |
#define | replace_dv(M, P, S) |
#define | request2size(req) (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req)) |
#define | RTCHECK(e) __builtin_expect(e, 1) |
#define | same_or_left_bits(x) ((x) | -(x)) |
#define | segment_holds(S, A) ((char*)(A) >= S->base && (char*)(A) < S->base + S->size) |
#define | set_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_foot = (s)) |
#define | set_free_with_pinuse(p, s, n) (clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s)) |
#define | set_inuse(M, p, s) |
#define | set_inuse_and_pinuse(M, p, s) |
#define | set_lock(M, L) |
#define | set_size_and_pinuse_of_free_chunk(p, s) ((p)->head = (s|PINUSE_BIT), set_foot(p, s)) |
#define | set_size_and_pinuse_of_inuse_chunk(M, p, s) ((p)->head = (s|PINUSE_BIT|CINUSE_BIT)) |
#define | should_trim(M, s) ((s) > (M)->trim_check) |
#define | SIX_SIZE_T_SIZES (FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES) |
#define | SIZE_T_BITSIZE (sizeof(size_t) << 3) |
#define | SIZE_T_ONE ((size_t)1) |
#define | SIZE_T_SIZE (sizeof(size_t)) |
#define | SIZE_T_TWO ((size_t)2) |
#define | SIZE_T_ZERO ((size_t)0) |
#define | small_index(s) ((s) >> SMALLBIN_SHIFT) |
#define | small_index2size(i) ((i) << SMALLBIN_SHIFT) |
#define | smallbin_at(M, i) ((sbinptr)((char*)&((M)->smallbins[(i)<<1]))) |
#define | SMALLBIN_SHIFT (3U) |
#define | SMALLBIN_WIDTH (SIZE_T_ONE << SMALLBIN_SHIFT) |
#define | smallmap_is_marked(M, i) ((M)->smallmap & idx2bit(i)) |
#define | TOP_FOOT_SIZE (align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE) |
#define | treebin_at(M, i) (&((M)->treebins[i])) |
#define | TREEBIN_SHIFT (8U) |
#define | treemap_is_marked(M, i) ((M)->treemap & idx2bit(i)) |
#define | TWO_SIZE_T_SIZES (SIZE_T_SIZE<<1) |
#define | unlink_chunk(M, P, S) |
#define | unlink_first_small_chunk(M, B, P, I) |
#define | unlink_large_chunk(M, X) |
#define | unlink_small_chunk(M, P, S) |
#define | USAGE_ERROR_ACTION(m, p) ABORT |
#define | use_lock(M) ((M)->mflags & USE_LOCK_BIT) |
#define | USE_LOCK_BIT (0U) |
#define | use_mmap(M) ((M)->mflags & USE_MMAP_BIT) |
#define | USE_MMAP_BIT (SIZE_T_ONE) |
#define | use_noncontiguous(M) ((M)->mflags & USE_NONCONTIGUOUS_BIT) |
#define | USE_NONCONTIGUOUS_BIT (4U) |
Typedefs | |
typedef unsigned int | bindex_t |
typedef unsigned int | binmap_t |
typedef unsigned int | flag_t |
typedef struct malloc_chunk | mchunk |
typedef struct malloc_chunk * | mchunkptr |
typedef struct malloc_segment | msegment |
typedef struct malloc_segment * | msegmentptr |
typedef struct malloc_state * | mstate |
typedef struct malloc_chunk * | sbinptr |
typedef struct malloc_tree_chunk * | tbinptr |
typedef struct malloc_tree_chunk | tchunk |
typedef struct malloc_tree_chunk * | tchunkptr |
Functions | |
static void | add_segment (mstate m, char *tbase, size_t tsize, flag_t mmapped) |
static int | change_mparam (int param_number, int value) |
void * | dlcalloc (size_t n_elements, size_t elem_size) |
void | dlfree (void *mem) |
void ** | dlindependent_calloc (size_t n_elements, size_t elem_size, void *chunks[]) |
void ** | dlindependent_comalloc (size_t n_elements, size_t sizes[], void *chunks[]) |
struct mallinfo | dlmallinfo (void) |
void * | dlmalloc (size_t bytes) |
size_t | dlmalloc_footprint (void) |
size_t | dlmalloc_max_footprint (void) |
void | dlmalloc_stats () |
int | dlmalloc_trim (size_t pad) |
size_t | dlmalloc_usable_size (void *mem) |
int | dlmallopt (int param_number, int value) |
void * | dlmemalign (size_t alignment, size_t bytes) |
void * | dlpvalloc (size_t bytes) |
void * | dlrealloc (void *oldmem, size_t bytes) |
void * | dlvalloc (size_t bytes) |
static int | has_segment_link (mstate m, msegmentptr ss) |
static void ** | ialloc (mstate m, size_t n_elements, size_t *sizes, int opts, void *chunks[]) |
static void | init_bins (mstate m) |
static int | init_mparams (void) |
static void | init_top (mstate m, mchunkptr p, size_t psize) |
static struct mallinfo | internal_mallinfo (mstate m) |
static void | internal_malloc_stats (mstate m) |
static void * | internal_memalign (mstate m, size_t alignment, size_t bytes) |
static void * | internal_realloc (mstate m, void *oldmem, size_t bytes) |
static void * | mmap_alloc (mstate m, size_t nb) |
static mchunkptr | mmap_resize (mstate m, mchunkptr oldp, size_t nb) |
static void * | prepend_alloc (mstate m, char *newbase, char *oldbase, size_t nb) |
static size_t | release_unused_segments (mstate m) |
static msegmentptr | segment_holding (mstate m, char *addr) |
static void * | sys_alloc (mstate m, size_t nb) |
static int | sys_trim (mstate m, size_t pad) |
static void * | tmalloc_large (mstate m, size_t nb) |
static void * | tmalloc_small (mstate m, size_t nb) |
Variables | |
static struct malloc_state | _gm_ |
static struct malloc_params | mparams |
#define ACQUIRE_MAGIC_INIT_LOCK | ( | ) |
Referenced by init_mparams().
#define ACQUIRE_MORECORE_LOCK | ( | ) |
Referenced by sys_alloc(), and sys_trim().
Referenced by internal_mallinfo(), internal_malloc_stats(), prepend_alloc(), and release_unused_segments().
#define align_offset | ( | A | ) |
Referenced by add_segment(), init_top(), and mmap_alloc().
#define assert | ( | x | ) |
Referenced by add_segment(), cmd_ping(), dlmalloc(), ialloc(), internal_memalign(), mmap_alloc(), prepend_alloc(), release_unused_segments(), tmalloc_large(), and tmalloc_small().
#define bit_for_tree_index | ( | i | ) | (i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2) |
#define CALL_MMAP | ( | s | ) | mmap(0, (s), MMAP_PROT, MMAP_FLAGS, -1, 0) |
Referenced by sys_alloc().
#define CALL_MORECORE | ( | S | ) | MORECORE(S) |
Referenced by sys_alloc(), and sys_trim().
#define CALL_MREMAP | ( | addr, | |
osz, | |||
nsz, | |||
mv | |||
) | MFAIL |
Referenced by mmap_resize(), and sys_trim().
Referenced by dlfree(), release_unused_segments(), and sys_trim().
#define calloc_must_clear | ( | p | ) | (!is_mmapped(p)) |
Referenced by dlcalloc().
#define check_free_chunk | ( | M, | |
P | |||
) |
Referenced by dlfree(), and prepend_alloc().
#define check_inuse_chunk | ( | M, | |
P | |||
) |
Referenced by dlfree(), ialloc(), internal_memalign(), and internal_realloc().
#define check_malloc_state | ( | M | ) |
Referenced by internal_mallinfo(), and internal_malloc_stats().
Referenced by dlmalloc(), prepend_alloc(), and sys_alloc().
#define check_mmapped_chunk | ( | M, | |
P | |||
) |
Referenced by mmap_alloc(), and mmap_resize().
#define check_top_chunk | ( | M, | |
P | |||
) |
Referenced by add_segment(), dlmalloc(), prepend_alloc(), sys_alloc(), and sys_trim().
#define chunk2mem | ( | p | ) | ((void*)((char*)(p) + TWO_SIZE_T_SIZES)) |
Referenced by add_segment(), dlmalloc(), ialloc(), init_top(), internal_memalign(), internal_realloc(), mmap_alloc(), prepend_alloc(), sys_alloc(), tmalloc_large(), and tmalloc_small().
#define CHUNK_ALIGN_MASK (MALLOC_ALIGNMENT - SIZE_T_ONE) |
Referenced by add_segment(), mmap_alloc(), and mmap_resize().
#define CHUNK_OVERHEAD (SIZE_T_SIZE) |
Referenced by ialloc(), and internal_memalign().
Referenced by add_segment(), dlfree(), dlmalloc(), ialloc(), init_top(), internal_memalign(), internal_realloc(), mmap_alloc(), mmap_resize(), prepend_alloc(), sys_alloc(), tmalloc_large(), and tmalloc_small().
#define chunksize | ( | p | ) | ((p)->head & ~(INUSE_BITS)) |
#define cinuse | ( | p | ) | ((p)->head & CINUSE_BIT) |
Referenced by dlfree(), dlmalloc_usable_size(), internal_mallinfo(), internal_malloc_stats(), prepend_alloc(), and release_unused_segments().
#define CINUSE_BIT (SIZE_T_TWO) |
Referenced by internal_memalign(), mmap_alloc(), and mmap_resize().
#define clear_cinuse | ( | p | ) | ((p)->head &= ~CINUSE_BIT) |
#define clear_pinuse | ( | p | ) | ((p)->head &= ~PINUSE_BIT) |
Referenced by mmap_alloc(), mmap_resize(), sys_alloc(), and sys_trim().
#define compute_bit2idx | ( | X, | |
I | |||
) |
Referenced by dlmalloc(), tmalloc_large(), and tmalloc_small().
#define compute_tree_index | ( | S, | |
I | |||
) |
Referenced by tmalloc_large().
#define CORRUPTION_ERROR_ACTION | ( | m | ) | ABORT |
Referenced by tmalloc_large(), and tmalloc_small().
Referenced by mmap_alloc().
#define disable_contiguous | ( | M | ) | ((M)->mflags |= USE_NONCONTIGUOUS_BIT) |
Referenced by sys_alloc().
#define disable_lock | ( | M | ) | ((M)->mflags &= ~USE_LOCK_BIT) |
#define disable_mmap | ( | M | ) | ((M)->mflags &= ~USE_MMAP_BIT) |
Referenced by ialloc().
#define enable_lock | ( | M | ) | ((M)->mflags |= USE_LOCK_BIT) |
#define enable_mmap | ( | M | ) | ((M)->mflags |= USE_MMAP_BIT) |
Referenced by ialloc().
#define EXTERN_BIT (8U) |
#define FENCEPOST_HEAD (INUSE_BITS|SIZE_T_SIZE) |
Referenced by add_segment(), internal_mallinfo(), internal_malloc_stats(), mmap_alloc(), and mmap_resize().
#define FOUR_SIZE_T_SIZES (SIZE_T_SIZE<<2) |
Referenced by add_segment().
#define gm (&_gm_) |
#define granularity_align | ( | S | ) | (((S) + (mparams.granularity)) & ~(mparams.granularity - SIZE_T_ONE)) |
Referenced by mmap_alloc(), mmap_resize(), and sys_alloc().
#define HALF_MAX_SIZE_T (MAX_SIZE_T / 2U) |
Referenced by sys_alloc(), and sys_trim().
Referenced by dlmalloc(), and tmalloc_large().
#define INITIAL_LOCK | ( | l | ) |
Referenced by init_mparams().
#define insert_chunk | ( | M, | |
P, | |||
S | |||
) |
Referenced by add_segment(), dlfree(), prepend_alloc(), and tmalloc_large().
#define insert_large_chunk | ( | M, | |
X, | |||
S | |||
) |
Referenced by release_unused_segments().
Referenced by internal_memalign(), and internal_realloc().
Referenced by ialloc(), internal_memalign(), and internal_realloc().
#define INUSE_BITS (PINUSE_BIT|CINUSE_BIT) |
Referenced by dlfree().
#define is_aligned | ( | A | ) | (((size_t)((A)) & (CHUNK_ALIGN_MASK)) == 0) |
Referenced by add_segment(), and mmap_alloc().
#define is_extern_segment | ( | S | ) | ((S)->sflags & EXTERN_BIT) |
Referenced by release_unused_segments(), sys_alloc(), and sys_trim().
Referenced by sys_alloc().
#define is_granularity_aligned | ( | S | ) | (((size_t)(S) & (mparams.granularity - SIZE_T_ONE)) == 0) |
Referenced by internal_mallinfo(), internal_malloc_stats(), sys_alloc(), and sys_trim().
#define is_mmapped | ( | p | ) | (!((p)->head & PINUSE_BIT) && ((p)->prev_foot & IS_MMAPPED_BIT)) |
Referenced by ialloc(), internal_memalign(), and internal_realloc().
#define IS_MMAPPED_BIT (SIZE_T_ONE) |
Referenced by dlfree(), mmap_alloc(), mmap_resize(), and sys_alloc().
#define is_mmapped_segment | ( | S | ) | ((S)->sflags & IS_MMAPPED_BIT) |
Referenced by release_unused_segments(), and sys_trim().
#define is_page_aligned | ( | S | ) | (((size_t)(S) & (mparams.page_size - SIZE_T_ONE)) == 0) |
Referenced by sys_alloc().
#define is_small | ( | s | ) | (((s) >> SMALLBIN_SHIFT) < NSMALLBINS) |
Referenced by mmap_resize().
Referenced by dlmalloc(), tmalloc_large(), and tmalloc_small().
Referenced by dlmalloc(), and tmalloc_large().
#define leftmost_child | ( | t | ) | ((t)->child[0] != 0? (t)->child[0] : (t)->child[1]) |
Referenced by tmalloc_large(), and tmalloc_small().
#define leftshift_for_tree_index | ( | i | ) |
Referenced by tmalloc_large().
#define malloc_getpagesize ((size_t)4096U) |
Referenced by init_mparams().
Referenced by mmap_alloc(), and mmap_resize().
#define MAX_REQUEST ((-MIN_CHUNK_SIZE) << 2) |
Referenced by dlmalloc(), internal_memalign(), internal_realloc(), and sys_trim().
#define MAX_SMALL_REQUEST (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD) |
Referenced by dlmalloc().
#define MAX_SMALL_SIZE (MIN_LARGE_SIZE - SIZE_T_ONE) |
#define MCHUNK_SIZE (sizeof(mchunk)) |
Referenced by init_mparams().
#define mem2chunk | ( | mem | ) | ((mchunkptr)((char*)(mem) - TWO_SIZE_T_SIZES)) |
Referenced by dlcalloc(), dlfree(), dlmalloc_usable_size(), dlrealloc(), ialloc(), internal_memalign(), internal_realloc(), and sys_alloc().
#define MFAIL ((void*)(MAX_SIZE_T)) |
Referenced by sys_trim().
#define MIN_CHUNK_SIZE ((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) |
Referenced by add_segment(), dlmalloc(), init_mparams(), internal_memalign(), internal_realloc(), prepend_alloc(), tmalloc_large(), and tmalloc_small().
#define MIN_LARGE_SIZE (SIZE_T_ONE << TREEBIN_SHIFT) |
#define MIN_REQUEST (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE) |
Referenced by dlmalloc().
#define MIN_SMALL_INDEX (small_index(MIN_CHUNK_SIZE)) |
#define minsize_for_tree_index | ( | i | ) |
#define MMAP_CHUNK_OVERHEAD (TWO_SIZE_T_SIZES) |
#define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS) |
#define MMAP_FOOT_PAD (FOUR_SIZE_T_SIZES) |
Referenced by dlfree(), mmap_alloc(), and mmap_resize().
#define MMAP_PROT (PROT_READ|PROT_WRITE) |
#define next_chunk | ( | p | ) | ((mchunkptr)( ((char*)(p)) + ((p)->head & ~INUSE_BITS))) |
Referenced by internal_mallinfo(), internal_malloc_stats(), and sys_alloc().
#define next_pinuse | ( | p | ) | ((next_chunk(p)->head) & PINUSE_BIT) |
#define NSMALLBINS (32U) |
Referenced by init_bins().
#define NTREEBINS (32U) |
Referenced by dlfree(), internal_realloc(), tmalloc_large(), and tmalloc_small().
#define ok_cinuse | ( | p | ) | cinuse(p) |
Referenced by dlfree(), and internal_realloc().
#define ok_magic | ( | M | ) | (1) |
Referenced by dlfree(), and dlrealloc().
Referenced by dlfree(), internal_realloc(), tmalloc_large(), and tmalloc_small().
#define ok_pinuse | ( | p | ) | pinuse(p) |
Referenced by dlfree(), and internal_realloc().
#define overhead_for | ( | p | ) | (is_mmapped(p)? MMAP_CHUNK_OVERHEAD : CHUNK_OVERHEAD) |
Referenced by dlmalloc_usable_size(), and internal_realloc().
#define pad_request | ( | req | ) | (((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) |
Referenced by add_segment(), and dlmalloc().
#define page_align | ( | S | ) | (((S) + (mparams.page_size)) & ~(mparams.page_size - SIZE_T_ONE)) |
Referenced by sys_alloc().
#define pinuse | ( | p | ) | ((p)->head & PINUSE_BIT) |
Referenced by dlfree(), and prepend_alloc().
#define PINUSE_BIT (SIZE_T_ONE) |
Referenced by dlfree(), dlmalloc(), init_top(), internal_realloc(), prepend_alloc(), and sys_alloc().
#define POSTACTION | ( | M | ) |
Referenced by dlfree(), dlmalloc(), dlmalloc_trim(), ialloc(), internal_mallinfo(), internal_malloc_stats(), internal_memalign(), and internal_realloc().
#define PREACTION | ( | M | ) | (0) |
Referenced by dlfree(), dlmalloc(), dlmalloc_trim(), ialloc(), internal_mallinfo(), internal_malloc_stats(), internal_memalign(), and internal_realloc().
#define prev_chunk | ( | p | ) | ((mchunkptr)( ((char*)(p)) - ((p)->prev_foot) )) |
#define RELEASE_MAGIC_INIT_LOCK | ( | ) |
Referenced by init_mparams().
#define RELEASE_MORECORE_LOCK | ( | ) |
Referenced by sys_alloc(), and sys_trim().
#define replace_dv | ( | M, | |
P, | |||
S | |||
) |
Referenced by dlmalloc(), and tmalloc_small().
#define request2size | ( | req | ) | (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req)) |
Referenced by ialloc(), internal_memalign(), and internal_realloc().
#define RTCHECK | ( | e | ) | __builtin_expect(e, 1) |
Referenced by dlfree(), internal_realloc(), tmalloc_large(), and tmalloc_small().
Referenced by internal_mallinfo(), internal_malloc_stats(), release_unused_segments(), and sys_alloc().
#define set_free_with_pinuse | ( | p, | |
s, | |||
n | |||
) | (clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s)) |
Referenced by add_segment(), dlfree(), and prepend_alloc().
Referenced by internal_memalign(), and internal_realloc().
Referenced by dlmalloc(), tmalloc_large(), and tmalloc_small().
#define set_lock | ( | M, | |
L | |||
) |
#define set_size_and_pinuse_of_free_chunk | ( | p, | |
s | |||
) | ((p)->head = (s|PINUSE_BIT), set_foot(p, s)) |
Referenced by dlfree(), dlmalloc(), prepend_alloc(), tmalloc_large(), and tmalloc_small().
#define set_size_and_pinuse_of_inuse_chunk | ( | M, | |
p, | |||
s | |||
) | ((p)->head = (s|PINUSE_BIT|CINUSE_BIT)) |
Referenced by add_segment(), dlmalloc(), ialloc(), prepend_alloc(), sys_alloc(), tmalloc_large(), and tmalloc_small().
#define SIX_SIZE_T_SIZES (FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES) |
Referenced by mmap_alloc(), and mmap_resize().
#define SIZE_T_BITSIZE (sizeof(size_t) << 3) |
Referenced by tmalloc_large().
#define SIZE_T_ONE ((size_t)1) |
Referenced by dlpvalloc(), init_mparams(), internal_mallinfo(), internal_memalign(), sys_alloc(), sys_trim(), and tmalloc_large().
#define SIZE_T_SIZE (sizeof(size_t)) |
Referenced by add_segment(), dlmalloc(), ialloc(), mmap_alloc(), and mmap_resize().
#define SIZE_T_TWO ((size_t)2) |
#define SIZE_T_ZERO ((size_t)0) |
#define small_index | ( | s | ) | ((s) >> SMALLBIN_SHIFT) |
Referenced by dlmalloc().
#define small_index2size | ( | i | ) | ((i) << SMALLBIN_SHIFT) |
Referenced by dlmalloc().
Referenced by dlmalloc(), and init_bins().
#define SMALLBIN_SHIFT (3U) |
#define SMALLBIN_WIDTH (SIZE_T_ONE << SMALLBIN_SHIFT) |
#define TOP_FOOT_SIZE (align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE) |
Referenced by add_segment(), init_top(), internal_mallinfo(), internal_malloc_stats(), release_unused_segments(), sys_alloc(), and sys_trim().
Referenced by tmalloc_large(), and tmalloc_small().
#define TREEBIN_SHIFT (8U) |
#define TWO_SIZE_T_SIZES (SIZE_T_SIZE<<1) |
#define unlink_chunk | ( | M, | |
P, | |||
S | |||
) |
Referenced by dlfree(), and prepend_alloc().
Referenced by dlmalloc().
#define unlink_large_chunk | ( | M, | |
X | |||
) |
Referenced by release_unused_segments(), tmalloc_large(), and tmalloc_small().
#define USAGE_ERROR_ACTION | ( | m, | |
p | |||
) | ABORT |
Referenced by dlfree(), dlrealloc(), and internal_realloc().
#define use_lock | ( | M | ) | ((M)->mflags & USE_LOCK_BIT) |
#define USE_LOCK_BIT (0U) |
Referenced by init_mparams().
#define use_mmap | ( | M | ) | ((M)->mflags & USE_MMAP_BIT) |
Referenced by ialloc(), and sys_alloc().
#define USE_MMAP_BIT (SIZE_T_ONE) |
Referenced by init_mparams().
#define use_noncontiguous | ( | M | ) | ((M)->mflags & USE_NONCONTIGUOUS_BIT) |
Referenced by sys_alloc().
#define USE_NONCONTIGUOUS_BIT (4U) |
Referenced by init_mparams().
typedef unsigned int bindex_t |
typedef unsigned int binmap_t |
typedef unsigned int flag_t |
typedef struct malloc_chunk mchunk |
typedef struct malloc_chunk* mchunkptr |
typedef struct malloc_segment msegment |
typedef struct malloc_segment* msegmentptr |
typedef struct malloc_state* mstate |
typedef struct malloc_chunk* sbinptr |
typedef struct malloc_tree_chunk* tbinptr |
typedef struct malloc_tree_chunk tchunk |
typedef struct malloc_tree_chunk* tchunkptr |
References align_offset, assert, malloc_segment::base, check_top_chunk, chunk2mem, CHUNK_ALIGN_MASK, chunk_plus_offset, FENCEPOST_HEAD, FOUR_SIZE_T_SIZES, malloc_chunk::head, init_top(), insert_chunk, is_aligned, MIN_CHUNK_SIZE, malloc_segment::next, pad_request, malloc_state::seg, segment_holding(), set_free_with_pinuse, set_size_and_pinuse_of_inuse_chunk, malloc_segment::sflags, malloc_segment::size, SIZE_T_SIZE, malloc_state::top, and TOP_FOOT_SIZE.
Referenced by sys_alloc().
|
static |
References malloc_params::granularity, init_mparams(), M_GRANULARITY, M_MMAP_THRESHOLD, M_TRIM_THRESHOLD, malloc_params::mmap_threshold, mparams, malloc_params::page_size, malloc_params::trim_threshold, and val.
Referenced by dlmallopt().
void* dlcalloc | ( | size_t | n_elements, |
size_t | elem_size | ||
) |
References calloc_must_clear, dlmalloc, MAX_SIZE_T, and mem2chunk.
void dlfree | ( | void * | mem | ) |
References CALL_MUNMAP, check_free_chunk, check_inuse_chunk, chunk_minus_offset, chunk_plus_offset, chunksize, cinuse, malloc_state::dv, malloc_state::dvsize, fm, malloc_state::footprint, malloc_chunk::head, insert_chunk, INUSE_BITS, IS_MMAPPED_BIT, mem2chunk, MMAP_FOOT_PAD, ok_address, ok_cinuse, ok_magic, ok_next, ok_pinuse, pinuse, PINUSE_BIT, POSTACTION, PREACTION, malloc_chunk::prev_foot, RTCHECK, set_free_with_pinuse, set_size_and_pinuse_of_free_chunk, should_trim, sys_trim(), malloc_state::top, malloc_state::topsize, unlink_chunk, and USAGE_ERROR_ACTION.
void** dlindependent_calloc | ( | size_t | n_elements, |
size_t | elem_size, | ||
void * | chunks[] | ||
) |
void** dlindependent_comalloc | ( | size_t | n_elements, |
size_t | sizes[], | ||
void * | chunks[] | ||
) |
struct mallinfo dlmallinfo | ( | void | ) |
References gm, and internal_mallinfo().
void* dlmalloc | ( | size_t | bytes | ) |
References assert, b, check_malloced_chunk, check_top_chunk, chunk2mem, chunk_plus_offset, chunksize, compute_bit2idx, malloc_chunk::fd, gm, malloc_chunk::head, i, idx2bit, least_bit, left_bits, MAX_REQUEST, MAX_SIZE_T, MAX_SMALL_REQUEST, MIN_CHUNK_SIZE, MIN_REQUEST, pad_request, PINUSE_BIT, POSTACTION, PREACTION, replace_dv, set_inuse_and_pinuse, set_size_and_pinuse_of_free_chunk, set_size_and_pinuse_of_inuse_chunk, SIZE_T_SIZE, small_index, small_index2size, smallbin_at, sys_alloc(), tmalloc_large(), tmalloc_small(), and unlink_first_small_chunk.
size_t dlmalloc_footprint | ( | void | ) |
References gm.
size_t dlmalloc_max_footprint | ( | void | ) |
References gm.
void dlmalloc_stats | ( | void | ) |
References gm, and internal_malloc_stats().
int dlmalloc_trim | ( | size_t | pad | ) |
References gm, POSTACTION, PREACTION, and sys_trim().
size_t dlmalloc_usable_size | ( | void * | mem | ) |
References chunksize, cinuse, mem2chunk, and overhead_for.
int dlmallopt | ( | int | param_number, |
int | value | ||
) |
References change_mparam().
void* dlmemalign | ( | size_t | alignment, |
size_t | bytes | ||
) |
References gm, and internal_memalign().
void* dlpvalloc | ( | size_t | bytes | ) |
References dlmemalign, init_mparams(), mparams, malloc_params::page_size, and SIZE_T_ONE.
void* dlrealloc | ( | void * | oldmem, |
size_t | bytes | ||
) |
References dlfree, dlmalloc, gm, internal_realloc(), mem2chunk, ok_magic, and USAGE_ERROR_ACTION.
void* dlvalloc | ( | size_t | bytes | ) |
References dlmemalign, init_mparams(), mparams, and malloc_params::page_size.
|
static |
References malloc_segment::base, malloc_segment::next, malloc_state::seg, and malloc_segment::size.
Referenced by sys_trim().
|
static |
References assert, check_inuse_chunk, chunk2mem, CHUNK_OVERHEAD, chunk_plus_offset, chunksize, disable_mmap, enable_mmap, i, internal_malloc, is_mmapped, mem2chunk, POSTACTION, PREACTION, request2size, set_size_and_pinuse_of_inuse_chunk, SIZE_T_SIZE, and use_mmap.
Referenced by dlindependent_calloc(), and dlindependent_comalloc().
|
static |
References malloc_chunk::bk, malloc_chunk::fd, i, NSMALLBINS, and smallbin_at.
Referenced by sys_alloc().
|
static |
References ABORT, ACQUIRE_MAGIC_INIT_LOCK, buf, close(), DEFAULT_GRANULARITY, malloc_params::default_mflags, DEFAULT_MMAP_THRESHOLD, DEFAULT_TRIM_THRESHOLD, gm, malloc_params::granularity, INITIAL_LOCK, malloc_params::magic, MALLOC_ALIGNMENT, malloc_getpagesize, MAX_SIZE_T, MCHUNK_SIZE, MIN_CHUNK_SIZE, malloc_params::mmap_threshold, mparams, O_RDONLY, open(), malloc_params::page_size, read(), RELEASE_MAGIC_INIT_LOCK, s, SIZE_T_ONE, malloc_params::trim_threshold, USE_LOCK_BIT, USE_MMAP_BIT, and USE_NONCONTIGUOUS_BIT.
Referenced by change_mparam(), dlpvalloc(), dlvalloc(), and sys_alloc().
References align_offset, chunk2mem, chunk_plus_offset, malloc_chunk::head, mparams, PINUSE_BIT, malloc_state::top, TOP_FOOT_SIZE, malloc_state::topsize, malloc_state::trim_check, and malloc_params::trim_threshold.
Referenced by add_segment(), sys_alloc(), and sys_trim().
References align_as_chunk, mallinfo::arena, malloc_segment::base, check_malloc_state, chunksize, cinuse, FENCEPOST_HEAD, malloc_state::footprint, mallinfo::fordblks, mallinfo::hblkhd, malloc_chunk::head, is_initialized, mallinfo::keepcost, malloc_state::max_footprint, malloc_segment::next, next_chunk, mallinfo::ordblks, POSTACTION, PREACTION, malloc_state::seg, segment_holds, SIZE_T_ONE, malloc_state::top, TOP_FOOT_SIZE, malloc_state::topsize, mallinfo::uordblks, and mallinfo::usmblks.
Referenced by dlmallinfo().
|
static |
References align_as_chunk, malloc_segment::base, check_malloc_state, chunksize, cinuse, FENCEPOST_HEAD, malloc_state::footprint, fprintf(), malloc_chunk::head, is_initialized, malloc_state::max_footprint, malloc_segment::next, next_chunk, POSTACTION, PREACTION, malloc_state::seg, segment_holds, malloc_state::top, TOP_FOOT_SIZE, and malloc_state::topsize.
Referenced by dlmalloc_stats().
|
static |
References a(), assert, check_inuse_chunk, chunk2mem, CHUNK_OVERHEAD, chunk_plus_offset, chunksize, CINUSE_BIT, malloc_chunk::head, internal_free, internal_malloc, is_mmapped, MALLOC_ALIGNMENT, MALLOC_FAILURE_ACTION, MAX_REQUEST, mem2chunk, MIN_CHUNK_SIZE, POSTACTION, PREACTION, malloc_chunk::prev_foot, request2size, set_inuse, and SIZE_T_ONE.
Referenced by dlmemalign().
|
static |
References check_inuse_chunk, chunk2mem, chunk_plus_offset, chunksize, malloc_chunk::head, internal_free, internal_malloc, is_mmapped, MALLOC_FAILURE_ACTION, MAX_REQUEST, mem2chunk, MIN_CHUNK_SIZE, mmap_resize(), ok_address, ok_cinuse, ok_next, ok_pinuse, overhead_for, PINUSE_BIT, POSTACTION, PREACTION, request2size, RTCHECK, set_inuse, malloc_state::top, malloc_state::topsize, and USAGE_ERROR_ACTION.
Referenced by dlrealloc().
|
static |
References align_offset, assert, check_mmapped_chunk, chunk2mem, CHUNK_ALIGN_MASK, chunk_plus_offset, CINUSE_BIT, CMFAIL, DIRECT_MMAP, FENCEPOST_HEAD, malloc_state::footprint, granularity_align, is_aligned, IS_MMAPPED_BIT, malloc_state::least_addr, mark_inuse_foot, malloc_state::max_footprint, MMAP_FOOT_PAD, malloc_chunk::prev_foot, SIX_SIZE_T_SIZES, and SIZE_T_SIZE.
Referenced by sys_alloc().
References CALL_MREMAP, check_mmapped_chunk, CHUNK_ALIGN_MASK, chunk_plus_offset, chunksize, CINUSE_BIT, CMFAIL, FENCEPOST_HEAD, malloc_state::footprint, malloc_params::granularity, granularity_align, malloc_chunk::head, IS_MMAPPED_BIT, is_small, malloc_state::least_addr, mark_inuse_foot, malloc_state::max_footprint, MMAP_FOOT_PAD, mparams, malloc_chunk::prev_foot, SIX_SIZE_T_SIZES, and SIZE_T_SIZE.
Referenced by internal_realloc().
|
static |
References align_as_chunk, assert, check_free_chunk, check_malloced_chunk, check_top_chunk, chunk2mem, chunk_plus_offset, chunksize, cinuse, malloc_state::dv, malloc_state::dvsize, malloc_chunk::head, insert_chunk, MIN_CHUNK_SIZE, pinuse, PINUSE_BIT, set_free_with_pinuse, set_size_and_pinuse_of_free_chunk, set_size_and_pinuse_of_inuse_chunk, malloc_state::top, malloc_state::topsize, and unlink_chunk.
Referenced by sys_alloc().
|
static |
References align_as_chunk, assert, malloc_segment::base, CALL_MUNMAP, chunksize, cinuse, malloc_state::dv, malloc_state::dvsize, malloc_state::footprint, insert_large_chunk, is_extern_segment, is_mmapped_segment, malloc_segment::next, malloc_state::seg, segment_holds, malloc_segment::size, TOP_FOOT_SIZE, and unlink_large_chunk.
Referenced by sys_trim().
|
static |
References malloc_segment::base, malloc_segment::next, malloc_state::seg, and malloc_segment::size.
Referenced by add_segment(), sys_alloc(), and sys_trim().
|
static |
References ACQUIRE_MORECORE_LOCK, add_segment(), malloc_segment::base, CALL_MMAP, CALL_MORECORE, check_malloced_chunk, check_top_chunk, chunk2mem, chunk_plus_offset, CMFAIL, disable_contiguous, end, malloc_state::footprint, granularity_align, HALF_MAX_SIZE_T, HAVE_MMAP, HAVE_MORECORE, malloc_chunk::head, init_bins(), init_mparams(), init_top(), is_extern_segment, is_global, is_initialized, IS_MMAPPED_BIT, is_page_aligned, malloc_state::least_addr, malloc_state::magic, malloc_params::magic, MALLOC_FAILURE_ACTION, malloc_state::max_footprint, mem2chunk, mmap_alloc(), malloc_params::mmap_threshold, MORECORE_CONTIGUOUS, mparams, malloc_segment::next, next_chunk, page_align, PINUSE_BIT, prepend_alloc(), RELEASE_MORECORE_LOCK, malloc_state::seg, segment_holding(), segment_holds, set_size_and_pinuse_of_inuse_chunk, malloc_segment::sflags, malloc_segment::size, SIZE_T_ONE, malloc_state::top, TOP_FOOT_SIZE, malloc_state::topsize, use_mmap, and use_noncontiguous.
Referenced by dlmalloc().
|
static |
References ACQUIRE_MORECORE_LOCK, malloc_segment::base, CALL_MORECORE, CALL_MREMAP, CALL_MUNMAP, check_top_chunk, CMFAIL, malloc_state::footprint, malloc_params::granularity, HALF_MAX_SIZE_T, has_segment_link(), HAVE_MMAP, HAVE_MORECORE, init_top(), is_extern_segment, is_initialized, is_mmapped_segment, MAX_REQUEST, MAX_SIZE_T, MFAIL, mparams, RELEASE_MORECORE_LOCK, release_unused_segments(), segment_holding(), malloc_segment::size, SIZE_T_ONE, malloc_state::top, TOP_FOOT_SIZE, malloc_state::topsize, and malloc_state::trim_check.
Referenced by dlfree(), and dlmalloc_trim().
|
static |
References assert, malloc_tree_chunk::child, chunk2mem, chunk_plus_offset, chunksize, compute_bit2idx, compute_tree_index, CORRUPTION_ERROR_ACTION, malloc_state::dvsize, i, idx2bit, insert_chunk, least_bit, left_bits, leftmost_child, leftshift_for_tree_index, MIN_CHUNK_SIZE, ok_address, ok_next, RTCHECK, set_inuse_and_pinuse, set_size_and_pinuse_of_free_chunk, set_size_and_pinuse_of_inuse_chunk, SIZE_T_BITSIZE, SIZE_T_ONE, treebin_at, malloc_state::treemap, and unlink_large_chunk.
Referenced by dlmalloc().
|
static |
References assert, chunk2mem, chunk_plus_offset, chunksize, compute_bit2idx, CORRUPTION_ERROR_ACTION, i, least_bit, leftmost_child, MIN_CHUNK_SIZE, ok_address, ok_next, replace_dv, RTCHECK, set_inuse_and_pinuse, set_size_and_pinuse_of_free_chunk, set_size_and_pinuse_of_inuse_chunk, treebin_at, malloc_state::treemap, and unlink_large_chunk.
Referenced by dlmalloc().
|
static |
|
static |
Referenced by change_mparam(), dlpvalloc(), dlvalloc(), init_mparams(), init_top(), mmap_resize(), sys_alloc(), and sys_trim().