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"
14 /* The mmalloc() package can use a single implicit malloc descriptor
15 for mmalloc/mrealloc/mfree operations which do not supply an explicit
16 descriptor. This allows mmalloc() to provide
17 backwards compatibility with the non-mmap'd version. */
18 xbt_mheap_t __mmalloc_default_mdp = NULL;
21 static xbt_mheap_t __mmalloc_current_heap = NULL; /* The heap we are currently using. */
23 xbt_mheap_t mmalloc_get_current_heap(void)
25 return __mmalloc_current_heap;
28 void mmalloc_set_current_heap(xbt_mheap_t new_heap)
30 __mmalloc_current_heap = new_heap;
33 #ifdef MMALLOC_WANT_OVERRIDE_LEGACY
34 void *malloc(size_t n)
36 xbt_mheap_t mdp = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit();
39 void *ret = mmalloc(mdp, n);
45 void *calloc(size_t nmemb, size_t size)
47 xbt_mheap_t mdp = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit();
50 void *ret = mmalloc(mdp, nmemb*size);
52 memset(ret, 0, nmemb * size);
58 void *realloc(void *p, size_t s)
61 xbt_mheap_t mdp = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit();
64 ret = mrealloc(mdp, p, s);
72 xbt_mheap_t mdp = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit();