Only register stacks when running on Valgrind to avoid false alarms from Asan.
/* 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_usable_stack_size;
+ 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_usable_stack_size, BoostContext::wrapper);
+ this->fc_ = boost::context::make_fcontext(stack, smx_context_stack_size, BoostContext::wrapper);
#else
- this->fc_ = boost::context::detail::make_fcontext(stack, smx_context_usable_stack_size, BoostContext::wrapper);
+ this->fc_ = boost::context::detail::make_fcontext(stack, smx_context_stack_size, BoostContext::wrapper);
#endif
} else {
: SwappedContext(std::move(code), actor, factory)
{
if (has_code()) {
- this->stack_top_ = raw_makecontext(get_stack(), smx_context_usable_stack_size, RawContext::wrapper, this);
+ this->stack_top_ = raw_makecontext(get_stack(), smx_context_stack_size, RawContext::wrapper, this);
} else {
if (MC_is_active())
MC_ignore_heap(&stack_top_, sizeof(stack_top_));
factory_->workers_context_[0] = this;
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
- ASAN_ONLY(this->asan_stack_ = this->stack_ + smx_context_usable_stack_size);
+ ASAN_ONLY(this->asan_stack_ = this->stack_ + smx_context_stack_size);
#else
ASAN_ONLY(this->asan_stack_ = this->stack_);
#endif
#if HAVE_VALGRIND_H
- unsigned int valgrind_stack_id = VALGRIND_STACK_REGISTER(this->stack_, this->stack_ + smx_context_stack_size);
- memcpy(this->stack_ + smx_context_usable_stack_size, &valgrind_stack_id, sizeof valgrind_stack_id);
+ if (RUNNING_ON_VALGRIND)
+ this->valgrind_stack_id_ = VALGRIND_STACK_REGISTER(this->stack_, this->stack_ + smx_context_stack_size);
#endif
}
}
return;
#if HAVE_VALGRIND_H
- unsigned int valgrind_stack_id;
- memcpy(&valgrind_stack_id, stack_ + smx_context_usable_stack_size, sizeof valgrind_stack_id);
- VALGRIND_STACK_DEREGISTER(valgrind_stack_id);
+ if (RUNNING_ON_VALGRIND)
+ VALGRIND_STACK_DEREGISTER(valgrind_stack_id_);
#endif
#ifndef _WIN32
private:
unsigned char* stack_ = nullptr; /* the thread stack */
SwappedContextFactory* const factory_; // for sequential and parallel run_all()
+
+#if HAVE_VALGRIND_H
+ unsigned int valgrind_stack_id_;
+#endif
};
} // namespace context
getcontext(&this->uc_);
this->uc_.uc_link = nullptr;
this->uc_.uc_stack.ss_sp = sg_makecontext_stack_addr(get_stack());
- this->uc_.uc_stack.ss_size = sg_makecontext_stack_size(smx_context_usable_stack_size);
+ this->uc_.uc_stack.ss_size = sg_makecontext_stack_size(smx_context_stack_size);
// Makecontext expects integer arguments; we want to pass a pointer.
// This context address is decomposed into a serie of integers, which are passed as arguments to makecontext.
#if SIMGRID_HAVE_MC
if (MC_is_active()) {
- MC_register_stack_area(get_stack(), actor, &(this->uc_), smx_context_usable_stack_size);
+ MC_register_stack_area(get_stack(), actor, &(this->uc_), smx_context_stack_size);
}
#endif
}
#define ASAN_FINISH_SWITCH(fake_stack_save, bottom_old, size_old) (void)0
#endif
-/* We are using the bottom of the stack to save some information, like the
- * valgrind_stack_id. Define smx_context_usable_stack_size to give the remaining
- * size for the stack. Round its value to a multiple of 16 (asan wants the stacks to be aligned this way). */
-#if HAVE_VALGRIND_H
-#define smx_context_usable_stack_size \
- ((smx_context_stack_size - sizeof(unsigned int)) & ~0xf) /* for valgrind_stack_id */
-#else
-#define smx_context_usable_stack_size (smx_context_stack_size & ~0xf)
-#endif
-
#endif