not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include "src/internal_config.h"
#include <sys/types.h>
#include <fcntl.h> /* After sys/types.h, at least for dpx/2. */
#include <sys/stat.h>
xbt_mheap_t mmalloc_preinit(void)
{
if (__mmalloc_default_mdp == NULL) {
- if (!mmalloc_pagesize)
- mmalloc_pagesize = getpagesize();
- unsigned long mask = ~((unsigned long)mmalloc_pagesize - 1);
- void *addr = (void*)(((unsigned long)sbrk(0) + HEAP_OFFSET) & mask);
- __mmalloc_default_mdp = xbt_mheap_new(addr, XBT_MHEAP_OPTION_MEMSET);
-
- // atfork mandated at least on FreeBSD, or simgrid-mc will fail to fork the verified app
- int res = pthread_atfork(mmalloc_fork_prepare, mmalloc_fork_parent, mmalloc_fork_child);
- mmalloc_assert(res == 0, "pthread_atfork() failed: return value %d", res);
- }
- mmalloc_assert(__mmalloc_default_mdp != NULL, "__mmalloc_default_mdp cannot be NULL");
+ xbt_mheap_t (*other)(void) = dlsym(RTLD_NEXT, "mmalloc_preinit");
+ if (other != NULL) { // This is the second time that this module is loaded, let's use the other one
+ __mmalloc_default_mdp = other();
+ // fprintf(stderr, "Reuse the other mmalloc_init\n");
+ } else {
+ // fprintf(stderr, "New mmalloc_init\n");
- return __mmalloc_default_mdp;
-}
+ if (!mmalloc_pagesize)
+ mmalloc_pagesize = getpagesize();
+ unsigned long mask = ~((unsigned long)mmalloc_pagesize - 1);
+ void* addr = (void*)(((unsigned long)sbrk(0) + HEAP_OFFSET) & mask);
+ __mmalloc_default_mdp = xbt_mheap_new(addr, XBT_MHEAP_OPTION_MEMSET);
-// This is the underlying implementation of mmalloc_get_bytes_used_remote.
-// Is it used directly in order to evaluate the bytes used from a different
-// process.
-size_t mmalloc_get_bytes_used_remote(size_t heaplimit, const malloc_info* heapinfo)
-{
- int bytes = 0;
- for (size_t i=0; i < heaplimit; ++i){
- if (heapinfo[i].type == MMALLOC_TYPE_UNFRAGMENTED){
- if (heapinfo[i].busy_block.busy_size > 0)
- bytes += heapinfo[i].busy_block.busy_size;
- } else if (heapinfo[i].type > 0) {
- for (size_t j=0; j < (size_t) (BLOCKSIZE >> heapinfo[i].type); j++){
- if(heapinfo[i].busy_frag.frag_size[j] > 0)
- bytes += heapinfo[i].busy_frag.frag_size[j];
- }
+ // atfork mandated at least on FreeBSD, or simgrid-mc will fail to fork the verified app
+ int res = pthread_atfork(mmalloc_fork_prepare, mmalloc_fork_parent, mmalloc_fork_child);
+ mmalloc_assert(res == 0, "pthread_atfork() failed: return value %d", res);
}
}
- return bytes;
+ mmalloc_assert(__mmalloc_default_mdp != NULL, "__mmalloc_default_mdp cannot be NULL");
+
+ return __mmalloc_default_mdp;
}