mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 01:49:59 -04:00
Let the first failure report end the run whole when another thread crashes or hits a fatal error beside it.
The platform layer calls the crash handler on every thread that faults, without waiting for the others (win32.c crash_veh, crash_filter), and main.c crash_handler ended any second entry with plat_exit(71) at once. So a second fault during the first report cut it after its first lines, together with its wait for a save Commit (fs_save_crash_wait) and RivaTuner's restore; the audit's probe showed it in 3 of 3 runs. fatal_end had no guard at all and none shared with the crash report: a crash during a FATAL's end wrote a whole crash report whose "FATAL: access violation" became the log's last FATAL line (the one the launcher shows) and replaced code 70 with 71, and a FATAL during a crash report cut it with code 70. dispatch.c rt_ending_enter is the one guard for both ends: the first caller reports and ends the process; the same thread again (a failure inside its own report) ends at once with its own code (crash_handler keeps plat_exit(71), fatal_end plat_terminate(code)); another thread waits in 10 ms sleeps, logging nothing since it may hold the log queue's lock, until the process ends, and after 30 s ends it with 71 should the first report hang. fatal_end calls it first; crash_handler calls it in place of its own busy flag. Reproduced before the change by tests/fatal_exit_check.py's new cases, which failed on the old guards: two faults at once (report lines 2 and 3 missing), a fault during rt_fatal (a crash report after the FATAL) and rt_fatal during a crash report (exit 70, the report cut). They pass now, with the earlier cases and the static check that crash_handler starts with the shared guard; the compile checks pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,13 @@
|
||||
// printed and its exit code. The exe has a TLS callback that prints a line when the process's libraries get their
|
||||
// detach call, which ExitProcess (and _Exit, which is ExitProcess in the C runtime) makes and TerminateProcess does not.
|
||||
//
|
||||
// fatal_exit_check fatal rt_fatal: exit code 70, the FATAL line, no detach line
|
||||
// fatal_exit_check fatal rt_fatal: exit code 70, the FATAL line, no detach line
|
||||
// fatal_exit_check crash_crash two threads fault at once: one whole crash report, exit code 71
|
||||
// fatal_exit_check fatal_crash a fault on another thread while rt_fatal reports: its FATAL line alone, exit code 70
|
||||
// fatal_exit_check crash_fatal rt_fatal on another thread while a crash is reported: the whole report, exit code 71
|
||||
//
|
||||
// The crash handler here is a stand-in for main.c crash_handler with its first line (the static check in
|
||||
// tests/fatal_exit_check.py holds main.c to it): it writes three report lines 100 ms apart and ends with plat_exit(71).
|
||||
#include "dispatch.c"
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -52,11 +58,61 @@ void prof_sampler_write(void) {}
|
||||
void rtss_limit_restore(void) {}
|
||||
void kern_checkpoint(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
|
||||
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());
|
||||
say(b);
|
||||
Sleep(100);
|
||||
}
|
||||
plat_exit(71);
|
||||
}
|
||||
|
||||
static volatile LONG go;
|
||||
static DWORD WINAPI fault(void *arg) {
|
||||
Sleep((DWORD)(uintptr_t)arg);
|
||||
while (!go) Sleep(0);
|
||||
*(volatile int *)(uintptr_t)16 = 1;
|
||||
return 0;
|
||||
}
|
||||
static DWORD WINAPI fatal_thread(void *arg) {
|
||||
Sleep((DWORD)(uintptr_t)arg);
|
||||
rt_fatal("the test's fatal error %d", 2);
|
||||
}
|
||||
static void slow_note(void) { // a fatal note that takes a while, as the card's and the memory settings' may
|
||||
say("fatal note: start\n");
|
||||
Sleep(300);
|
||||
say("fatal note: end\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
const char *mode = argc > 1 ? argv[1] : "";
|
||||
tls_var = 1;
|
||||
plat_crash_hook(crash);
|
||||
if (!strcmp(mode, "fatal")) rt_fatal("the test's fatal error %d", 1);
|
||||
printf("usage: fatal_exit_check fatal\n");
|
||||
if (!strcmp(mode, "crash_crash")) {
|
||||
CloseHandle(CreateThread(NULL, 0, fault, (void *)0, 0, NULL));
|
||||
CloseHandle(CreateThread(NULL, 0, fault, (void *)0, 0, NULL));
|
||||
Sleep(50);
|
||||
go = 1;
|
||||
Sleep(10000);
|
||||
return 3;
|
||||
}
|
||||
if (!strcmp(mode, "fatal_crash")) {
|
||||
rt_fatal_note_add(slow_note);
|
||||
go = 1;
|
||||
CloseHandle(CreateThread(NULL, 0, fault, (void *)100, 0, NULL));
|
||||
rt_fatal("the test's fatal error %d", 1);
|
||||
}
|
||||
if (!strcmp(mode, "crash_fatal")) {
|
||||
CloseHandle(CreateThread(NULL, 0, fatal_thread, (void *)100, 0, NULL));
|
||||
go = 1;
|
||||
fault(0);
|
||||
return 3;
|
||||
}
|
||||
printf("usage: fatal_exit_check fatal|crash_crash|fatal_crash|crash_fatal\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user