static void xbt_preinit(void) { #ifdef MMALLOC_WANT_OVERRIDE_LEGACY mmalloc_preinit(); #endif xbt_log_preinit(); xbt_backtrace_preinit(); xbt_os_thread_mod_preinit(); xbt_fifo_preinit(); xbt_dict_preinit(); atexit(xbt_postexit); }
/** Constructor functions used to initialize the malloc implementation */ static void __attribute__((constructor(101))) mm_legacy_constructor() { if (mm_initialized) return; mm_initializing = 1; __malloc_use_mmalloc = getenv(MC_ENV_VARIABLE) ? 1 : 0; if (__malloc_use_mmalloc) { __mmalloc_current_heap = mmalloc_preinit(); } else { mm_real_realloc = dlsym(RTLD_NEXT, "realloc"); mm_real_malloc = dlsym(RTLD_NEXT, "malloc"); mm_real_free = dlsym(RTLD_NEXT, "free"); mm_real_calloc = dlsym(RTLD_NEXT, "calloc"); } mm_initializing = 0; mm_initialized = 1; }
/** Constructor functions used to initialize the malloc implementation */ XBT_ATTRIB_CONSTRUCTOR(101) static void mm_legacy_constructor() { if (mm_initialized) return; mm_initializing = 1; __malloc_use_mmalloc = getenv(MC_ENV_VARIABLE) ? 1 : 0; if (__malloc_use_mmalloc) { __mmalloc_current_heap = mmalloc_preinit(); } else { #if HAVE_DLFUNC mm_real_realloc = (void *(*)(void *, size_t))dlfunc(RTLD_NEXT, "realloc"); mm_real_malloc = (void *(*)(size_t))dlfunc(RTLD_NEXT, "malloc"); mm_real_free = (void (*)(void *))dlfunc(RTLD_NEXT, "free"); mm_real_calloc = (void *(*)(size_t, size_t))dlfunc(RTLD_NEXT, "calloc"); #else mm_real_realloc = dlsym(RTLD_NEXT, "realloc"); mm_real_malloc = dlsym(RTLD_NEXT, "malloc"); mm_real_free = dlsym(RTLD_NEXT, "free"); mm_real_calloc = dlsym(RTLD_NEXT, "calloc"); #endif } mm_initializing = 0; mm_initialized = 1; }
// This area is used to allocate memory at initilization time. if(allocated_junk && p==junkareas[allocated_junk-1]) { // Last junkarea. We can reuse it. allocated_junk--; } else { // We currently cannot reuse freed junkareas in the general case. } } } #else /* NO GNU_LD */ void *malloc(size_t n) { xbt_mheap_t mdp = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit(); LOCK(mdp); void *ret = mmalloc(mdp, n); UNLOCK(mdp); return ret; } void *calloc(size_t nmemb, size_t size) { xbt_mheap_t mdp = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit(); LOCK(mdp); void *ret = mmalloc(mdp, nmemb*size);