1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 /* Redefine the classical malloc/free/realloc functions so that they fit well in the mmalloc framework */
10 #include "gras_config.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_mm_legacy, xbt,
14 "Logging specific to mm_legacy in mmalloc");
16 /* The mmalloc() package can use a single implicit malloc descriptor
17 for mmalloc/mrealloc/mfree operations which do not supply an explicit
18 descriptor. This allows mmalloc() to provide
19 backwards compatibility with the non-mmap'd version. */
20 xbt_mheap_t __mmalloc_default_mdp = NULL;
23 static xbt_mheap_t __mmalloc_current_heap = NULL; /* The heap we are currently using. */
25 xbt_mheap_t mmalloc_get_current_heap(void)
27 return __mmalloc_current_heap;
30 void mmalloc_set_current_heap(xbt_mheap_t new_heap)
32 __mmalloc_current_heap = new_heap;
35 #ifdef MMALLOC_WANT_OVERIDE_LEGACY
36 void *malloc(size_t n)
38 xbt_mheap_t mdp = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit();
41 void *ret = mmalloc(mdp, n);
47 void *calloc(size_t nmemb, size_t size)
49 xbt_mheap_t mdp = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit();
52 void *ret = mmalloc(mdp, nmemb*size);
54 memset(ret, 0, nmemb * size);
60 void *realloc(void *p, size_t s)
63 xbt_mheap_t mdp = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit();
66 ret = mrealloc(mdp, p, s);
74 xbt_mheap_t mdp = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit();