From d052a579008b239a856c0fe055cb25b3cb3a8fd2 Mon Sep 17 00:00:00 2001 From: Kuba Brecka Date: Mon, 2 May 2016 15:06:08 +0000 Subject: [PATCH] [sanitizer] Don't reuse the main thread in ThreadRegistry There is a hard-to-reproduce crash happening on OS X that involves terminating the main thread (dispatch_main does that, see discussion at http://reviews.llvm.org/D18496) and later reusing the main thread's ThreadContext. This patch disables reuse of the main thread. I believe this problem exists only on OS X, because on other systems the main thread cannot be terminated without exiting the process. Differential Revision: http://reviews.llvm.org/D19722 llvm-svn: 268238 --- compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.cc b/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.cc index 2ec92ff..6e7ddfa 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.cc @@ -277,6 +277,8 @@ void ThreadRegistry::StartThread(u32 tid, uptr os_id, void *arg) { } void ThreadRegistry::QuarantinePush(ThreadContextBase *tctx) { + if (tctx->tid == 0) + return; // Don't reuse the main thread. It's a special snowflake. dead_threads_.push_back(tctx); if (dead_threads_.size() <= thread_quarantine_size_) return; -- 2.7.4