End fatal errors and a lost device with TerminateProcess instead of _Exit, which ran every library's detach.

dispatch.c fatal_end and vk_device.c lost_wait_exit ended with _Exit, which in the C runtime is ExitProcess: it
stops the other threads wherever they are and then runs every library's DLL_PROCESS_DETACH on the ending thread
(the audit's probes show the exe's TLS callback getting it after _Exit and not after TerminateProcess). That is
the detach plat_exit already avoids, after NGX's faulted once at the end of a clean run. After a FATAL such a
fault would enter the crash handler and replace code 70 or 72 with a crash report and code 71; after a device
loss a driver detach that hangs would hold the process for good, since ExitProcess had stopped the watchdog too.

The new platform plat_terminate ends the process with the code and nothing else (no exit hook, no stream flush:
the failing paths have written their lines and flushed). fatal_end calls it after its existing log sync and
flushes. lost_wait_exit tells its watchdog (spawned with a non-NULL argument) from the threads that stop there:
after LOST_EXIT_MS the watchdog alone writes "vk: the end of the run did not finish in 10 s; ending it" through
rt_log_sync's bounded trylocks, and the others end 2 s later only should the watchdog not have started. Exit
codes stay 70 and 72.

Not reproduced before the change (no detach fault on a fatal path has been seen). tests/fatal_exit_check.py
(new: dispatch.c and the platform layer with a TLS callback; rt_fatal ends with 70, its FATAL line and no detach
call, which it showed with _Exit; and statically, no _Exit in runtime outside the platform layer, and both ends
call plat_terminate) and the compile checks pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 17:11:26 -05:00
parent e39f71df39
commit 8f952d2841
7 changed files with 199 additions and 7 deletions

View File

@@ -80,7 +80,10 @@ static void fatal_end(int code, const char *fmt, va_list ap) {
rtss_limit_restore();
fflush(stdout);
fflush(stderr);
_Exit(code);
// Not _Exit: in the C runtime it is ExitProcess, which stops the other threads wherever they are and then runs every
// library's detach on this thread. A driver's detach that faults there turned a fatal error's end into a crash
// report with another code (platform/win32.c plat_exit names one such detach), and one that hangs held the process.
plat_terminate(code);
}
void rt_fatal(const char *fmt, ...) {