Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Align top of stacks to a multiple of 16.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 27 Sep 2017 21:31:25 +0000 (23:31 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 28 Sep 2017 14:31:35 +0000 (16:31 +0200)
It's needed for Asan not to whine.

include/simgrid/simix.h
src/kernel/context/Context.hpp
src/kernel/context/ContextBoost.cpp
src/simix/smx_context.cpp
src/simix/smx_global.cpp

index de1ac3a..4d55193 100644 (file)
@@ -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()
index a60ea33..090e7f4 100644 (file)
@@ -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). */
index fa2faf1..6c5b2a5 100644 (file)
@@ -166,7 +166,7 @@ BoostContext::BoostContext(std::function<void()> 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<char*>(this->stack_) + smx_context_usable_stack_size - 1;
+    void* stack = static_cast<char*>(this->stack_) + smx_context_usable_stack_size;
 #else
     void* stack = this->stack_;
 #endif
index 5906e9d..e399163 100644 (file)
@@ -79,9 +79,9 @@ static simgrid::config::Flag<std::string> 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;
index 90deaa8..db75282 100644 (file)
@@ -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"