00001 #include "conv-config.h"
00002
00003 #if CMK_DLL_USE_DLOPEN && CMK_HAS_RTLD_NEXT
00004
00005
00006
00007
00008 #ifndef _GNU_SOURCE
00009 # define _GNU_SOURCE
00010 #endif
00011 #ifndef __USE_GNU
00012 # define __USE_GNU
00013 #endif
00014
00015 #include <sys/types.h>
00016 #include <dlfcn.h>
00017
00018 struct mallinfo;
00019
00020 extern void * (*mm_malloc)(size_t);
00021 extern void * (*mm_calloc)(size_t,size_t);
00022 extern void * (*mm_realloc)(void*,size_t);
00023 extern void * (*mm_memalign)(size_t,size_t);
00024 extern int (*mm_posix_memalign)(void **,size_t,size_t);
00025 extern void * (*mm_aligned_alloc)(size_t,size_t);
00026 extern void * (*mm_valloc)(size_t);
00027 extern void * (*mm_pvalloc)(size_t);
00028 extern void (*mm_free)(void*);
00029 extern void (*mm_cfree)(void*);
00030 extern struct mallinfo (*mm_mallinfo)(void);
00031
00032
00033 extern char initialize_memory_wrapper_status;
00034 char initialize_memory_wrapper_status;
00035
00036 void initialize_memory_wrapper() {
00037 initialize_memory_wrapper_status = 1;
00038
00039
00040 void * (*os_malloc)(size_t) = (void *(*)(size_t)) dlsym(RTLD_NEXT, "malloc");
00041 void * (*os_calloc)(size_t,size_t) = (void *(*)(size_t,size_t)) dlsym(RTLD_NEXT, "calloc");
00042 void (*os_free)(void*) = (void (*)(void*)) dlsym(RTLD_NEXT, "free");
00043
00044 mm_malloc = os_malloc;
00045 mm_calloc = os_calloc;
00046 mm_free = os_free;
00047
00048 mm_realloc = (void *(*)(void*,size_t)) dlsym(RTLD_NEXT, "realloc");
00049 mm_memalign = (void *(*)(size_t,size_t)) dlsym(RTLD_NEXT, "memalign");
00050 mm_posix_memalign = (int (*)(void **,size_t,size_t)) dlsym(RTLD_NEXT, "posix_memalign");
00051 mm_aligned_alloc = (void *(*)(size_t,size_t)) dlsym(RTLD_NEXT, "aligned_alloc");
00052 mm_valloc = (void *(*)(size_t)) dlsym(RTLD_NEXT, "valloc");
00053 mm_pvalloc = (void *(*)(size_t)) dlsym(RTLD_NEXT, "pvalloc");
00054 mm_cfree = (void (*)(void*)) dlsym(RTLD_NEXT, "cfree");
00055 mm_mallinfo = (struct mallinfo (*)(void)) dlsym(RTLD_NEXT, "mallinfo");
00056 }
00057
00058 #endif