upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/shims/process.cpp
diff options
context:
space:
mode:
authorAAyberkU <97833630+AAyberkU@users.noreply.github.com>2026-11-23 02:04:13 +0300
committerAAyberkU <97833630+AAyberkU@users.noreply.github.com>2026-11-23 02:04:13 +0300
commitb6299c9d825c9a03703a636f8205fb70c7028d60 (patch)
tree345fd89d19dd4cf274e0b200d00c4b690ec90b55 /runtime/shims/process.cpp
parentaa2988cc555bad7ecd508b48a702adbb32fe7c95 (diff)
process shim: the game thread that ends a run no longer exits the process before gta6rt finishes
end_run signalled g_done and only then read g_running. run_entry wakes on g_done, closes it and clears g_running, so the game thread could read false and take the "run is already over" path: ExitProcess with the game's code while main.cpp was still printing "game exited with code N", reporting unimplemented imports, writing the trace "exit" event and cleaning up TLS clones. The exit code stayed right, but the lost line made run_startup_cmdline and the other checks that look for it flaky. end_run now reads g_running before it signals. g_running is set before the game thread starts and is cleared only after g_exited is claimed and g_done is set, so a read taken before the CAS is true for any thread that ends a live run. The exit during host shutdown (no run active) still calls ExitProcess, and so does an exit with no run started, which an "always park the CAS winner" fix would have hung. process_cmdline_test runs 50 entry points that return 77 on one CPU and fails (exit 77) without the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/process.cpp')
-rw-r--r--runtime/shims/process.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/runtime/shims/process.cpp b/runtime/shims/process.cpp
index 1fc4fee7f..c9cbcf9d3 100644
--- a/runtime/shims/process.cpp
+++ b/runtime/shims/process.cpp
@@ -71,13 +71,16 @@ std::string narrow(const std::wstring& w) {
71} 71}
72 72
73[[noreturn]] void end_run(int code) { 73[[noreturn]] void end_run(int code) {
74 // Read before signalling: once g_done is set, run_entry can return and clear g_running while the host is still
75 // finishing the run (main.cpp's "game exited" line and cleanup), which this thread must not cut short.
76 const bool running = g_running;
74 bool expected = false; 77 bool expected = false;
75 if (g_exited.compare_exchange_strong(expected, true)) { 78 if (g_exited.compare_exchange_strong(expected, true)) {
76 g_exit_code = code; 79 g_exit_code = code;
77 if (g_done) SetEvent(g_done); 80 if (g_done) SetEvent(g_done);
78 } 81 }
79 // Park until the host's ExitProcess, not ExitThread: Wine < 11.2 can exit 0 if the two race (4a9bc42a). 82 // Park until the host's ExitProcess, not ExitThread: Wine < 11.2 can exit 0 if the two race (4a9bc42a).
80 if (g_running) for (;;) Sleep(INFINITE); 83 if (running) for (;;) Sleep(INFINITE);
81 // The run is already over: this is game code running during host shutdown (an atexit handler the game 84 // The run is already over: this is game code running during host shutdown (an atexit handler the game
82 // registered with the shared CRT calling exit again). Finish the process with the game's exit code; ending 85 // registered with the shared CRT calling exit again). Finish the process with the game's exit code; ending
83 // just this thread here would make the host's last thread, and so the process, exit with `code` instead. 86 // just this thread here would make the host's last thread, and so the process, exit with `code` instead.