XGameRuntime: fix waiter data race, token double-free, and self-unregister deadlock #1229
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1239"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T13:35:31Z.
XTaskQueueRegisterWaiter/XTaskQueueUnregisterWaiterhad three safety/liveness bugs:(*w).wait = wh as usizemutated a non-atomic field onWaiterafterRegisterWaitForSingleObjectactivated the wait, racing withwaiter_firedon a pre-signaled handle.token.tokenwas a rawBox<Waiter>pointer with no live-token registry, so callingXTaskQueueUnregisterWaitertwice with the same token or with an invalid token double-freed or dereferenced bogus memory.XTaskQueueUnregisterWaiterfrom inside aMODE_IMMEDIATEcallback deadlocked deterministically inUnregisterWaitEx(wh, INVALID_HANDLE_VALUE).This tracks live waiters in a
WAITERSmap keyed by monotonicu64tokens, keepsWaiterimmutable afterRegisterWaitForSingleObject, and offloads blockingUnregisterWaitEx+ the finalArcdrop to a helper thread when unregistering from inside that waiter's own callback.What is in it
crates/xcl/src/hle/xgameruntime/taskqueue.rs: track waiters inWAITERSwith monotonic tokens andArc<Waiter>, track the active callback token inCURRENT_WAITERto avoid self-unregister deadlocks, and addunregister_waiter_is_idempotent_and_self_unregister_does_not_deadlock(verified deadlocking before the fix).Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 742 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2no wave64—gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)cargo test -p xcl --lib unregister_waiter_is_idempotent_and_self_unregister_does_not_deadlock: 1 passed, 0 failed (deadlocked/timed out before the fix)Regression run
main:
PR:
Not tested
AI use
taskqueue.rs, wrote the fix and regression test, ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T14:02:23Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:Thanks!
upstream-sync referenced this pull request2026-11-25 04:08:41 +00:00
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T04:32:23Z.
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:31:29Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:12:27Z.
Triage (#1607) – head
f6e94fb#315 makes the same change to
XTaskQueueRegisterWaiter/XTaskQueueUnregisterWaiterin taskqueue.rs: the waiter becomes anArcbehind a token map,waiter_firedstops once the waiter is unregistered, and a self-unregister from inside the waiter callback handsUnregisterWaitEx(INVALID_HANDLE_VALUE)to another thread. #315 was opened first, has a test of the same self-unregister/duplicate-token case, and also unregisters a queue's remaining waiters inXTaskQueueTerminate. Neither is on main.No problems found in this diff itself.
Recommendation: close (duplicate of #315).
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by throny on 2026-12-02T09:08:42Z.
Two contributors checked independently and found that this PR makes the same change as #315 #1276: #1607, group D170. They suggest keeping #315. If you agree, closing this PR or joining the other one would save the maintainers a review. If the two differ in a way the checks missed, a note in #1607 helps.
This is a hint from the community triage in #1607, not a maintainer decision.
AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Imported from ivall/xcl. Originally posted by throny on 2026-12-02T10:17:45Z.
Closing as a duplicate of #315: #1607 group D170, checked by Foniass and Decodere, who both read the diffs and suggest keeping #315. If something here is not in #315, say so and reopen it, or ask and I will.
AI use: Claude Code (Claude Opus 5.5) ran the closing script.
Pull request closed