Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Pass large parameter by address.
[simgrid.git] / src / mc / remote / Client.cpp
index 4a9f0bf..61e5591 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2015-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2015-2020. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -6,10 +6,11 @@
 #include "src/mc/remote/Client.hpp"
 #include "src/internal_config.h"
 #include <simgrid/modelchecker.h>
-#include <xbt/system_error.hpp>
 
+#include <cerrno>
 #include <cstdlib>
 #include <cstring>
+#include <sys/ptrace.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 
@@ -37,7 +38,7 @@ Client* Client::initialize()
   _sg_do_model_check = 1;
 
   // Fetch socket from MC_ENV_SOCKET_FD:
-  char* fd_env = std::getenv(MC_ENV_SOCKET_FD);
+  const char* fd_env = std::getenv(MC_ENV_SOCKET_FD);
   if (not fd_env)
     xbt_die("No MC socket passed in the environment");
   int fd =
@@ -56,14 +57,22 @@ Client* Client::initialize()
   instance_.reset(new simgrid::mc::Client(fd));
 
   // Wait for the model-checker:
-  if (raise(SIGSTOP) != 0)
-    throw simgrid::xbt::errno_error("Could not wait for the model-checker");
+  errno = 0;
+#if defined __linux__
+  ptrace(PTRACE_TRACEME, 0, nullptr, nullptr);
+#elif defined BSD
+  ptrace(PT_TRACE_ME, 0, nullptr, 0);
+#else
+#error "no ptrace equivalent coded for this platform"
+#endif
+  if (errno != 0 || raise(SIGSTOP) != 0)
+    xbt_die("Could not wait for the model-checker (errno = %d: %s)", errno, strerror(errno));
 
   instance_->handle_messages();
   return instance_.get();
 }
 
-void Client::handle_deadlock_check(s_mc_message_t*)
+void Client::handle_deadlock_check(const s_mc_message_t*)
 {
   bool deadlock = false;
   if (not simix_global->process_list.empty()) {
@@ -79,21 +88,21 @@ void Client::handle_deadlock_check(s_mc_message_t*)
   s_mc_message_int_t answer{MC_MESSAGE_DEADLOCK_CHECK_REPLY, deadlock};
   xbt_assert(channel_.send(answer) == 0, "Could not send response");
 }
-void Client::handle_continue(s_mc_message_t*)
+void Client::handle_continue(const s_mc_message_t*)
 {
   /* Nothing to do */
 }
-void Client::handle_simcall(s_mc_message_simcall_handle_t* message)
+void Client::handle_simcall(const s_mc_message_simcall_handle_t* message)
 {
   smx_actor_t process = SIMIX_process_from_PID(message->pid);
   if (not process)
     xbt_die("Invalid pid %lu", (unsigned long)message->pid);
-  SIMIX_simcall_handle(&process->simcall, message->value);
+  process->simcall_handle(message->value);
   if (channel_.send(MC_MESSAGE_WAITING))
     xbt_die("Could not send MESSAGE_WAITING to model-checker");
 }
 
-void Client::handle_actor_enabled(s_mc_message_actor_enabled_t* msg)
+void Client::handle_actor_enabled(const s_mc_message_actor_enabled_t* msg)
 {
   bool res = simgrid::mc::actor_is_enabled(SIMIX_process_from_PID(msg->aid));
   s_mc_message_int_t answer{MC_MESSAGE_ACTOR_ENABLED_REPLY, res};
@@ -111,9 +120,8 @@ void Client::handle_messages()
     if (received_size < 0)
       xbt_die("Could not receive commands from the model-checker");
 
-    s_mc_message_t* message = (s_mc_message_t*)message_buffer;
+    const s_mc_message_t* message = (s_mc_message_t*)message_buffer;
     switch (message->type) {
-
       case MC_MESSAGE_DEADLOCK_CHECK:
         xbt_assert(received_size == sizeof(s_mc_message_t), "Unexpected size for DEADLOCK_CHECK (%zd != %zu)",
                    received_size, sizeof(s_mc_message_t));
@@ -175,7 +183,7 @@ void Client::ignore_memory(void* addr, std::size_t size)
 
 void Client::ignore_heap(void* address, std::size_t size)
 {
-  xbt_mheap_t heap = mmalloc_get_current_heap();
+  const s_xbt_mheap_t* heap = mmalloc_get_current_heap();
 
   s_mc_message_ignore_heap_t message;
   message.type    = MC_MESSAGE_IGNORE_HEAP;
@@ -219,7 +227,7 @@ void Client::declare_symbol(const char* name, int* value)
 
 void Client::declare_stack(void* stack, size_t size, ucontext_t* context)
 {
-  xbt_mheap_t heap = mmalloc_get_current_heap();
+  const s_xbt_mheap_t* heap = mmalloc_get_current_heap();
 
   s_stack_region_t region;
   memset(&region, 0, sizeof(region));
@@ -234,5 +242,5 @@ void Client::declare_stack(void* stack, size_t size, ucontext_t* context)
   if (channel_.send(message))
     xbt_die("Could not send STACK_REGION to model-checker");
 }
-}
-}
+} // namespace mc
+} // namespace simgrid