首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

Glibc内存储器管理-ptmalloc2源代码分析(十八)

2012-07-31 
Glibc内存管理--ptmalloc2源代码分析(十八)5.5 Ptmalloc初始化?__malloc_ptr_t (*hook) (size_t, __const

Glibc内存管理--ptmalloc2源代码分析(十八)

5.5 Ptmalloc初始化

?

__malloc_ptr_t (*hook) (size_t, __const __malloc_ptr_t) = force_reg (__malloc_hook); if (__builtin_expect (hook != NULL, 0)) return (*hook)(bytes, RETURN_ADDRESS (0));

?在定义了__malloc_hook()全局函数的情况下,只是执行__malloc_hook()函数,在进程初始化时__malloc_hook指向的函数为malloc_hook_ini()。

__malloc_ptr_t weak_variable (*__malloc_hook)     (size_t __size, const __malloc_ptr_t) = malloc_hook_ini;

static Void_t*#if __STD_Cmalloc_hook_ini(size_t sz, const __malloc_ptr_t caller)#elsemalloc_hook_ini(sz, caller) size_t sz; const __malloc_ptr_t caller;#endif{ __malloc_hook = NULL; ptmalloc_init(); return public_mALLOc(sz);}

static Void_t*#if __STD_Cmalloc_starter(size_t sz, const Void_t *caller)#elsemalloc_starter(sz, caller) size_t sz; const Void_t *caller;#endif{ Void_t* victim; victim = _int_malloc(&main_arena, sz); return victim ? BOUNDED_N(victim, sz) : 0;}static Void_t*#if __STD_Cmemalign_starter(size_t align, size_t sz, const Void_t *caller)#elsememalign_starter(align, sz, caller) size_t align, sz; const Void_t *caller;#endif{ Void_t* victim; victim = _int_memalign(&main_arena, align, sz); return victim ? BOUNDED_N(victim, sz) : 0;}static void#if __STD_Cfree_starter(Void_t* mem, const Void_t *caller)#elsefree_starter(mem, caller) Void_t* mem; const Void_t *caller;#endif{ mchunkptr p; if(!mem) return; p = mem2chunk(mem);#if HAVE_MMAP if (chunk_is_mmapped(p)) { munmap_chunk(p); return; }#endif#ifdef ATOMIC_FASTBINS _int_free(&main_arena, p, 1);#else _int_free(&main_arena, p);#endif}

?

热点排行