-/* Copyright (c) 2010-2014. The SimGrid Team.
+/* Copyright (c) 2010-2015. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
#include <dlfcn.h>
-#include "../../mc/mc_base.h"
+#include "src/mc/mc_base.h"
#include "mmprivate.h"
-#include "xbt_modinter.h"
-#include "internal_config.h"
+#include "src/xbt_modinter.h"
+#include "src/internal_config.h"
#include <math.h>
-#include "../mc/mc_protocol.h"
+#include "src/mc/mc_protocol.h"
/* ***** Whether to use `mmalloc` of the undrlying malloc ***** */
return heap;
}
-#ifdef MMALLOC_WANT_OVERRIDE_LEGACY
+/* Override the malloc-like functions if MC is activated at compile time */
+#if HAVE_MC
/* ***** Temporary allocator
*
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;
mfree(mdp, p);
UNLOCK(mdp);
}
-#endif /* WANT_MALLOC_OVERRIDE */
+#endif /* HAVE_MC */