+simgrid::kernel::activity::CommImpl* Api::get_comm(smx_simcall_t const r) const
+{
+ switch (r->call_) {
+ case Simcall::COMM_WAIT:
+ return simcall_comm_wait__getraw__comm(r);
+ case Simcall::COMM_TEST:
+ return simcall_comm_test__getraw__comm(r);
+ default:
+ return nullptr;
+ }
+}
+
+/** Statically "upcast" a s_smx_actor_t into an ActorInformation
+ *
+ * This gets 'actorInfo' from '&actorInfo->copy'. It upcasts in the
+ * sense that we could achieve the same thing by having ActorInformation
+ * inherit from s_smx_actor_t but we don't really want to do that.
+ */
+simgrid::mc::ActorInformation* Api::actor_info_cast(smx_actor_t actor) const
+{
+ simgrid::mc::ActorInformation temp;
+ std::size_t offset = (char*)temp.copy.get_buffer() - (char*)&temp;
+
+ auto* process_info = reinterpret_cast<simgrid::mc::ActorInformation*>((char*)actor - offset);
+ return process_info;
+}
+
+// Does half the job
+bool Api::request_depend_asymmetric(smx_simcall_t r1, smx_simcall_t r2) const
+{
+ if (r1->call_ == Simcall::COMM_ISEND && r2->call_ == Simcall::COMM_IRECV)
+ return false;
+
+ if (r1->call_ == Simcall::COMM_IRECV && r2->call_ == Simcall::COMM_ISEND)
+ return false;
+
+ // Those are internal requests, we do not need indirection because those objects are copies:
+ const kernel::activity::CommImpl* synchro1 = get_comm(r1);
+ const kernel::activity::CommImpl* synchro2 = get_comm(r2);
+
+ if ((r1->call_ == Simcall::COMM_ISEND || r1->call_ == Simcall::COMM_IRECV) && r2->call_ == Simcall::COMM_WAIT) {
+ auto mbox = get_mbox_remote_addr(r1);
+ RemotePtr<kernel::activity::MailboxImpl> synchro2_mbox_cpy = remote(synchro2->mbox_cpy);
+
+ if (mbox != synchro2_mbox_cpy && simcall_comm_wait__get__timeout(r2) <= 0)
+ return false;
+
+ if ((r1->issuer_ != synchro2->src_actor_.get()) && (r1->issuer_ != synchro2->dst_actor_.get()) &&
+ simcall_comm_wait__get__timeout(r2) <= 0)
+ return false;
+
+ if ((r1->call_ == Simcall::COMM_ISEND) && (synchro2->type_ == kernel::activity::CommImpl::Type::SEND) &&
+ (synchro2->src_buff_ != simcall_comm_isend__get__src_buff(r1)) && simcall_comm_wait__get__timeout(r2) <= 0)
+ return false;
+
+ if ((r1->call_ == Simcall::COMM_IRECV) && (synchro2->type_ == kernel::activity::CommImpl::Type::RECEIVE) &&
+ (synchro2->dst_buff_ != simcall_comm_irecv__get__dst_buff(r1)) && simcall_comm_wait__get__timeout(r2) <= 0)
+ return false;
+ }
+
+ /* FIXME: the following rule assumes that the result of the isend/irecv call is not stored in a buffer used in the
+ * test call. */
+#if 0
+ if((r1->call == Simcall::COMM_ISEND || r1->call == Simcall::COMM_IRECV)
+ && r2->call == Simcall::COMM_TEST)
+ return false;
+#endif
+
+ if (r1->call_ == Simcall::COMM_WAIT && (r2->call_ == Simcall::COMM_WAIT || r2->call_ == Simcall::COMM_TEST) &&
+ (synchro1->src_actor_.get() == nullptr || synchro1->dst_actor_.get() == nullptr))
+ return false;
+
+ if (r1->call_ == Simcall::COMM_TEST &&
+ (simcall_comm_test__get__comm(r1) == nullptr || synchro1->src_buff_ == nullptr || synchro1->dst_buff_ == nullptr))
+ return false;
+
+ if (r1->call_ == Simcall::COMM_TEST && r2->call_ == Simcall::COMM_WAIT &&
+ synchro1->src_buff_ == synchro2->src_buff_ && synchro1->dst_buff_ == synchro2->dst_buff_)
+ return false;
+
+ if (r1->call_ == Simcall::COMM_WAIT && r2->call_ == Simcall::COMM_TEST && synchro1->src_buff_ != nullptr &&
+ synchro1->dst_buff_ != nullptr && synchro2->src_buff_ != nullptr && synchro2->dst_buff_ != nullptr &&
+ synchro1->dst_buff_ != synchro2->src_buff_ && synchro1->dst_buff_ != synchro2->dst_buff_ &&
+ synchro2->dst_buff_ != synchro1->src_buff_)
+ return false;
+
+ return true;
+}
+
+const char* Api::actor_get_host_name(smx_actor_t actor) const
+{
+ return get_actor_host_name(actor).c_str();
+}
+
+xbt::string const& Api::get_actor_host_name(smx_actor_t actor) const
+{
+ if (mc_model_checker == nullptr)
+ return actor->get_host()->get_name();
+
+ const simgrid::mc::RemoteSimulation* process = &mc_model_checker->get_remote_simulation();
+
+ // Read the simgrid::xbt::string in the MCed process:
+ simgrid::mc::ActorInformation* info = actor_info_cast(actor);
+ auto remote_string_address =
+ remote(reinterpret_cast<const simgrid::xbt::string_data*>(&actor->get_host()->get_name()));
+ simgrid::xbt::string_data remote_string = process->read(remote_string_address);
+ std::vector<char> hostname(remote_string.len + 1);
+ // no need to read the terminating null byte, and thus hostname[remote_string.len] is guaranteed to be '\0'
+ process->read_bytes(hostname.data(), remote_string.len, remote(remote_string.data));
+ info->hostname = &mc_model_checker->get_host_name(hostname.data());
+ return *info->hostname;
+}
+
+const char* Api::actor_get_name(smx_actor_t actor) const
+{
+ if (mc_model_checker == nullptr)
+ return actor->get_cname();
+
+ const simgrid::mc::RemoteSimulation* process = &mc_model_checker->get_remote_simulation();
+
+ simgrid::mc::ActorInformation* info = actor_info_cast(actor);
+ if (info->name.empty()) {
+ simgrid::xbt::string_data string_data = simgrid::xbt::string::to_string_data(actor->name_);
+ info->name = process->read_string(remote(string_data.data), string_data.len);
+ }
+ return info->name.c_str();
+}
+