diff options
Diffstat (limited to 'source/core/StarSignalHandler_windows.cpp')
-rw-r--r-- | source/core/StarSignalHandler_windows.cpp | 39 |
1 files changed, 8 insertions, 31 deletions
diff --git a/source/core/StarSignalHandler_windows.cpp b/source/core/StarSignalHandler_windows.cpp index 2fbde88..a3b4478 100644 --- a/source/core/StarSignalHandler_windows.cpp +++ b/source/core/StarSignalHandler_windows.cpp @@ -1,38 +1,15 @@ +#include "StarMiniDump.hpp" #include "StarSignalHandler.hpp" #include "StarFormat.hpp" #include "StarString.hpp" #include "StarLogging.hpp" #include <windows.h> -#include "minidumpapiset.h" namespace Star { String g_sehMessage; -static DWORD WINAPI writeMiniDump(void* ExceptionInfo) { - auto hFile = CreateFileA("starbound.dmp", GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - if (hFile == INVALID_HANDLE_VALUE) - return 0; - MINIDUMP_EXCEPTION_INFORMATION dumpExceptionInfo{}; - dumpExceptionInfo.ThreadId = GetCurrentThreadId(); - dumpExceptionInfo.ExceptionPointers = (PEXCEPTION_POINTERS)ExceptionInfo; - dumpExceptionInfo.ClientPointers = FALSE; - MiniDumpWriteDump( - GetCurrentProcess(), - GetCurrentProcessId(), - hFile, - MiniDumpNormal, - &dumpExceptionInfo, - NULL, - NULL); - CloseHandle(hFile); - if (dumpExceptionInfo.ExceptionPointers->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) { - MessageBoxA(NULL, "Fatal stack overflow encountered\nA minidump has been generated", NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND); - } - return 0; -}; - struct SignalHandlerImpl { bool handlingFatal; bool handlingInterrupt; @@ -122,10 +99,14 @@ struct SignalHandlerImpl { } static LONG CALLBACK vectoredExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) { - HANDLE thread = NULL; LONG result = EXCEPTION_CONTINUE_SEARCH; if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) { - thread = CreateThread(NULL, 0, writeMiniDump, (void*)ExceptionInfo, 0, NULL); + if (HANDLE thread = CreateThread(NULL, 0, writeMiniDump, (void*)ExceptionInfo, 0, NULL)) { + WaitForSingleObject(thread, 10000); + CloseHandle(thread); + } + handleFatalError("Stack overflow detected", ExceptionInfo); + result = EXCEPTION_CONTINUE_EXECUTION; } if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { handleFatalError("Access violation detected", ExceptionInfo); @@ -144,7 +125,6 @@ struct SignalHandlerImpl { || (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_FLT_OVERFLOW) || (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_FLT_STACK_CHECK) || (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_FLT_UNDERFLOW) - ) { handleFatalError("Floating point exception", ExceptionInfo); result = EXCEPTION_CONTINUE_EXECUTION; @@ -169,10 +149,7 @@ struct SignalHandlerImpl { handleFatalError("Error occurred", ExceptionInfo); result = EXCEPTION_CONTINUE_EXECUTION; } - if (thread != NULL) { - WaitForSingleObject(thread, 10000); - CloseHandle(thread); - } + return result; } |