[PATCH] D58641: [winasan] Unpoison stack memory when threads exit (redux)
David Major via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 25 11:42:18 PST 2019
dmajor created this revision.
dmajor added a reviewer: rnk.
Herald added subscribers: Sanitizers, llvm-commits, jdoerfert.
Herald added projects: LLVM, Sanitizers.
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.
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D58641
Files:
asan_win.cc
Index: asan_win.cc
===================================================================
--- asan_win.cc
+++ asan_win.cc
@@ -354,6 +354,19 @@
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$XLZ", long, read) // NOLINT
+__declspec(allocate(".CRT$XLZ")) void (NTAPI *__asan_tls_exit)(void *,
+ unsigned long, void *) = asan_thread_exit;
+
WIN_FORCE_LINK(__asan_dso_reg_hook)
// }}}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58641.188229.patch
Type: text/x-patch
Size: 797 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190225/950cd867/attachment.bin>
More information about the llvm-commits
mailing list