Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Remote support for filling state->internal_comm
[simgrid.git] / src / mc / mc_process.c
index 65c77a8..7e047ab 100644 (file)
@@ -25,6 +25,7 @@
 #include "mc_unw.h"
 #include "mc_snapshot.h"
 #include "mc_ignore.h"
+#include "mc_smx.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_process, mc,
                                 "MC process information");
@@ -80,6 +81,9 @@ void MC_process_init(mc_process_t process, pid_t pid, int sockfd)
     &process->heap_address, std_heap_var->address, sizeof(struct mdesc*),
     MC_PROCESS_INDEX_DISABLED);
 
+  process->smx_process_infos = MC_smx_process_info_list_new();
+  process->smx_old_process_infos = MC_smx_process_info_list_new();
+
   process->checkpoint_ignore = MC_checkpoint_ignore_new();
 
   process->unw_addr_space = unw_create_addr_space(&mc_unw_accessors  , __BYTE_ORDER);
@@ -106,6 +110,9 @@ void MC_process_clear(mc_process_t process)
 
   xbt_dynar_free(&process->checkpoint_ignore);
 
+  xbt_dynar_free(&process->smx_process_infos);
+  xbt_dynar_free(&process->smx_old_process_infos);
+
   size_t i;
   for (i=0; i!=process->object_infos_size; ++i) {
     MC_free_object_info(&process->object_infos[i]);
@@ -371,15 +378,37 @@ dw_variable_t MC_process_find_variable_by_name(mc_process_t process, const char*
 {
   const size_t n = process->object_infos_size;
   size_t i;
+
+  // First lookup the variable in the executable shared object.
+  // A global variable used directly by the executable code from a library
+  // is reinstanciated in the executable memory .data/.bss.
+  // We need to look up the variable in the execvutable first.
+  if (process->binary_info) {
+    mc_object_info_t info = process->binary_info;
+    dw_variable_t var = MC_file_object_info_find_variable_by_name(info, name);
+    if (var)
+      return var;
+  }
+
   for (i=0; i!=n; ++i) {
     mc_object_info_t info =process->object_infos[i];
     dw_variable_t var = MC_file_object_info_find_variable_by_name(info, name);
     if (var)
       return var;
   }
+
   return NULL;
 }
 
+void MC_process_read_variable(mc_process_t process, const char* name, void* target, size_t size)
+{
+  dw_variable_t var = MC_process_find_variable_by_name(process, name);
+  if (!var->address)
+    xbt_die("No simple location for this variable");
+  MC_process_read(process, MC_PROCESS_NO_FLAG, target, var->address, size,
+    MC_PROCESS_INDEX_ANY);
+}
+
 // ***** Memory access
 
 int MC_process_vm_open(pid_t pid, int flags)
@@ -473,6 +502,24 @@ const void* MC_process_read(mc_process_t process, e_adress_space_read_flags_t fl
   }
 }
 
+const void* MC_process_read_simple(mc_process_t process,
+  void* local, const void* remote, size_t len)
+{
+  e_adress_space_read_flags_t flags = MC_PROCESS_NO_FLAG;
+  int index = MC_PROCESS_INDEX_ANY;
+   MC_process_read(process, flags, local, remote, len, index);
+   return local;
+}
+
+const void* MC_process_read_dynar_element(mc_process_t process,
+  void* local, const void* remote_dynar, size_t i)
+{
+  s_xbt_dynar_t d;
+  MC_process_read_simple(process, &d, remote_dynar, sizeof(d));
+  MC_process_read_simple(process, local, xbt_dynar_get_ptr(&d, i), i);
+  return local;
+}
+
 void MC_process_write(mc_process_t process, const void* local, void* remote, size_t len)
 {
   if (MC_process_is_self(process)) {
@@ -512,3 +559,35 @@ void MC_process_clear_memory(mc_process_t process, void* remote, size_t len)
     }
   }
 }
+
+void MC_simcall_handle(smx_simcall_t req, int value)
+{
+  if (MC_process_is_self(&mc_model_checker->process)) {
+    SIMIX_simcall_handle(req, value);
+    return;
+  }
+
+  MC_process_smx_refresh(&mc_model_checker->process);
+
+  unsigned i;
+  mc_smx_process_info_t pi = NULL;
+
+  xbt_dynar_foreach_ptr(mc_model_checker->process.smx_process_infos, i, pi) {
+    smx_process_t p = (smx_process_t) pi->address;
+    if (req == &pi->copy.simcall) {
+      smx_simcall_t real_req = &p->simcall;
+      // TODO, use a remote call
+      SIMIX_simcall_handle(real_req, value);
+      return;
+    }
+  }
+
+  // Check (remove afterwards):
+  xbt_dynar_foreach_ptr(mc_model_checker->process.smx_process_infos, i, pi) {
+    smx_process_t p = (smx_process_t) pi->address;
+    if (req == &p->simcall)
+      xbt_die("The real simcall was passed. We expected the local copy.");
+  }
+
+  xbt_die("Could not find the request");
+}