Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Do not call malloc_no_memset in mc_snapshot
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 6 Feb 2015 11:08:12 +0000 (12:08 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Fri, 6 Feb 2015 12:15:24 +0000 (13:15 +0100)
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.

include/xbt/mmalloc.h
src/include/mc/mc.h
src/mc/mc_memory.c
src/mc/mc_page_snapshot.cpp
src/mc/mc_process.c
src/surf/surf_interface.cpp
src/xbt/mmalloc/mm_legacy.c

index 3b11dbe..40275c8 100644 (file)
@@ -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
index 5657e8d..5dc7c8c 100644 (file)
@@ -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()
 
index bc0617a..72f51a9 100644 (file)
@@ -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);
 }
index 16c8508..c8aa50f 100644 (file)
@@ -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);
   }
 
index 10d0a45..2ed9f26 100644 (file)
@@ -17,6 +17,8 @@
 #include <libunwind.h>
 #include <libunwind-ptrace.h>
 
+#include <xbt/mmalloc.h>
+
 #include "mc_process.h"
 #include "mc_object_info.h"
 #include "mc_address_space.h"
index 2e79954..16b6f4e 100644 (file)
@@ -1101,4 +1101,3 @@ void Action::updateRemainingLazy(double now)
   m_lastUpdate = now;
   m_lastValue = lmm_variable_getvalue(getVariable());
 }
-
index d4f75a3..3f91455 100644 (file)
@@ -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) {