summaryrefslogtreecommitdiff
path: root/lib/asan/asan_win.cc
diff options
context:
space:
mode:
authorDavid Major <dmajor@mozilla.com>2019-02-26 01:35:48 +0000
committerDavid Major <dmajor@mozilla.com>2019-02-26 01:35:48 +0000
commit3ad5c29b75c27873d4d27100e9db031407f251eb (patch)
tree13aea56cf72ddccb097c0a7c7ce7818a8ab99372 /lib/asan/asan_win.cc
parent4ff984bdfee09a2609a8fbe8573d911d1984240f (diff)
downloadcompiler-rt-3ad5c29b75c27873d4d27100e9db031407f251eb.tar.gz
[winasan] Unpoison stack memory when threads exit (redux)
This is a second attempt at r342652 using a TLS callback instead of an interceptor. 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 callback that unpoisons the stack memory when a thread exits. Differential Revision: https://reviews.llvm.org/D58641 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@354836 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/asan/asan_win.cc')
-rw-r--r--lib/asan/asan_win.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/asan/asan_win.cc b/lib/asan/asan_win.cc
index 692da5823..3eee845ee 100644
--- a/lib/asan/asan_win.cc
+++ b/lib/asan/asan_win.cc
@@ -354,6 +354,19 @@ __declspec(allocate(".CRT$XLAB")) void (NTAPI *__asan_tls_init)(void *,
unsigned long, void *) = asan_thread_init;
#endif
+static void NTAPI asan_thread_exit(void *module, DWORD reason, void *reserved) {
+ if (reason == DLL_THREAD_DETACH) {
+ // Unpoison the 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);
+ }
+}
+
+#pragma section(".CRT$XLY", long, read) // NOLINT
+__declspec(allocate(".CRT$XLY")) void (NTAPI *__asan_tls_exit)(void *,
+ unsigned long, void *) = asan_thread_exit;
+
WIN_FORCE_LINK(__asan_dso_reg_hook)
// }}}