build/build-clang/r342652-unpoison-thread-stacks.patch
author James Graham <james@hoppipolla.co.uk>
Thu, 15 Nov 2018 20:40:50 +0000
changeset 503174 9702f65efe224bcb14f64db9eeb99ca2ad5ef8f8
parent 493429 8846c0a176c80b45854d7b29c6f117c9b389ed65
child 508143 c8a4a6617e305d5adec50b8cad2ec54c5893b270
permissions -rw-r--r--
Bug 1507532 - Add support for running reftests in fennec, r=KWierso Add a ReftestExecutor implementation matching the one that we use for Desktop Firefox. Differential Revision: https://phabricator.services.mozilla.com/D12034

[winasan] Unpoison the stack in NtTerminateThread

In long-running builds we've seen some ASan complaints during thread creation that we suspect are due to leftover poisoning from previous threads whose stacks occupied that memory. This patch adds a hook that unpoisons the stack just before the NtTerminateThread syscall.

Differential Revision: https://reviews.llvm.org/D52091

--- a/compiler-rt/lib/asan/asan_win.cc	(revision 342651)
+++ b/compiler-rt/lib/asan/asan_win.cc	(revision 342652)
@@ -154,6 +154,14 @@
                             asan_thread_start, t, thr_flags, tid);
 }
 
+INTERCEPTOR_WINAPI(void, NtTerminateThread, void *rcx) {
+  // Unpoison the terminating thread's stack because the memory may be re-used.
+  NT_TIB *tib = (NT_TIB *)NtCurrentTeb();
+  uptr stackSize = (uptr)tib->StackBase - (uptr)tib->StackLimit;
+  __asan_unpoison_memory_region(tib->StackLimit, stackSize);
+  return REAL(NtTerminateThread(rcx));
+}
+
 // }}}
 
 namespace __asan {
@@ -161,7 +169,9 @@
 void InitializePlatformInterceptors() {
   ASAN_INTERCEPT_FUNC(CreateThread);
   ASAN_INTERCEPT_FUNC(SetUnhandledExceptionFilter);
-
+  CHECK(::__interception::OverrideFunction("NtTerminateThread",
+                                           (uptr)WRAP(NtTerminateThread),
+                                           (uptr *)&REAL(NtTerminateThread)));
 #ifdef _WIN64
   ASAN_INTERCEPT_FUNC(__C_specific_handler);
 #else