#include "src/kernel/actor/SimcallObserver.hpp"
#include "src/mc/mc_base.hpp"
#include "src/mc/mc_config.hpp"
+#if SIMGRID_HAVE_STATEFUL_MC
#include "src/mc/sosp/RemoteProcessMemory.hpp"
+#endif
#if HAVE_SMPI
#include "src/smpi/include/private.hpp"
#endif
std::unique_ptr<AppSide> AppSide::instance_;
-AppSide* AppSide::initialize()
+AppSide* AppSide::get()
{
- if (not std::getenv(MC_ENV_SOCKET_FD)) // We are not in MC mode: don't initialize the MC world
+ // Only initialize the MC world once
+ if (instance_ != nullptr)
+ return instance_.get();
+
+ if (std::getenv(MC_ENV_SOCKET_FD) == nullptr) // We are not in MC mode: don't initialize the MC world
return nullptr;
- // Do not break if we are called multiple times:
- if (instance_)
- return instance_.get();
+ XBT_DEBUG("Initialize the MC world. MC_NEED_PTRACE=%s", std::getenv("MC_NEED_PTRACE"));
- simgrid::mc::model_checking_mode = ModelCheckingMode::APP_SIDE;
+ simgrid::mc::set_model_checking_mode(ModelCheckingMode::APP_SIDE);
setvbuf(stdout, nullptr, _IOLBF, 0);
answer.type = MessageType::FORK_REPLY;
answer.value = getpid();
xbt_assert(channel_.send(answer) == 0, "Could not send response to WAIT_CHILD_REPLY: %s", strerror(errno));
+ } else {
+ XBT_DEBUG("App %d forks subprocess %d.", getpid(), pid);
}
}
void AppSide::handle_wait_child(const s_mc_message_int_t* msg)
}
void AppSide::handle_need_meminfo()
{
+#if SIMGRID_HAVE_STATEFUL_MC
this->need_memory_info_ = true;
s_mc_message_need_meminfo_reply_t answer = {};
answer.type = MessageType::NEED_MEMINFO_REPLY;
answer.mmalloc_default_mdp = mmalloc_get_current_heap();
xbt_assert(channel_.send(answer) == 0, "Could not send response to the request for meminfo.");
+#else
+ xbt_die("SimGrid was compiled without MC suppport, so liveness and similar features are not available.");
+#endif
}
void AppSide::handle_actors_status() const
{
if (not MC_is_active() || not need_memory_info_)
return;
+#if SIMGRID_HAVE_STATEFUL_MC
s_mc_message_ignore_memory_t message = {};
message.type = MessageType::IGNORE_MEMORY;
message.addr = (std::uintptr_t)addr;
message.size = size;
xbt_assert(channel_.send(message) == 0, "Could not send IGNORE_MEMORY message to model-checker");
+#else
+ xbt_die("Cannot really call ignore_heap() in non-SIMGRID_MC mode.");
+#endif
}
void AppSide::ignore_heap(void* address, std::size_t size) const
if (not MC_is_active() || not need_memory_info_)
return;
+#if SIMGRID_HAVE_STATEFUL_MC
const s_xbt_mheap_t* heap = mmalloc_get_current_heap();
s_mc_message_ignore_heap_t message = {};
}
xbt_assert(channel_.send(message) == 0, "Could not send ignored region to MCer");
+#else
+ xbt_die("Cannot really call ignore_heap() in non-SIMGRID_MC mode.");
+#endif
}
void AppSide::unignore_heap(void* address, std::size_t size) const
if (not MC_is_active() || not need_memory_info_)
return;
+#if SIMGRID_HAVE_STATEFUL_MC
s_mc_message_ignore_memory_t message = {};
message.type = MessageType::UNIGNORE_HEAP;
message.addr = (std::uintptr_t)address;
message.size = size;
xbt_assert(channel_.send(message) == 0, "Could not send IGNORE_HEAP message to model-checker");
+#else
+ xbt_die("Cannot really call unignore_heap() in non-SIMGRID_MC mode.");
+#endif
}
void AppSide::declare_symbol(const char* name, int* value) const
return;
}
+#if SIMGRID_HAVE_STATEFUL_MC
s_mc_message_register_symbol_t message = {};
message.type = MessageType::REGISTER_SYMBOL;
xbt_assert(strlen(name) + 1 <= message.name.size(), "Symbol is too long");
message.callback = nullptr;
message.data = value;
xbt_assert(channel_.send(message) == 0, "Could send REGISTER_SYMBOL message to model-checker");
+#else
+ xbt_die("Cannot really call declare_symbol() in non-SIMGRID_MC mode.");
+#endif
}
/** Register a stack in the model checker
if (not MC_is_active() || not need_memory_info_)
return;
+#if SIMGRID_HAVE_STATEFUL_MC
const s_xbt_mheap_t* heap = mmalloc_get_current_heap();
s_stack_region_t region = {};
message.type = MessageType::STACK_REGION;
message.stack_region = region;
xbt_assert(channel_.send(message) == 0, "Could not send STACK_REGION to model-checker");
+#else
+ xbt_die("Cannot really call declare_stack() in non-SIMGRID_MC mode.");
+#endif
}
} // namespace simgrid::mc