Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Check for a dlfunc() function to get handle if present
authorMatthieu Volat <mazhe@alkumuna.eu>
Mon, 7 Nov 2016 11:25:21 +0000 (12:25 +0100)
committerdegomme <augustin.degomme@unibas.ch>
Mon, 7 Nov 2016 13:33:23 +0000 (14:33 +0100)
dlfunc() is a (for now) FreeBSD-only function that is to be used when
trying to retrieve function handles from code segments, rather
than dlsym(), but let's make the code generic in case somebody else
likes the idea...

CMakeLists.txt
src/xbt/mmalloc/mm_legacy.c
tools/cmake/src/internal_config.h.in

index aa1e753..d1bf3e8 100644 (file)
@@ -305,6 +305,7 @@ CHECK_INCLUDE_FILE("ucontext.h" HAVE_UCONTEXT_H)
 CHECK_INCLUDE_FILE("linux/futex.h" HAVE_FUTEX_H)
 
 CHECK_FUNCTION_EXISTS(backtrace HAVE_BACKTRACE)
+CHECK_FUNCTION_EXISTS(dlfunc HAVE_DLFUNC)
 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
 CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
 CHECK_FUNCTION_EXISTS(getdtablesize HAVE_GETDTABLESIZE)
index 1652eb4..790ead6 100644 (file)
@@ -123,10 +123,17 @@ static void __attribute__((constructor(101))) mm_legacy_constructor()
   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;
index 172bc4c..b5c7fdc 100644 (file)
@@ -59,6 +59,7 @@
 
 /* Other function checks */
 #define HAVE_BACKTRACE @HAVE_BACKTRACE@ /* Function backtrace */
+#define HAVE_DLFUNC    @HAVE_DLFUNC@ /* Function dlfunc */
 #define HAVE_MMAP      @HAVE_MMAP@ /* Function mmap */
 #define HAVE_MREMAP    @HAVE_MREMAP@ /* Function mremap */
 #define HAVE_SEM_INIT  @HAVE_SEM_INIT@ /* Function sem_init (part of XPG6 standard only) */
@@ -69,4 +70,4 @@
 /* Other checks */
 #cmakedefine ADDR2LINE       "@ADDR2LINE@" /* Path to the addr2line tool */
 #define HAVE_GRAPHVIZ   @HAVE_GRAPHVIZ@ /* The graphviz library */
-#define HAVE_LIBUNWIND  @HAVE_LIBUNWIND@ /* The lib unwind library (for MC and backtrace display) */
\ No newline at end of file
+#define HAVE_LIBUNWIND  @HAVE_LIBUNWIND@ /* The lib unwind library (for MC and backtrace display) */