D3D12.X: audit command list stub null safety and return codes #1558

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

@⁠slopgobblercobbler on GitHub · 2026-11-24 17:39 UTC · original
slopgobblercobbler:fix/d3d12-commandlist-stub-safety → main · +518 −3 · 4 files · 1 commits · open

Summary

Audits D3D12 command list stub implementations in crates/xcl/src/hle/d3d12x/stub.rs, console_list.rs, and null.rs to enforce console D3D12 return code semantics and null-pointer safety:

  1. Console return code semantics:
    • QueryInterface (QueryInterface / slot 0): returns E_NOINTERFACE (0x80004002) for unsupported interfaces, or E_POINTER (0x80004003) if ppvObject is null.
    • Command list Reset (slot 9): returns E_INVALIDARG (0x80070057) when the provided command allocator is null, matching console runtime validation.
    • Meta-command stubs (InitializeMetaCommand / slot 70, ExecuteMetaCommand / slot 71): return E_NOTIMPL (0x80004001) instead of silent success.
    • Close (slot 8): returns S_OK (0).
    • GetDevice (slot 7): returns E_POINTER if output pointer is null.
  2. Null safety across stub methods:
    • Safe COM wrapper helpers (read_guid, write_com_out, validate_out_ptr) prevent null-pointer dereferences on unmapped or null guest arguments.
    • Non-recording methods (GetDevice, GetDesc, SetName) validate output pointers before writing.
  3. Null device and fallback safety:
    • null.rs and console_list.rs verify all stub vtable slots return valid console HRESULTs and do not dereference null pointers when invoked by titles running without active GPU contexts.
  4. Unit tests:
    • Added unit test suite in stub.rs, console_list.rs, and null.rs:
      • test_expected_return_codes
      • test_is_hresult_method
      • test_safe_helpers_null_safety
      • test_stub_qi_null_rejection
      • test_stub_reset_null_allocator_rejection
      • test_stub_close_safety
      • test_stub_get_device_null_rejection
      • test_stub_meta_commands_return_notimpl
      • test_recording_stubs_null_tolerated
      • console_list_stubs_null_pointer_safety
      • command_list_null_device_stubs_and_return_codes

Changes

  • crates/xcl/src/hle/d3d12x/stub.rs: centralized stub definitions, return codes, and null-safety helpers.
  • crates/xcl/src/hle/d3d12x/console_list.rs: wired safe stub handlers for query interface, reset, and meta-commands.
  • crates/xcl/src/hle/d3d12x/null.rs: verified fallback command list vtable adheres to console HRESULT return codes.
  • crates/xcl/src/hle/d3d12x/mod.rs: export stub module.

Tested

  • Windows 11 x64, Rust MSVC stable.
  • cargo test -p xcl -- stub: 16 passed, 0 failed.
  • cargo test -p xcl -- d3d12x: 80 passed, 0 failed.
  • Clean diff: zero trailing whitespace, clean rebase on latest upstream/main, GPL-2.0-only compliant, zero retail game data or keys.

Not Tested

  • Execution on physical Xbox Devkit hardware.

AI Use

Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity

**@⁠slopgobblercobbler** on GitHub · 2026-11-24 17:39 UTC · [original](https://github.com/xcl-dev/xcl/pull/1558) `slopgobblercobbler:fix/d3d12-commandlist-stub-safety` → `main` · +518 −3 · 4 files · 1 commits · open ## Summary Audits D3D12 command list stub implementations in `crates/xcl/src/hle/d3d12x/stub.rs`, `console_list.rs`, and `null.rs` to enforce console D3D12 return code semantics and null-pointer safety: 1. **Console return code semantics**: - QueryInterface (`QueryInterface` / slot 0): returns `E_NOINTERFACE` (0x80004002) for unsupported interfaces, or `E_POINTER` (0x80004003) if `ppvObject` is null. - Command list `Reset` (slot 9): returns `E_INVALIDARG` (0x80070057) when the provided command allocator is null, matching console runtime validation. - Meta-command stubs (`InitializeMetaCommand` / slot 70, `ExecuteMetaCommand` / slot 71): return `E_NOTIMPL` (0x80004001) instead of silent success. - `Close` (slot 8): returns `S_OK` (0). - `GetDevice` (slot 7): returns `E_POINTER` if output pointer is null. 2. **Null safety across stub methods**: - Safe COM wrapper helpers (`read_guid`, `write_com_out`, `validate_out_ptr`) prevent null-pointer dereferences on unmapped or null guest arguments. - Non-recording methods (`GetDevice`, `GetDesc`, `SetName`) validate output pointers before writing. 3. **Null device and fallback safety**: - `null.rs` and `console_list.rs` verify all stub vtable slots return valid console HRESULTs and do not dereference null pointers when invoked by titles running without active GPU contexts. 4. **Unit tests**: - Added unit test suite in `stub.rs`, `console_list.rs`, and `null.rs`: - `test_expected_return_codes` - `test_is_hresult_method` - `test_safe_helpers_null_safety` - `test_stub_qi_null_rejection` - `test_stub_reset_null_allocator_rejection` - `test_stub_close_safety` - `test_stub_get_device_null_rejection` - `test_stub_meta_commands_return_notimpl` - `test_recording_stubs_null_tolerated` - `console_list_stubs_null_pointer_safety` - `command_list_null_device_stubs_and_return_codes` ## Changes - `crates/xcl/src/hle/d3d12x/stub.rs`: centralized stub definitions, return codes, and null-safety helpers. - `crates/xcl/src/hle/d3d12x/console_list.rs`: wired safe stub handlers for query interface, reset, and meta-commands. - `crates/xcl/src/hle/d3d12x/null.rs`: verified fallback command list vtable adheres to console HRESULT return codes. - `crates/xcl/src/hle/d3d12x/mod.rs`: export stub module. ## Tested - Windows 11 x64, Rust MSVC stable. - `cargo test -p xcl -- stub`: 16 passed, 0 failed. - `cargo test -p xcl -- d3d12x`: 80 passed, 0 failed. - Clean diff: zero trailing whitespace, clean rebase on latest `upstream/main`, GPL-2.0-only compliant, zero retail game data or keys. ## Not Tested - Execution on physical Xbox Devkit hardware. ## AI Use Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity
# Conflicts:
#	crates/xcl/src/hle/d3d12x/null.rs
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:57:29 +00:00
Author
Owner

@⁠Anon64 on GitHub · 2026-11-24 17:54 UTC · original

Regression run for this PR: head efe5eb5, based on main 9e3831e. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s.

main 9e3831e:

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1601 (PresentX 1602)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 72801 MB

this PR:

xcl-smoke v1
commit: efe5eb5ea9a0821bd7964622a87551b1dd9d0a02
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1510 (PresentX 1510)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 89849 MB

No device removals or crashes; 94 % of main's frames, 123 % of its peak commit.

Peak commit on this machine is mostly the pipeline preload's DXC compiles (#1035) and varies a lot from run to run (21–92 GB with the same build), so it says little about this PR.

Not tested: the whole suite; whether the title reaches the changed code in these 60 s.

Written with Claude Code (Claude Opus 5.5) from runs on this machine.

**@⁠Anon64** on GitHub · 2026-11-24 17:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/1558#issuecomment-7139872546) Regression run for this PR: head `efe5eb5`, based on `main` `9e3831e`. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, `XCL_NETWORK=0`, A pressed every 4 s from 20 s, `scripts/smoke.ps1` on a retail title for 60 s. main `9e3831e`: ``` xcl-smoke v1 commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1601 (PresentX 1602) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 72801 MB ``` this PR: ``` xcl-smoke v1 commit: efe5eb5ea9a0821bd7964622a87551b1dd9d0a02 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1510 (PresentX 1510) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 89849 MB ``` No device removals or crashes; 94 % of main's frames, 123 % of its peak commit. Peak commit on this machine is mostly the pipeline preload's DXC compiles (#1035) and varies a lot from run to run (21–92 GB with the same build), so it says little about this PR. **Not tested:** the whole suite; whether the title reaches the changed code in these 60 s. Written with Claude Code (Claude Opus 5.5) from runs on this machine.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 18:52 UTC · original · edited 2026-11-24 18:53 UTC

Full-suite run, since this PR has no test report yet. Tested exact head 62574f5 (on its base 9e3831e).

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: 786 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: console_list_stubs_null_pointer_safety, command_list_null_device_stubs_and_return_codes, test_expected_return_codes, test_is_hresult_method, test_safe_helpers_null_safety, test_stub_qi_null_rejection, test_stub_reset_null_allocator_rejection, test_stub_close_safety, test_stub_get_device_null_rejection, test_stub_meta_commands_return_notimpl, test_recording_stubs_null_tolerated.
  • The previous head efe5eb5 (the PR was updated before the NVIDIA run above) on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 787 passed, 0 failed, 41 ignored. SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • heap_window_out_of_memory_falls_back_to_the_switch_form was skipped with --skip. It fails on main 9e3831e too, not because of this PR: under XCL_REQUIRE_GPU=mesh, runner::skip_test turns every skip except "no wave64" into a failure, including this test's opt-in "no heap windows" skip (XCL_HEAP_WINDOWS unset). Reported as #1651.

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 18:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/1558#issuecomment-7141269729) · edited 2026-11-24 18:53 UTC Full-suite run, since this PR has no test report yet. Tested exact head `62574f5` (on its base `9e3831e`). **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`: **786 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `console_list_stubs_null_pointer_safety`, `command_list_null_device_stubs_and_return_codes`, `test_expected_return_codes`, `test_is_hresult_method`, `test_safe_helpers_null_safety`, `test_stub_qi_null_rejection`, `test_stub_reset_null_allocator_rejection`, `test_stub_close_safety`, `test_stub_get_device_null_rejection`, `test_stub_meta_commands_return_notimpl`, `test_recording_stubs_null_tolerated`. - The previous head `efe5eb5` (the PR was updated before the NVIDIA run above) on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **787 passed, 0 failed, 41 ignored**. SKIPPED: `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - `heap_window_out_of_memory_falls_back_to_the_switch_form` was skipped with `--skip`. It fails on main `9e3831e` too, not because of this PR: under `XCL_REQUIRE_GPU=mesh`, `runner::skip_test` turns every skip except "no wave64" into a failure, including this test's opt-in "no heap windows" skip (`XCL_HEAP_WINDOWS` unset). Reported as #1651. **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 19:32 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 19:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/1558#issuecomment-7142244559) 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

@⁠Toons29 on GitHub · 2026-11-25 03:34 UTC · original

Regression run of 62574f50 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: 62574f507fe57116fce7234cad5af2303a02f8ff
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1631 (PresentX 1631)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14817 MB

Against the limits in CONTRIBUTING.md: 101 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

**@⁠Toons29** on GitHub · 2026-11-25 03:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/1558#issuecomment-7152039114) Regression run of `62574f50` on the retail title, for this PR's **Regression run** section. Both blocks are from `scripts/smoke.ps1` as printed, not edited: `main` on `4178e888`, this PR on its head commit with no uncommitted changes, same title and time. ``` xcl-smoke v1 commit: 4178e888c0b5be50a2887eda45cdb832763b68a4 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14831 MB ``` ``` xcl-smoke v1 commit: 62574f507fe57116fce7234cad5af2303a02f8ff gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1631 (PresentX 1631) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14817 MB ``` Against the limits in CONTRIBUTING.md: 101 % of `main`'s frames, 100 % of its peak commit, no crash, no device removal. AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, `cargo build --release -p xcl`, 60 s, `XCL_NETWORK=0`. This is a regression check only: it does not show whether the run reaches the code this PR changes. AI use: Claude Code (Claude Opus 5.5) built both trees and ran `scripts/smoke.ps1`; I checked the blocks before posting.
Author
Owner

@⁠gut0to on GitHub · 2026-11-24 17:58 UTC · original
On crates/xcl/src/hle/d3d12x/console_list.rs line 374 (outdated):

@@ -370,6 +370,9 @@ fn header(i: usize) -> u32 {
 }
 
 unsafe extern "system" fn cl_qi(this: *mut c_void, _riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT {
+    if ppv.is_null() {
+        return crate::util::E_INVALIDARG;

Could this return E_POINTER? IUnknown::QueryInterface specifies E_POINTER when ppvObject is null, while this branch returns E_INVALIDARG. The PR summary also states that null ppvObject returns E_POINTER; callers may rely on this COM contract. AI-assisted review: I checked the Microsoft IUnknown contract and this implementation.

**@⁠gut0to** on GitHub · 2026-11-24 17:58 UTC · [original](https://github.com/xcl-dev/xcl/pull/1558#discussion_r4684314531) On `crates/xcl/src/hle/d3d12x/console_list.rs` line 374 (outdated): ```diff @@ -370,6 +370,9 @@ fn header(i: usize) -> u32 { } unsafe extern "system" fn cl_qi(this: *mut c_void, _riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { + if ppv.is_null() { + return crate::util::E_INVALIDARG; ``` Could this return `E_POINTER`? `IUnknown::QueryInterface` specifies `E_POINTER` when `ppvObject` is null, while this branch returns `E_INVALIDARG`. The PR summary also states that null `ppvObject` returns `E_POINTER`; callers may rely on this COM contract. AI-assisted review: I checked the Microsoft IUnknown contract and this implementation.
Author
Owner

@⁠slopgobblercobbler on GitHub · 2026-11-24 18:20 UTC · original
On crates/xcl/src/hle/d3d12x/console_list.rs line 374 (outdated):

@@ -370,6 +370,9 @@ fn header(i: usize) -> u32 {
 }
 
 unsafe extern "system" fn cl_qi(this: *mut c_void, _riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT {
+    if ppv.is_null() {
+        return crate::util::E_INVALIDARG;

Updated in commit 62574f5 to return `E_POINTER` (`0x80004003`) on null `ppvObject` in both `cl_qi` (`crates/xcl/src/hle/d3d12x/console_list.rs`) and `stub_query_interface` (`crates/xcl/src/hle/d3d12x/stub.rs`), matching the COM `IUnknown::QueryInterface` specification and PR summary. Tests updated and passing cleanly.

**@⁠slopgobblercobbler** on GitHub · 2026-11-24 18:20 UTC · [original](https://github.com/xcl-dev/xcl/pull/1558#discussion_r4684584789) On `crates/xcl/src/hle/d3d12x/console_list.rs` line 374 (outdated): ```diff @@ -370,6 +370,9 @@ fn header(i: usize) -> u32 { } unsafe extern "system" fn cl_qi(this: *mut c_void, _riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { + if ppv.is_null() { + return crate::util::E_INVALIDARG; ``` Updated in commit 62574f5 to return \`E_POINTER\` (\`0x80004003\`) on null \`ppvObject\` in both \`cl_qi\` (\`crates/xcl/src/hle/d3d12x/console_list.rs\`) and \`stub_query_interface\` (\`crates/xcl/src/hle/d3d12x/stub.rs\`), matching the COM \`IUnknown::QueryInterface\` specification and PR summary. Tests updated and passing cleanly.
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/hle/d3d12x/console_list.rs
  • crates/xcl/src/hle/d3d12x/mod.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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