Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : text segment is read and exec only
[simgrid.git] / src / mc / mc_checkpoint.c
index e9830d5..d23fbf5 100644 (file)
@@ -16,7 +16,9 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc,
 
 void *start_text_libsimgrid;
 void *start_plt_libsimgrid, *end_plt_libsimgrid;
+void *start_got_plt_libsimgrid, *end_got_plt_libsimgrid;
 void *start_plt_binary, *end_plt_binary;
+void *start_got_plt_binary, *end_got_plt_binary;
 char *libsimgrid_path;
 void *start_data_libsimgrid, *start_bss_libsimgrid;
 void *start_data_binary, *start_bss_binary;
@@ -76,46 +78,9 @@ static void MC_snapshot_add_region(mc_snapshot_t snapshot, int type, void *start
   return;
 } 
 
-void MC_take_snapshot(mc_snapshot_t snapshot)
-{
-  unsigned int i = 0;
-  s_map_region_t reg;
-  memory_map_t maps = get_memory_map();
-
-  /* Save the std heap and the writable mapped pages of libsimgrid */
-  while (i < maps->mapsize) {
-    reg = maps->regions[i];
-    if ((reg.prot & PROT_WRITE)){
-      if (maps->regions[i].pathname == NULL){
-        if (reg.start_addr == std_heap){ // only save the std heap (and not the raw one)
-          MC_snapshot_add_region(snapshot, 0, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr);
-        }
-        i++;
-      } else {
-        if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
-          MC_snapshot_add_region(snapshot, 1, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr);
-          i++;
-          reg = maps->regions[i];
-          while(reg.pathname == NULL && (reg.prot & PROT_WRITE) && i < maps->mapsize){
-            MC_snapshot_add_region(snapshot, 1, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr);
-            i++;
-            reg = maps->regions[i];
-          }
-        }else{
-          i++;
-        } 
-      }
-    }else{
-      i++;
-    }
-  }
-
-  free_memory_map(maps);
-}
-
 void MC_init_memory_map_info(){
 
-  raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
+  int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
 
   MC_SET_RAW_MEM;
   
@@ -147,7 +112,7 @@ void MC_init_memory_map_info(){
           }
         }
       }
-    }else if ((reg.prot & PROT_READ)){
+    }else if ((reg.prot & PROT_READ) && (reg.prot & PROT_EXEC)){
       if (maps->regions[i].pathname != NULL){
         if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
           start_text_libsimgrid = reg.start_addr;
@@ -171,11 +136,15 @@ void MC_init_memory_map_info(){
 
 }
 
-mc_snapshot_t MC_take_snapshot_liveness()
-{
+mc_snapshot_t SIMIX_pre_mc_snapshot(smx_simcall_t simcall){
+  return MC_take_snapshot();
+}
 
-  raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
+mc_snapshot_t MC_take_snapshot()
+{
 
+  int raw_mem = (mmalloc_get_current_heap() == raw_heap);
+  
   MC_SET_RAW_MEM;
 
   mc_snapshot_t snapshot = xbt_new0(s_mc_snapshot_t, 1);
@@ -245,13 +214,14 @@ mc_snapshot_t MC_take_snapshot_liveness()
     }
   }
 
-  snapshot->stacks = take_snapshot_stacks(heap);
+  if(_surf_mc_visited > 0 || strcmp(_surf_mc_property_file,""))
+    snapshot->stacks = take_snapshot_stacks(heap);
   
   free_memory_map(maps);
 
   MC_UNSET_RAW_MEM;
 
-  if(raw_mem_set)
+  if(raw_mem)
     MC_SET_RAW_MEM;
 
   return snapshot;
@@ -286,7 +256,7 @@ void get_libsimgrid_plt_section(){
   size_t n = 0;                 /* Amount of bytes to read by getline */
 
   char *lfields[7];
-  int i, plt_not_found = 1;
+  int i, plt_found = 0;
   unsigned long int size, offset;
 
   if(libsimgrid_path == NULL)
@@ -296,10 +266,12 @@ void get_libsimgrid_plt_section(){
 
   fp = popen(command, "r");
 
-  if(fp == NULL)
+  if(fp == NULL){
     perror("popen failed");
+    xbt_abort();
+  }
 
-  while ((read = getline(&line, &n, fp)) != -1 && plt_not_found == 1) {
+  while ((read = getline(&line, &n, fp)) != -1 && plt_found != 2) {
 
     if(n == 0)
       continue;
@@ -325,8 +297,15 @@ void get_libsimgrid_plt_section(){
         offset = strtoul(lfields[5], NULL, 16);
         start_plt_libsimgrid = (char *)start_text_libsimgrid + offset;
         end_plt_libsimgrid = (char *)start_plt_libsimgrid + size;
-        plt_not_found = 0;
-      }
+        plt_found++;
+      }else if(strcmp(lfields[1], ".got.plt") == 0){
+        size = strtoul(lfields[2], NULL, 16);
+        offset = strtoul(lfields[5], NULL, 16);
+        start_got_plt_libsimgrid = (char *)start_text_libsimgrid + offset;
+        end_got_plt_libsimgrid = (char *)start_got_plt_libsimgrid + size;
+        plt_found++;
+       }
+
     }
     
   }
@@ -345,17 +324,19 @@ void get_binary_plt_section(){
   size_t n = 0;                 /* Amount of bytes to read by getline */
 
   char *lfields[7];
-  int i, plt_not_found = 1;
-  unsigned long int size, offset;
+  int i, plt_found = 0;
+  unsigned long int size;
 
   char *command = bprintf( "objdump --section-headers %s", xbt_binary_name);
 
   fp = popen(command, "r");
 
-  if(fp == NULL)
+  if(fp == NULL){
     perror("popen failed");
+    xbt_abort();
+  }
 
-  while ((read = getline(&line, &n, fp)) != -1 && plt_not_found == 1) {
+  while ((read = getline(&line, &n, fp)) != -1 && plt_found != 2) {
 
     if(n == 0)
       continue;
@@ -378,11 +359,15 @@ void get_binary_plt_section(){
     if(i>=6){
       if(strcmp(lfields[1], ".plt") == 0){
         size = strtoul(lfields[2], NULL, 16);
-        offset = strtoul(lfields[5], NULL, 16);
-        start_plt_binary = (char *)start_text_binary + offset;
+        start_plt_binary = (void *)strtoul(lfields[3], NULL, 16);
         end_plt_binary = (char *)start_plt_binary + size;
-        plt_not_found = 0;
-      }
+        plt_found++;
+      }else if(strcmp(lfields[1], ".got.plt") == 0){
+        size = strtoul(lfields[2], NULL, 16);
+        start_got_plt_binary = (char *)strtoul(lfields[3], NULL, 16);
+        end_got_plt_binary = (char *)start_got_plt_binary + size;
+        plt_found++;
+       }
     }
     
     
@@ -445,7 +430,6 @@ static xbt_strbuff_t get_local_variables_values(void *stack_context, void *heap)
   
   unw_cursor_t c;
   int ret;
-  //char *stack_name;
 
   char frame_name[256];
   
@@ -455,8 +439,6 @@ static xbt_strbuff_t get_local_variables_values(void *stack_context, void *heap)
     xbt_abort();
   }
 
-  //stack_name = strdup(((smx_process_t)((smx_ctx_sysv_t)(stack->address))->super.data)->name);
-
   unw_word_t ip, sp, off;
   dw_frame_t frame;
  
@@ -541,8 +523,6 @@ static xbt_strbuff_t get_local_variables_values(void *stack_context, void *heap)
     frame_found = 0;
     cursor = 0;
 
-    //XBT_INFO("Frame %s", frame->name);
-
     xbt_dict_foreach(frame->variables, dict_cursor, variable_name, current_variable){
       if(current_variable->location != NULL){
         switch(current_variable->location->type){
@@ -572,24 +552,18 @@ static xbt_strbuff_t get_local_variables_values(void *stack_context, void *heap)
           }
           
           if(xbt_dynar_length(compose) > 0){
-            //XBT_INFO("Variable : %s", current_variable->name);
             if(strcmp(xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->type, "value") == 0){
-              //XBT_INFO("Variable : %s - value : %lx", current_variable->name, xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.res);
               xbt_strbuff_append(variables, bprintf("%s=%lx\n", current_variable->name, xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.res));
             }else{
               if((long)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1,variable_value_t)->value.address < 0 || *((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1,variable_value_t)->value.address) == NULL){
-                //XBT_INFO("Variable : %s - address : NULL", current_variable->name);
                 xbt_strbuff_append(variables, bprintf("%s=NULL\n", current_variable->name));
               }else if(((long)*((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1,variable_value_t)->value.address) > 0xffffffff) || ((long)*((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1,variable_value_t)->value.address) < (long)start_text_binary)){
-                //XBT_INFO("Variable : %s - value : %zd", current_variable->name, (size_t)*((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.address));
                 xbt_strbuff_append(variables, bprintf("%s=%d\n", current_variable->name, (int)(long)*((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.address)));
-              }else{
-                //XBT_INFO("Variable : %s - address : %p", current_variable->name, *((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.address));  
+              }else{ 
                 xbt_strbuff_append(variables, bprintf("%s=%p\n", current_variable->name, *((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.address)));
               }
             }
           }else{
-            //XBT_INFO("Variable %s undefined", current_variable->name);
             xbt_strbuff_append(variables, bprintf("%s=undefined\n", current_variable->name));
           }
           break;
@@ -597,19 +571,14 @@ static xbt_strbuff_t get_local_variables_values(void *stack_context, void *heap)
           break;
         }
       }else{
-        //XBT_INFO("Variable : %s, no location", current_variable->name);
         xbt_strbuff_append(variables, bprintf("%s=undefined\n", current_variable->name));
       }
     }    
  
     ret = unw_step(&c);
-
-    //XBT_INFO(" ");
      
   }
 
-  //free(stack_name);
-
   return variables;
 
 }