diff options
Diffstat (limited to 'runtime/src/main.cpp')
| -rw-r--r-- | runtime/src/main.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index eb04c4f34..98e377f1c 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp | |||
| @@ -248,6 +248,15 @@ static BOOL WINAPI stop_compiles_on_console_exit(DWORD event) { | |||
| 248 | // left alone apart from that write; the exception then goes on as before (the previous filter, or Windows' own | 248 | // left alone apart from that write; the exception then goes on as before (the previous filter, or Windows' own |
| 249 | // handling), so the exit code is the exception's. Not for a stack overflow: no stack is left to write with. | 249 | // handling), so the exit code is the exception's. Not for a stack overflow: no stack is left to write with. |
| 250 | static LPTOP_LEVEL_EXCEPTION_FILTER previous_fatal_filter = nullptr; | 250 | static LPTOP_LEVEL_EXCEPTION_FILTER previous_fatal_filter = nullptr; |
| 251 | // The retail title installs a filter of its own (SetUnhandledExceptionFilter from api-ms-win-core-errorhandling), | ||
| 252 | // which replaced this one and ended the process without it (measured: a title fault at 354 s wrote nothing). Its | ||
| 253 | // call is served here instead: this filter stays installed and hands the exception to the title's, as Windows would. | ||
| 254 | static void* volatile title_fatal_filter = nullptr; | ||
| 255 | |||
| 256 | static LPTOP_LEVEL_EXCEPTION_FILTER WINAPI title_set_unhandled_exception_filter(LPTOP_LEVEL_EXCEPTION_FILTER filter) { | ||
| 257 | return reinterpret_cast<LPTOP_LEVEL_EXCEPTION_FILTER>( | ||
| 258 | InterlockedExchangePointer(&title_fatal_filter, reinterpret_cast<void*>(filter))); | ||
| 259 | } | ||
| 251 | 260 | ||
| 252 | static LONG WINAPI save_caches_on_fatal_exception(EXCEPTION_POINTERS* info) { | 261 | static LONG WINAPI save_caches_on_fatal_exception(EXCEPTION_POINTERS* info) { |
| 253 | const DWORD code = info && info->ExceptionRecord ? info->ExceptionRecord->ExceptionCode : 0; | 262 | const DWORD code = info && info->ExceptionRecord ? info->ExceptionRecord->ExceptionCode : 0; |
| @@ -258,6 +267,9 @@ static LONG WINAPI save_caches_on_fatal_exception(EXCEPTION_POINTERS* info) { | |||
| 258 | rt::d3d12::save_pipeline_caches_at_exit(kExitCacheWaitMs); | 267 | rt::d3d12::save_pipeline_caches_at_exit(kExitCacheWaitMs); |
| 259 | std::fflush(stderr); | 268 | std::fflush(stderr); |
| 260 | } | 269 | } |
| 270 | if (auto* title = reinterpret_cast<LPTOP_LEVEL_EXCEPTION_FILTER>( | ||
| 271 | InterlockedCompareExchangePointer(&title_fatal_filter, nullptr, nullptr))) | ||
| 272 | return title(info); | ||
| 261 | return previous_fatal_filter ? previous_fatal_filter(info) : EXCEPTION_CONTINUE_SEARCH; | 273 | return previous_fatal_filter ? previous_fatal_filter(info) : EXCEPTION_CONTINUE_SEARCH; |
| 262 | } | 274 | } |
| 263 | 275 | ||
| @@ -368,6 +380,13 @@ int wmain(int argc, wchar_t** argv) { | |||
| 368 | rt::fs::configure(game_dir, overlay_dir); | 380 | rt::fs::configure(game_dir, overlay_dir); |
| 369 | #ifdef LEONIDA_VULKAN_DEVICE | 381 | #ifdef LEONIDA_VULKAN_DEVICE |
| 370 | if (run) { | 382 | if (run) { |
| 383 | // Before the image is loaded, so its import binds here (save_caches_on_fatal_exception). | ||
| 384 | const rt::shims::Entry filter_imports[] = { | ||
| 385 | {"api-ms-win-core-errorhandling-l1-1-0.dll", "SetUnhandledExceptionFilter", | ||
| 386 | reinterpret_cast<void*>(&title_set_unhandled_exception_filter)}, | ||
| 387 | {"kernel32.dll", "SetUnhandledExceptionFilter", reinterpret_cast<void*>(&title_set_unhandled_exception_filter)}, | ||
| 388 | }; | ||
| 389 | rt::shims::Table{filter_imports, std::size(filter_imports)}; | ||
| 371 | rt::package_splash::configure(game_dir); | 390 | rt::package_splash::configure(game_dir); |
| 372 | if (rt::package_splash::configured()) { | 391 | if (rt::package_splash::configured()) { |
| 373 | const rt::shims::Entry window_imports[] = { | 392 | const rt::shims::Entry window_imports[] = { |