From 31edbd7b3bd167f8a20ba9c715eb5fcdac4006ee Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Mon, 11 Jun 2012 16:16:46 -0700 Subject: [PATCH] Bug 426163 - Make MOZ_CRASH() use TerminateProcess on Windows rather than exit so that destructors and atexit handlers aren't called. r=ted --HG-- extra : rebase_source : 0e340516158d36931fd00824a6ff9e665a9f9354 --- mfbt/Assertions.h | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/mfbt/Assertions.h b/mfbt/Assertions.h index a6615c2f0fb8..25d7d8ebd207 100644 --- a/mfbt/Assertions.h +++ b/mfbt/Assertions.h @@ -13,7 +13,23 @@ #include #include -#ifndef WIN32 +#ifdef WIN32 + /* + * TerminateProcess and GetCurrentProcess are defined in , which + * further depends on . We hardcode these few definitions manually + * because those headers clutter the global namespace with a significant + * number of undesired macros and symbols. + */ +# ifdef __cplusplus + extern "C" { +# endif + __declspec(dllimport) int __stdcall + TerminateProcess(void* hProcess, unsigned int uExitCode); + __declspec(dllimport) void* __stdcall GetCurrentProcess(void); +# ifdef __cplusplus + } +# endif +#else # include #endif #ifdef ANDROID @@ -120,22 +136,30 @@ extern "C" { * On MSVC use the __debugbreak compiler intrinsic, which produces an inline * (not nested in a system function) breakpoint. This distinctively invokes * Breakpad without requiring system library symbols on all stack-processing - * machines, as a nested breakpoint would require. (Technically all Windows - * compilers would require this, but practically only MSVC matters.) + * machines, as a nested breakpoint would require. We use TerminateProcess + * with the exit code aborting would generate because we don't want to invoke + * atexit handlers, destructors, library unload handlers, and so on when our + * process might be in a compromised state. We don't use abort() because + * it'd cause Windows to annoyingly pop up the process error dialog multiple + * times. See bug 345118 and bug 426163. + * + * (Technically these are Windows requirements, not MSVC requirements. But + * practically you need MSVC for debugging, and we only ship builds created + * by MSVC, so doing it this way reduces complexity.) */ # ifdef __cplusplus # define MOZ_CRASH() \ do { \ __debugbreak(); \ *((volatile int*) NULL) = 123; \ - ::exit(3); \ + ::TerminateProcess(::GetCurrentProcess(), 3); \ } while (0) # else # define MOZ_CRASH() \ do { \ __debugbreak(); \ *((volatile int*) NULL) = 123; \ - exit(3); \ + TerminateProcess(GetCurrentProcess(), 3); \ } while (0) # endif #else