mirror of
https://github.com/mitch030504/Wiicompiled_VR_Frame.git
synced 2026-10-06 06:00:25 +02:00
Refine SEH crash handling on Windows
This commit is contained in:
1 parent
243eb86021
commit
13b6d0b447
1 file changed
+25
-2
+25
-2
@@ -921,6 +921,7 @@ constexpr DWORD kCppExceptionCodeMsvc = 0xE06D7363;
|
|||||||
// AddressSanitizer uses STATUS_FATAL_APP_EXIT when it detects an error and wants to report it.
|
// AddressSanitizer uses STATUS_FATAL_APP_EXIT when it detects an error and wants to report it.
|
||||||
// We must let ASan's handler run so it can print file/line information.
|
// We must let ASan's handler run so it can print file/line information.
|
||||||
constexpr DWORD kAsanFatalAppExit = 0x40000015; // STATUS_FATAL_APP_EXIT
|
constexpr DWORD kAsanFatalAppExit = 0x40000015; // STATUS_FATAL_APP_EXIT
|
||||||
|
LONG ReportFatalSehAndExit(EXCEPTION_POINTERS* info);
|
||||||
|
|
||||||
void ReportStructuredException(EXCEPTION_POINTERS* info) {
|
void ReportStructuredException(EXCEPTION_POINTERS* info) {
|
||||||
if (!info || !info->ExceptionRecord) {
|
if (!info || !info->ExceptionRecord) {
|
||||||
@@ -1022,13 +1023,34 @@ LONG CALLBACK SehLogger(EXCEPTION_POINTERS* info) {
|
|||||||
info->ExceptionRecord->ExceptionCode == kAsanFatalAppExit) { // ASan reporting - let it print first
|
info->ExceptionRecord->ExceptionCode == kAsanFatalAppExit) { // ASan reporting - let it print first
|
||||||
return EXCEPTION_CONTINUE_SEARCH;
|
return EXCEPTION_CONTINUE_SEARCH;
|
||||||
}
|
}
|
||||||
|
// Software-raised exceptions (customer bit set) are used for internal control flow by
|
||||||
|
// system DLLs (e.g. msxml6 while mscms parses a display colour profile) and are caught
|
||||||
|
// by their own frame handlers. Only hardware faults are fatal at first chance; anything
|
||||||
|
// else that truly goes unhandled reaches UnhandledSehFilter.
|
||||||
|
if ((info->ExceptionRecord->ExceptionCode & 0x20000000u) != 0) {
|
||||||
|
return EXCEPTION_CONTINUE_SEARCH;
|
||||||
|
}
|
||||||
|
return ReportFatalSehAndExit(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
LONG WINAPI UnhandledSehFilter(EXCEPTION_POINTERS* info) {
|
||||||
|
if (info == nullptr || info->ExceptionRecord == nullptr) {
|
||||||
|
return EXCEPTION_CONTINUE_SEARCH;
|
||||||
|
}
|
||||||
|
const DWORD code = info->ExceptionRecord->ExceptionCode;
|
||||||
|
if (code == kCppExceptionCodeGcc || code == kCppExceptionCodeMsvc || code == kAsanFatalAppExit) {
|
||||||
|
return EXCEPTION_CONTINUE_SEARCH;
|
||||||
|
}
|
||||||
|
return ReportFatalSehAndExit(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
LONG ReportFatalSehAndExit(EXCEPTION_POINTERS* info) {
|
||||||
// Guard against re-entrancy: if we crash while reporting, don't recurse
|
// Guard against re-entrancy: if we crash while reporting, don't recurse
|
||||||
static std::atomic_flag s_inCrashHandler = ATOMIC_FLAG_INIT;
|
static std::atomic_flag s_inCrashHandler = ATOMIC_FLAG_INIT;
|
||||||
if (s_inCrashHandler.test_and_set()) {
|
if (s_inCrashHandler.test_and_set()) {
|
||||||
std::_Exit(EXIT_FAILURE);
|
std::_Exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report the structured exception with detailed information
|
// Report the structured exception with detailed information
|
||||||
ReportStructuredException(info);
|
ReportStructuredException(info);
|
||||||
const auto* record = info->ExceptionRecord;
|
const auto* record = info->ExceptionRecord;
|
||||||
@@ -1063,6 +1085,7 @@ LONG CALLBACK SehLogger(EXCEPTION_POINTERS* info) {
|
|||||||
void InstallSehLogger() {
|
void InstallSehLogger() {
|
||||||
if (!g_vectoredSehHandle) {
|
if (!g_vectoredSehHandle) {
|
||||||
g_vectoredSehHandle = AddVectoredExceptionHandler(1, SehLogger);
|
g_vectoredSehHandle = AddVectoredExceptionHandler(1, SehLogger);
|
||||||
|
SetUnhandledExceptionFilter(UnhandledSehFilter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|||||||
Reference in new issue
Block a user