Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Disable alternate signal stack before thread exit.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 18 Sep 2017 19:35:51 +0000 (21:35 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 18 Sep 2017 19:37:49 +0000 (21:37 +0200)
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)

src/kernel/context/ContextThread.cpp

index 67a6418..a2b2165 100644 (file)
@@ -179,6 +179,10 @@ void *ThreadContext::maestro_wrapper(void *param)
   // Tell main that we have finished:
   xbt_os_sem_release(context->end_);
 
   // 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;
 }
 
   return nullptr;
 }
 
@@ -198,6 +202,11 @@ void ThreadContext::stop()
   // Signal to the maestro that it has finished:
   xbt_os_sem_release(this->end_);
 
   // 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);
 }
 
   xbt_os_thread_exit(nullptr);
 }