From 772b27f677a94b83523c0b44e018f1feb4b558ef Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Thu, 16 Jan 2020 11:25:25 +0100 Subject: [PATCH] Define and use ContextSwapped::get_stack_bottom() to get the address for the bottom of the stack. --- src/kernel/context/ContextBoost.cpp | 12 +++--------- src/kernel/context/ContextSwapped.cpp | 15 ++++----------- src/kernel/context/ContextSwapped.hpp | 5 ++++- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/kernel/context/ContextBoost.cpp b/src/kernel/context/ContextBoost.cpp index 27f801fdd1..b6da4a1436 100644 --- a/src/kernel/context/ContextBoost.cpp +++ b/src/kernel/context/ContextBoost.cpp @@ -28,17 +28,11 @@ BoostContext::BoostContext(std::function&& 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 } } diff --git a/src/kernel/context/ContextSwapped.cpp b/src/kernel/context/ContextSwapped.cpp index c86e48c554..093cf731fc 100644 --- a/src/kernel/context/ContextSwapped.cpp +++ b/src/kernel/context/ContextSwapped.cpp @@ -48,7 +48,7 @@ SwappedContext::SwappedContext(std::function&& 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&& code, smx_actor_t actor, this->stack_ = static_cast(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(); diff --git a/src/kernel/context/ContextSwapped.hpp b/src/kernel/context/ContextSwapped.hpp index 644245e36a..c495b34b70 100644 --- a/src/kernel/context/ContextSwapped.hpp +++ b/src/kernel/context/ContextSwapped.hpp @@ -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; -- 2.20.1