git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7932
48e7efb5-ca39-0410-a469-
dd3cf9ba447f
static void *__mmalloc_current_heap=NULL; /* The heap we are currently using. */
static void *__mmalloc_current_heap=NULL; /* The heap we are currently using. */
+#include "xbt_modinter.h"
+
void* mmalloc_get_current_heap(void) {
return __mmalloc_current_heap;
}
void* mmalloc_get_current_heap(void) {
return __mmalloc_current_heap;
}
#ifdef MMALLOC_WANT_OVERIDE_LEGACY
void *malloc(size_t n) {
#ifdef MMALLOC_WANT_OVERIDE_LEGACY
void *malloc(size_t n) {
+#ifdef HAVE_MMAP
+ if (!__mmalloc_current_heap) mmalloc_preinit();
+#endif
void *ret = mmalloc(__mmalloc_current_heap, n);
return ret;
void *ret = mmalloc(__mmalloc_current_heap, n);
return ret;
void *calloc(size_t nmemb, size_t size) {
size_t total_size = nmemb * size;
void *calloc(size_t nmemb, size_t size) {
size_t total_size = nmemb * size;
+#ifdef HAVE_MMAP
+ if (!__mmalloc_current_heap) mmalloc_preinit();
+#endif
void *ret = mmalloc(__mmalloc_current_heap, total_size);
/* Fill the allocated memory with zeroes to mimic calloc behaviour */
void *ret = mmalloc(__mmalloc_current_heap, total_size);
/* Fill the allocated memory with zeroes to mimic calloc behaviour */
void *realloc(void *p, size_t s) {
void *ret = NULL;
void *realloc(void *p, size_t s) {
void *ret = NULL;
+#ifdef HAVE_MMAP
+ if (!__mmalloc_current_heap) mmalloc_preinit();
+#endif
- if (p)
- ret = mrealloc(__mmalloc_current_heap, p,s);
- else
- ret = mmalloc(__mmalloc_current_heap,s);
+ if (p)
+ ret = mrealloc(__mmalloc_current_heap, p,s);
+ else
+ ret = mmalloc(__mmalloc_current_heap,s);
- if (p)
- mfree(__mmalloc_current_heap,p);
+ if (p)
+ mfree(__mmalloc_current_heap,p);
}
/* Initialize the default malloc descriptor. */
}
/* Initialize the default malloc descriptor. */
-#include "xbt_modinter.h"
void mmalloc_preinit(void) {
void mmalloc_preinit(void) {
- __mmalloc_default_mdp = mmalloc_attach(-1, (char *)sbrk(0) + HEAP_OFFSET);
+ if(!__mmalloc_default_mdp) __mmalloc_default_mdp = mmalloc_attach(-1, (char *)sbrk(0) + HEAP_OFFSET);
xbt_assert(__mmalloc_default_mdp != NULL);
}
void mmalloc_postexit(void) {
xbt_assert(__mmalloc_default_mdp != NULL);
}
void mmalloc_postexit(void) {