upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/main.cpp
diff options
context:
space:
mode:
authorkurrutako <kurrutako@users.noreply.github.com>2026-11-25 16:36:44 +0100
committerkurrutako <kurrutako@users.noreply.github.com>2026-11-25 16:36:44 +0100
commit27a861adc904fb42af043aafb99ddf2fbd9a0322 (patch)
treecabb77a3d95fd089793f2462871eb20bb3e67b40 /runtime/src/main.cpp
parentf95b23e51864996b7a25a4cd4566ae24882efe2e (diff)
gta6rt: keep the exit-save filter when the title installs its own (RT-SESSION-CACHE-AT-EXIT)
The retail title calls SetUnhandledExceptionFilter (from api-ms-win-core-errorhandling-l1-1-0), which replaced the runtime's filter: a title fault at 354 s ended the process without the cache write. The title's call is now served by the runtime, which keeps its filter installed and passes the exception on to the title's. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/main.cpp')
-rw-r--r--runtime/src/main.cpp19
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.
250static LPTOP_LEVEL_EXCEPTION_FILTER previous_fatal_filter = nullptr; 250static 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.
254static void* volatile title_fatal_filter = nullptr;
255
256static 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
252static LONG WINAPI save_caches_on_fatal_exception(EXCEPTION_POINTERS* info) { 261static 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[] = {