typedef struct _heap_info {
mstate ar_ptr; /* Arena for this heap. */
struct _heap_info * prev; /* Previous heap. */
size_t size; /* Current size in bytes. */
char pad[-5 * SIZE_SZ & MALLOC_ALIGN_MASK]; } heap_info;
struct malloc_state {
mutex_t mutex; /* Serialize access. */
int flags; /* Flags (formerly in max_fast). */
#if THREAD_STATS
/* Statistics for locking. Only used if THREAD_STATS is defined. */
long stat_lock_direct, stat_lock_loop, stat_lock_wait; #endif
mfastbinptr fastbins[NFASTBINS]; /* Fastbins */
mchunkptr top; 、
mchunkptr last_remainder;
mchunkptr bins[NBINS * 2];
unsigned int binmap[BINMAPSIZE]; /* Bitmap of bins */
struct malloc_state *next; /* Linked list */
INTERNAL_SIZE_T system_mem;
INTERNAL_SIZE_T max_system_mem;
};
struct malloc_chunk {
INTERNAL_SIZE_T prev_size;
INTERNAL_SIZE_T size;
struct malloc_chunk* fd;
struct malloc_chunk* bk;
}
1.分配的块通过指针算数遍历(借助 size )
2.空闲块通过循环链接列表遍历(借助 malloc_chunk fd 和 malloc_chunk bk )
??内存被 free 之后存储在称为 bin 的链接链表中,它们按照大小排序,以允许的最快速度进行检索。也就是说,释放内存后,它实际并没有返回操作系统,而是可能进行了碎片整理和合并,并存储在 bin 中的链接列表中,以便以后进行分配。
??Bin 分为 fastbin 和 normal bin
black hat heap exploitation 笔记
原文:https://www.cnblogs.com/luoleqi/p/12332909.html