void init_tbbmalloc() { #if MALLOC_LD_PRELOAD if (malloc_proxy && __TBB_internal_find_original_malloc) { const char *alloc_names[] = { "malloc", "free", "realloc", "calloc"}; void *orig_alloc_ptrs[4]; if (__TBB_internal_find_original_malloc(4, alloc_names, orig_alloc_ptrs)) { (void *&)original_malloc_ptr = orig_alloc_ptrs[0]; (void *&)original_free_ptr = orig_alloc_ptrs[1]; (void *&)original_realloc_ptr = orig_alloc_ptrs[2]; (void *&)original_calloc_ptr = orig_alloc_ptrs[3]; MALLOC_ASSERT( original_malloc_ptr!=malloc_proxy, "standard malloc not found" ); /* It's workaround for a bug in GNU Libc 2.9 (as it shipped with Fedora 10). 1st call to libc's malloc should be not from threaded code. */ original_free_ptr(original_malloc_ptr(1024)); original_malloc_found = 1; } } #endif /* MALLOC_LD_PRELOAD */ #if DO_ITT_NOTIFY MallocInitializeITT(); #endif }
void * __TBB_internal_malloc(size_t size) { if ( underRecursiveMallocFlag() ) { if ( original_malloc_found ){ return original_malloc_ptr(size); }else{ return NULL; } }else{ return (void*)scalable_malloc(size); } }
void * __TBB_internal_calloc(size_t num, size_t size) { if ( underRecursiveMallocFlag() ) { if ( original_malloc_found ){ #if __sun /* There seem to be run time problems on Solaris if original_calloc_ptr is used. */ size_t arraySize = num * size; void *result = original_malloc_ptr(arraySize); if (result) memset(result, 0, arraySize); return result; #else return original_calloc_ptr(num, size); #endif }else{ return NULL; } }else{ return scalable_calloc(num, size); } }
void init_tbbmalloc() { #if MALLOC_UNIXLIKE_OVERLOAD_ENABLED if (malloc_proxy && __TBB_internal_find_original_malloc) { const char *alloc_names[] = { "malloc", "free", "realloc", "calloc"}; void *orig_alloc_ptrs[4]; if (__TBB_internal_find_original_malloc(4, alloc_names, orig_alloc_ptrs)) { (void *&)original_malloc_ptr = orig_alloc_ptrs[0]; (void *&)original_free_ptr = orig_alloc_ptrs[1]; (void *&)original_realloc_ptr = orig_alloc_ptrs[2]; (void *&)original_calloc_ptr = orig_alloc_ptrs[3]; MALLOC_ASSERT( original_malloc_ptr!=malloc_proxy, "standard malloc not found" ); /* It's workaround for a bug in GNU Libc 2.9 (as it shipped with Fedora 10). 1st call to libc's malloc should be not from threaded code. */ original_free_ptr(original_malloc_ptr(1024)); original_malloc_found = 1; } } #endif /* MALLOC_UNIXLIKE_OVERLOAD_ENABLED */ #if DO_ITT_NOTIFY MallocInitializeITT(); #endif /* Preventing TBB allocator library from unloading to prevent resource leak, as memory is not released on the library unload. */ #if USE_WINTHREAD && !__TBB_SOURCE_DIRECTLY_INCLUDED && !__TBB_WIN8UI_SUPPORT // Prevent Windows from displaying message boxes if it fails to load library UINT prev_mode = SetErrorMode (SEM_FAILCRITICALERRORS); HMODULE lib; BOOL ret = GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |GET_MODULE_HANDLE_EX_FLAG_PIN, (LPCTSTR)&scalable_malloc, &lib); MALLOC_ASSERT(lib && ret, "Allocator can't find itself."); SetErrorMode (prev_mode); #endif /* USE_PTHREAD && !__TBB_SOURCE_DIRECTLY_INCLUDED */ }
void init_tbbmalloc() { #if MALLOC_LD_PRELOAD if (malloc_proxy && __TBB_internal_find_original_malloc) { const char *alloc_names[] = { "malloc", "free", "realloc", "calloc"}; void *orig_alloc_ptrs[4]; if (__TBB_internal_find_original_malloc(4, alloc_names, orig_alloc_ptrs)) { (void *&)original_malloc_ptr = orig_alloc_ptrs[0]; (void *&)original_free_ptr = orig_alloc_ptrs[1]; (void *&)original_realloc_ptr = orig_alloc_ptrs[2]; (void *&)original_calloc_ptr = orig_alloc_ptrs[3]; MALLOC_ASSERT( original_malloc_ptr!=malloc_proxy, "standard malloc not found" ); /* It's workaround for a bug in GNU Libc 2.9 (as it shipped with Fedora 10). 1st call to libc's malloc should be not from threaded code. */ original_free_ptr(original_malloc_ptr(1024)); original_malloc_found = 1; } } #endif /* MALLOC_LD_PRELOAD */ #if DO_ITT_NOTIFY MallocInitializeITT(); #endif /* Preventing TBB allocator library from unloading to prevent resource leak, as memory is not released on the library unload. */ #if USE_WINTHREAD // Prevent Windows from displaying message boxes if it fails to load library UINT prev_mode = SetErrorMode (SEM_FAILCRITICALERRORS); LoadLibrary(MALLOCLIB_NAME); SetErrorMode (prev_mode); #endif /* USE_PTHREAD */ }