End a hung fatal error's report with its own code when a thread waiting beside it gives up, not with the crash code.

The review of the shared failure guard found that a thread parked in dispatch.c rt_ending_enter ended the process
with 71 after 30 s even when the first report was a FATAL (70, or 72 for a lost device), so a fatal error whose report
hung read as a crash to the launcher.

rt_ending_enter now takes the code its caller ends with: fatal_end passes its own, main.c crash_handler 71. The first
caller stores it next to ending_tid, and a waiting thread that gives up after 30 s ends the process with it. Before
the store the value is 71, as before.

Reproduced before the change with a one-off build of tests/fatal_exit_check.c given a fatal note that never returns
and a fault on another thread: the process ended with 71 after 30.5 s; with this change it ends with 70 after 30.5 s.
That case takes 30 s, so the matrix gets a static check instead: tests/fatal_exit_check.py holds rt_ending_enter to
storing the first caller's code and ending with it, fatal_end to passing its code, and crash_handler to its first
line `if (!rt_ending_enter(71)) plat_exit(71);`. fatal_exit_check and the compile check of every runtime file (a
header changed) pass, with no new -Wall warnings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 18:30:49 -05:00
parent e6a6d6a809
commit 66c607414b
5 changed files with 27 additions and 12 deletions

View File

@@ -74,7 +74,7 @@ void input_rumble_hd_stop(void) {
// ---- the crash report and the threads that fail beside it
static void crash(const PlatCrash *x) {
if (!rt_ending_enter()) plat_exit(71); // main.c crash_handler's first line
if (!rt_ending_enter(71)) plat_exit(71); // main.c crash_handler's first line
char b[160];
for (int i = 1; i <= 3; i++) {
snprintf(b, sizeof b, "report line %d: %s on thread %lu\n", i, x->what, (unsigned long)GetCurrentThreadId());

View File

@@ -75,7 +75,7 @@ def static_checks():
main_c = (RT / 'main.c').read_text(encoding='utf-8')
body = re.sub(r'//[^\n]*', '', function(main_c, 'static void crash_handler(const PlatCrash *x)'))
first = body[body.index('{') + 1:].strip().split('\n')[0].strip()
ok = first == 'if (!rt_ending_enter()) plat_exit(71);'
ok = first == 'if (!rt_ending_enter(71)) plat_exit(71);'
print(f'static: main.c crash_handler starts with the shared guard: {"ok" if ok else "FAIL (" + first + ")"}',
flush=True)
bad += not ok
@@ -95,6 +95,15 @@ def static_checks():
print(f'static: {name} stops HD rumble through rt_rumble_stop_bounded after the RTSS restore: '
f'{"ok" if ok else "FAIL"}', flush=True)
bad += not ok
# a first report that hangs: the thread that waits for it ends the process after 30 s with that report's code, and
# fatal_end hands its own code to the guard (a hung FATAL must not read as a crash to the launcher)
dispatch = re.sub(r'//[^\n]*', '', (RT / 'dispatch.c').read_text(encoding='utf-8'))
enter = function(dispatch, 'int rt_ending_enter(int code)')
ok = ('__atomic_store_n(&ending_code, code' in enter
and 'plat_terminate(__atomic_load_n(&ending_code' in enter and 'rt_ending_enter(code)' in fatal)
print(f'static: dispatch.c rt_ending_enter ends a hung first report with that report\'s code: '
f'{"ok" if ok else "FAIL"}', flush=True)
bad += not ok
# the fatal error's frame-time summary comes after the RTSS restore and the rumble stop, as in the orderly end
s, p = fatal.find('rt_rumble_stop_bounded('), fatal.find('perf_summary_flush_try(')
ok = 0 <= s < p