From 3ad5c29b75c27873d4d27100e9db031407f251eb Mon Sep 17 00:00:00 2001 From: David Major Date: Tue, 26 Feb 2019 01:35:48 +0000 Subject: [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 --- lib/asan/asan_win.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/asan/asan_win.cc') 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) // }}} -- cgit v1.2.1