diff options
author | David Major <dmajor@mozilla.com> | 2019-02-26 01:35:48 +0000 |
---|---|---|
committer | David Major <dmajor@mozilla.com> | 2019-02-26 01:35:48 +0000 |
commit | b4e16e6ad152163f455e0a7dbe9f42eeeb6f63cb (patch) | |
tree | 4cec8b2cc8333f64069bf0d9468e2401ece2cbeb | |
parent | 7429228f20133193334319f637c1fe6e6a92b78a (diff) | |
download | bcm5719-llvm-b4e16e6ad152163f455e0a7dbe9f42eeeb6f63cb.tar.gz bcm5719-llvm-b4e16e6ad152163f455e0a7dbe9f42eeeb6f63cb.zip |
[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
llvm-svn: 354836
-rw-r--r-- | compiler-rt/lib/asan/asan_win.cc | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/compiler-rt/lib/asan/asan_win.cc b/compiler-rt/lib/asan/asan_win.cc index 692da58234a..3eee845ee41 100644 --- a/compiler-rt/lib/asan/asan_win.cc +++ b/compiler-rt/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) // }}} |