diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2025-04-30 15:14:49 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2025-04-30 15:14:49 +1000 |
commit | a521dc5c74d54466dd3fc432057b96c30504a748 (patch) | |
tree | 8240eff0bdf1aba309c27ed0a9e772a2db43e425 /source | |
parent | d8db6199e13b5405123f18cc1a9631f7e7f4794a (diff) |
Guarantee stack space in exception handling so printing stack overflows doesn't fail
Diffstat (limited to 'source')
-rw-r--r-- | source/application/StarMainApplication.hpp | 2 | ||||
-rw-r--r-- | source/core/StarSignalHandler_windows.cpp | 4 | ||||
-rw-r--r-- | source/core/StarThread_windows.cpp | 2 | ||||
-rw-r--r-- | source/server/main.cpp | 8 |
4 files changed, 14 insertions, 2 deletions
diff --git a/source/application/StarMainApplication.hpp b/source/application/StarMainApplication.hpp index 5ba06e7..172e2da 100644 --- a/source/application/StarMainApplication.hpp +++ b/source/application/StarMainApplication.hpp @@ -22,6 +22,8 @@ namespace Star { freopen("CONOUT$", "w", stdout); \ freopen("CONOUT$", "w", stderr); \ } \ + unsigned long exceptionStackSize = 16384; \ + SetThreadStackGuarantee(&exceptionStackSize); \ return Star::runMainApplication(Star::make_unique<ApplicationClass>(), args); \ } diff --git a/source/core/StarSignalHandler_windows.cpp b/source/core/StarSignalHandler_windows.cpp index 676734c..2fbde88 100644 --- a/source/core/StarSignalHandler_windows.cpp +++ b/source/core/StarSignalHandler_windows.cpp @@ -28,7 +28,7 @@ static DWORD WINAPI writeMiniDump(void* ExceptionInfo) { NULL); CloseHandle(hFile); if (dumpExceptionInfo.ExceptionPointers->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) { - MessageBoxA(NULL, "Stack overflow encountered\nA minidump has been generated", NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND); + MessageBoxA(NULL, "Fatal stack overflow encountered\nA minidump has been generated", NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND); } return 0; }; @@ -166,7 +166,7 @@ struct SignalHandlerImpl { || (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_NONCONTINUABLE_EXCEPTION) || (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_INVALID_DISPOSITION) || (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_INVALID_HANDLE)) { - handleFatalError("Error occured", ExceptionInfo); + handleFatalError("Error occurred", ExceptionInfo); result = EXCEPTION_CONTINUE_EXECUTION; } if (thread != NULL) { diff --git a/source/core/StarThread_windows.cpp b/source/core/StarThread_windows.cpp index a7d09be..b63101d 100644 --- a/source/core/StarThread_windows.cpp +++ b/source/core/StarThread_windows.cpp @@ -46,6 +46,8 @@ struct ThreadImpl { static DWORD WINAPI runThread(void* data) { ThreadImpl* ptr = static_cast<ThreadImpl*>(data); try { + unsigned long exceptionStackSize = 16384; + SetThreadStackGuarantee(&exceptionStackSize); ptr->function(); } catch (std::exception const& e) { if (ptr->name.empty()) diff --git a/source/server/main.cpp b/source/server/main.cpp index ac40524..3bfb197 100644 --- a/source/server/main.cpp +++ b/source/server/main.cpp @@ -12,6 +12,10 @@ using namespace Star; +#if defined STAR_SYSTEM_WINDOWS +#include <windows.h> +#endif + Json const AdditionalDefaultConfiguration = Json::parseJson(R"JSON( { "configurationVersion" : { @@ -35,6 +39,10 @@ Json const AdditionalDefaultConfiguration = Json::parseJson(R"JSON( int main(int argc, char** argv) { try { + #if defined STAR_SYSTEM_WINDOWS + unsigned long exceptionStackSize = 16384; + SetThreadStackGuarantee(&exceptionStackSize); + #endif RootLoader rootLoader({{}, AdditionalDefaultConfiguration, String("starbound_server.log"), LogLevel::Info, false, String("starbound_server.config")}); RootUPtr root = rootLoader.commandInitOrDie(argc, argv).first; root->fullyLoad(); |