Skip to content

XGameRuntime: forward every IID of a forwarding class through its own clone (#2399) - #2623

Open
kotekompotek wants to merge 1 commit into
xcl-dev:mainfrom
kotekompotek:fix/xgrt-forward-alias
Open

kotekompotek wants to merge 1 commit into
xcl-dev:mainfrom
kotekompotek:fix/xgrt-forward-alias

Conversation

@kotekompotek

Copy link
Copy Markdown

QueryApiImpl filled a forwarding class's shared Obj.pc from a load-then-store pair: two concurrent queries for the same class could both call pc_object and leak the loser's COM reference (a per-IID clone would take the alias-map lock instead). The same shared Obj is also what layout() builds when a class's iids merge several interface versions: a PC object cached for one version's IID can be reused for another's, and forward() then indexes the PC vtable past its end. Both holes close by routing every IID of a forwarding class through forward_alias_obj, which already makes a per-IID clone under the alias-map lock – the shared Obj keeps pc empty. No forwarding class in today's gdk_table merges IIDs, so the vtable over-read is latent; the refcount race is reachable on XGameUi alone. Fixes #2399.

What is in it

  • QueryApiImpl: !o.iface.forward.is_empty() → forward_alias_obj(o, c, i) unconditionally (crates/xcl/src/hle/xgameruntime/api.rs).
  • a_forwarding_class_answers_with_a_per_iid_clone: queries XGameUi for a known IID, asserts the title gets a clone (not the shared Obj), that the shared Obj.pc stays empty, and that a repeat query returns the same clone. Fails on the old dispatch ("the title must not get the shared Obj").

Tested

  • NVIDIA GeForce GTX 1050 (driver 32.0.15.8129, 32-lane waves only), AMD Ryzen 5 3600, Windows 11, Rust 1.91.0; debug build for the tests, release for the smoke runs
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1421 passed, 3 failed, 46 ignored (the lib was rerun alone after parallel release builds flaked 8 timing-sensitive tests; cargo test -p xcl --lib: 1296 passed, 3 failed, 26 ignored)
  • SKIPPED: 355 (no mesh shader / wave64 / SM 6.6 on this adapter)
  • This PR's new test in the workspace run:
    • a_forwarding_class_answers_with_a_per_iid_clone: ok
  • The 3 failures are environmental (driver HRESULT/0x80070057, no SM 6.6 PSOs) and reproduce identically on main; details below.

Regression run (0 s, default settings, a retail title)

main:

xcl-smoke v1
commit: e1d84b7d9153f86a97d2ec5d209d196046fc0bea
gpu: NVIDIA GeForce GTX 1050
title: 9cc6a39e
seconds: 0
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 903 MB

this PR:

xcl-smoke v1
commit: 41e715e5d39fc51ecd0c2227efbf232b67686294
gpu: NVIDIA GeForce GTX 1050
title: 9cc6a39e
seconds: 0
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 897 MB

Not tested

  • hle::d3d12x::vram::tests::gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark, shaders::pipeline_cap_tests::stale_blob_cannot_bypass_the_offline_pipeline_cap, shaders::pipeline_cap_tests::split_compute_program_prebuilds_and_caches_chain_pieces: fail on main identically (GTX 1050 is SM 6.5 max; driver answers 0x80070057).
  • Anything needing SM 6.6, wave64, or mesh shaders: skipped on this adapter.
  • The GTA6 title used for the smoke blocks crashes ~2–12 s into its own early init on this hardware (breakpad catch, not an XCL removal), so only -Seconds 0 produces a clean run; frames shown is 0 in both blocks.

AI use

  • Devin (SWE-2 High) verified the issue claims against the code, wrote the fix and the test, ran the suite and the smoke runs, and opened the PR.

… clone (xcl-dev#2399)

QueryApiImpl filled a forwarding class's shared Obj.pc from the load/store
pair in the known-IID path: two concurrent queries could both call
pc_object and leak the loser's COM reference, and an Obj whose iids merge
several interface versions would reuse a PC object made for the wrong
vtable length (a read past its end in forward()). forward_alias_obj
already makes a per-IID clone with its own PC object under the alias map's
lock; routing known IIDs through it too closes both holes – the shared
Obj's pc stays empty.
@DarkPanda69

Copy link
Copy Markdown

The three GPU tests listed as not tested (they fail on the GTX 1050, which has SM 6.5 at most) pass with this PR on two SM 6.6 cards, an RX 9070 XT and an RTX 3060. The new test passes too.

Head 41e715e applied on main b49be18, debug, Windows 11 Pro 26200, card chosen with XCL_ADAPTER, each run with --nocapture:

cargo test -p xcl --lib -- <filter> RX 9070 XT (RDNA4, 32.0.32029.2010) RTX 3060 (32.0.16.1088)
gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark ok, no SKIPPED ok, no SKIPPED
pipeline_cap_tests (stale_blob_cannot_bypass_the_offline_pipeline_cap, split_compute_program_prebuilds_and_caches_chain_pieces and the cap test) 3 passed, no SKIPPED 3 passed, no SKIPPED
a_forwarding_class_answers_with_a_per_iid_clone ok
xgameruntime 76 passed, 0 failed

Not tested: the whole suite with this PR, a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@oni-swr

oni-swr commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Test report: AMD RX 7800 XT, exact head 41e715e5d39fc51ecd0c2227efbf232b67686294, with its exact parent e1d84b7d9153f86a97d2ec5d209d196046fc0bea as control. Both were clean detached checkouts (no uncommitted changes), not merged with current main (b49be18).

Hardware / setup

  • AMD Radeon RX 7800 XT (RDNA3), driver 32.0.31035.1003. Windows 11 Pro 10.0.26200, Rust 1.100.0, debug builds, XCL_NETWORK=0, cargo -j 4, a separate CARGO_TARGET_DIR. The logs show Compiling xcl from the checkout for each commit. No XCL_SAMPLE_* variables set (game-data tests do nothing).

Tested

  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 (37 test binaries):
  • cargo test -p xcl --lib hle::xgameruntime -- --test-threads=4: head 76 passed, 0 failed; parent 75 passed, 0 failed.
  • The three tests listed under "Not tested" in the description (they fail on the GTX 1050) are ok, not skipped, on this card in the workspace run, on both head and parent: hle::d3d12x::vram::tests::gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark, and shaders::pipeline_cap_tests::stale_blob_cannot_bypass_the_offline_pipeline_cap and ::split_compute_program_prebuilds_and_caches_chain_pieces.

Causal control for the new test (local only, not proposed for the PR)
On a head checkout, I put the parent's dispatch back in QueryApiImpl (the block that, for a known IID, does a load-then-store on pc and returns the shared Obj, and calls forward_alias_obj otherwise) and kept the PR's test. cargo test -p xcl --lib hle::xgameruntime: 75 passed, 1 failed. The failing test is a_forwarding_class_answers_with_a_per_iid_clone, with the title must not get the shared Obj. With the PR's one-line change restored (the clean head), it passes. So the test is red without the fix and green with it. The working tree was restored (git status clean).

Not tested

  • scripts/smoke.ps1 / any retail title, so no regression run is given here. Other AMD generations (RDNA2/4) and the concurrent-query refcount race itself: the test checks which object the title gets, not the race.
  • No review verdict on the change.

AI use: Claude Code (Claude Sonnet 5.5), coordinated by Codex (gpt-6.2-sol), ran these tests and wrote this report. The results come from the runs above on this machine.

@luckyteagirl luckyteagirl 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.

Could the cache-hit path retry the PC query while a forwarding clone's pc is zero? The first pc_object(&c, &i) can fail temporarily, but forward_alias_obj inserts that clone with pc=0 and every later query returns it without trying the PC runtime again. The known-IID path on main retried on the next query, so a transient initialization failure now leaves that IID using the fallback stub indefinitely. The existing map lock could serialize a retry while preserving the clone's pointer identity. A fixture where PC lookup returns None once and a valid object next would cover recovery. Source review only at head 41e715e5; I did not reproduce a live runtime failure. AI-assisted with Codex (GPT-6.2 Sol).

@DavidM1911

Copy link
Copy Markdown
Contributor

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

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
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.

XGameRuntime: QueryApiImpl forwarding classes can read past PC vtable and leak COM refs

5 participants