Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / src / mc / remote / AppSide.cpp
index 21fa56b..8c3cb1d 100644 (file)
@@ -1,15 +1,17 @@
-/* Copyright (c) 2015-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2015-2021. 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. */
 
 #include "src/mc/remote/AppSide.hpp"
 #include "src/internal_config.h"
+#include "src/kernel/actor/ActorImpl.hpp"
 #include <simgrid/modelchecker.h>
 
 #include <cerrno>
 #include <cstdlib>
 #include <cstring>
+#include <memory>
 #include <sys/ptrace.h>
 #include <sys/socket.h>
 #include <sys/types.h>
@@ -48,7 +50,7 @@ AppSide* AppSide::initialize()
   xbt_assert(type == SOCK_SEQPACKET, "Unexpected socket type %i", type);
   XBT_DEBUG("Model-checked application found expected socket type");
 
-  instance_.reset(new simgrid::mc::AppSide(fd));
+  instance_ = std::make_unique<simgrid::mc::AppSide>(fd);
 
   // Wait for the model-checker:
   errno = 0;
@@ -79,7 +81,7 @@ void AppSide::handle_deadlock_check(const s_mc_message_t*) const
   }
 
   // Send result:
-  s_mc_message_int_t answer{MC_MESSAGE_DEADLOCK_CHECK_REPLY, deadlock};
+  s_mc_message_int_t answer{MessageType::DEADLOCK_CHECK_REPLY, deadlock};
   xbt_assert(channel_.send(answer) == 0, "Could not send response");
 }
 void AppSide::handle_continue(const s_mc_message_t*) const
@@ -88,17 +90,17 @@ void AppSide::handle_continue(const s_mc_message_t*) const
 }
 void AppSide::handle_simcall(const s_mc_message_simcall_handle_t* message) const
 {
-  smx_actor_t process = SIMIX_process_from_PID(message->pid);
+  kernel::actor::ActorImpl* process = kernel::actor::ActorImpl::by_PID(message->pid);
   xbt_assert(process != nullptr, "Invalid pid %lu", message->pid);
   process->simcall_handle(message->value);
-  if (channel_.send(MC_MESSAGE_WAITING))
+  if (channel_.send(MessageType::WAITING))
     xbt_die("Could not send MESSAGE_WAITING to model-checker");
 }
 
 void AppSide::handle_actor_enabled(const s_mc_message_actor_enabled_t* msg) const
 {
-  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};
+  bool res = simgrid::mc::actor_is_enabled(kernel::actor::ActorImpl::by_PID(msg->aid));
+  s_mc_message_int_t answer{MessageType::ACTOR_ENABLED_REPLY, res};
   channel_.send(answer);
 }
 
@@ -111,35 +113,36 @@ void AppSide::handle_messages() const
   while (true) {
     XBT_DEBUG("Waiting messages from model-checker");
 
-    char message_buffer[MC_MESSAGE_LENGTH];
-    ssize_t received_size = channel_.receive(&message_buffer, sizeof(message_buffer));
+    std::array<char, MC_MESSAGE_LENGTH> message_buffer;
+    ssize_t received_size = channel_.receive(message_buffer.data(), message_buffer.size());
 
     xbt_assert(received_size >= 0, "Could not receive commands from the model-checker");
 
-    const s_mc_message_t* message = (s_mc_message_t*)message_buffer;
+    const s_mc_message_t* message = (s_mc_message_t*)message_buffer.data();
     switch (message->type) {
-      case MC_MESSAGE_DEADLOCK_CHECK:
+      case MessageType::DEADLOCK_CHECK:
         assert_msg_size("DEADLOCK_CHECK", s_mc_message_t);
         handle_deadlock_check(message);
         break;
 
-      case MC_MESSAGE_CONTINUE:
+      case MessageType::CONTINUE:
         assert_msg_size("MESSAGE_CONTINUE", s_mc_message_t);
         handle_continue(message);
         return;
 
-      case MC_MESSAGE_SIMCALL_HANDLE:
+      case MessageType::SIMCALL_HANDLE:
         assert_msg_size("SIMCALL_HANDLE", s_mc_message_simcall_handle_t);
-        handle_simcall((s_mc_message_simcall_handle_t*)message_buffer);
+        handle_simcall((s_mc_message_simcall_handle_t*)message_buffer.data());
         break;
 
-      case MC_MESSAGE_ACTOR_ENABLED:
+      case MessageType::ACTOR_ENABLED:
         assert_msg_size("ACTOR_ENABLED", s_mc_message_actor_enabled_t);
-        handle_actor_enabled((s_mc_message_actor_enabled_t*)message_buffer);
+        handle_actor_enabled((s_mc_message_actor_enabled_t*)message_buffer.data());
         break;
 
       default:
-        xbt_die("Received unexpected message %s (%i)", MC_message_type_name(message->type), message->type);
+        xbt_die("Received unexpected message %s (%i)", MC_message_type_name(message->type),
+                static_cast<int>(message->type));
         break;
     }
   }
@@ -149,14 +152,14 @@ void AppSide::main_loop() const
 {
   while (true) {
     simgrid::mc::wait_for_requests();
-    xbt_assert(channel_.send(MC_MESSAGE_WAITING) == 0, "Could not send WAITING message to model-checker");
+    xbt_assert(channel_.send(MessageType::WAITING) == 0, "Could not send WAITING message to model-checker");
     this->handle_messages();
   }
 }
 
 void AppSide::report_assertion_failure() const
 {
-  if (channel_.send(MC_MESSAGE_ASSERTION_FAILED))
+  if (channel_.send(MessageType::ASSERTION_FAILED))
     xbt_die("Could not send assertion to model-checker");
   this->handle_messages();
 }
@@ -164,7 +167,7 @@ void AppSide::report_assertion_failure() const
 void AppSide::ignore_memory(void* addr, std::size_t size) const
 {
   s_mc_message_ignore_memory_t message;
-  message.type = MC_MESSAGE_IGNORE_MEMORY;
+  message.type = MessageType::IGNORE_MEMORY;
   message.addr = (std::uintptr_t)addr;
   message.size = size;
   if (channel_.send(message))
@@ -176,7 +179,7 @@ void AppSide::ignore_heap(void* address, std::size_t size) const
   const s_xbt_mheap_t* heap = mmalloc_get_current_heap();
 
   s_mc_message_ignore_heap_t message;
-  message.type    = MC_MESSAGE_IGNORE_HEAP;
+  message.type    = MessageType::IGNORE_HEAP;
   message.address = address;
   message.size    = size;
   message.block   = ((char*)address - (char*)heap->heapbase) / BLOCKSIZE + 1;
@@ -195,7 +198,7 @@ void AppSide::ignore_heap(void* address, std::size_t size) const
 void AppSide::unignore_heap(void* address, std::size_t size) const
 {
   s_mc_message_ignore_memory_t message;
-  message.type = MC_MESSAGE_UNIGNORE_HEAP;
+  message.type = MessageType::UNIGNORE_HEAP;
   message.addr = (std::uintptr_t)address;
   message.size = size;
   if (channel_.send(message))
@@ -205,10 +208,10 @@ void AppSide::unignore_heap(void* address, std::size_t size) const
 void AppSide::declare_symbol(const char* name, int* value) const
 {
   s_mc_message_register_symbol_t message;
-  message.type = MC_MESSAGE_REGISTER_SYMBOL;
-  if (strlen(name) + 1 > sizeof(message.name))
+  message.type = MessageType::REGISTER_SYMBOL;
+  if (strlen(name) + 1 > message.name.size())
     xbt_die("Symbol is too long");
-  strncpy(message.name, name, sizeof(message.name));
+  strncpy(message.name.data(), name, message.name.size());
   message.callback = nullptr;
   message.data     = value;
   if (channel_.send(message))
@@ -227,7 +230,7 @@ void AppSide::declare_stack(void* stack, size_t size, ucontext_t* context) const
   region.block   = ((char*)stack - (char*)heap->heapbase) / BLOCKSIZE + 1;
 
   s_mc_message_stack_region_t message;
-  message.type         = MC_MESSAGE_STACK_REGION;
+  message.type         = MessageType::STACK_REGION;
   message.stack_region = region;
   if (channel_.send(message))
     xbt_die("Could not send STACK_REGION to model-checker");