From: Arnaud Giersch Date: Mon, 18 Sep 2017 19:35:51 +0000 (+0200) Subject: Disable alternate signal stack before thread exit. X-Git-Tag: v3_17~100 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/911232a13bacc6c120600c8e1fc70e6a73ca761f?ds=inline Disable alternate signal stack before thread exit. AddressSanitizer (ASan) reports an error if the alternate signal stack remains active when a thread exits: ==28272==ERROR: AddressSanitizer failed to deallocate 0x2000 (8192) bytes at address 0x7f53ebba7c00 ==28272==AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_posix.cc:141 "(("unable to unmap" && 0)) != (0)" (0x0, 0x0) #0 0x7f53ebc950e5 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe40e5) #1 0x7f53ebcb1c15 in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x100c15) #2 0x7f53ebca975f (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xf875f) #3 0x7f53ebcaa560 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xf9560) #4 0x7f53ebc98764 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe7764) #5 0x7f53ea57a5e8 in __nptl_deallocate_tsd.part.4 (/lib/x86_64-linux-gnu/libpthread.so.0+0x65e8) #6 0x7f53ea57b647 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7647) #7 0x7f53e93e0abe in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe8abe) --- diff --git a/src/kernel/context/ContextThread.cpp b/src/kernel/context/ContextThread.cpp index 67a641879e..a2b2165baf 100644 --- a/src/kernel/context/ContextThread.cpp +++ b/src/kernel/context/ContextThread.cpp @@ -179,6 +179,10 @@ void *ThreadContext::maestro_wrapper(void *param) // Tell main that we have finished: xbt_os_sem_release(context->end_); +#ifndef WIN32 + stack.ss_flags = SS_DISABLE; + sigaltstack(&stack, nullptr); +#endif return nullptr; } @@ -198,6 +202,11 @@ void ThreadContext::stop() // Signal to the maestro that it has finished: xbt_os_sem_release(this->end_); +#ifndef WIN32 + stack_t stack; + stack.ss_flags = SS_DISABLE; + sigaltstack(&stack, nullptr); +#endif xbt_os_thread_exit(nullptr); }