mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 12:29:57 -04:00
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:
@@ -868,21 +868,28 @@ static void device_fault_report(void) {
|
||||
// the run, and nothing else touches the device meanwhile: the paths that would read vk_lost and return, and a thread
|
||||
// that gets the loss as a result of its own stops here for good.
|
||||
// LOST_EXIT_MS bounds the end. The first thread writes the report and waits for a save commit (fs_host.c
|
||||
// fs_save_crash_wait, 2 s at most); should it hang on a lock that a stopped thread holds, the watchdog ends the
|
||||
// process with the same code, and the lines already written are in the log (rt_fatal_code wrote them itself).
|
||||
// fs_save_crash_wait, 2 s at most); should it hang on a lock that a stopped thread holds, the watchdog (arg non-NULL)
|
||||
// says so in one line and ends the process with the same code, and the lines already written are in the log
|
||||
// (rt_fatal_code wrote them itself). The end is plat_terminate: ExitProcess would stop the watchdog too and then run
|
||||
// every library's detach, and a driver's detach that hangs on a lost device would hold the process for good. A thread
|
||||
// that stops here otherwise ends the process a little later, should the watchdog not have started.
|
||||
#define LOST_EXIT_MS 10000
|
||||
volatile int32_t vk_lost;
|
||||
|
||||
static void lost_wait_exit(void *arg) {
|
||||
(void)arg;
|
||||
for (int t = 0; t < LOST_EXIT_MS; t += 50) plat_sleep_ms(50);
|
||||
_Exit(RT_LOST_EXIT);
|
||||
int watchdog = arg != NULL;
|
||||
for (int t = 0; t < LOST_EXIT_MS + (watchdog ? 0 : 2000); t += 50) plat_sleep_ms(50);
|
||||
if (watchdog) {
|
||||
rt_log_sync(); // the queue's locks only tried (bounded): their holder may be the thread that hangs
|
||||
rt_log("vk: the end of the run did not finish in %d s; ending it", LOST_EXIT_MS / 1000);
|
||||
}
|
||||
plat_terminate(RT_LOST_EXIT);
|
||||
}
|
||||
|
||||
void vk_device_lost_check(VkResult r, const char *where) {
|
||||
if (r != VK_ERROR_DEVICE_LOST) return;
|
||||
if (plat_xchg32(&vk_lost, 1)) lost_wait_exit(NULL); // another thread is ending the run: this one stops here
|
||||
plat_thread_spawn(lost_wait_exit, NULL, "vk lost exit", 0);
|
||||
plat_thread_spawn(lost_wait_exit, (void *)1, "vk lost exit", 0);
|
||||
device_fault_report();
|
||||
rt_fatal_code(RT_LOST_EXIT, "vk: the GPU device was lost (seen at: %s). The run ends here; the lines above name what "
|
||||
"the GPU was doing", where);
|
||||
|
||||
Reference in New Issue
Block a user