XGameRuntime: validate XAsyncBlock before PC runtime forwarding (#1390) #1588

Closed
github-bot wants to merge 2 commits from gh-pr/1588/head into gh-pr/1588/base
Owner

@⁠hajduzsolt on GitHub · 2026-11-24 17:59 UTC · original
hajduzsolt:xgameruntime/xasync-validate-before-pc-forward → main · +86 −13 · 1 files · 2 commits · closed without merging

Validates null XAsyncBlock, missing provider/work pointers, and E_PENDING before forwarding XAsync* entry points through pc(slot) to system xgameruntime.dll. Fixes #1390.

What is in it

  • crates/xcl/src/hle/xgameruntime/xasync.rs: move b.is_null() (and provider == 0 / work == 0 / result == E_PENDING) checks before pc(slot) forwarding in XAsyncBegin, XAsyncSchedule, XAsyncComplete, XAsyncGetStatus, XAsyncGetResultSize, XAsyncGetResult, XAsyncCancel, and XAsyncRun.
  • crates/xcl/src/hle/xgameruntime/xasync.rs: add unit test pc_forwarding_validates_null_and_args_before_dispatching installing a mock PC_ASYNC vtable and verifying all null/invalid calls fail cleanly without invoking any forwarded slot while valid calls still forward.

Tested

  • Hardware & toolchain: AMD Radeon RX 9070 XT (driver 32.0.32029.2010), AMD Ryzen 7 9800X3D, Windows 11 10.0.26300.9974, rustc 1.98.1 (48a229cea 2026-09-01), debug (cargo test).
  • cargo test -p xcl --lib hle::xgameruntime::xasync::tests -- --test-threads=2: 15 passed, 0 failed, 0 ignored.
  • cargo test --workspace -- --test-threads=2: 777 passed, 0 failed, 41 ignored (xcl --lib: 728 passed, 0 failed, 21 ignored; integration/e2e suites: 49 passed, 0 failed, 20 ignored).
  • SKIPPED runtime tests: SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows.

Regression run

main:

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1594 (PresentX 1594)
presents per 2 s (last 3): 49 48 14
device removals: 0
crashes: 0
peak commit: 20195 MB

PR:

xcl-smoke v1
commit: 66f0068bc0ea263afa2c1cb7c5ceabf9e7263dde
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1674 (PresentX 1674)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 14842 MB

Not tested

  • Live System32\xgameruntime.dll COM object (unit test uses a mock PC_ASYNC COM vtable).

AI use

  • Antigravity (Gemini 4 Hydrogen, high): reordered validation checks ahead of pc() forwarding in xasync.rs, added mock-vtable unit test, ran the workspace test suite, and drafted commit and PR description.
**@⁠hajduzsolt** on GitHub · 2026-11-24 17:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/1588) `hajduzsolt:xgameruntime/xasync-validate-before-pc-forward` → `main` · +86 −13 · 1 files · 2 commits · closed without merging Validates null XAsyncBlock, missing provider/work pointers, and E_PENDING before forwarding XAsync* entry points through pc(slot) to system xgameruntime.dll. Fixes #1390. **What is in it** - crates/xcl/src/hle/xgameruntime/xasync.rs: move b.is_null() (and provider == 0 / work == 0 / result == E_PENDING) checks before pc(slot) forwarding in XAsyncBegin, XAsyncSchedule, XAsyncComplete, XAsyncGetStatus, XAsyncGetResultSize, XAsyncGetResult, XAsyncCancel, and XAsyncRun. - crates/xcl/src/hle/xgameruntime/xasync.rs: add unit test pc_forwarding_validates_null_and_args_before_dispatching installing a mock PC_ASYNC vtable and verifying all null/invalid calls fail cleanly without invoking any forwarded slot while valid calls still forward. **Tested** - Hardware & toolchain: AMD Radeon RX 9070 XT (driver 32.0.32029.2010), AMD Ryzen 7 9800X3D, Windows 11 10.0.26300.9974, rustc 1.98.1 (48a229cea 2026-09-01), debug (cargo test). - cargo test -p xcl --lib hle::xgameruntime::xasync::tests -- --test-threads=2: 15 passed, 0 failed, 0 ignored. - cargo test --workspace -- --test-threads=2: 777 passed, 0 failed, 41 ignored (xcl --lib: 728 passed, 0 failed, 21 ignored; integration/e2e suites: 49 passed, 0 failed, 20 ignored). - SKIPPED runtime tests: SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows. **Regression run** main: ``` xcl-smoke v1 commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0 gpu: AMD Radeon RX 9070 XT title: A newer retail game seconds: 60 exit: 0x0 frames shown: 1594 (PresentX 1594) presents per 2 s (last 3): 49 48 14 device removals: 0 crashes: 0 peak commit: 20195 MB ``` PR: ``` xcl-smoke v1 commit: 66f0068bc0ea263afa2c1cb7c5ceabf9e7263dde gpu: AMD Radeon RX 9070 XT title: A newer retail game seconds: 60 exit: 0x0 frames shown: 1674 (PresentX 1674) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 14842 MB ``` **Not tested** - Live System32\xgameruntime.dll COM object (unit test uses a mock PC_ASYNC COM vtable). **AI use** - Antigravity (Gemini 4 Hydrogen, high): reordered validation checks ahead of pc() forwarding in xasync.rs, added mock-vtable unit test, ran the workspace test suite, and drafted commit and PR description.
All eight XAsync* entry points in xasync.rs forwarded to pc(slot) before checking for a null XAsyncBlock, missing provider/work function, or E_PENDING result, causing host xgameruntime.dll to dereference null b+0x24.

Run pointer and argument validation checks before pc() dispatch in XAsyncBegin, XAsyncSchedule, XAsyncComplete, XAsyncGetStatus, XAsyncGetResultSize, XAsyncGetResult, XAsyncCancel, and XAsyncRun.

Fixes #1390

Assisted-by: Antigravity (Gemini 4 Hydrogen, high)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:58:27 +00:00
github-bot closed this pull request 2026-11-26 04:58:27 +00:00
Author
Owner

@⁠pickles976 on GitHub · 2026-11-24 18:05 UTC · original

Verdict: correct and well-scoped — the invariant "never forward null into a host binary that will not check" is exactly right, and failing with E_INVALIDARG at our boundary is doubly right when the host would have AV-ed inside a Microsoft DLL (whose stack the user then pastes, sending the hunt to Redmond). This is the same family as my #836 (loader write-site hardening) moved to the HLE-forwarding edge: four sibling projects keep finding that manual forwarding layers validate at the wrong time — and the completion that stops the next five issues of this family is mechanical: enumerate every remaining pc(slot) forwarding entry point once and classify each as check-optional (host documents its own validation) vs check-required, with the list living as a table in the forwarding module so future HLE additions answer the question at the review stage. Happy to cross-check the resulting list against the sibling runtime's equivalent surface (we forward to the real d3d12/xgameruntime too) — two runtimes running the same enumeration is how #836's class finally stopped producing incidents: the parse-time invariant, once adopted, ate five bugs at once.

**@⁠pickles976** on GitHub · 2026-11-24 18:05 UTC · [original](https://github.com/xcl-dev/xcl/pull/1588#issuecomment-7140145579) Verdict: correct and well-scoped — the invariant "never forward null into a host binary that will not check" is exactly right, and failing with `E_INVALIDARG` at our boundary is doubly right when the host would have AV-ed inside a Microsoft DLL (whose stack the user then pastes, sending the hunt to Redmond). This is the same family as my #836 (loader write-site hardening) moved to the HLE-forwarding edge: four sibling projects keep finding that manual forwarding layers validate at the wrong time — and the completion that stops the next five issues of this family is mechanical: **enumerate every remaining `pc(slot)` forwarding entry point once and classify each as check-optional (host documents its own validation) vs check-required**, with the list living as a table in the forwarding module so future HLE additions answer the question at the review stage. Happy to cross-check the resulting list against the sibling runtime's equivalent surface (we forward to the real d3d12/xgameruntime too) — two runtimes running the same enumeration is how #836's class finally stopped producing incidents: the parse-time invariant, once adopted, ate five bugs at once.
Author
Owner

@⁠hajduzsolt on GitHub · 2026-11-24 19:06 UTC · original

Thanks for catching the ABI mismatch. The slot 3 mock now has the exact XAsyncGetStatus signature. cargo test --workspace -- --test-threads=2 passed (with the existing ignored tests).

**@⁠hajduzsolt** on GitHub · 2026-11-24 19:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/1588#issuecomment-7141605728) Thanks for catching the ABI mismatch. The slot 3 mock now has the exact XAsyncGetStatus signature. `cargo test --workspace -- --test-threads=2` passed (with the existing ignored tests).
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 20:02 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 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 20:02 UTC · [original](https://github.com/xcl-dev/xcl/pull/1588#issuecomment-7142968639) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠JJAutoCompare on GitHub · 2026-11-25 05:14 UTC · original

Empirical test report (66f0068b)

Hardware / environment

  • Windows 11 Enterprise Evaluation x64, build 26200.9974. AMD Ryzen 7 3800X. Intel Arc A770 16 GiB, driver 32.0.101.9175. The focused test did not use the GPU.
  • rustc --version returned rustc 1.100.0 (0ef1bc386 2026-11-09). dxc.exe --version returned dxcompiler.dll: 1.9(5512-01b62ad4)(1.9.2609.5) - 1.9.2609.5 (01b62ad47).
  • Tested commit 66f0068bc0ea263afa2c1cb7c5ceabf9e7263dde.

Commands and results

  • cargo test --workspace --no-run completed with exit code 0 and built 19 test executables. It executed zero tests.
  • With XCL_ADAPTER=NONE_CPU_ONLY and RUST_TEST_NOCAPTURE=1, cargo test -p xcl --lib hle::xgameruntime::xasync::tests::pc_forwarding_validates_null_and_args_before_dispatching -- --exact --nocapture completed with exit code 0. The log recorded 1 passed, 0 failed, 0 ignored, 0 skipped, and 831 filtered out.
  • Both commands emitted two deprecation warnings for Atomic*::fetch_update. Neither command used Invoke-ArcTest.ps1 or held the Arc GPU mutex.

Observed behavior

The regression test uses an in-process mock PC runtime vtable. Null async blocks, a zero provider in XAsyncBegin, a zero work callback in XAsyncRun, and E_PENDING in XAsyncComplete produced zero mock calls. The HRESULT-returning invalid calls returned E_INVALIDARG. A valid XAsyncGetStatus call reached the mock exactly once and returned S_OK.

Not tested

Coverage was limited to the focused CPU regression test and compilation of the workspace tests. The full GPU workspace suite and game smoke runs were omitted.

AI use

Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1588-focused.log and published.

**@⁠JJAutoCompare** on GitHub · 2026-11-25 05:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/1588#issuecomment-7153586805) ### Empirical test report (66f0068b) **Hardware / environment** - Windows 11 Enterprise Evaluation x64, build 26200.9974. AMD Ryzen 7 3800X. Intel Arc A770 16 GiB, driver 32.0.101.9175. The focused test did not use the GPU. - `rustc --version` returned `rustc 1.100.0 (0ef1bc386 2026-11-09)`. `dxc.exe --version` returned `dxcompiler.dll: 1.9(5512-01b62ad4)(1.9.2609.5) - 1.9.2609.5 (01b62ad47)`. - Tested commit `66f0068bc0ea263afa2c1cb7c5ceabf9e7263dde`. **Commands and results** - `cargo test --workspace --no-run` completed with exit code 0 and built 19 test executables. It executed zero tests. - With `XCL_ADAPTER=NONE_CPU_ONLY` and `RUST_TEST_NOCAPTURE=1`, `cargo test -p xcl --lib hle::xgameruntime::xasync::tests::pc_forwarding_validates_null_and_args_before_dispatching -- --exact --nocapture` completed with exit code 0. The log recorded 1 passed, 0 failed, 0 ignored, 0 skipped, and 831 filtered out. - Both commands emitted two deprecation warnings for `Atomic*::fetch_update`. Neither command used `Invoke-ArcTest.ps1` or held the Arc GPU mutex. **Observed behavior** The regression test uses an in-process mock PC runtime vtable. Null async blocks, a zero provider in `XAsyncBegin`, a zero work callback in `XAsyncRun`, and `E_PENDING` in `XAsyncComplete` produced zero mock calls. The HRESULT-returning invalid calls returned `E_INVALIDARG`. A valid `XAsyncGetStatus` call reached the mock exactly once and returned `S_OK`. **Not tested** Coverage was limited to the focused CPU regression test and compilation of the workspace tests. The full GPU workspace suite and game smoke runs were omitted. **AI use** Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against `pr1588-focused.log` and published.
Author
Owner

@⁠hajduzsolt on GitHub · 2026-11-25 14:59 UTC · original

Thank you for the ABI review and the forwarding audit suggestion. This PR duplicates the earlier #1406, which now includes exact-signature mocks and a valid-forwarding control in dbe475c, so I am closing this copy. The broader inventory of other forwarding entry points remains a separate follow-up and has not been completed by this change.

**@⁠hajduzsolt** on GitHub · 2026-11-25 14:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/1588#issuecomment-7166127117) Thank you for the ABI review and the forwarding audit suggestion. This PR duplicates the earlier #1406, which now includes exact-signature mocks and a valid-forwarding control in `dbe475c`, so I am closing this copy. The broader inventory of other forwarding entry points remains a separate follow-up and has not been completed by this change.
@ -1230,0 +1267,4 @@
let mut vtable = [0usize; 12];
vtable[3] = trap_status as *const () as usize;
for s in [4usize, 6, 7, 9, 11] {
vtable[s] = trap_hr as *const () as usize;
Author
Owner

@⁠gut0to on GitHub · 2026-11-24 18:04 UTC · original

Slot 3 is used by XAsyncGetStatus, which calls it through the three-argument type fn(usize, *mut XAsyncBlock, bool) -> HRESULT. trap_hr above has six usize parameters, so invoking this pointer with that incompatible Rust function signature is undefined behavior even if the Windows x64 ABI happens to tolerate extra arguments. Please give slot 3 a stub with the exact XAsyncGetStatus signature. AI-assisted review: I verified the call site and function pointer type.

**@⁠gut0to** on GitHub · 2026-11-24 18:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/1588#discussion_r4684387994) Slot 3 is used by `XAsyncGetStatus`, which calls it through the three-argument type `fn(usize, *mut XAsyncBlock, bool) -> HRESULT`. `trap_hr` above has six `usize` parameters, so invoking this pointer with that incompatible Rust function signature is undefined behavior even if the Windows x64 ABI happens to tolerate extra arguments. Please give slot 3 a stub with the exact `XAsyncGetStatus` signature. AI-assisted review: I verified the call site and function pointer type.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.