Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define and use ContextSwapped::get_stack_bottom() to get the address for the bottom...
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 16 Jan 2020 10:25:25 +0000 (11:25 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 16 Jan 2020 21:30:20 +0000 (22:30 +0100)
src/kernel/context/ContextBoost.cpp
src/kernel/context/ContextSwapped.cpp
src/kernel/context/ContextSwapped.hpp

index 27f801f..b6da4a1 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
   }
 }
index c86e48c..093cf73 100644 (file)
@@ -48,7 +48,7 @@ SwappedContext::SwappedContext(std::function<void()>&& code, smx_actor_t actor,
   if (has_code()) {
     xbt_assert((smx_context_stack_size & 0xf) == 0, "smx_context_stack_size should be multiple of 16");
     if (smx_context_guard_size > 0 && not MC_is_active()) {
-#if !defined(PTH_STACKGROWTH) || (PTH_STACKGROWTH != -1)
+#if PTH_STACKGROWTH != -1
       xbt_die(
           "Stack overflow protection is known to be broken on your system: you stacks grow upwards (or detection is "
           "broken). "
@@ -91,14 +91,12 @@ SwappedContext::SwappedContext(std::function<void()>&& code, smx_actor_t actor,
       this->stack_ = static_cast<unsigned char*>(xbt_malloc0(smx_context_stack_size));
     }
 
-#if PTH_STACKGROWTH == -1
-    ASAN_ONLY(this->asan_stack_ = this->stack_ + smx_context_stack_size);
-#else
-    ASAN_ONLY(this->asan_stack_ = this->stack_);
-#endif
 #if HAVE_VALGRIND_H
     if (RUNNING_ON_VALGRIND)
       this->valgrind_stack_id_ = VALGRIND_STACK_REGISTER(this->stack_, this->stack_ + smx_context_stack_size);
+#endif
+#if HAVE_SANITIZER_ADDRESS_FIBER_SUPPORT
+    this->asan_stack_ = get_stack_bottom();
 #endif
   }
 }
@@ -130,11 +128,6 @@ SwappedContext::~SwappedContext()
   xbt_free(stack_);
 }
 
-unsigned char* SwappedContext::get_stack()
-{
-  return stack_;
-}
-
 void SwappedContext::stop()
 {
   Context::stop();
index 644245e..c495b34 100644 (file)
@@ -45,7 +45,10 @@ public:
 
   virtual void swap_into(SwappedContext* to) = 0; // Defined in Raw, Boost and UContext subclasses
 
-  unsigned char* get_stack();
+  unsigned char* get_stack() const { return stack_; }
+  // Return the address for the bottom of the stack.  Depending on the stack direction it may be the lower or higher
+  // address
+  unsigned char* get_stack_bottom() const { return PTH_STACKGROWTH == -1 ? stack_ + smx_context_stack_size : stack_; }
 
 #if HAVE_SANITIZER_ADDRESS_FIBER_SUPPORT
   const void* asan_stack_   = nullptr;