[PATCH] D52091: [winasan] Unpoison the stack in NtTerminateThread
David Major via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 14 06:01:05 PDT 2018
dmajor created this revision.
dmajor added a reviewer: rnk.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.
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 hook that unpoisons the stack just before the NtTerminateThread syscall.
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D52091
Files:
lib/asan/asan_win.cc
Index: lib/asan/asan_win.cc
===================================================================
--- lib/asan/asan_win.cc
+++ lib/asan/asan_win.cc
@@ -154,14 +154,24 @@
asan_thread_start, t, thr_flags, tid);
}
+INTERCEPTOR_WINAPI(void, NtTerminateThread, void* rcx) {
+ // Unpoison the terminating thread's stack because the memory may be re-used.
+ NT_TIB* pTib = reinterpret_cast<NT_TIB*>(NtCurrentTeb());
+ uptr stackSize = (uptr)pTib->StackBase - (uptr)pTib->StackLimit;
+ __asan_unpoison_memory_region(pTib->StackLimit, stackSize);
+ return REAL(NtTerminateThread(rcx));
+}
+
// }}}
namespace __asan {
void InitializePlatformInterceptors() {
ASAN_INTERCEPT_FUNC(CreateThread);
ASAN_INTERCEPT_FUNC(SetUnhandledExceptionFilter);
-
+ CHECK(::__interception::OverrideFunction("NtTerminateThread",
+ (uptr)WRAP(NtTerminateThread),
+ (uptr *)&REAL(NtTerminateThread)));
#ifdef _WIN64
ASAN_INTERCEPT_FUNC(__C_specific_handler);
#else
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52091.165483.patch
Type: text/x-patch
Size: 1084 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180914/0f35ed11/attachment.bin>
More information about the llvm-commits
mailing list