]> AND Public Git Repository - simgrid.git/blobdiff - src/mc/mc_checkpoint.c
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Define one struct per MC message type
[simgrid.git] / src / mc / mc_checkpoint.c
index 1825cdc498c310c24320170df882d07b79646f5b..bce4bbd5c6d50335cefc328a99c2157acdfa4493 100644 (file)
@@ -5,7 +5,6 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #define _GNU_SOURCE
-#define UNW_LOCAL_ONLY
 
 #include <unistd.h>
 
@@ -25,7 +24,6 @@
 
 #include "../simix/smx_private.h"
 
-#define UNW_LOCAL_ONLY
 #include <libunwind.h>
 #include <libelf.h>
 
@@ -35,6 +33,7 @@
 #include "mc_snapshot.h"
 #include "mc_object_info.h"
 #include "mc_mmu.h"
+#include "mc_unw.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc,
                                 "Logging specific to mc_checkpoint");
@@ -47,13 +46,16 @@ static void MC_snapshot_stack_free(mc_snapshot_stack_t s)
   if (s) {
     xbt_dynar_free(&(s->local_variables));
     xbt_dynar_free(&(s->stack_frames));
+    mc_unw_destroy_context(s->context);
+    xbt_free(s->context);
     xbt_free(s);
   }
 }
 
 static void MC_snapshot_stack_free_voidp(void *s)
 {
-  MC_snapshot_stack_free((mc_snapshot_stack_t) * (void **) s);
+  mc_snapshot_stack_t stack = (mc_snapshot_stack_t) * (void **) s;
+  MC_snapshot_stack_free(stack);
 }
 
 static void local_variable_free(local_variable_t v)
@@ -187,6 +189,8 @@ static void MC_region_restore(mc_mem_region_t region, mc_mem_region_t ref_region
   }
 }
 
+// FIXME, multiple privatisation regions
+// FIXME, cross-process
 static inline
 void* MC_privatization_address(mc_process_t process, int process_index)
 {
@@ -272,6 +276,7 @@ static void MC_get_memory_regions(mc_process_t process, mc_snapshot_t snapshot)
 
 #ifdef HAVE_SMPI
   if (smpi_privatize_global_variables && smpi_process_count()) {
+    // FIXME, cross-process
     snapshot->privatization_index = smpi_loaded_page;
   } else
 #endif
@@ -282,7 +287,7 @@ static void MC_get_memory_regions(mc_process_t process, mc_snapshot_t snapshot)
 
 /** \brief Fills the position of the segments (executable, read-only, read/write).
  *
- * TODO, use dl_iterate_phdr to be more robust
+ *  `dl_iterate_phdr` would be more robust but would not work in cross-process.
  * */
 void MC_find_object_address(memory_map_t maps, mc_object_info_t result)
 {
@@ -378,6 +383,7 @@ static void mc_fill_local_variables_values(mc_stack_frame_t stack_frame,
       continue;
 
     int region_type;
+    // FIXME, get rid of `region_type`
     if ((long) stack_frame->ip > (long) process->libsimgrid_info->start_exec)
       region_type = 1;
     else
@@ -394,6 +400,7 @@ static void mc_fill_local_variables_values(mc_stack_frame_t stack_frame,
       new_var->address = current_variable->address;
     } else if (current_variable->locations.size != 0) {
       s_mc_location_t location;
+      // FIXME, cross-process support
       mc_dwarf_resolve_locations(&location, &current_variable->locations,
                                               current_variable->object_info,
                                               &(stack_frame->unw_cursor),
@@ -447,7 +454,7 @@ static void MC_stack_frame_free_voipd(void *s)
   }
 }
 
-static xbt_dynar_t MC_unwind_stack_frames(void *stack_context)
+static xbt_dynar_t MC_unwind_stack_frames(mc_unw_context_t stack_context)
 {
   mc_process_t process = &mc_model_checker->process;
   xbt_dynar_t result =
@@ -456,7 +463,7 @@ static xbt_dynar_t MC_unwind_stack_frames(void *stack_context)
   unw_cursor_t c;
 
   // TODO, check condition check (unw_init_local==0 means end of frame)
-  if (unw_init_local(&c, (unw_context_t *) stack_context) != 0) {
+  if (mc_unw_init_cursor(&c, stack_context) != 0) {
 
     xbt_die("Could not initialize stack unwinding");
 
@@ -495,11 +502,11 @@ static xbt_dynar_t MC_unwind_stack_frames(void *stack_context)
           && !strcmp(frame->name, "smx_ctx_sysv_wrapper"))
         break;
 
-      int ret = ret = unw_step(&c);
+      int ret = unw_step(&c);
       if (ret == 0) {
         xbt_die("Unexpected end of stack.");
       } else if (ret < 0) {
-        xbt_die("Error while unwinding stack.");
+        xbt_die("Error while unwinding stack");
       }
     }
 
@@ -521,9 +528,19 @@ static xbt_dynar_t MC_take_snapshot_stacks(mc_snapshot_t * snapshot)
   unsigned int cursor = 0;
   stack_region_t current_stack;
 
+  // FIXME, cross-process support (stack_areas)
   xbt_dynar_foreach(stacks_areas, cursor, current_stack) {
     mc_snapshot_stack_t st = xbt_new(s_mc_snapshot_stack_t, 1);
-    st->stack_frames = MC_unwind_stack_frames(current_stack->context);
+
+    unw_context_t* original_context = (unw_context_t*) current_stack->context;
+
+    st->context = xbt_new0(s_mc_unw_context_t, 1);
+    if (mc_unw_init_context(st->context, &mc_model_checker->process,
+      original_context) < 0) {
+      xbt_die("Could not initialise the libunwind context.");
+    }
+
+    st->stack_frames = MC_unwind_stack_frames(st->context);
     st->local_variables = MC_get_local_variables_values(st->stack_frames, current_stack->process_index);
     st->process_index = current_stack->process_index;
 
@@ -540,6 +557,7 @@ static xbt_dynar_t MC_take_snapshot_stacks(mc_snapshot_t * snapshot)
 
 }
 
+// FIXME, cross-process support (mc_heap_comparison_ignore)
 static xbt_dynar_t MC_take_snapshot_ignore()
 {
 
@@ -580,6 +598,7 @@ static void MC_snapshot_handle_ignore(mc_snapshot_t snapshot)
   // Copy the memory:
   unsigned int cursor = 0;
   mc_checkpoint_ignore_region_t region;
+  // FIXME, cross-process support (mc_checkpoint_ignore)
   xbt_dynar_foreach (mc_checkpoint_ignore, cursor, region) {
     s_mc_snapshot_ignored_data_t ignored_data;
     ignored_data.start = region->addr;
@@ -628,17 +647,18 @@ int mc_important_snapshot(mc_snapshot_t snapshot)
   return false;
 }
 
-static void MC_get_current_fd(mc_snapshot_t snapshot){
+static void MC_get_current_fd(mc_snapshot_t snapshot)
+{
 
   snapshot->total_fd = 0;
 
   const size_t fd_dir_path_size = 20;
   char fd_dir_path[fd_dir_path_size];
   if (snprintf(fd_dir_path, fd_dir_path_size,
-    "/proc/%lli/fd", (long long int) getpid()) > fd_dir_path_size)
+    "/proc/%lli/fd", (long long int) snapshot->process->pid) > fd_dir_path_size)
     xbt_die("Unexpected buffer is too small for fd_dir_path");
 
-  DIR* fd_dir = opendir (fd_dir_path);
+  DIR* fd_dir = opendir(fd_dir_path);
   if (fd_dir == NULL)
     xbt_die("Cannot open directory '/proc/self/fd'\n");
 
@@ -653,7 +673,8 @@ static void MC_get_current_fd(mc_snapshot_t snapshot){
 
     const size_t source_size = 25;
     char source[25];
-    if (snprintf(source, source_size, "/proc/self/fd/%s", fd_number->d_name) > source_size)
+    if (snprintf(source, source_size, "/proc/%lli/fd/%s",
+        (long long int) snapshot->process->pid, fd_number->d_name) > source_size)
       xbt_die("Unexpected buffer is too small for fd %s", fd_number->d_name);
 
     const size_t link_size = 200;
@@ -712,6 +733,7 @@ mc_snapshot_t MC_take_snapshot(int num_state)
 
   snapshot->enabled_processes = xbt_dynar_new(sizeof(int), NULL);
   smx_process_t process;
+  // FIXME, cross-process support (simix_global->process_list)
   xbt_swag_foreach(process, simix_global->process_list) {
     xbt_dynar_push_as(snapshot->enabled_processes, int, (int)process->pid);
   }
@@ -775,6 +797,9 @@ void MC_restore_snapshot_regions(mc_snapshot_t snapshot)
 #endif
 }
 
+// FIXME, cross-process support ~ we need to implement this on the app side
+// or use some form of [remote syscall execution](http://criu.org/Remote_syscall_execution)
+// based on [parasite code execution](http://criu.org/Parasite_code).
 static inline
 void MC_restore_snapshot_fds(mc_snapshot_t snapshot)
 {