Skip to content

Ptmalloc

Ptmalloc (pthreads malloc)

  • Used in Glibc
  • Biased off the pthreads malloc algorithm version 2
    • Improves heap management on child threads
    • Improves heap management for more than one heap on child process threads

Glibc Heap

Uses an arena which contains information about all of the heaps for the process. This is so that each thread has a separate heap.

Chunks

Malloc Chunk Structure

struct malloc_chunk {

  INTERNAL_SIZE_T      mchunk_prev_size;  /* Size of previous chunk (if free).  */
  INTERNAL_SIZE_T      mchunk_size;       /* Size in bytes, including overhead. */

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

  /* Only used for large blocks: pointer to next larger size.  */
  struct malloc_chunk* fd_nextsize; /* double links -- used only if free. */
  struct malloc_chunk* bk_nextsize;
};

House of Corrosion

https://github.com/CptGibbon/House-of-Corrosion