XGameRuntime: unregistering an association callback cancels it #1753

Open
github-bot wants to merge 1 commit from github-bot/gh-1753 into main AGit
Owner

@⁠b3IKK on GitHub · 2026-11-24 20:16 UTC · original
b3IKK:xgameruntime/association-context-uaf → main · +121 −13 · 1 files · 1 commits · open

Addresses XCL-BT-041 from #1488.

XUserUnregisterForDeviceAssociationChanged dropped the registration, ignored wait, and left the callbacks it had already handed to the title's queue untouched: one queued behind the call still ran the title's callback with the title's context, which the title is free to free once the call returns (wait = true is the documented way to know it is safe). A running callback was not waited for either.

This tracks each queued callback's state (Queued / Running / Done): the unregister marks a queued one done — the queue's later call then skips the title's callback and just releases the record — and with wait it waits for a running one to finish before returning.

What is in it

  • crates/xcl/src/hle/xgameruntime/mod.rs: AssociationCall carries its token and a Queued/Running/Done state with a condvar; ASSOCIATION_CALLS holds the live records; association_call skips a call that was unregistered (or whose queue was terminated) and signals when it is done; XUserUnregisterForDeviceAssociationChanged(token, wait) cancels queued calls and waits for running ones; notify_association passes the token.
  • Test an_unregistered_association_callback_does_not_run (manual queue: queued, unregistered, dispatched → not called; a later registration still runs). Fails on main with left: 1, right: 0 (the callback was unregistered: its context may be gone).

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (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): 960 passed, 0 failed, 43 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, no heap windows, and cannot disable the driver cache (Windows Developer Mode is required))
  • cargo test -p xcl --lib xgameruntime: 74 passed, 0 failed

Regression run

main (c4d37be, clean tree, no local changes):

xcl-smoke v1
commit: c4d37bec1bb4286eb373aea963404a23f13401fa
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1639 (PresentX 1640)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14618 MB

PR (d7ced4d, clean tree, no local changes):

xcl-smoke v1
commit: d7ced4d6ad1913c0b28280dc287755eac9e3b41c
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1644 (PresentX 1644)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14486 MB

Not tested

  • a title that unregisters from inside a running association callback (the unregister would wait for it from that thread: wait = false is the one for that)
  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: checked XCL-BT-041 against the queue and xasync callback paths, wrote the state machine and the test (and confirmed it fails without the fix), rebased onto c4d37be, ran the test suite and scripts/smoke.ps1 regression runs with #677's title hashing, and drafted this PR description.
**@⁠b3IKK** on GitHub · 2026-11-24 20:16 UTC · [original](https://github.com/xcl-dev/xcl/pull/1753) `b3IKK:xgameruntime/association-context-uaf` → `main` · +121 −13 · 1 files · 1 commits · open Addresses `XCL-BT-041` from #1488. `XUserUnregisterForDeviceAssociationChanged` dropped the registration, ignored `wait`, and left the callbacks it had already handed to the title's queue untouched: one queued behind the call still ran the title's callback with the title's context, which the title is free to free once the call returns (`wait = true` is the documented way to know it is safe). A running callback was not waited for either. This tracks each queued callback's state (`Queued` / `Running` / `Done`): the unregister marks a queued one done — the queue's later call then skips the title's callback and just releases the record — and with `wait` it waits for a running one to finish before returning. **What is in it** - `crates/xcl/src/hle/xgameruntime/mod.rs`: `AssociationCall` carries its token and a `Queued`/`Running`/`Done` state with a condvar; `ASSOCIATION_CALLS` holds the live records; `association_call` skips a call that was unregistered (or whose queue was terminated) and signals when it is done; `XUserUnregisterForDeviceAssociationChanged(token, wait)` cancels queued calls and waits for running ones; `notify_association` passes the token. - Test `an_unregistered_association_callback_does_not_run` (manual queue: queued, unregistered, dispatched → not called; a later registration still runs). Fails on `main` with `left: 1, right: 0` (`the callback was unregistered: its context may be gone`). **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`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`): 960 passed, 0 failed, 43 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, `no heap windows`, and `cannot disable the driver cache (Windows Developer Mode is required)`) - `cargo test -p xcl --lib xgameruntime`: 74 passed, 0 failed **Regression run** main (`c4d37be`, clean tree, no local changes): ``` xcl-smoke v1 commit: c4d37bec1bb4286eb373aea963404a23f13401fa gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1639 (PresentX 1640) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14618 MB ``` PR (`d7ced4d`, clean tree, no local changes): ``` xcl-smoke v1 commit: d7ced4d6ad1913c0b28280dc287755eac9e3b41c gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1644 (PresentX 1644) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14486 MB ``` **Not tested** - a title that unregisters from inside a running association callback (the unregister would wait for it from that thread: `wait = false` is the one for that) - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Gemini 4 Neon: checked `XCL-BT-041` against the queue and `xasync` callback paths, wrote the state machine and the test (and confirmed it fails without the fix), rebased onto `c4d37be`, ran the test suite and `scripts/smoke.ps1` regression runs with #677's title hashing, and drafted this PR description.
XUserUnregisterForDeviceAssociationChanged dropped the registration and
ignored both the wait flag and the callbacks already handed to the
title's queue: a callback queued behind it still ran, with the title's
context - which the title is free to free once the call returns - and
`wait = true` returned without waiting for a running one.

Track each queued callback (queued / running / done): the unregister
marks a queued one done (the queue's later call skips it) and, with
`wait`, waits for a running one to finish before returning.

Assisted-by: OpenCode (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:03:49 +00:00
Author
Owner

@⁠b3IKK on GitHub · 2026-11-24 21:32 UTC · original

Rebased onto c4d37be and re-ran both with the current scripts/smoke.ps1 (#677's hashed itle: line): 960 passed, 0 failed, 43 ignored.

**@⁠b3IKK** on GitHub · 2026-11-24 21:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/1753#issuecomment-7145070521) Rebased onto c4d37be and re-ran both with the current scripts/smoke.ps1 (#677's hashed itle: line): 960 passed, 0 failed, 43 ignored.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 21:18 UTC · original · edited 2026-11-24 21:40 UTC

Full-suite run, since this PR has no test report yet. Tested exact head 8cd4248 (on its base c160d86).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip pso_measurement_compiles_an_exact_synthetic_record: 858 passed, 0 failed, 42 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: an_unregistered_association_callback_does_not_run.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 859 passed, 0 failed, 42 ignored. SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • Two tests were skipped with --skip on NVIDIA. Both fail on main 7f7e768 too, not because of this PR: under XCL_REQUIRE_GPU=mesh, runner::skip_test turns their skips into failures. heap_window_out_of_memory_falls_back_to_the_switch_form skips when XCL_HEAP_WINDOWS is unset (#1651), and shaders::tests::pso_measurement_compiles_an_exact_synthetic_record skips because Developer Mode is off on this PC (it cannot disable the driver cache). The AMD run does not set XCL_REQUIRE_GPU, so there both just print SKIPPED.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 21:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/1753#issuecomment-7144754328) · edited 2026-11-24 21:40 UTC Full-suite run, since this PR has no test report yet. Tested exact head `8cd4248` (on its base `c160d86`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip pso_measurement_compiles_an_exact_synthetic_record`: **858 passed, 0 failed, 42 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `an_unregistered_association_callback_does_not_run`. - Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **859 passed, 0 failed, 42 ignored**. SKIPPED: `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - Two tests were skipped with `--skip` on NVIDIA. Both fail on main `7f7e768` too, not because of this PR: under `XCL_REQUIRE_GPU=mesh`, `runner::skip_test` turns their skips into failures. `heap_window_out_of_memory_falls_back_to_the_switch_form` skips when `XCL_HEAP_WINDOWS` is unset (#1651), and `shaders::tests::pso_measurement_compiles_an_exact_synthetic_record` skips because Developer Mode is off on this PC (it cannot disable the driver cache). The AMD run does not set `XCL_REQUIRE_GPU`, so there both just print SKIPPED. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 23:04 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 23:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/1753#issuecomment-7146985449) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠throny on GitHub · 2026-11-25 00:37 UTC · original

Two contributors checked independently and found that #1418 #1583 solves the same problem (for #1389) in a different way: #1607, group D58. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

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.

**@⁠throny** on GitHub · 2026-11-25 00:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/1753#issuecomment-7148712938) <!-- xcl-1607-hint:D58 --> Two contributors checked independently and found that #1418 #1583 solves the same problem (for #1389) in a different way: #1607, group D58. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. 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.
Author
Owner

@⁠JJAutoCompare on GitHub · 2026-11-25 03:32 UTC · original

PR #1753 compatibility verification

Tested XGameRuntime association callback cancellation at d7ced4d6ad1913c0b28280dc287755eac9e3b41c.

Tested

  • STOR-WINLAB, Windows 11 Enterprise Evaluation build 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 16 GiB (driver 32.0.101.9175, wave range 8–32, DoublePrecisionFloatShaderOps=0). DXC/DXIL 1.9.2609.5. D3D12 SDK layers absent. rustc 1.100.0 (0ef1bc386 2026-11-09). Unoptimized dev and test profiles with debug info disabled.
  • cargo build --workspace and cargo test --workspace --no-run succeeded outside the GPU lock.
  • cargo test -p xcl xgameruntime -- --nocapture reported 74 unit tests passed, 0 failed, 0 ignored. The matching libHttpClient integration test also reported a pass after returning early because XCL_SAMPLE_DLLS was unset. Two unit tests returned early for missing system xgameruntime.dll and audio endpoint.
  • an_unregistered_association_callback_does_not_run passed in both runs. Dispatching the manual completion queue after unregistering with wait=true left the callback count at zero. A separate registration received one callback when dispatched.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 ran once under the shared Arc lock. Cargo exited 101. Summed across 20 result lines in pr1753-suite.log: 941 passed, 19 failed, 43 ignored. The log contains 22 SKIPPED lines. Raw pass totals include tests that returned early.

Failures and skips

  • GPU unit tests accounted for 18 failures: 14 compute PSO creation errors (0x80070057) and four result mismatches involving FMA, mip sampling, f16 lane preservation, and a pixel-shader wave reduction. The built-in test title had one failure: RSSetDepthBiasX left the test pixel blue where green was expected.
  • The 22 skip lines comprise 17 for unavailable wave64, three for refused wave32 per-lane forms, one for driver-cache control, and one for unavailable heap windows.

Not tested

Retail-title smoke runs, a main baseline, other GPUs, and game-data cases requiring the unset XCL_SAMPLE_* inputs. The callback regression test exercises queued cancellation. Waiting for a callback already in flight was untested.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1753-suite.log and published this report.

**@⁠JJAutoCompare** on GitHub · 2026-11-25 03:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/1753#issuecomment-7152008119) # PR #1753 compatibility verification Tested XGameRuntime association callback cancellation at `d7ced4d6ad1913c0b28280dc287755eac9e3b41c`. **Tested** - STOR-WINLAB, Windows 11 Enterprise Evaluation build 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 16 GiB (driver 32.0.101.9175, wave range 8–32, `DoublePrecisionFloatShaderOps=0`). DXC/DXIL 1.9.2609.5. D3D12 SDK layers absent. `rustc 1.100.0 (0ef1bc386 2026-11-09)`. Unoptimized dev and test profiles with debug info disabled. - `cargo build --workspace` and `cargo test --workspace --no-run` succeeded outside the GPU lock. - `cargo test -p xcl xgameruntime -- --nocapture` reported 74 unit tests passed, 0 failed, 0 ignored. The matching libHttpClient integration test also reported a pass after returning early because `XCL_SAMPLE_DLLS` was unset. Two unit tests returned early for missing system `xgameruntime.dll` and audio endpoint. - `an_unregistered_association_callback_does_not_run` passed in both runs. Dispatching the manual completion queue after unregistering with `wait=true` left the callback count at zero. A separate registration received one callback when dispatched. - `cargo test --workspace --no-fail-fast -- --test-threads=4` ran once under the shared Arc lock. Cargo exited 101. Summed across 20 result lines in `pr1753-suite.log`: **941 passed, 19 failed, 43 ignored**. The log contains **22 `SKIPPED` lines**. Raw pass totals include tests that returned early. **Failures and skips** - GPU unit tests accounted for 18 failures: 14 compute PSO creation errors (`0x80070057`) and four result mismatches involving FMA, mip sampling, f16 lane preservation, and a pixel-shader wave reduction. The built-in test title had one failure: `RSSetDepthBiasX` left the test pixel blue where green was expected. - The 22 skip lines comprise 17 for unavailable wave64, three for refused wave32 per-lane forms, one for driver-cache control, and one for unavailable heap windows. **Not tested** Retail-title smoke runs, a `main` baseline, other GPUs, and game-data cases requiring the unset `XCL_SAMPLE_*` inputs. The callback regression test exercises queued cancellation. Waiting for a callback already in flight was untested. **AI use** T3 Code / Codex (`gpt-6.2-sol`, `reasoningEffort: high`) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, `gemini-4-neon`) verified counts against `pr1753-suite.log` and published this report.
Author
Owner

@⁠thehollowedone on GitHub · 2026-11-25 10:13 UTC · original

Independent Windows run on d7ced4d. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC.

cargo build --workspace --offline --locked -j 4 passed. cargo test --workspace --offline --locked --no-fail-fast -j 4 -- --nocapture --test-threads=4 finished with 960 passed, 0 failed, 43 ignored, with 23 runtime skips in Cargo’s pass count. The queued-callback regression passed.

I also tested a callback that had already started on another thread. With wait=false, unregister returned while the callback was still running. With wait=true, unregister returned after the callback finished. The callback context stayed alive until both threads joined. The scratch fixture passed 1 of 1 with cargo test --offline --locked -j 4 -p xcl --lib local_unregister_waits_only_when_requested_for_running_callback -- --nocapture --test-threads=1, then passed in 20 of 20 fresh test processes. This covers unregister from a separate thread on a synthetic manual queue.

AI use: Codex (GPT-6, exact variant unspecified) wrote the scratch fixture, ran the tests and drafted this report.

**@⁠thehollowedone** on GitHub · 2026-11-25 10:13 UTC · [original](https://github.com/xcl-dev/xcl/pull/1753#issuecomment-7159411653) Independent Windows run on [d7ced4d](https://github.com/xcl-dev/xcl/commit/d7ced4d6ad1913c0b28280dc287755eac9e3b41c). Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC. `cargo build --workspace --offline --locked -j 4` passed. `cargo test --workspace --offline --locked --no-fail-fast -j 4 -- --nocapture --test-threads=4` finished with **960 passed, 0 failed, 43 ignored**, with 23 runtime skips in Cargo’s pass count. The queued-callback regression passed. I also tested a callback that had already started on another thread. With `wait=false`, unregister returned while the callback was still running. With `wait=true`, unregister returned after the callback finished. The callback context stayed alive until both threads joined. The scratch fixture passed 1 of 1 with `cargo test --offline --locked -j 4 -p xcl --lib local_unregister_waits_only_when_requested_for_running_callback -- --nocapture --test-threads=1`, then passed in 20 of 20 fresh test processes. This covers unregister from a separate thread on a synthetic manual queue. AI use: Codex (GPT-6, exact variant unspecified) wrote the scratch fixture, ran the tests and drafted this report.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1753/head:github-bot/gh-1753'
git switch 'github-bot/gh-1753'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1753'
git switch 'github-bot/gh-1753'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1753'
git switch 'github-bot/gh-1753'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1753'
git switch 'main'
git merge --squash 'github-bot/gh-1753'
git switch 'main'
git merge --ff-only 'github-bot/gh-1753'
git switch 'main'
git merge 'github-bot/gh-1753'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.