Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define and use SwappedContext::verify_previous_context().
[simgrid.git] / src / kernel / context / ContextBoost.cpp
index 71274db..759837a 100644 (file)
@@ -28,17 +28,11 @@ BoostContext::BoostContext(std::function<void()>&& code, actor::ActorImpl* actor
 
   /* if the user provided a function for the process then use it, otherwise it is the context for maestro */
   if (has_code()) {
-    /* We need to pass the bottom of the stack to make_fcontext,
-       depending on the stack direction it may be the lower or higher address: */
-#if PTH_STACKGROWTH == -1
-    unsigned char* stack = get_stack() + smx_context_stack_size;
-#else
-    unsigned char* stack = get_stack();
-#endif
 #if BOOST_VERSION < 106100
-    this->fc_ = boost::context::make_fcontext(stack, smx_context_stack_size, BoostContext::wrapper);
+    this->fc_ = boost::context::make_fcontext(get_stack_bottom(), smx_context_stack_size, BoostContext::wrapper);
 #else
-    this->fc_ = boost::context::detail::make_fcontext(stack, smx_context_stack_size, BoostContext::wrapper);
+    this->fc_ =
+        boost::context::detail::make_fcontext(get_stack_bottom(), smx_context_stack_size, BoostContext::wrapper);
 #endif
   }
 }
@@ -49,7 +43,7 @@ void BoostContext::wrapper(BoostContext::arg_type arg)
   BoostContext* context = reinterpret_cast<BoostContext*>(arg);
 #else
   BoostContext* context = static_cast<BoostContext**>(arg.data)[1];
-  ASAN_ONLY(xbt_assert(context->asan_ctx_ == static_cast<BoostContext**>(arg.data)[0]));
+  context->verify_previous_context(static_cast<BoostContext**>(arg.data)[0]);
   ASAN_FINISH_SWITCH(nullptr, &context->asan_ctx_->asan_stack_, &context->asan_ctx_->asan_stack_size_);
   static_cast<BoostContext**>(arg.data)[0]->fc_ = arg.fctx;
 #endif
@@ -64,6 +58,7 @@ void BoostContext::wrapper(BoostContext::arg_type arg)
   }
   ASAN_ONLY(context->asan_stop_ = true);
   context->suspend();
+  THROW_IMPOSSIBLE;
 }
 
 void BoostContext::swap_into(SwappedContext* to_)
@@ -77,7 +72,7 @@ void BoostContext::swap_into(SwappedContext* to_)
   ASAN_ONLY(to->asan_ctx_ = this);
   ASAN_START_SWITCH(this->asan_stop_ ? nullptr : &fake_stack, to->asan_stack_, to->asan_stack_size_);
   boost::context::detail::transfer_t arg = boost::context::detail::jump_fcontext(to->fc_, ctx);
-  ASAN_ONLY(xbt_assert(this->asan_ctx_ == static_cast<BoostContext**>(arg.data)[0]));
+  this->verify_previous_context(static_cast<BoostContext**>(arg.data)[0]);
   ASAN_FINISH_SWITCH(fake_stack, &this->asan_ctx_->asan_stack_, &this->asan_ctx_->asan_stack_size_);
   static_cast<BoostContext**>(arg.data)[0]->fc_ = arg.fctx;
 #endif