From e36a2202155d007c72d9f54fdddf3f422a8503f8 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 27 Sep 2017 23:31:25 +0200 Subject: [PATCH 1/1] Align top of stacks to a multiple of 16. It's needed for Asan not to whine. --- include/simgrid/simix.h | 4 ++-- src/kernel/context/Context.hpp | 8 ++++---- src/kernel/context/ContextBoost.cpp | 2 +- src/simix/smx_context.cpp | 4 ++-- src/simix/smx_global.cpp | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index de1ac3ad5f..4d551932c5 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -65,9 +65,9 @@ typedef enum { /* Process creation/destruction callbacks */ typedef void (*void_pfn_smxprocess_t) (smx_actor_t); -extern int smx_context_stack_size; +extern unsigned smx_context_stack_size; extern int smx_context_stack_size_was_set; -extern int smx_context_guard_size; +extern unsigned smx_context_guard_size; extern int smx_context_guard_size_was_set; SG_BEGIN_DECL() diff --git a/src/kernel/context/Context.hpp b/src/kernel/context/Context.hpp index a60ea33971..090e7f4876 100644 --- a/src/kernel/context/Context.hpp +++ b/src/kernel/context/Context.hpp @@ -159,12 +159,12 @@ XBT_PUBLIC_DATA(char sigsegv_stack[SIGSTKSZ]); /* 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. */ + * size for the stack. Round its value to a multiple of 16 (for stack alignment). */ #if HAVE_VALGRIND_H -# define smx_context_usable_stack_size \ - (smx_context_stack_size - sizeof(unsigned int)) /* for valgrind_stack_id */ +#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 +#define smx_context_usable_stack_size (smx_context_stack_size & ~0xf) #endif /** @brief Executes all the processes to run (in parallel if possible). */ diff --git a/src/kernel/context/ContextBoost.cpp b/src/kernel/context/ContextBoost.cpp index fa2faf195b..6c5b2a5de3 100644 --- a/src/kernel/context/ContextBoost.cpp +++ b/src/kernel/context/ContextBoost.cpp @@ -166,7 +166,7 @@ BoostContext::BoostContext(std::function 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 - void* stack = static_cast(this->stack_) + smx_context_usable_stack_size - 1; + void* stack = static_cast(this->stack_) + smx_context_usable_stack_size; #else void* stack = this->stack_; #endif diff --git a/src/simix/smx_context.cpp b/src/simix/smx_context.cpp index 5906e9d9d1..e3991634b7 100644 --- a/src/simix/smx_context.cpp +++ b/src/simix/smx_context.cpp @@ -79,9 +79,9 @@ static simgrid::config::Flag context_factory_name( (std::string("Possible values: ")+contexts_list()).c_str(), context_factories[0].first); -int smx_context_stack_size; +unsigned smx_context_stack_size; int smx_context_stack_size_was_set = 0; -int smx_context_guard_size; +unsigned smx_context_guard_size; int smx_context_guard_size_was_set = 0; #if HAVE_THREAD_LOCAL_STORAGE static XBT_THREAD_LOCAL smx_context_t smx_current_context_parallel; diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index 90deaa8ede..db7528256f 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -86,7 +86,7 @@ static void segvhandler(int signum, siginfo_t *siginfo, void *context) fprintf(stderr, "Access violation detected.\n" "This probably comes from a programming error in your code, or from a stack\n" "overflow. If you are certain of your code, try increasing the stack size\n" - " --cfg=contexts/stack-size=XXX (current size is %d KiB).\n" + " --cfg=contexts/stack-size=XXX (current size is %u KiB).\n" "\n" "If it does not help, this may have one of the following causes:\n" "a bug in SimGrid, a bug in the OS or a bug in a third-party libraries.\n" -- 2.20.1