[compiler-rt] r354836 - [winasan] Unpoison stack memory when threads exit (redux)
David Major via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 25 17:35:49 PST 2019
Author: dmajor
Date: Mon Feb 25 17:35:48 2019
New Revision: 354836
URL: http://llvm.org/viewvc/llvm-project?rev=354836&view=rev
Log:
[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
Modified:
compiler-rt/trunk/lib/asan/asan_win.cc
Modified: compiler-rt/trunk/lib/asan/asan_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win.cc?rev=354836&r1=354835&r2=354836&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_win.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_win.cc Mon Feb 25 17:35:48 2019
@@ -354,6 +354,19 @@ __declspec(allocate(".CRT$XLAB")) 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)
// }}}
More information about the llvm-commits
mailing list