diff options
author | Reid Kleckner <rnk@google.com> | 2016-11-15 21:54:58 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2016-11-15 21:54:58 +0000 |
commit | c9b27ba11d76430b6541e81a2ef8d992bf538526 (patch) | |
tree | 6690cfbeb819af4449cc7b0baabdbf74871ed7c5 | |
parent | 26168ad5c50f63e676184c207adf643ca7707ce9 (diff) | |
download | bcm5719-llvm-c9b27ba11d76430b6541e81a2ef8d992bf538526.tar.gz bcm5719-llvm-c9b27ba11d76430b6541e81a2ef8d992bf538526.zip |
Allow users to call ASan's deadly exception report mechanism
Users often have their own unhandled exception filters installed. ASan
already goes to great lengths to install its own filter, but our core
wars with Chrome crashpad have escalated to the point that its time to
declare a truce. By exposing this hook, they can call us directly when
they want ASan crash reporting without worrying about who initializes
when.
llvm-svn: 287040
-rw-r--r-- | compiler-rt/lib/asan/asan_win.cc | 20 | ||||
-rw-r--r-- | compiler-rt/lib/asan/asan_win_dll_thunk.cc | 21 |
2 files changed, 25 insertions, 16 deletions
diff --git a/compiler-rt/lib/asan/asan_win.cc b/compiler-rt/lib/asan/asan_win.cc index 236647ac9b1..4e676de8b61 100644 --- a/compiler-rt/lib/asan/asan_win.cc +++ b/compiler-rt/lib/asan/asan_win.cc @@ -293,17 +293,25 @@ const char *DescribeSignalOrException(int signo) { return nullptr; } -static long WINAPI SEHHandler(EXCEPTION_POINTERS *info) { +extern "C" SANITIZER_INTERFACE_ATTRIBUTE +long __asan_unhandled_exception_filter(EXCEPTION_POINTERS *info) { EXCEPTION_RECORD *exception_record = info->ExceptionRecord; CONTEXT *context = info->ContextRecord; - if (ShouldReportDeadlyException(exception_record->ExceptionCode)) { - SignalContext sig = SignalContext::Create(exception_record, context); - ReportDeadlySignal(exception_record->ExceptionCode, sig); - } - + // Continue the search if the signal wasn't deadly. + if (!ShouldReportDeadlyException(exception_record->ExceptionCode)) + return EXCEPTION_CONTINUE_SEARCH; // FIXME: Handle EXCEPTION_STACK_OVERFLOW here. + SignalContext sig = SignalContext::Create(exception_record, context); + ReportDeadlySignal(exception_record->ExceptionCode, sig); + UNREACHABLE("returned from reporting deadly signal"); +} + +static long WINAPI SEHHandler(EXCEPTION_POINTERS *info) { + __asan_unhandled_exception_filter(info); + + // Bubble out to the default exception filter. return default_seh_handler(info); } diff --git a/compiler-rt/lib/asan/asan_win_dll_thunk.cc b/compiler-rt/lib/asan/asan_win_dll_thunk.cc index 5e1e71dd1c7..fb691e3e552 100644 --- a/compiler-rt/lib/asan/asan_win_dll_thunk.cc +++ b/compiler-rt/lib/asan/asan_win_dll_thunk.cc @@ -23,10 +23,16 @@ #include "interception/interception.h" #include "sanitizer_common/sanitizer_platform_interceptors.h" +#ifdef _M_IX86 +#define WINAPI __stdcall +#else +#define WINAPI +#endif + // ---------- Function interception helper functions and macros ----------- {{{1 extern "C" { -void *__stdcall GetModuleHandleA(const char *module_name); -void *__stdcall GetProcAddress(void *module, const char *proc_name); +void *WINAPI GetModuleHandleA(const char *module_name); +void *WINAPI GetProcAddress(void *module, const char *proc_name); void abort(); } @@ -229,6 +235,7 @@ extern "C" void __asan_version_mismatch_check() { } INTERFACE_FUNCTION(__asan_handle_no_return) +INTERFACE_FUNCTION(__asan_unhandled_exception_filter) INTERFACE_FUNCTION(__asan_report_store1) INTERFACE_FUNCTION(__asan_report_store2) @@ -456,19 +463,13 @@ static int call_asan_init() { #pragma section(".CRT$XIB", long, read) // NOLINT __declspec(allocate(".CRT$XIB")) int (*__asan_preinit)() = call_asan_init; -#ifdef _M_IX86 -#define NTAPI __stdcall -#else -#define NTAPI -#endif - -static void NTAPI asan_thread_init(void *mod, unsigned long reason, +static void WINAPI asan_thread_init(void *mod, unsigned long reason, void *reserved) { if (reason == /*DLL_PROCESS_ATTACH=*/1) __asan_init(); } #pragma section(".CRT$XLAB", long, read) // NOLINT -__declspec(allocate(".CRT$XLAB")) void (NTAPI *__asan_tls_init)(void *, +__declspec(allocate(".CRT$XLAB")) void (WINAPI *__asan_tls_init)(void *, unsigned long, void *) = asan_thread_init; #endif // ASAN_DLL_THUNK |