Skip to content

process: park game threads that end the run until the host exits - #1013

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
kmorales13:fix/wine-exit-race
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
kmorales13:fix/wine-exit-race

Conversation

@kmorales13

Copy link
Copy Markdown
Contributor

Item: new RT item, @ayozetr's Wine exit-code finding (claim).

Under Wine before 11.2, gta6rt --run sometimes exited 0 although the game ended with 1. run_tiny_game_exit_code failed this way in 13 of the last 64 CI Wine runs (Ubuntu's Wine 9.0).

Cause. end_run signalled the host and then called ExitThread. The host's ExitProcess can send SIGQUIT to that thread while it is still exiting. Wine 9.0 doesn't block SIGQUIT there, so the thread counts itself out twice (exit_thread, then abort_thread from quit_handler), the thread count reaches 0 and Wine calls _exit(0) before the host's exit(1). Upstream fixed this in 4a9bc42a ("ntdll: Add SIGQUIT to the blocked signals"), first in wine-11.2, so CI's Wine 9.0 and distro Wines older than 11.2 still have it.

Change. While a run is in progress, end_run parks every caller (Sleep(INFINITE)), the first one after recording the code and signalling the host, so no game thread is mid-exit when the host calls ExitProcess. This also fixes a bug on every OS: when two game threads called exit at once, the second one called ExitProcess itself, sometimes before the first had stored its code, and the process ended with 0. Calls after the run (during host shutdown) still end the process with the game's code, as before. CI requires run_tiny_game_exit_code again (reverts 734fe50).

Not covered. Under Wine < 11.2, any other thread that happens to be exiting by itself at the moment the host calls ExitProcess can still turn the exit code into 0. That can't be fixed from the PE side without tracking every game thread; tiny_game joins its worker, so CI isn't affected.

Tested on CachyOS, Ryzen 7 7700X iGPU (RDNA2, RADV, Mesa 26.3.1), Windows runtime cross-built with clang-cl + xwin (#888's setup). The native MSVC build wasn't run here; the change is plain Win32.

Wine Test main this PR
9.0 (ubuntu:24.04 container, CI's package) tiny_game -- wrong args 30 of 1500 exit 0 0 of 1500
9.0 two game threads call exit(1) at once 8 of 400 exit 0 0 of 400
11.22 two game threads call exit(1) at once 11 of 400 exit 0 0 of 400
9.0 tiny_game -- hello 42 200 of 200 exit 0
Proton Experimental (11.0) tiny_game -- wrong args 100 of 100 exit 1

Full ctest under Wine 11.22: the same 4 failures as main (the tests that compare with the host's D3D12: root_sig_test, device_proxy, root_sig, d3d12_vulkan_device). The plain Linux build is unaffected (process.cpp is Windows-only).

#802 edits the comment lines just above the wine job, so expect a small rebase conflict there.

AI-assisted (Claude-Opus).

Under Wine before 11.2, gta6rt --run sometimes exited 0 although the game
ended with 1 (run_tiny_game_exit_code in CI's Wine 9.0 job: 13 of 64 runs).
end_run signalled the host and called ExitThread; the host's ExitProcess
could then send SIGQUIT to that thread while it was exiting, Wine counted
the thread out twice and the process ended with _exit(0). Upstream fixed
it by blocking SIGQUIT during thread exit (4a9bc42a, wine-11.2).

end_run now parks every caller while a run is in progress (the first one
after recording the code and signalling), so no game thread is mid-exit
when the host calls ExitProcess. This also fixes two threads calling exit
at once: the second one called ExitProcess itself, sometimes before the
first had stored its code, and ended the process with 0 on any OS.

CI requires run_tiny_game_exit_code again.
@LocranKing

Copy link
Copy Markdown
Contributor

Tested 8b51490 on Windows 11 Build 26200, native MSVC 14.44.35207 (Windows SDK 10.0.26100, Ninja RelWithDebInfo via scripts\build_runtime.ps1), NVIDIA GeForce RTX 3060 Ti (driver 621.01): pass.

  • Native MSVC build succeeded cleanly (0 warnings in runtime/shims/process.cpp).
  • ctest --test-dir runtime/build --output-on-failure (with LEONIDA_VK_VALIDATION=1, VK_LOADER_LAYERS_DISABLE=~implicit~): 33/33 passed (100%), including run_tiny_game and run_tiny_game_exit_code (gameinput disabled as expected without SDL3).

AI-assisted. No game files.

@BACONMANXDGOD

Copy link
Copy Markdown
Contributor

Tested 8b51490 with the native MSVC build (the part not run above): Windows 11 26200, MSVC 19.44, RelWithDebInfo. I applied it to main 43d4703; it merges cleanly. Pass, no regression:

  • ctest -R tiny_game: run_tiny_game and run_tiny_game_exit_code pass.
  • gta6rt --run tiny_game -- wrong args 300 times: exit 1 every time (300/300).
  • gta6rt --run tiny_game -- hello 42 100 times: exit 0 every time (100/100).
  • Control: with 43d4703's process.cpp the wrong args loop is also 300/300 exit 1 natively. That's expected: tiny_game has one thread calling exit, so the two-thread race isn't exercised on Windows. This run only shows the parked end_run doesn't change native behaviour.

The machine has an Intel Arrow Lake iGPU and an RTX 5070 Ti, but this path doesn't touch the GPU. No game files. AI-assisted (Claude Code).

@quackottu quackottu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 8b51490 on NVIDIA GeForce RTX 5070, driver 621.24, Windows 11 Pro (26300), VS 2022 Build Tools, Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1 and LEONIDA_D3D12=vulkan: pass

  • ctest -C RelWithDebInfo: 100% tests passed, 0 tests failed out of 33
  • 39 test programs in the build pass with 0 validation errors
  • Not run (they take an input file, not covered here): vk_overlapping_occlusion_test
  • d3d12_clear_test fails (R8G8B8A8_UNORM/SNORM 0.5 ties and a D16 clear byte differ from WARP) exactly as on main 4a36bb1 here, so not from this PR; #521 addresses it

Implicit Vulkan layers (overlays) were off through an empty VK_IMPLICIT_LAYER_PATH.

@ItsNotRexed
ItsNotRexed merged commit 97234e2 into ItsNotRexed:main Nov 22, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants