D3D12.X: read the adopted vtable pointer unaligned in is_adopted #1434

Closed
github-bot wants to merge 1 commit from gh-pr/1434/head into gh-pr/1434/base
Owner

@⁠JorgeMJM on GitHub · 2026-11-24 15:54 UTC · original
JorgeMJM:d3d12x/is-adopted-unaligned → main · +12 −1 · 1 files · 1 commits · closed without merging

Fixes #1130.

this_first passes both arguments of struct-returning hooks to is_adopted, including 4-byte-aligned return buffers such as D3D12_HEAP_PROPERTIES. The aligned 8-byte load is UB and aborts debug builds with a misaligned-pointer panic. read_unaligned() answers the same question with no trap; genuine adopted objects are heap COM pointers and never misaligned, so no verdict changes.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs: is_adopted uses (obj as *const usize).read_unaligned(); new regression test four_byte_aligned_return_buffer_does_not_trap in this_first_tests.

Tested

  • Hardware: RTX 3070 Laptop 8 GB (OEM OC profile via Lenovo Vantage, core 2.10 GHz; VRAM stock 7001 MHz; sustained clock not sampled), driver 621.40, Windows 11 26300, rustc 1.100.0, debug + release.
  • cargo test --workspace -- --test-threads=4: lib 708 passed, 0 failed, 21 ignored (2 GPU tests SKIPPED on this adapter); all other targets green, 0 failed. One full-suite run hit coherent_buffer_sanitizes_console_flags_and_state failing at VirtualFree; it passes in isolation and in the rerun and on clean origin/main (707/707) — flake, left untouched as a separate issue.
  • New test fails without the fix (exact abort from the issue: misaligned-pointer panic, exit 0xc0000409) and passes with it. The without-fix run was measured pre-rebase (base 508a0c7 + fix, test against reverted line); the with-fix result holds on this PR's head.
  • Review: advisor agent found nothing blocking (keep); its one nit (readable precondition) is in.

Regression run

xcl-smoke v1
commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56
gpu: NVIDIA GeForce RTX 3070 Laptop GPU
title: 78b7bda4
seconds: 60
exit: 0x0
frames shown: 1532 (PresentX 1532)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15259 MB
xcl-smoke v1
commit: a4202ed12b80d5bda0069d1e36fd0aa7df996008
gpu: NVIDIA GeForce RTX 3070 Laptop GPU
title: 78b7bda4
seconds: 60
exit: 0x0
frames shown: 1467 (PresentX 1467)
presents per 2 s (last 3): 60 60 58
device removals: 0
crashes: 0
peak commit: 14784 MB

Not tested

  • AMD GPUs; other titles.
  • Not confirmed whether the smoked title hits the misaligned-buffer path (no GetCustomHeapProperties trace in the smoke logs); the run counts as a no-regression check on the touched area.
  • The flake above was not investigated further.

AI use

  • opencode-go (muse-spark-1.3): wrote the fix, the regression test, ran the suites/smokes and this description.
  • Advisor review by a second agent (Opus 5.5, per operator): keep, no blocking findings.
**@⁠JorgeMJM** on GitHub · 2026-11-24 15:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/1434) `JorgeMJM:d3d12x/is-adopted-unaligned` → `main` · +12 −1 · 1 files · 1 commits · closed without merging Fixes #1130. `this_first` passes both arguments of struct-returning hooks to `is_adopted`, including 4-byte-aligned return buffers such as `D3D12_HEAP_PROPERTIES`. The aligned 8-byte load is UB and aborts debug builds with a misaligned-pointer panic. `read_unaligned()` answers the same question with no trap; genuine adopted objects are heap COM pointers and never misaligned, so no verdict changes. **What is in it** - `crates/xcl/src/hle/d3d12x/real.rs`: `is_adopted` uses `(obj as *const usize).read_unaligned()`; new regression test `four_byte_aligned_return_buffer_does_not_trap` in `this_first_tests`. **Tested** - Hardware: RTX 3070 Laptop 8 GB (OEM OC profile via Lenovo Vantage, core 2.10 GHz; VRAM stock 7001 MHz; sustained clock not sampled), driver 621.40, Windows 11 26300, rustc 1.100.0, debug + release. - `cargo test --workspace -- --test-threads=4`: lib 708 passed, 0 failed, 21 ignored (2 GPU tests SKIPPED on this adapter); all other targets green, 0 failed. One full-suite run hit `coherent_buffer_sanitizes_console_flags_and_state` failing at `VirtualFree`; it passes in isolation and in the rerun and on clean `origin/main` (707/707) — flake, left untouched as a separate issue. - New test fails without the fix (exact abort from the issue: misaligned-pointer panic, exit 0xc0000409) and passes with it. The without-fix run was measured pre-rebase (base `508a0c7` + fix, test against reverted line); the with-fix result holds on this PR's head. - Review: advisor agent found nothing blocking (keep); its one nit (readable precondition) is in. **Regression run** `````` xcl-smoke v1 commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56 gpu: NVIDIA GeForce RTX 3070 Laptop GPU title: 78b7bda4 seconds: 60 exit: 0x0 frames shown: 1532 (PresentX 1532) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15259 MB `````` `````` xcl-smoke v1 commit: a4202ed12b80d5bda0069d1e36fd0aa7df996008 gpu: NVIDIA GeForce RTX 3070 Laptop GPU title: 78b7bda4 seconds: 60 exit: 0x0 frames shown: 1467 (PresentX 1467) presents per 2 s (last 3): 60 60 58 device removals: 0 crashes: 0 peak commit: 14784 MB `````` **Not tested** - AMD GPUs; other titles. - Not confirmed whether the smoked title hits the misaligned-buffer path (no `GetCustomHeapProperties` trace in the smoke logs); the run counts as a no-regression check on the touched area. - The flake above was not investigated further. **AI use** - opencode-go (muse-spark-1.3): wrote the fix, the regression test, ran the suites/smokes and this description. - Advisor review by a second agent (Opus 5.5, per operator): keep, no blocking findings.
this_first passes both arguments of struct-returning hooks to
is_adopted, including 4-byte-aligned return buffers such as
D3D12_HEAP_PROPERTIES. The aligned 8-byte load is UB and aborts
debug builds with a misaligned-pointer panic. read_unaligned()
answers the same question with no trap; genuine adopted objects
are heap COM pointers and never misaligned, so no verdict changes.

Adds a regression test with a 4-byte-misaligned stack word: it
aborts with STATUS_STACK_BUFFER_OVERRUN without the fix.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:53:45 +00:00
github-bot closed this pull request 2026-11-26 04:53:45 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 16:52 UTC · original · edited 2026-11-24 17:01 UTC

Full-suite run, since this PR has no test report yet. Tested exact head a4202ed (on its base 930e8b4).

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, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 752 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: four_byte_aligned_return_buffer_does_not_trap.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored, no skips.

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 16:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/1434#issuecomment-7138351818) · edited 2026-11-24 17:01 UTC Full-suite run, since this PR has no test report yet. Tested exact head `a4202ed` (on its base `930e8b4`). **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, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **752 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: `four_byte_aligned_return_buffer_does_not_trap`. - Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **752 passed, 0 failed, 41 ignored**, no skips. **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

@⁠JorgeMJM on GitHub · 2026-11-24 17:05 UTC · original

Withdrawn by the author.

**@⁠JorgeMJM** on GitHub · 2026-11-24 17:05 UTC · [original](https://github.com/xcl-dev/xcl/pull/1434#issuecomment-7138675727) Withdrawn by the author.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 18:52 UTC · original

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

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

Thanks!

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

Pull request closed

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