From 6c0bb3758e291ff34cd0cde885eae9b5f6f288f7 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 9 Nov 2018 22:06:59 +0000 Subject: [PATCH] Re-land r343606 "[winasan] Unpoison the stack in NtTerminateThread" This change was reverted because it caused some nacl tests in chromium to fail. I attempted to reproduce those problems locally, but I was unable to. Let's reland this and let Chromium's test infrastructure discover any problems. llvm-svn: 346560 --- compiler-rt/lib/asan/asan_win.cc | 12 +++++++++++- compiler-rt/test/asan/TestCases/Windows/dll_host.cc | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/asan/asan_win.cc b/compiler-rt/lib/asan/asan_win.cc index 5661d911cab8..889c5ba7db31 100644 --- a/compiler-rt/lib/asan/asan_win.cc +++ b/compiler-rt/lib/asan/asan_win.cc @@ -154,6 +154,14 @@ INTERCEPTOR_WINAPI(DWORD, CreateThread, asan_thread_start, t, thr_flags, tid); } +INTERCEPTOR_WINAPI(LONG, NtTerminateThread, HANDLE handle, LONG status) { + // Unpoison the terminating 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); + return REAL(NtTerminateThread(handle, status)); +} + // }}} namespace __asan { @@ -169,7 +177,9 @@ 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 diff --git a/compiler-rt/test/asan/TestCases/Windows/dll_host.cc b/compiler-rt/test/asan/TestCases/Windows/dll_host.cc index 512f930bc34f..324bd586d33a 100644 --- a/compiler-rt/test/asan/TestCases/Windows/dll_host.cc +++ b/compiler-rt/test/asan/TestCases/Windows/dll_host.cc @@ -29,6 +29,7 @@ // IMPORT: __asan_wrap_HeapReAlloc // IMPORT: __asan_wrap_HeapSize // IMPORT: __asan_wrap_CreateThread +// IMPORT: __asan_wrap_NtTerminateThread // IMPORT: __asan_wrap_RaiseException // IMPORT: __asan_wrap_RtlRaiseException // IMPORT: __asan_wrap_SetUnhandledExceptionFilter