Classes | Defines | Typedefs | Functions | Variables
dlmalloc.c File Reference
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/param.h>
Include dependency graph for dlmalloc.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mallinfo
struct  malloc_chunk
struct  malloc_params
struct  malloc_segment
struct  malloc_state
struct  malloc_tree_chunk

Defines

#define ABORT   abort()
#define ABORT_ON_ASSERT_FAILURE   1
#define ACQUIRE_MALLOC_GLOBAL_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_DIRECT_MMAP(s)   DIRECT_MMAP_DEFAULT(s)
#define CALL_MMAP(s)   MMAP_DEFAULT(s)
#define CALL_MORECORE(S)   MORECORE_DEFAULT(S)
#define CALL_MREMAP(addr, osz, nsz, mv)   MFAIL
#define CALL_MUNMAP(a, s)   MUNMAP_DEFAULT((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 & ~(FLAG_BITS))
#define cinuse(p)   ((p)->head & CINUSE_BIT)
#define CINUSE_BIT   (SIZE_T_TWO)
#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 DEBUG   0
#define DEFAULT_GRANULARITY   (0) /* 0 means to compute in init_mparams */
#define DEFAULT_MMAP_THRESHOLD   ((size_t)256U * (size_t)1024U)
#define DEFAULT_TRIM_THRESHOLD   ((size_t)2U * (size_t)1024U * (size_t)1024U)
#define DIRECT_MMAP_DEFAULT(s)   MMAP_DEFAULT(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 DLMALLOC_VERSION   20804
#define enable_lock(M)   ((M)->mflags |= USE_LOCK_BIT)
#define enable_mmap(M)   ((M)->mflags |= USE_MMAP_BIT)
#define ensure_initialization()   (void)(mparams.magic != 0 || init_mparams())
#define EXTERN_BIT   (8U)
#define FENCEPOST_HEAD   (INUSE_BITS|SIZE_T_SIZE)
#define FLAG4_BIT   (SIZE_T_FOUR)
#define FLAG_BITS   (PINUSE_BIT|CINUSE_BIT|FLAG4_BIT)
#define fm   gm
#define FOOTERS   0
#define FORCEINLINE
#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)
#define HALF_MAX_SIZE_T   (MAX_SIZE_T / 2U)
#define HAVE_MMAP   1
#define HAVE_MORECORE   1
#define HAVE_MREMAP   0
#define idx2bit(i)   ((binmap_t)(1) << (i))
#define INITIAL_LOCK(l)
#define INSECURE   0
#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_inuse(p)   (((p)->head & INUSE_BITS) != PINUSE_BIT)
#define is_mmapped(p)   (((p)->head & INUSE_BITS) == 0)
#define is_mmapped_segment(S)   ((S)->sflags & USE_MMAP_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 M_GRANULARITY   (-2)
#define M_MMAP_THRESHOLD   (-3)
#define M_TRIM_THRESHOLD   (-1)
#define MALLINFO_FIELD_TYPE   size_t
#define MALLOC_ALIGNMENT   ((size_t)8U)
#define MALLOC_FAILURE_ACTION   errno = ENOMEM;
#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_RELEASE_CHECK_RATE   4095
#define MAX_REQUEST   ((-MIN_CHUNK_SIZE) << 2)
#define MAX_SIZE_T   (~(size_t)0)
#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_align(S)   page_align(S)
#define MMAP_CHUNK_OVERHEAD   (TWO_SIZE_T_SIZES)
#define MMAP_CLEARS   1
#define MMAP_DEFAULT(s)
#define MMAP_FLAGS   (MAP_PRIVATE)
#define MMAP_FOOT_PAD   (FOUR_SIZE_T_SIZES)
#define MMAP_PROT   (PROT_READ|PROT_WRITE)
#define MORECORE_CONTIGUOUS   1
#define MORECORE_DEFAULT   sbrk
#define MSPACES   0
#define MUNMAP_DEFAULT(a, s)   munmap((a), (s))
#define next_chunk(p)   ((mchunkptr)( ((char*)(p)) + ((p)->head & ~FLAG_BITS)))
#define next_pinuse(p)   ((next_chunk(p)->head) & PINUSE_BIT)
#define NO_MALLINFO   0
#define NO_SEGMENT_TRAVERSAL   1
#define NOINLINE
#define NSMALLBINS   (32U)
#define NTREEBINS   (32U)
#define ok_address(M, a)   ((char*)(a) >= (M)->least_addr)
#define ok_inuse(p)   is_inuse(p)
#define ok_magic(M)   (1)
#define ok_next(p, n)   ((char*)(p) < (char*)(n))
#define ok_pinuse(p)   pinuse(p)
#define ONLY_MSPACES   0 /* define to a value */
#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 - SIZE_T_ONE)) & ~(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 PROCEED_ON_ERROR   0
#define RELEASE_MALLOC_GLOBAL_LOCK()
#define replace_dv(M, P, S)
#define request2size(req)   (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req))
#define RTCHECK(e)   (e)
#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_FOUR   ((size_t)4)
#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 SPIN_LOCKS_AVAILABLE   0
#define STRUCT_MALLINFO_DECLARED   1
#define SYS_ALLOC_PADDING   (TOP_FOOT_SIZE + MALLOC_ALIGNMENT)
#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_BUILTIN_FFS   0
#define USE_DEV_RANDOM   0
#define USE_DL_PREFIX
#define use_lock(M)   ((M)->mflags & USE_LOCK_BIT)
#define USE_LOCK_BIT   (0U)
#define USE_LOCKS   0
#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)
#define USE_SPIN_LOCKS   0

Typedefs

typedef unsigned int bindex_t
typedef unsigned int binmap_t
typedef unsigned int flag_t
typedef struct malloc_chunk mchunk
typedef struct malloc_chunkmchunkptr
typedef struct malloc_segment msegment
typedef struct malloc_segmentmsegmentptr
typedef struct malloc_statemstate
typedef struct malloc_chunksbinptr
typedef struct malloc_tree_chunktbinptr
typedef struct malloc_tree_chunk tchunk
typedef struct malloc_tree_chunktchunkptr

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, size_t)
void dlfree (void *)
void ** dlindependent_calloc (size_t, size_t, void **)
void ** dlindependent_calloc (size_t n_elements, size_t elem_size, void *chunks[])
void ** dlindependent_comalloc (size_t, size_t *, void **)
void ** dlindependent_comalloc (size_t n_elements, size_t sizes[], void *chunks[])
struct mallinfo dlmallinfo (void)
void * dlmalloc (size_t)
size_t dlmalloc_footprint (void)
size_t dlmalloc_max_footprint (void)
void dlmalloc_stats (void)
int dlmalloc_trim (size_t)
size_t dlmalloc_usable_size (void *)
int dlmallopt (int, int)
void * dlmemalign (size_t, size_t)
void * dlpvalloc (size_t)
void * dlrealloc (void *, size_t)
void * dlvalloc (size_t)
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 int dev_zero_fd = -1
static struct malloc_params mparams

Define Documentation

#define ABORT   abort()

Definition at line 568 of file dlmalloc.c.

#define ABORT_ON_ASSERT_FAILURE   1

Definition at line 571 of file dlmalloc.c.

Definition at line 1916 of file dlmalloc.c.

#define align_as_chunk (   A)    (mchunkptr)((A) + align_offset(chunk2mem(A)))

Definition at line 2095 of file dlmalloc.c.

#define align_offset (   A)
Value:
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :\
  ((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))

Definition at line 1463 of file dlmalloc.c.

#define assert (   x)

Definition at line 1310 of file dlmalloc.c.

#define bit_for_tree_index (   i)    (i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2)

Definition at line 2758 of file dlmalloc.c.

#define CALL_DIRECT_MMAP (   s)    DIRECT_MMAP_DEFAULT(s)

Definition at line 1584 of file dlmalloc.c.

#define CALL_MMAP (   s)    MMAP_DEFAULT(s)

Definition at line 1574 of file dlmalloc.c.

#define CALL_MORECORE (   S)    MORECORE_DEFAULT(S)

Define CALL_MORECORE

Definition at line 1559 of file dlmalloc.c.

#define CALL_MREMAP (   addr,
  osz,
  nsz,
  mv 
)    MFAIL

Define CALL_MREMAP

Definition at line 1607 of file dlmalloc.c.

#define CALL_MUNMAP (   a,
 
)    MUNMAP_DEFAULT((a), (s))

Definition at line 1579 of file dlmalloc.c.

#define calloc_must_clear (   p)    (!is_mmapped(p))

Definition at line 2168 of file dlmalloc.c.

#define check_free_chunk (   M,
 
)

Definition at line 2652 of file dlmalloc.c.

#define check_inuse_chunk (   M,
 
)

Definition at line 2653 of file dlmalloc.c.

#define check_malloc_state (   M)

Definition at line 2656 of file dlmalloc.c.

#define check_malloced_chunk (   M,
  P,
 
)

Definition at line 2654 of file dlmalloc.c.

#define check_mmapped_chunk (   M,
 
)

Definition at line 2655 of file dlmalloc.c.

#define check_top_chunk (   M,
 
)

Definition at line 2657 of file dlmalloc.c.

#define chunk2mem (   p)    ((void*)((char*)(p) + TWO_SIZE_T_SIZES))

Definition at line 2092 of file dlmalloc.c.

Definition at line 1457 of file dlmalloc.c.

#define chunk_minus_offset (   p,
 
)    ((mchunkptr)(((char*)(p)) - (s)))

Definition at line 2141 of file dlmalloc.c.

#define CHUNK_OVERHEAD   (SIZE_T_SIZE)

Definition at line 2079 of file dlmalloc.c.

#define chunk_plus_offset (   p,
 
)    ((mchunkptr)(((char*)(p)) + (s)))

Definition at line 2140 of file dlmalloc.c.

#define chunksize (   p)    ((p)->head & ~(FLAG_BITS))

Definition at line 2135 of file dlmalloc.c.

#define cinuse (   p)    ((p)->head & CINUSE_BIT)

Definition at line 2130 of file dlmalloc.c.

#define CINUSE_BIT   (SIZE_T_TWO)

Definition at line 2121 of file dlmalloc.c.

#define clear_pinuse (   p)    ((p)->head &= ~PINUSE_BIT)

Definition at line 2137 of file dlmalloc.c.

#define clear_smallmap (   M,
  i 
)    ((M)->smallmap &= ~idx2bit(i))

Definition at line 2779 of file dlmalloc.c.

#define clear_treemap (   M,
  i 
)    ((M)->treemap &= ~idx2bit(i))

Definition at line 2783 of file dlmalloc.c.

#define CMFAIL   ((char*)(MFAIL)) /* defined for convenience */

Definition at line 1478 of file dlmalloc.c.

#define compute_bit2idx (   X,
 
)
Value:
{\
  unsigned int Y = X - 1;\
  unsigned int K = Y >> (16-4) & 16;\
  unsigned int N = K;        Y >>= K;\
  N += K = Y >> (8-3) &  8;  Y >>= K;\
  N += K = Y >> (4-2) &  4;  Y >>= K;\
  N += K = Y >> (2-1) &  2;  Y >>= K;\
  N += K = Y >> (1-0) &  1;  Y >>= K;\
  I = (bindex_t)(N + Y);\
}

Definition at line 2825 of file dlmalloc.c.

#define compute_tree_index (   S,
 
)
Value:
{\
  size_t X = S >> TREEBIN_SHIFT;\
  if (X == 0)\
    I = 0;\
  else if (X > 0xFFFF)\
    I = NTREEBINS-1;\
  else {\
    unsigned int Y = (unsigned int)X;\
    unsigned int N = ((Y - 0x100) >> 16) & 8;\
    unsigned int K = (((Y <<= N) - 0x1000) >> 16) & 4;\
    N += K;\
    N += K = (((Y <<= K) - 0x4000) >> 16) & 2;\
    K = 14 - N + ((Y <<= K) >> 15);\
    I = (K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1));\
  }\
}

Definition at line 2738 of file dlmalloc.c.

#define CORRUPTION_ERROR_ACTION (   m)    ABORT

Definition at line 2639 of file dlmalloc.c.

#define DEBUG   0

Definition at line 1312 of file dlmalloc.c.

#define DEFAULT_GRANULARITY   (0) /* 0 means to compute in init_mparams */

Definition at line 622 of file dlmalloc.c.

#define DEFAULT_MMAP_THRESHOLD   ((size_t)256U * (size_t)1024U)

Definition at line 636 of file dlmalloc.c.

#define DEFAULT_TRIM_THRESHOLD   ((size_t)2U * (size_t)1024U * (size_t)1024U)

Definition at line 629 of file dlmalloc.c.

#define DIRECT_MMAP_DEFAULT (   s)    MMAP_DEFAULT(s)

Definition at line 1504 of file dlmalloc.c.

#define disable_contiguous (   M)    ((M)->mflags |= USE_NONCONTIGUOUS_BIT)

Definition at line 2520 of file dlmalloc.c.

#define disable_lock (   M)    ((M)->mflags &= ~USE_LOCK_BIT)

Definition at line 2513 of file dlmalloc.c.

#define disable_mmap (   M)    ((M)->mflags &= ~USE_MMAP_BIT)

Definition at line 2517 of file dlmalloc.c.

#define DLMALLOC_VERSION   20804

Definition at line 490 of file dlmalloc.c.

#define enable_lock (   M)    ((M)->mflags |= USE_LOCK_BIT)

Definition at line 2512 of file dlmalloc.c.

#define enable_mmap (   M)    ((M)->mflags |= USE_MMAP_BIT)

Definition at line 2516 of file dlmalloc.c.

#define ensure_initialization ( )    (void)(mparams.magic != 0 || init_mparams())

Definition at line 2494 of file dlmalloc.c.

#define EXTERN_BIT   (8U)

Definition at line 1614 of file dlmalloc.c.

Definition at line 2127 of file dlmalloc.c.

#define FLAG4_BIT   (SIZE_T_FOUR)

Definition at line 2122 of file dlmalloc.c.

Definition at line 2124 of file dlmalloc.c.

#define fm   gm
#define FOOTERS   0

Definition at line 565 of file dlmalloc.c.

#define FORCEINLINE

Definition at line 752 of file dlmalloc.c.

#define FOUR_SIZE_T_SIZES   (SIZE_T_SIZE<<2)

Definition at line 1452 of file dlmalloc.c.

#define get_foot (   p,
 
)    (((mchunkptr)((char*)(p) + (s)))->prev_foot)

Definition at line 2151 of file dlmalloc.c.

#define gm   (&_gm_)

Definition at line 2500 of file dlmalloc.c.

#define granularity_align (   S)
Value:

Definition at line 2532 of file dlmalloc.c.

#define HALF_MAX_SIZE_T   (MAX_SIZE_T / 2U)

Definition at line 1454 of file dlmalloc.c.

#define HAVE_MMAP   1

Definition at line 590 of file dlmalloc.c.

#define HAVE_MORECORE   1

Definition at line 609 of file dlmalloc.c.

#define HAVE_MREMAP   0

Definition at line 599 of file dlmalloc.c.

#define idx2bit (   i)    ((binmap_t)(1) << (i))

Definition at line 2775 of file dlmalloc.c.

#define INITIAL_LOCK (   l)

Definition at line 1905 of file dlmalloc.c.

#define INSECURE   0

Definition at line 587 of file dlmalloc.c.

#define insert_chunk (   M,
  P,
 
)
Value:
if (is_small(S)) insert_small_chunk(M, P, S)\
  else { tchunkptr TP = (tchunkptr)(P); insert_large_chunk(M, TP, S); }

Definition at line 3630 of file dlmalloc.c.

#define insert_large_chunk (   M,
  X,
 
)

Definition at line 3489 of file dlmalloc.c.

#define insert_small_chunk (   M,
  P,
 
)
Value:
{\
  bindex_t I  = small_index(S);\
  mchunkptr B = smallbin_at(M, I);\
  mchunkptr F = B;\
  assert(S >= MIN_CHUNK_SIZE);\
  if (!smallmap_is_marked(M, I))\
    mark_smallmap(M, I);\
  else if (RTCHECK(ok_address(M, B->fd)))\
    F = B->fd;\
  else {\
    CORRUPTION_ERROR_ACTION(M);\
  }\
  B->fd = P;\
  F->bk = P;\
  P->fd = F;\
  P->bk = B;\
}

Definition at line 3416 of file dlmalloc.c.

#define internal_free (   m,
  mem 
)    dlfree(mem)

Definition at line 3652 of file dlmalloc.c.

#define internal_malloc (   m,
  b 
)    dlmalloc(b)

Definition at line 3651 of file dlmalloc.c.

Definition at line 2123 of file dlmalloc.c.

#define is_aligned (   A)    (((size_t)((A)) & (CHUNK_ALIGN_MASK)) == 0)

Definition at line 1460 of file dlmalloc.c.

#define is_extern_segment (   S)    ((S)->sflags & EXTERN_BIT)

Definition at line 2348 of file dlmalloc.c.

#define is_global (   M)    ((M) == &_gm_)

Definition at line 2501 of file dlmalloc.c.

#define is_granularity_aligned (   S)    (((size_t)(S) & (mparams.granularity - SIZE_T_ONE)) == 0)

Definition at line 2549 of file dlmalloc.c.

#define is_initialized (   M)    ((M)->top != 0)

Definition at line 2505 of file dlmalloc.c.

#define is_inuse (   p)    (((p)->head & INUSE_BITS) != PINUSE_BIT)

Definition at line 2132 of file dlmalloc.c.

#define is_mmapped (   p)    (((p)->head & INUSE_BITS) == 0)

Definition at line 2133 of file dlmalloc.c.

#define is_mmapped_segment (   S)    ((S)->sflags & USE_MMAP_BIT)

Definition at line 2347 of file dlmalloc.c.

#define is_page_aligned (   S)    (((size_t)(S) & (mparams.page_size - SIZE_T_ONE)) == 0)

Definition at line 2547 of file dlmalloc.c.

#define is_small (   s)    (((s) >> SMALLBIN_SHIFT) < NSMALLBINS)

Definition at line 2683 of file dlmalloc.c.

#define least_bit (   x)    ((x) & -(x))

Definition at line 2787 of file dlmalloc.c.

#define left_bits (   x)    ((x<<1) | -(x<<1))

Definition at line 2790 of file dlmalloc.c.

#define leftmost_child (   t)    ((t)->child[0] != 0? (t)->child[0] : (t)->child[1])

Definition at line 2281 of file dlmalloc.c.

#define leftshift_for_tree_index (   i)
Value:
((i == NTREEBINS-1)? 0 : \
    ((SIZE_T_BITSIZE-SIZE_T_ONE) - (((i) >> 1) + TREEBIN_SHIFT - 2)))

Definition at line 2762 of file dlmalloc.c.

#define M_GRANULARITY   (-2)

Definition at line 672 of file dlmalloc.c.

#define M_MMAP_THRESHOLD   (-3)

Definition at line 673 of file dlmalloc.c.

#define M_TRIM_THRESHOLD   (-1)

Definition at line 671 of file dlmalloc.c.

#define MALLINFO_FIELD_TYPE   size_t

Definition at line 658 of file dlmalloc.c.

#define MALLOC_ALIGNMENT   ((size_t)8U)

Definition at line 562 of file dlmalloc.c.

#define MALLOC_FAILURE_ACTION   errno = ENOMEM;

Definition at line 603 of file dlmalloc.c.

#define malloc_getpagesize   ((size_t)4096U)

Definition at line 1426 of file dlmalloc.c.

#define mark_inuse_foot (   M,
  p,
 
)

Definition at line 2907 of file dlmalloc.c.

#define mark_smallmap (   M,
  i 
)    ((M)->smallmap |= idx2bit(i))

Definition at line 2778 of file dlmalloc.c.

#define mark_treemap (   M,
  i 
)    ((M)->treemap |= idx2bit(i))

Definition at line 2782 of file dlmalloc.c.

#define MAX_RELEASE_CHECK_RATE   4095

Definition at line 643 of file dlmalloc.c.

#define MAX_REQUEST   ((-MIN_CHUNK_SIZE) << 2)

Definition at line 2098 of file dlmalloc.c.

#define MAX_SIZE_T   (~(size_t)0)

Definition at line 547 of file dlmalloc.c.

Definition at line 2445 of file dlmalloc.c.

Definition at line 2444 of file dlmalloc.c.

#define MCHUNK_SIZE   (sizeof(mchunk))

Definition at line 2074 of file dlmalloc.c.

#define mem2chunk (   mem)    ((mchunkptr)((char*)(mem) - TWO_SIZE_T_SIZES))

Definition at line 2093 of file dlmalloc.c.

#define MFAIL   ((void*)(MAX_SIZE_T))

Definition at line 1477 of file dlmalloc.c.

Definition at line 2088 of file dlmalloc.c.

Definition at line 2443 of file dlmalloc.c.

Definition at line 2099 of file dlmalloc.c.

Definition at line 2686 of file dlmalloc.c.

#define minsize_for_tree_index (   i)
Value:
((SIZE_T_ONE << (((i) >> 1) + TREEBIN_SHIFT)) |  \
   (((size_t)((i) & SIZE_T_ONE)) << (((i) >> 1) + TREEBIN_SHIFT - 1)))

Definition at line 2767 of file dlmalloc.c.

#define mmap_align (   S)    page_align(S)

Definition at line 2541 of file dlmalloc.c.

Definition at line 2083 of file dlmalloc.c.

#define MMAP_CLEARS   1

Definition at line 593 of file dlmalloc.c.

#define MMAP_DEFAULT (   s)
Value:
((dev_zero_fd < 0) ? \
           (dev_zero_fd = open("/dev/zero", O_RDWR), \
            mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) : \
            mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0))

Definition at line 1498 of file dlmalloc.c.

#define MMAP_FLAGS   (MAP_PRIVATE)

Definition at line 1496 of file dlmalloc.c.

Definition at line 2085 of file dlmalloc.c.

#define MMAP_PROT   (PROT_READ|PROT_WRITE)

Definition at line 1484 of file dlmalloc.c.

#define MORECORE_CONTIGUOUS   1

Definition at line 617 of file dlmalloc.c.

#define MORECORE_DEFAULT   sbrk

Definition at line 615 of file dlmalloc.c.

#define MSPACES   0

Definition at line 558 of file dlmalloc.c.

#define MUNMAP_DEFAULT (   a,
 
)    munmap((a), (s))

Definition at line 1483 of file dlmalloc.c.

#define next_chunk (   p)    ((mchunkptr)( ((char*)(p)) + ((p)->head & ~FLAG_BITS)))

Definition at line 2144 of file dlmalloc.c.

#define next_pinuse (   p)    ((next_chunk(p)->head) & PINUSE_BIT)

Definition at line 2148 of file dlmalloc.c.

#define NO_MALLINFO   0

Definition at line 655 of file dlmalloc.c.

#define NO_SEGMENT_TRAVERSAL   1

Definition at line 486 of file dlmalloc.c.

#define NOINLINE

Definition at line 741 of file dlmalloc.c.

#define NSMALLBINS   (32U)

Definition at line 2438 of file dlmalloc.c.

#define NTREEBINS   (32U)

Definition at line 2439 of file dlmalloc.c.

#define ok_address (   M,
  a 
)    ((char*)(a) >= (M)->least_addr)

Definition at line 2869 of file dlmalloc.c.

#define ok_inuse (   p)    is_inuse(p)

Definition at line 2873 of file dlmalloc.c.

#define ok_magic (   M)    (1)

Definition at line 2888 of file dlmalloc.c.

#define ok_next (   p,
 
)    ((char*)(p) < (char*)(n))

Definition at line 2871 of file dlmalloc.c.

#define ok_pinuse (   p)    pinuse(p)

Definition at line 2875 of file dlmalloc.c.

#define ONLY_MSPACES   0 /* define to a value */

Definition at line 550 of file dlmalloc.c.

Definition at line 2163 of file dlmalloc.c.

#define pad_request (   req)    (((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK)

Definition at line 2102 of file dlmalloc.c.

#define page_align (   S)    (((S) + (mparams.page_size - SIZE_T_ONE)) & ~(mparams.page_size - SIZE_T_ONE))

Definition at line 2528 of file dlmalloc.c.

#define pinuse (   p)    ((p)->head & PINUSE_BIT)

Definition at line 2131 of file dlmalloc.c.

#define PINUSE_BIT   (SIZE_T_ONE)

Definition at line 2120 of file dlmalloc.c.

#define POSTACTION (   M)

Definition at line 2612 of file dlmalloc.c.

#define PREACTION (   M)    (0)

Definition at line 2608 of file dlmalloc.c.

#define prev_chunk (   p)    ((mchunkptr)( ((char*)(p)) - ((p)->prev_foot) ))

Definition at line 2145 of file dlmalloc.c.

#define PROCEED_ON_ERROR   0

Definition at line 574 of file dlmalloc.c.

Definition at line 1917 of file dlmalloc.c.

#define replace_dv (   M,
  P,
 
)
Value:
{\
  size_t DVS = M->dvsize;\
  if (DVS != 0) {\
    mchunkptr DV = M->dv;\
    assert(is_small(DVS));\
    insert_small_chunk(M, DV, DVS);\
  }\
  M->dvsize = S;\
  M->dv = P;\
}

Definition at line 3475 of file dlmalloc.c.

#define request2size (   req)    (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req))

Definition at line 2106 of file dlmalloc.c.

#define RTCHECK (   e)    (e)

Definition at line 2897 of file dlmalloc.c.

#define same_or_left_bits (   x)    ((x) | -(x))

Definition at line 2793 of file dlmalloc.c.

#define segment_holds (   S,
  A 
)    ((char*)(A) >= S->base && (char*)(A) < S->base + S->size)

Definition at line 2553 of file dlmalloc.c.

#define set_foot (   p,
 
)    (((mchunkptr)((char*)(p) + (s)))->prev_foot = (s))

Definition at line 2152 of file dlmalloc.c.

#define set_free_with_pinuse (   p,
  s,
 
)    (clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s))

Definition at line 2159 of file dlmalloc.c.

#define set_inuse (   M,
  p,
 
)
Value:
((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\
  ((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT)

Definition at line 2912 of file dlmalloc.c.

#define set_inuse_and_pinuse (   M,
  p,
 
)
Value:
((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\
  ((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT)

Definition at line 2917 of file dlmalloc.c.

#define set_lock (   M,
 
)
Value:
((M)->mflags = (L)?\
  ((M)->mflags | USE_LOCK_BIT) :\
  ((M)->mflags & ~USE_LOCK_BIT))

Definition at line 2522 of file dlmalloc.c.

#define set_size_and_pinuse_of_free_chunk (   p,
 
)    ((p)->head = (s|PINUSE_BIT), set_foot(p, s))

Definition at line 2155 of file dlmalloc.c.

#define set_size_and_pinuse_of_inuse_chunk (   M,
  p,
 
)    ((p)->head = (s|PINUSE_BIT|CINUSE_BIT))

Definition at line 2922 of file dlmalloc.c.

#define should_trim (   M,
 
)    ((s) > (M)->trim_check)

Definition at line 2579 of file dlmalloc.c.

Definition at line 1453 of file dlmalloc.c.

#define SIZE_T_BITSIZE   (sizeof(size_t) << 3)

Definition at line 1443 of file dlmalloc.c.

#define SIZE_T_FOUR   ((size_t)4)

Definition at line 1450 of file dlmalloc.c.

#define SIZE_T_ONE   ((size_t)1)

Definition at line 1448 of file dlmalloc.c.

#define SIZE_T_SIZE   (sizeof(size_t))

Definition at line 1442 of file dlmalloc.c.

#define SIZE_T_TWO   ((size_t)2)

Definition at line 1449 of file dlmalloc.c.

#define SIZE_T_ZERO   ((size_t)0)

Definition at line 1447 of file dlmalloc.c.

#define small_index (   s)    ((s) >> SMALLBIN_SHIFT)

Definition at line 2684 of file dlmalloc.c.

#define small_index2size (   i)    ((i) << SMALLBIN_SHIFT)

Definition at line 2685 of file dlmalloc.c.

#define smallbin_at (   M,
  i 
)    ((sbinptr)((char*)&((M)->smallbins[(i)<<1])))

Definition at line 2689 of file dlmalloc.c.

#define SMALLBIN_SHIFT   (3U)

Definition at line 2440 of file dlmalloc.c.

Definition at line 2441 of file dlmalloc.c.

#define smallmap_is_marked (   M,
  i 
)    ((M)->smallmap & idx2bit(i))

Definition at line 2780 of file dlmalloc.c.

#define SPIN_LOCKS_AVAILABLE   0

Definition at line 543 of file dlmalloc.c.

#define STRUCT_MALLINFO_DECLARED   1

Definition at line 706 of file dlmalloc.c.

Definition at line 2545 of file dlmalloc.c.

Definition at line 2589 of file dlmalloc.c.

#define treebin_at (   M,
  i 
)    (&((M)->treebins[i]))

Definition at line 2690 of file dlmalloc.c.

#define TREEBIN_SHIFT   (8U)

Definition at line 2442 of file dlmalloc.c.

#define treemap_is_marked (   M,
  i 
)    ((M)->treemap & idx2bit(i))

Definition at line 2784 of file dlmalloc.c.

#define TWO_SIZE_T_SIZES   (SIZE_T_SIZE<<1)

Definition at line 1451 of file dlmalloc.c.

#define unlink_chunk (   M,
  P,
 
)
Value:
if (is_small(S)) unlink_small_chunk(M, P, S)\
  else { tchunkptr TP = (tchunkptr)(P); unlink_large_chunk(M, TP); }

Definition at line 3634 of file dlmalloc.c.

#define unlink_first_small_chunk (   M,
  B,
  P,
 
)
Value:
{\
  mchunkptr F = P->fd;\
  assert(P != B);\
  assert(P != F);\
  assert(chunksize(P) == small_index2size(I));\
  if (B == F)\
    clear_smallmap(M, I);\
  else if (RTCHECK(ok_address(M, F))) {\
    B->fd = F;\
    F->bk = B;\
  }\
  else {\
    CORRUPTION_ERROR_ACTION(M);\
  }\
}

Definition at line 3455 of file dlmalloc.c.

#define unlink_large_chunk (   M,
  X 
)

Definition at line 3557 of file dlmalloc.c.

#define unlink_small_chunk (   M,
  P,
 
)
Value:
{\
  mchunkptr F = P->fd;\
  mchunkptr B = P->bk;\
  bindex_t I = small_index(S);\
  assert(P != B);\
  assert(P != F);\
  assert(chunksize(P) == small_index2size(I));\
  if (F == B)\
    clear_smallmap(M, I);\
  else if (RTCHECK((F == smallbin_at(M,I) || ok_address(M, F)) &&\
                   (B == smallbin_at(M,I) || ok_address(M, B)))) {\
    F->bk = B;\
    B->fd = F;\
  }\
  else {\
    CORRUPTION_ERROR_ACTION(M);\
  }\
}

Definition at line 3435 of file dlmalloc.c.

#define USAGE_ERROR_ACTION (   m,
 
)    ABORT

Definition at line 2643 of file dlmalloc.c.

#define USE_BUILTIN_FFS   0

Definition at line 649 of file dlmalloc.c.

#define USE_DEV_RANDOM   0

Definition at line 652 of file dlmalloc.c.

#define USE_DL_PREFIX

Definition at line 483 of file dlmalloc.c.

#define use_lock (   M)    ((M)->mflags & USE_LOCK_BIT)

Definition at line 2511 of file dlmalloc.c.

#define USE_LOCK_BIT   (0U)

Definition at line 1904 of file dlmalloc.c.

#define USE_LOCKS   0

Definition at line 577 of file dlmalloc.c.

#define use_mmap (   M)    ((M)->mflags & USE_MMAP_BIT)

Definition at line 2515 of file dlmalloc.c.

#define USE_MMAP_BIT   (SIZE_T_ONE)

Define CALL_MMAP/CALL_MUNMAP/CALL_DIRECT_MMAP

Definition at line 1569 of file dlmalloc.c.

#define use_noncontiguous (   M)    ((M)->mflags & USE_NONCONTIGUOUS_BIT)

Definition at line 2519 of file dlmalloc.c.

#define USE_NONCONTIGUOUS_BIT   (4U)

Definition at line 1611 of file dlmalloc.c.

#define USE_SPIN_LOCKS   0

Definition at line 583 of file dlmalloc.c.


Typedef Documentation

typedef unsigned int bindex_t

Definition at line 2068 of file dlmalloc.c.

typedef unsigned int binmap_t

Definition at line 2069 of file dlmalloc.c.

typedef unsigned int flag_t

Definition at line 2070 of file dlmalloc.c.

typedef struct malloc_chunk mchunk

Definition at line 2065 of file dlmalloc.c.

typedef struct malloc_chunk* mchunkptr

Definition at line 2066 of file dlmalloc.c.

typedef struct malloc_segment msegment

Definition at line 2350 of file dlmalloc.c.

typedef struct malloc_segment* msegmentptr

Definition at line 2351 of file dlmalloc.c.

typedef struct malloc_state* mstate

Definition at line 2471 of file dlmalloc.c.

typedef struct malloc_chunk* sbinptr

Definition at line 2067 of file dlmalloc.c.

typedef struct malloc_tree_chunk* tbinptr

Definition at line 2278 of file dlmalloc.c.

typedef struct malloc_tree_chunk tchunk

Definition at line 2276 of file dlmalloc.c.

typedef struct malloc_tree_chunk* tchunkptr

Definition at line 2277 of file dlmalloc.c.


Function Documentation

static void add_segment ( mstate  m,
char *  tbase,
size_t  tsize,
flag_t  mmapped 
) [static]

Definition at line 3816 of file dlmalloc.c.

static int change_mparam ( int  param_number,
int  value 
) [static]

Definition at line 3039 of file dlmalloc.c.

void * dlcalloc ( size_t  n_elements,
size_t  elem_size 
)

Definition at line 4838 of file dlmalloc.c.

void dlfree ( void *  mem)

Definition at line 4729 of file dlmalloc.c.

void** dlindependent_calloc ( size_t  ,
size_t  ,
void **   
)
void** dlindependent_calloc ( size_t  n_elements,
size_t  elem_size,
void *  chunks[] 
)

Definition at line 4880 of file dlmalloc.c.

void** dlindependent_comalloc ( size_t  ,
size_t *  ,
void **   
)
void** dlindependent_comalloc ( size_t  n_elements,
size_t  sizes[],
void *  chunks[] 
)

Definition at line 4886 of file dlmalloc.c.

struct mallinfo dlmallinfo ( void  ) [read]

Definition at line 4924 of file dlmalloc.c.

void * dlmalloc ( size_t  bytes)

Definition at line 4593 of file dlmalloc.c.

size_t dlmalloc_footprint ( void  )

Definition at line 4915 of file dlmalloc.c.

size_t dlmalloc_max_footprint ( void  )

Definition at line 4919 of file dlmalloc.c.

void dlmalloc_stats ( void  )

Definition at line 4929 of file dlmalloc.c.

int dlmalloc_trim ( size_t  pad)

Definition at line 4905 of file dlmalloc.c.

size_t dlmalloc_usable_size ( void *  mem)

Definition at line 4939 of file dlmalloc.c.

int dlmallopt ( int  param_number,
int  value 
)

Definition at line 4933 of file dlmalloc.c.

void * dlmemalign ( size_t  alignment,
size_t  bytes 
)

Definition at line 4876 of file dlmalloc.c.

void * dlpvalloc ( size_t  bytes)

Definition at line 4898 of file dlmalloc.c.

void * dlrealloc ( void *  oldmem,
size_t  bytes 
)

Definition at line 4853 of file dlmalloc.c.

void * dlvalloc ( size_t  bytes)

Definition at line 4891 of file dlmalloc.c.

static int has_segment_link ( mstate  m,
msegmentptr  ss 
) [static]

Definition at line 2568 of file dlmalloc.c.

static void** ialloc ( mstate  m,
size_t  n_elements,
size_t *  sizes,
int  opts,
void *  chunks[] 
) [static]

Definition at line 4461 of file dlmalloc.c.

static void init_bins ( mstate  m) [static]

Definition at line 3745 of file dlmalloc.c.

static int init_mparams ( void  ) [static]

Definition at line 2954 of file dlmalloc.c.

static void init_top ( mstate  m,
mchunkptr  p,
size_t  psize 
) [static]

Definition at line 3730 of file dlmalloc.c.

static struct mallinfo internal_mallinfo ( mstate  m) [static, read]

Definition at line 3333 of file dlmalloc.c.

static void internal_malloc_stats ( mstate  m) [static]

Definition at line 3373 of file dlmalloc.c.

static void* internal_memalign ( mstate  m,
size_t  alignment,
size_t  bytes 
) [static]

Definition at line 4374 of file dlmalloc.c.

static void* internal_realloc ( mstate  m,
void *  oldmem,
size_t  bytes 
) [static]

Definition at line 4299 of file dlmalloc.c.

static void* mmap_alloc ( mstate  m,
size_t  nb 
) [static]

Definition at line 3667 of file dlmalloc.c.

static mchunkptr mmap_resize ( mstate  m,
mchunkptr  oldp,
size_t  nb 
) [static]

Definition at line 3694 of file dlmalloc.c.

static void* prepend_alloc ( mstate  m,
char *  newbase,
char *  oldbase,
size_t  nb 
) [static]

Definition at line 3774 of file dlmalloc.c.

static size_t release_unused_segments ( mstate  m) [static]

Definition at line 4074 of file dlmalloc.c.

static msegmentptr segment_holding ( mstate  m,
char *  addr 
) [static]

Definition at line 2557 of file dlmalloc.c.

static void* sys_alloc ( mstate  m,
size_t  nb 
) [static]

Definition at line 3871 of file dlmalloc.c.

static int sys_trim ( mstate  m,
size_t  pad 
) [static]

Definition at line 4121 of file dlmalloc.c.

static void* tmalloc_large ( mstate  m,
size_t  nb 
) [static]

Definition at line 4189 of file dlmalloc.c.

static void* tmalloc_small ( mstate  m,
size_t  nb 
) [static]

Definition at line 4260 of file dlmalloc.c.


Variable Documentation

struct malloc_state _gm_ [static]

Definition at line 2499 of file dlmalloc.c.

int dev_zero_fd = -1 [static]

Definition at line 1497 of file dlmalloc.c.

struct malloc_params mparams [static]

Definition at line 2491 of file dlmalloc.c.



libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:34:05