Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into mc-process
[simgrid.git] / src / mc / mc_diff.c
index 03dfb36..c526fe9 100644 (file)
@@ -20,7 +20,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_diff, xbt,
 
 xbt_dynar_t mc_heap_comparison_ignore;
 xbt_dynar_t stacks_areas;
-void *maestro_stack_start, *maestro_stack_end;
+
 
 
 /********************************* Backtrace ***********************************/
@@ -142,8 +142,7 @@ static int compare_backtrace(int b1, int f1, int b2, int f2)
 typedef char *type_name;
 
 struct s_mc_diff {
-  /** \brief Base address of the real heap */
-  void *s_heap;
+  s_xbt_mheap_t std_heap_copy;
   size_t heaplimit;
   // Number of blocks in the heaps:
   size_t heapsize1, heapsize2;
@@ -229,7 +228,7 @@ static int add_heap_area_pair(xbt_dynar_t list, int block1, int fragment1,
 }
 
 static ssize_t heap_comparison_ignore_size(xbt_dynar_t ignore_list,
-                                           void *address)
+                                           const void *address)
 {
 
   unsigned int cursor = 0;
@@ -253,7 +252,7 @@ static ssize_t heap_comparison_ignore_size(xbt_dynar_t ignore_list,
   return -1;
 }
 
-static int is_stack(void *address)
+static int is_stack(const void *address)
 {
   unsigned int cursor = 0;
   stack_region_t stack;
@@ -366,10 +365,8 @@ int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1,
     return -1;
 
   state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
-
-  // Mamailloute in order to find the base address of the main heap:
-  state->s_heap =
-      (char *) mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
+  
+  state->std_heap_copy = *MC_process_get_heap(&mc_model_checker->process);
 
   state->heapsize1 = heap1->heapsize;
   state->heapsize2 = heap2->heapsize;
@@ -415,9 +412,22 @@ void reset_heap_information()
 
 }
 
-int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
+// TODO, have a robust way to find it in O(1)
+static inline
+mc_mem_region_t MC_get_heap_region(mc_snapshot_t snapshot)
 {
+  size_t n = snapshot->snapshot_regions_count;
+  for (size_t i=0; i!=n; ++i) {
+    mc_mem_region_t region = snapshot->snapshot_regions[i];
+    if (region->region_type == MC_REGION_TYPE_HEAP)
+      return region;
+  }
+  xbt_die("No heap region");
+}
 
+int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
+{
+  mc_process_t process = &mc_model_checker->process;
   struct s_mc_diff *state = mc_diff_info;
 
   /* Start comparison */
@@ -434,17 +444,20 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
   malloc_info heapinfo_temp1, heapinfo_temp2;
   malloc_info heapinfo_temp2b;
 
-  mc_mem_region_t heap_region1 = snapshot1->regions[0];
-  mc_mem_region_t heap_region2 = snapshot2->regions[0];
+  mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
+  mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
+
+  // This is the address of std_heap->heapinfo in the application process:
+  void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
 
   // This is in snapshot do not use them directly:
-  malloc_info* heapinfos1 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot1, MC_NO_PROCESS_INDEX);
-  malloc_info* heapinfos2 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot2, MC_NO_PROCESS_INDEX);
+  const malloc_info* heapinfos1 = MC_snapshot_read_pointer(snapshot1, heapinfo_address, MC_PROCESS_INDEX_MISSING);
+  const malloc_info* heapinfos2 = MC_snapshot_read_pointer(snapshot2, heapinfo_address, MC_PROCESS_INDEX_MISSING);
 
   while (i1 <= state->heaplimit) {
 
-    malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[i1], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
-    malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[i1], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
+    const malloc_info* heapinfo1 = MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[i1], sizeof(malloc_info));
+    const malloc_info* heapinfo2 = MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[i1], sizeof(malloc_info));
 
     if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) {      /* Free block */
       i1 ++;
@@ -458,7 +471,7 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
 
     addr_block1 =
         ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
-                   (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
+                   (char *) state->std_heap_copy.heapbase));
 
     if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) {       /* Large block */
 
@@ -485,12 +498,11 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
 
         if (state->equals_to2_(i1, 0).valid == 0) {
 
-          addr_block2 =
-              ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
-                         (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
+          addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
+                         (char *) state->std_heap_copy.heapbase;
 
           res_compare =
-              compare_heap_area(MC_NO_PROCESS_INDEX, addr_block1, addr_block2, snapshot1, snapshot2,
+              compare_heap_area(MC_PROCESS_INDEX_MISSING, addr_block1, addr_block2, snapshot1, snapshot2,
                                 NULL, NULL, 0);
 
           if (res_compare != 1) {
@@ -508,16 +520,15 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
 
       while (i2 <= state->heaplimit && !equal) {
 
-        addr_block2 =
-            ((void *) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE +
-                       (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
+        addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE +
+                       (char *) state->std_heap_copy.heapbase;
 
         if (i2 == i1) {
           i2++;
           continue;
         }
 
-        malloc_info* heapinfo2b = mc_snapshot_read_region(&heapinfos2[i2], heap_region2, &heapinfo_temp2b, sizeof(malloc_info));
+        const malloc_info* heapinfo2b = MC_region_read(heap_region2, &heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
 
         if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) {
           i2++;
@@ -530,7 +541,7 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
         }
 
         res_compare =
-            compare_heap_area(MC_NO_PROCESS_INDEX, addr_block1, addr_block2, snapshot1, snapshot2,
+            compare_heap_area(MC_PROCESS_INDEX_MISSING, addr_block1, addr_block2, snapshot1, snapshot2,
                               NULL, NULL, 0);
 
         if (res_compare != 1) {
@@ -575,15 +586,14 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
 
           if (state->equals_to2_(i1, j1).valid == 0) {
 
-            addr_block2 =
-                ((void *) (((ADDR2UINT(i1)) - 1) * BLOCKSIZE +
-                           (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
+            addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
+                           (char *) state->std_heap_copy.heapbase;
             addr_frag2 =
                 (void *) ((char *) addr_block2 +
                           (j1 << heapinfo2->type));
 
             res_compare =
-                compare_heap_area(MC_NO_PROCESS_INDEX, addr_frag1, addr_frag2, snapshot1, snapshot2,
+                compare_heap_area(MC_PROCESS_INDEX_MISSING, addr_frag1, addr_frag2, snapshot1, snapshot2,
                                   NULL, NULL, 0);
 
             if (res_compare != 1)
@@ -595,7 +605,7 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
 
         while (i2 <= state->heaplimit && !equal) {
 
-          malloc_info* heapinfo2b = mc_snapshot_read_region(&heapinfos2[i2], heap_region2, &heapinfo_temp2b, sizeof(malloc_info));
+          const malloc_info* heapinfo2b = MC_region_read(heap_region2, &heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
 
           if (heapinfo2b->type == MMALLOC_TYPE_FREE || heapinfo2b->type == MMALLOC_TYPE_HEAPINFO) {
             i2 ++;
@@ -622,15 +632,14 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
             if (state->equals_to2_(i2, j2).valid)
               continue;
 
-            addr_block2 =
-                ((void *) (((ADDR2UINT(i2)) - 1) * BLOCKSIZE +
-                           (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
+            addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE +
+                           (char *) state->std_heap_copy.heapbase;
             addr_frag2 =
                 (void *) ((char *) addr_block2 +
                           (j2 << heapinfo2b->type));
 
             res_compare =
-                compare_heap_area(MC_NO_PROCESS_INDEX, addr_frag1, addr_frag2, snapshot2, snapshot2,
+                compare_heap_area(MC_PROCESS_INDEX_MISSING, addr_frag1, addr_frag2, snapshot2, snapshot2,
                                   NULL, NULL, 0);
 
             if (res_compare != 1) {
@@ -667,7 +676,7 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
   size_t i = 1, j = 0;
 
   for(i = 1; i <= state->heaplimit; i++) {
-    malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[i], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
+    const malloc_info* heapinfo1 = MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info));
     if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) {
       if (i1 == state->heaplimit) {
         if (heapinfo1->busy_block.busy_size > 0) {
@@ -708,7 +717,7 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
     XBT_DEBUG("Number of blocks/fragments not found in heap1 : %d", nb_diff1);
 
   for (i=1; i <= state->heaplimit; i++) {
-    malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[i], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
+    const malloc_info* heapinfo2 = MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info));
     if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) {
       if (i1 == state->heaplimit) {
         if (heapinfo2->busy_block.busy_size > 0) {
@@ -763,20 +772,21 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2)
  * @param check_ignore
  */
 static int compare_heap_area_without_type(struct s_mc_diff *state, int process_index,
-                                          void *real_area1, void *real_area2,
+                                          const void *real_area1, const void *real_area2,
                                           mc_snapshot_t snapshot1,
                                           mc_snapshot_t snapshot2,
                                           xbt_dynar_t previous, int size,
                                           int check_ignore)
 {
+  mc_process_t process = &mc_model_checker->process;
 
   int i = 0;
-  void *addr_pointed1, *addr_pointed2;
+  const void *addr_pointed1, *addr_pointed2;
   int pointer_align, res_compare;
   ssize_t ignore1, ignore2;
 
-  mc_mem_region_t heap_region1 = snapshot1->regions[0];
-  mc_mem_region_t heap_region2 = snapshot2->regions[0];
+  mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
+  mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
 
   while (i < size) {
 
@@ -799,21 +809,21 @@ static int compare_heap_area_without_type(struct s_mc_diff *state, int process_i
       }
     }
 
-    if (mc_snapshot_region_memcmp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
+    if (MC_snapshot_region_memcmp(((char *) real_area1) + i, heap_region1, ((char *) real_area2) + i, heap_region2, 1) != 0) {
 
       pointer_align = (i / sizeof(void *)) * sizeof(void *);
-      addr_pointed1 = mc_snapshot_read_pointer((char *) real_area1 + pointer_align, snapshot1, process_index);
-      addr_pointed2 = mc_snapshot_read_pointer((char *) real_area2 + pointer_align, snapshot2, process_index);
+      addr_pointed1 = MC_snapshot_read_pointer(snapshot1, (char *) real_area1 + pointer_align, process_index);
+      addr_pointed2 = MC_snapshot_read_pointer(snapshot2, (char *) real_area2 + pointer_align, process_index);
 
-      if (addr_pointed1 > maestro_stack_start
-          && addr_pointed1 < maestro_stack_end
-          && addr_pointed2 > maestro_stack_start
-          && addr_pointed2 < maestro_stack_end) {
+      if (addr_pointed1 > process->maestro_stack_start
+          && addr_pointed1 < process->maestro_stack_end
+          && addr_pointed2 > process->maestro_stack_start
+          && addr_pointed2 < process->maestro_stack_end) {
         i = pointer_align + sizeof(void *);
         continue;
-      } else if (addr_pointed1 > state->s_heap
+      } else if (addr_pointed1 > state->std_heap_copy.heapbase
                  && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
-                 && addr_pointed2 > state->s_heap
+                 && addr_pointed2 > state->std_heap_copy.heapbase
                  && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)) {
         // Both addreses are in the heap:
         res_compare =
@@ -853,7 +863,7 @@ static int compare_heap_area_without_type(struct s_mc_diff *state, int process_i
  * @return               0 (same), 1 (different), -1 (unknown)
  */
 static int compare_heap_area_with_type(struct s_mc_diff *state, int process_index,
-                                       void *real_area1, void *real_area2,
+                                       const void *real_area1, const void *real_area2,
                                        mc_snapshot_t snapshot1,
                                        mc_snapshot_t snapshot2,
                                        xbt_dynar_t previous, dw_type_t type,
@@ -878,10 +888,10 @@ top:
   int res, elm_size, i;
   unsigned int cursor = 0;
   dw_type_t member;
-  void *addr_pointed1, *addr_pointed2;;
+  const void *addr_pointed1, *addr_pointed2;;
 
-  mc_mem_region_t heap_region1 = snapshot1->regions[0];
-  mc_mem_region_t heap_region2 = snapshot2->regions[0];
+  mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
+  mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
 
   switch (type->type) {
   case DW_TAG_unspecified_type:
@@ -892,12 +902,12 @@ top:
       if (real_area1 == real_area2)
         return -1;
       else
-        return (mc_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, area_size) != 0);
+        return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, area_size) != 0);
     } else {
       if (area_size != -1 && type->byte_size != area_size)
         return -1;
       else {
-        return (mc_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
+        return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
       }
     }
     break;
@@ -905,7 +915,7 @@ top:
     if (area_size != -1 && type->byte_size != area_size)
       return -1;
     else
-      return (mc_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
+      return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
     break;
   case DW_TAG_typedef:
   case DW_TAG_const_type:
@@ -962,18 +972,18 @@ top:
   case DW_TAG_rvalue_reference_type:
   case DW_TAG_pointer_type:
     if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
-      addr_pointed1 = mc_snapshot_read_pointer(real_area1, snapshot1, process_index);
-      addr_pointed2 = mc_snapshot_read_pointer(real_area2, snapshot2, process_index);
+      addr_pointed1 = MC_snapshot_read_pointer(snapshot1, real_area1, process_index);
+      addr_pointed2 = MC_snapshot_read_pointer(snapshot2, real_area2, process_index);
       return (addr_pointed1 != addr_pointed2);;
     } else {
       pointer_level++;
       if (pointer_level > 1) {  /* Array of pointers */
         for (i = 0; i < (area_size / sizeof(void *)); i++) {
-          addr_pointed1 = mc_snapshot_read_pointer((char*) real_area1 + i * sizeof(void *), snapshot1, process_index);
-          addr_pointed2 = mc_snapshot_read_pointer((char*) real_area2 + i * sizeof(void *), snapshot2, process_index);
-          if (addr_pointed1 > state->s_heap
+          addr_pointed1 = MC_snapshot_read_pointer(snapshot1, (char*) real_area1 + i * sizeof(void *), process_index);
+          addr_pointed2 = MC_snapshot_read_pointer(snapshot2, (char*) real_area2 + i * sizeof(void *), process_index);
+          if (addr_pointed1 > state->std_heap_copy.heapbase
               && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
-              && addr_pointed2 > state->s_heap
+              && addr_pointed2 > state->std_heap_copy.heapbase
               && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
             res =
                 compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
@@ -985,11 +995,11 @@ top:
             return res;
         }
       } else {
-        addr_pointed1 = mc_snapshot_read_pointer(real_area1, snapshot1, process_index);
-        addr_pointed2 = mc_snapshot_read_pointer(real_area2, snapshot2, process_index);
-        if (addr_pointed1 > state->s_heap
+        addr_pointed1 = MC_snapshot_read_pointer(snapshot1, real_area1, process_index);
+        addr_pointed2 = MC_snapshot_read_pointer(snapshot2, real_area2, process_index);
+        if (addr_pointed1 > state->std_heap_copy.heapbase
             && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)
-            && addr_pointed2 > state->s_heap
+            && addr_pointed2 > state->std_heap_copy.heapbase
             && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2))
           return compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
                                    snapshot2, previous, type->subtype,
@@ -1023,9 +1033,9 @@ top:
       xbt_dynar_foreach(type->members, cursor, member) {
         // TODO, optimize this? (for the offset case)
         char *real_member1 =
-            mc_member_resolve(real_area1, type, member, snapshot1, process_index);
+            mc_member_resolve(real_area1, type, member, (mc_address_space_t) snapshot1, process_index);
         char *real_member2 =
-            mc_member_resolve(real_area2, type, member, snapshot2, process_index);
+            mc_member_resolve(real_area2, type, member, (mc_address_space_t) snapshot2, process_index);
         res =
             compare_heap_area_with_type(state, process_index, real_member1, real_member2,
                                         snapshot1, snapshot2,
@@ -1091,7 +1101,7 @@ static dw_type_t get_offset_type(void *real_base_address, dw_type_t type,
             return member->subtype;
         } else {
           char *real_member =
-              mc_member_resolve(real_base_address, type, member, snapshot, process_index);
+              mc_member_resolve(real_base_address, type, member, (mc_address_space_t) snapshot, process_index);
           if (real_member - (char *) real_base_address == offset)
             return member->subtype;
         }
@@ -1118,10 +1128,11 @@ static dw_type_t get_offset_type(void *real_base_address, dw_type_t type,
  * @param pointer_level
  * @return 0 (same), 1 (different), -1
  */
-int compare_heap_area(int process_index, void *area1, void *area2, mc_snapshot_t snapshot1,
+int compare_heap_area(int process_index, const void *area1, const void *area2, mc_snapshot_t snapshot1,
                       mc_snapshot_t snapshot2, xbt_dynar_t previous,
                       dw_type_t type, int pointer_level)
 {
+  mc_process_t process = &mc_model_checker->process;
 
   struct s_mc_diff *state = mc_diff_info;
 
@@ -1138,8 +1149,11 @@ int compare_heap_area(int process_index, void *area1, void *area2, mc_snapshot_t
 
   int match_pairs = 0;
 
-  malloc_info* heapinfos1 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot1, process_index);
-  malloc_info* heapinfos2 = mc_snapshot_read_pointer(&std_heap->heapinfo, snapshot2, process_index);
+  // This is the address of std_heap->heapinfo in the application process:
+  void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
+
+  const malloc_info* heapinfos1 = MC_snapshot_read_pointer(snapshot1, heapinfo_address, process_index);
+  const malloc_info* heapinfos2 = MC_snapshot_read_pointer(snapshot2, heapinfo_address, process_index);
 
   malloc_info heapinfo_temp1, heapinfo_temp2;
 
@@ -1151,10 +1165,10 @@ int compare_heap_area(int process_index, void *area1, void *area2, mc_snapshot_t
   // Get block number:
   block1 =
       ((char *) area1 -
-       (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
+       (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
   block2 =
       ((char *) area2 -
-       (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
+       (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
 
   // If either block is a stack block:
   if (is_block_stack((int) block1) && is_block_stack((int) block2)) {
@@ -1166,9 +1180,9 @@ int compare_heap_area(int process_index, void *area1, void *area2, mc_snapshot_t
     return 0;
   }
   // If either block is not in the expected area of memory:
-  if (((char *) area1 < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
+  if (((char *) area1 < (char *) state->std_heap_copy.heapbase)
       || (block1 > state->heapsize1) || (block1 < 1)
-      || ((char *) area2 < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
+      || ((char *) area2 < (char *) state->std_heap_copy.heapbase)
       || (block2 > state->heapsize2) || (block2 < 1)) {
     if (match_pairs) {
       xbt_dynar_free(&previous);
@@ -1177,12 +1191,10 @@ int compare_heap_area(int process_index, void *area1, void *area2, mc_snapshot_t
   }
 
   // Process address of the block:
-  real_addr_block1 =
-      ((void *) (((ADDR2UINT(block1)) - 1) * BLOCKSIZE +
-                 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
-  real_addr_block2 =
-      ((void *) (((ADDR2UINT(block2)) - 1) * BLOCKSIZE +
-                 (char *) ((xbt_mheap_t) state->s_heap)->heapbase));
+  real_addr_block1 = (ADDR2UINT(block1) - 1) * BLOCKSIZE +
+                 (char *) state->std_heap_copy.heapbase;
+  real_addr_block2 = (ADDR2UINT(block2) - 1) * BLOCKSIZE +
+                 (char *) state->std_heap_copy.heapbase;
 
   if (type) {
 
@@ -1203,11 +1215,11 @@ int compare_heap_area(int process_index, void *area1, void *area2, mc_snapshot_t
 
   }
 
-  mc_mem_region_t heap_region1 = snapshot1->regions[0];
-  mc_mem_region_t heap_region2 = snapshot2->regions[0];
+  mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1);
+  mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2);
 
-  malloc_info* heapinfo1 = mc_snapshot_read_region(&heapinfos1[block1], heap_region1, &heapinfo_temp1, sizeof(malloc_info));
-  malloc_info* heapinfo2 = mc_snapshot_read_region(&heapinfos2[block2], heap_region2, &heapinfo_temp2, sizeof(malloc_info));
+  const malloc_info* heapinfo1 = MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info));
+  const malloc_info* heapinfo2 = MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[block2], sizeof(malloc_info));
 
   if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
     && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
@@ -1526,9 +1538,9 @@ static int get_pointed_area_size(void *area, int heap)
 
   block =
       ((char *) area -
-       (char *) ((xbt_mheap_t) state->s_heap)->heapbase) / BLOCKSIZE + 1;
+       (char *) state->std_heap_copy.heapbase) / BLOCKSIZE + 1;
 
-  if (((char *) area < (char *) ((xbt_mheap_t) state->s_heap)->heapbase)
+  if (((char *) area < (char *) state->std_heap_copy.heapbase)
       || (block > state->heapsize1) || (block < 1))
     return -1;
 
@@ -1587,10 +1599,7 @@ int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2)
   /* Heap information */
   state->heaplimit = ((struct mdesc *) heap1)->heaplimit;
 
-
-  // Mamailloute in order to find the base address of the main heap:
-  state->s_heap =
-      (char *) mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
+  state->std_heap_copy = *MC_process_get_heap(&mc_model_checker->process);
 
   state->heapbase1 = (char *) heap1 + BLOCKSIZE;
   state->heapbase2 = (char *) heap2 + BLOCKSIZE;