From: Gabriel Corona Date: Fri, 6 Feb 2015 11:08:12 +0000 (+0100) Subject: [mc] Do not call malloc_no_memset in mc_snapshot X-Git-Tag: v3_12~732^2~131 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/6a1a64f72c3f699c137b1352b0a93f4b5a1c8fd6 [mc] Do not call malloc_no_memset in mc_snapshot The main code should not called mmalloc/mmfree/mmrealloc directly because it will fail in client/server mode: the server does not have separate heap and will choke on this. Replace mmalloc_no_memset with malloc_no_memset which does the right thing: * either call mmalloc_no_memset; * or call malloc. --- diff --git a/include/xbt/mmalloc.h b/include/xbt/mmalloc.h index 3b11dbe8fa..40275c8c59 100644 --- a/include/xbt/mmalloc.h +++ b/include/xbt/mmalloc.h @@ -77,6 +77,8 @@ void reset_heap_information(void); size_t mmalloc_get_bytes_used(xbt_mheap_t); ssize_t mmalloc_get_busy_size(xbt_mheap_t, void *ptr); +void* malloc_no_memset(size_t n); + SG_END_DECL() #endif diff --git a/src/include/mc/mc.h b/src/include/mc/mc.h index 5657e8d96e..5dc7c8c67e 100644 --- a/src/include/mc/mc.h +++ b/src/include/mc/mc.h @@ -86,6 +86,7 @@ XBT_PUBLIC(void) MC_new_stack_area(void *stack, smx_process_t process, void *con /********************************* Memory *************************************/ XBT_PUBLIC(void) MC_memory_init(void); /* Initialize the memory subsystem */ XBT_PUBLIC(void) MC_memory_exit(void); +XBT_PUBLIC(void) MC_memory_init_server(void); SG_END_DECL() diff --git a/src/mc/mc_memory.c b/src/mc/mc_memory.c index bc0617af8d..72f51a9159 100644 --- a/src/mc/mc_memory.c +++ b/src/mc/mc_memory.c @@ -46,6 +46,6 @@ void MC_memory_init() #include "xbt_modinter.h" void MC_memory_exit(void) { - if (mc_heap) + if (mc_heap && mc_heap != std_heap) xbt_mheap_destroy(mc_heap); } diff --git a/src/mc/mc_page_snapshot.cpp b/src/mc/mc_page_snapshot.cpp index 16c85084ac..c8aa50fadd 100644 --- a/src/mc/mc_page_snapshot.cpp +++ b/src/mc/mc_page_snapshot.cpp @@ -208,7 +208,7 @@ mc_mem_region_t mc_region_new_sparse(mc_region_type_t region_type, uint64_t* pagemap = NULL; if (_sg_mc_soft_dirty && mc_model_checker->parent_snapshot && MC_process_is_self(process)) { - pagemap = (uint64_t*) mmalloc_no_memset(mc_heap, sizeof(uint64_t) * page_count); + pagemap = (uint64_t*) malloc_no_memset(sizeof(uint64_t) * page_count); mc_read_pagemap(pagemap, mc_page_number(NULL, permanent_addr), page_count); } @@ -237,7 +237,7 @@ void mc_region_restore_sparse(mc_process_t process, mc_mem_region_t reg, mc_mem_ // Read soft-dirty bits if necessary in order to know which pages have changed: if (_sg_mc_soft_dirty && mc_model_checker->parent_snapshot && MC_process_is_self(process)) { - pagemap = (uint64_t*) mmalloc_no_memset(mc_heap, sizeof(uint64_t) * page_count); + pagemap = (uint64_t*) malloc_no_memset(sizeof(uint64_t) * page_count); mc_read_pagemap(pagemap, mc_page_number(NULL, reg->permanent_addr), page_count); } diff --git a/src/mc/mc_process.c b/src/mc/mc_process.c index 10d0a45d6e..2ed9f26b30 100644 --- a/src/mc/mc_process.c +++ b/src/mc/mc_process.c @@ -17,6 +17,8 @@ #include #include +#include + #include "mc_process.h" #include "mc_object_info.h" #include "mc_address_space.h" diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 2e799547f8..16b6f4eacf 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -1101,4 +1101,3 @@ void Action::updateRemainingLazy(double now) m_lastUpdate = now; m_lastValue = lmm_variable_getvalue(getVariable()); } - diff --git a/src/xbt/mmalloc/mm_legacy.c b/src/xbt/mmalloc/mm_legacy.c index d4f75a3368..3f9145514a 100644 --- a/src/xbt/mmalloc/mm_legacy.c +++ b/src/xbt/mmalloc/mm_legacy.c @@ -84,6 +84,22 @@ static void __attribute__((constructor(101))) mm_legacy_constructor() } } +void* malloc_no_memset(size_t n) +{ + if (!__malloc_use_mmalloc) { + return mm_real_malloc(n); + } + + xbt_mheap_t mdp = GET_HEAP(); + if (!mdp) + return NULL; + + LOCK(mdp); + void *ret = mmalloc_no_memset(mdp, n); + UNLOCK(mdp); + return ret; +} + void *malloc(size_t n) { if (!__malloc_use_mmalloc) {