diff --git a/toolkit/crashreporter/test/CrashTestUtils.jsm b/toolkit/crashreporter/test/CrashTestUtils.jsm index 39d6b9052c8..18f9d42d527 100644 --- a/toolkit/crashreporter/test/CrashTestUtils.jsm +++ b/toolkit/crashreporter/test/CrashTestUtils.jsm @@ -42,6 +42,13 @@ CrashTestUtils.lockDir = lib.declare("LockDir", ctypes.voidptr_t); // nsISupports* +try { + CrashTestUtils.TryOverrideExceptionHandler = lib.declare("TryOverrideExceptionHandler", + ctypes.default_abi, + ctypes.void_t); +} +catch(ex) {} + CrashTestUtils.dumpHasStream = lib.declare("DumpHasStream", ctypes.default_abi, ctypes.bool, diff --git a/toolkit/crashreporter/test/nsTestCrasher.cpp b/toolkit/crashreporter/test/nsTestCrasher.cpp index 4e9147c88a9..a824bd6d723 100644 --- a/toolkit/crashreporter/test/nsTestCrasher.cpp +++ b/toolkit/crashreporter/test/nsTestCrasher.cpp @@ -104,3 +104,17 @@ uint64_t SaveAppMemory() return (int64_t)testData; } + +#ifdef XP_WIN32 +static LONG WINAPI HandleException(EXCEPTION_POINTERS* exinfo) +{ + TerminateProcess(GetCurrentProcess(), 0); + return 0; +} + +extern "C" NS_EXPORT +void TryOverrideExceptionHandler() +{ + SetUnhandledExceptionFilter(HandleException); +} +#endif diff --git a/toolkit/crashreporter/test/unit/test_override_exception_handler.js b/toolkit/crashreporter/test/unit/test_override_exception_handler.js new file mode 100644 index 00000000000..7e7787d80e7 --- /dev/null +++ b/toolkit/crashreporter/test/unit/test_override_exception_handler.js @@ -0,0 +1,12 @@ +function run_test() +{ + // Ensure that attempting to override the exception handler doesn't cause + // us to lose our exception handler. + do_crash( + function() { + CrashTestUtils.TryOverrideExceptionHandler(); + }, + function(mdump, extra) { + }, + true); +} diff --git a/toolkit/crashreporter/test/unit/xpcshell.ini b/toolkit/crashreporter/test/unit/xpcshell.ini index fce8bbc9fd6..7c147187d46 100644 --- a/toolkit/crashreporter/test/unit/xpcshell.ini +++ b/toolkit/crashreporter/test/unit/xpcshell.ini @@ -11,6 +11,8 @@ skip-if = os == 'win' && debug [test_crashreporter.js] [test_crashreporter_crash.js] [test_crashreporter_crash_profile_lock.js] +[test_override_exception_handler.js] +run-if = os == 'win' [test_crashreporter_appmem.js] run-if = os == 'win' || os == 'linux'