Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] mprotect the region *after* zero-ing ignored parts:
authorGabriel Corona <gabriel.corona@loria.fr>
Thu, 24 Apr 2014 11:07:56 +0000 (13:07 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Thu, 24 Apr 2014 11:31:02 +0000 (13:31 +0200)
Doing it the other way round segfaults.

src/mc/mc_checkpoint.c

index 53c64dc..cd2beff 100644 (file)
@@ -89,7 +89,6 @@ static mc_mem_region_t MC_region_new(int type, void *start_addr, size_t size)
   new_reg->size = size;
   new_reg->data = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
   memcpy(new_reg->data, start_addr, size);
-  mprotect(new_reg->data, size, PROT_READ);
   madvise(new_reg->data, size, MADV_MERGEABLE);
 
   XBT_DEBUG("New region : type : %d, data : %p (real addr %p), size : %zu", type, new_reg->data, start_addr, size);
@@ -497,6 +496,13 @@ mc_snapshot_t MC_take_snapshot(int num_state){
   if(num_state > 0)
     MC_dump_checkpoint_ignore(snapshot);
 
+  // mprotect the region after zero-ing ignored parts:
+  size_t i;
+  for(i=0; i!=NB_REGIONS; ++i) {
+    mc_mem_region_t region = snapshot->regions[i];
+    mprotect(region->data, region->size, PROT_READ);
+  }
+
   return snapshot;
 
 }