forked from OSchip/llvm-project
[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
This commit is contained in:
parent
7429228f20
commit
b4e16e6ad1
|
@ -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)
|
||||
|
||||
// }}}
|
||||
|
|
Loading…
Reference in New Issue