capsule-malloc

capsule-malloc

Functions

int (*fputsfunc) ()
#define CAN_DEBUG_ALLOCS
#define FETCH_FPUTS
#define dump_ptr()
#define SIZE_SZ
#define chunk2mem()
#define mem2chunk()
#define chunk_is_mmapped()
#define chunk_non_main_arena()
#define fastbin()
#define fastbin_index()
#define MAX_FAST_SIZE
#define MALLOC_ALIGNMENT
#define MALLOC_ALIGN_MASK
#define MIN_CHUNK_SIZE
#define request2size()
#define NFASTBINS
#define BITSPERMAP
#define BINMAPSIZE
#define DEFAULT_MMAP_THRESHOLD_MAX
#define HEAP_MIN_SIZE
#define HEAP_MAX_SIZE
#define heap_for_ptr()
#define arena_for_chunk()
#define chunk_at_offset()
#define NONCONTIGUOUS_BIT
#define contiguous()
#define noncontiguous()
#define SIZE_BITS
#define chunksize()

Types and Values

#define CAPSULE_MALLOC_EXTRA_CHECKS
#define DEBUG_MALLOC_VOODOO
unsigned long x
ssize_t start
size_t c
struct malloc_chunk
typedef mchunkptr
#define IS_MMAPPED
#define PREV_INUSE
#define NON_MAIN_ARENA
typedef mfastbinptr
typedef mutex_t
#define MINSIZE
#define NBINS
#define BINMAPSHIFT
struct malloc_state
typedef mstate

Description

Functions

fputsfunc ()

int
(*fputsfunc) (const char *buf,
              FILE *s);

Returns


CAN_DEBUG_ALLOCS

#define CAN_DEBUG_ALLOCS (wf != NULL)


FETCH_FPUTS

#define             FETCH_FPUTS()


dump_ptr()

#define dump_ptr(a,b)


SIZE_SZ

#define SIZE_SZ (sizeof(size_t))


chunk2mem()

#define chunk2mem(p)   ((void*)((char*)(p) + 2*SIZE_SZ))


mem2chunk()

#define mem2chunk(mem) ((mchunkptr)((char*)(mem) - 2*SIZE_SZ))


chunk_is_mmapped()

#define chunk_is_mmapped(p)     ((p)->size & IS_MMAPPED)


chunk_non_main_arena()

#define chunk_non_main_arena(p) ((p)->size & NON_MAIN_ARENA)


fastbin()

#define fastbin(ar_ptr, idx) ((ar_ptr)->fastbinsY[idx])


fastbin_index()

#define             fastbin_index(sz)


MAX_FAST_SIZE

#define MAX_FAST_SIZE  (80 * SIZE_SZ / 4)


MALLOC_ALIGNMENT

#define             MALLOC_ALIGNMENT


MALLOC_ALIGN_MASK

#define MALLOC_ALIGN_MASK (MALLOC_ALIGNMENT - 1)


MIN_CHUNK_SIZE

#define MIN_CHUNK_SIZE    (offsetof(struct malloc_chunk, fd_nextsize))


request2size()

#define             request2size(req)


NFASTBINS

#define NFASTBINS   (fastbin_index (request2size (MAX_FAST_SIZE)) + 1)


BITSPERMAP

#define BITSPERMAP  (1U << BINMAPSHIFT)


BINMAPSIZE

#define BINMAPSIZE  (NBINS / BITSPERMAP)


DEFAULT_MMAP_THRESHOLD_MAX

#  define DEFAULT_MMAP_THRESHOLD_MAX (512 * 1024)


HEAP_MIN_SIZE

#define HEAP_MIN_SIZE (32 * 1024)


HEAP_MAX_SIZE

#  define HEAP_MAX_SIZE (2 * DEFAULT_MMAP_THRESHOLD_MAX)


heap_for_ptr()

#define             heap_for_ptr(ptr)


arena_for_chunk()

#define             arena_for_chunk(ptr)


chunk_at_offset()

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


NONCONTIGUOUS_BIT

#define NONCONTIGUOUS_BIT (2U)


contiguous()

#define contiguous(M)     (((M)->flags & NONCONTIGUOUS_BIT) == 0)


noncontiguous()

#define noncontiguous(M)  (((M)->flags & NONCONTIGUOUS_BIT) != 0)


SIZE_BITS

#define SIZE_BITS    (PREV_INUSE | IS_MMAPPED | NON_MAIN_ARENA)


chunksize()

#define chunksize(p) ((p)->size & ~(SIZE_BITS))

Types and Values

CAPSULE_MALLOC_EXTRA_CHECKS

#define CAPSULE_MALLOC_EXTRA_CHECKS


DEBUG_MALLOC_VOODOO

#define DEBUG_MALLOC_VOODOO 0


x

    unsigned long x = (unsigned long) ptr;


start

    ssize_t start = sizeof(long) * 2;


c

        size_t c = (x >> ((((sizeof(long) * 2) - 1) - i) * 4)) & 0b01111;


struct malloc_chunk

struct malloc_chunk {
  size_t               prev_size;  /* Size of previous chunk (if free).  */
  size_t               size;       /* Size in bytes, including overhead. */

  struct malloc_chunk* fd;         /* double links -- used only if free. */
  struct malloc_chunk* bk;

  struct malloc_chunk* fd_nextsize; /* double links -- used only if free. */
  struct malloc_chunk* bk_nextsize;
};


mchunkptr

typedef struct malloc_chunk* mchunkptr;


IS_MMAPPED

#define IS_MMAPPED     0x2


PREV_INUSE

#define PREV_INUSE     0x1


NON_MAIN_ARENA

#define NON_MAIN_ARENA 0x4


mfastbinptr

typedef struct malloc_chunk *mfastbinptr;


mutex_t

typedef int mutex_t;


MINSIZE

#define             MINSIZE


NBINS

#define NBINS       128


BINMAPSHIFT

#define BINMAPSHIFT 5


struct malloc_state

struct malloc_state {
  /* Serialize access.  */
  mutex_t mutex;

  /* Flags (formerly in max_fast).  */
  int flags;

  /* Fastbins */
  mfastbinptr fastbinsY[NFASTBINS];

  /* Base of the topmost chunk -- not otherwise kept in a bin */
  mchunkptr top;

  /* The remainder from the most recent split of a small request */
  mchunkptr last_remainder;

  /* Normal bins packed as described above */
  mchunkptr bins[NBINS * 2 - 2];

  /* Bitmap of bins */
  unsigned int binmap[BINMAPSIZE];

  /* Linked list */
  struct malloc_state *next;

  /* Linked list for free arenas.  Access to this field is serialized
     by free_list_lock in arena.c.  */
  struct malloc_state *next_free;

  /* Number of threads attached to this arena.  0 if the arena is on
     the free list.  Access to this field is serialized by
     free_list_lock in arena.c.  */
  size_t attached_threads;

  /* Memory allocated from the system in this arena.  */
  size_t system_mem;
  size_t max_system_mem;
};


mstate

typedef struct malloc_state *mstate;