From: Arnaud Giersch Date: Thu, 16 Jan 2020 13:20:47 +0000 (+0100) Subject: Move smx_ctx_wrapper from ContextUnix to ContextSwapped. X-Git-Tag: v3.25~95 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7c7b545ea545e6b24c560f3b27b22b664ca6056c Move smx_ctx_wrapper from ContextUnix to ContextSwapped. The goal is to use it later with the other kinds of SwappedContext (raw and boost). --- diff --git a/src/kernel/context/ContextSwapped.cpp b/src/kernel/context/ContextSwapped.cpp index 093cf731fc..8d7e071a63 100644 --- a/src/kernel/context/ContextSwapped.cpp +++ b/src/kernel/context/ContextSwapped.cpp @@ -31,6 +31,29 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context); +// The name of this function is currently hardcoded in MC (as string). +// Do not change it without fixing those references as well. +void smx_ctx_wrapper(simgrid::kernel::context::SwappedContext* context) +{ +#if HAVE_SANITIZER_ADDRESS_FIBER_SUPPORT + __sanitizer_finish_switch_fiber(nullptr, &context->asan_ctx_->asan_stack_, &context->asan_ctx_->asan_stack_size_); +#endif + try { + (*context)(); + context->Context::stop(); + } catch (simgrid::ForcefulKillException const&) { + XBT_DEBUG("Caught a ForcefulKillException"); + } catch (simgrid::Exception const& e) { + XBT_INFO("Actor killed by an uncaught exception %s", simgrid::xbt::demangle(typeid(e).name()).get()); + throw; + } +#if HAVE_SANITIZER_ADDRESS_FIBER_SUPPORT + context->asan_stop_ = true; +#endif + context->suspend(); + THROW_IMPOSSIBLE; +} + namespace simgrid { namespace kernel { namespace context { diff --git a/src/kernel/context/ContextSwapped.hpp b/src/kernel/context/ContextSwapped.hpp index cabea51f29..b83ae9fdaa 100644 --- a/src/kernel/context/ContextSwapped.hpp +++ b/src/kernel/context/ContextSwapped.hpp @@ -14,6 +14,16 @@ namespace simgrid { namespace kernel { namespace context { class SwappedContext; +} // namespace context +} // namespace kernel +} // namespace simgrid + +/* Use extern "C" to make sure that this symbol is easy to recognize by name, even on exotic platforms */ +extern "C" XBT_ATTRIB_NORETURN void smx_ctx_wrapper(simgrid::kernel::context::SwappedContext* context); + +namespace simgrid { +namespace kernel { +namespace context { class SwappedContextFactory : public ContextFactory { friend SwappedContext; // Reads whether we are in parallel mode @@ -33,6 +43,8 @@ private: }; class SwappedContext : public Context { + friend void ::smx_ctx_wrapper(simgrid::kernel::context::SwappedContext*); + public: SwappedContext(std::function&& code, smx_actor_t get_actor, SwappedContextFactory* factory); SwappedContext(const SwappedContext&) = delete; diff --git a/src/kernel/context/ContextUnix.cpp b/src/kernel/context/ContextUnix.cpp index 264b603318..882dd743e2 100644 --- a/src/kernel/context/ContextUnix.cpp +++ b/src/kernel/context/ContextUnix.cpp @@ -23,33 +23,16 @@ constexpr int CTX_ADDR_LEN = 2; static_assert(sizeof(simgrid::kernel::context::UContext*) <= CTX_ADDR_LEN * sizeof(int), "Ucontexts are not supported on this arch yet. Please increase CTX_ADDR_LEN."); -/* Make sure that this symbol is easy to recognize by name, even on exotic platforms */ +// This function is called by makecontext(3): use extern "C" to have C language linkage for its type extern "C" { -XBT_ATTRIB_NORETURN void smx_ctx_wrapper(int i1, int i2); -} - -// The name of this function is currently hardcoded in MC (as string). -// Do not change it without fixing those references as well. -void smx_ctx_wrapper(int i1, int i2) +XBT_ATTRIB_NORETURN static void sysv_ctx_wrapper(int i1, int i2) { // Rebuild the Context* pointer from the integers: int ctx_addr[CTX_ADDR_LEN] = {i1, i2}; simgrid::kernel::context::UContext* context; memcpy(&context, ctx_addr, sizeof context); - - ASAN_FINISH_SWITCH(nullptr, &context->asan_ctx_->asan_stack_, &context->asan_ctx_->asan_stack_size_); - try { - (*context)(); - context->Context::stop(); - } catch (simgrid::ForcefulKillException const&) { - XBT_DEBUG("Caught a ForcefulKillException"); - } catch (simgrid::Exception const& e) { - XBT_INFO("Actor killed by an uncaught exception %s", simgrid::xbt::demangle(typeid(e).name()).get()); - throw; - } - ASAN_ONLY(context->asan_stop_ = true); - context->suspend(); - THROW_IMPOSSIBLE; + smx_ctx_wrapper(context); +} } namespace simgrid { @@ -80,7 +63,7 @@ UContext::UContext(std::function&& code, actor::ActorImpl* actor, Swappe int ctx_addr[CTX_ADDR_LEN]{}; UContext* arg = this; memcpy(ctx_addr, &arg, sizeof this); - makecontext(&this->uc_, (void (*)())smx_ctx_wrapper, 2, ctx_addr[0], ctx_addr[1]); + makecontext(&this->uc_, (void (*)())sysv_ctx_wrapper, 2, ctx_addr[0], ctx_addr[1]); #if SIMGRID_HAVE_MC if (MC_is_active()) {