Skip to content

[upstream #1139] D3D12.X: check pointer alignment in is_adopted before dereferencing (#1130) - #23

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1139
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1139

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Fixes xcl-dev#1130.

d3d12x::real::is_adopted previously dereferenced *(obj as *const usize) without checking pointer alignment. Because this_first(a, b) probes both arguments of struct-returning device hooks — including GetCustomHeapProperties (slot 26, returning [u32; 5], 4-byte aligned) — passing a 4-byte-aligned return buffer caused undefined behavior and aborted debug builds with a misaligned pointer dereference panic.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs: require pointer alignment ((obj as usize) & (std::mem::align_of::<usize>() - 1) == 0) in is_adopted before readable() and the vtable read (adopted COM objects are always pointer-aligned); add unit test this_first_tests::misaligned_return_buffer_is_not_adopted_and_does_not_panic covering 4-byte-aligned stack buffers (including one containing a stale vtable copy).
  • crates/xcl/src/hle/d3d12x/device_x.rs: cache real::this_first(a, b) once in get_resource_allocation_info2_x; add GPU host-driver parity test custom_heap_properties_match_host_in_cpp_and_c_abi verifying get_custom_heap_properties_x in both C++ (this, ret, ...) and C (ret, this, ...) ABI orders with a 4-byte-aligned [u32; 5] return buffer.

Tested

  • Hardware: NVIDIA GeForce RTX 4070 (driver 32.0.16.2124), Intel Core i7-14700K, Windows 11 (10.0.26300.0), rustc 1.100.0 (0ef1bc386 2026-11-09), debug (tests) and release (smoke).
  • cargo test --workspace -- --test-threads=4: 743 passed, 0 failed, 41 ignored.
  • SKIPPED GPU tests on this adapter (Wave32-only):
    • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64
    • gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64
  • cargo test -p xcl --lib this_first_tests -- --nocapture: 2 passed, 0 failed.
  • cargo test -p xcl --lib custom_heap_properties_match_host_in_cpp_and_c_abi -- --nocapture: 1 passed, 0 failed.

Regression run
main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 4070
title: GTA6.Xbox.v1.0.2.1-CYBERLEEK
seconds: 60
exit: 0x0
frames shown: 1348 (PresentX 1348)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15639 MB

PR head:

xcl-smoke v1
commit: 20a893f3a962ec28ebcb16e31ffe08bf69673efb
gpu: NVIDIA GeForce RTX 4070
title: GTA6.Xbox.v1.0.2.1-CYBERLEEK
seconds: 60
exit: 0x0
frames shown: 1463 (PresentX 1464)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15766 MB

Not tested

  • AMD / Wave64 hardware (the two wave64-hardware GPU tests were skipped on the RTX 4070).
  • stable-x86_64-pc-windows-gnullvm toolchain (tested on stable-x86_64-pc-windows-msvc).

AI use

  • Antigravity with Gemini 4 Neon: implemented the alignment check and this_first caching, wrote the unit and host-driver ABI parity tests, ran the workspace test suite and smoke regression, and drafted this PR description.

Mirror of xcl-dev#1139 (auto-synced, do not edit).

…cl-dev#1130)

is_adopted() previously dereferenced *(obj as *const usize) without checking
pointer alignment. When this_first(a, b) inspects both arguments of a
struct-returning device hook such as GetCustomHeapProperties (whose return
buffer D3D12_HEAP_PROPERTIES is [u32; 5], 4-byte aligned), a 4-byte-aligned
stack buffer triggers UB and aborts debug builds with a misaligned pointer
dereference panic.

Require pointer alignment in is_adopted() before readable() and the vtable
read (adopted COM objects are always pointer-aligned), cache the this_first()
result once in get_resource_allocation_info2_x(), and add unit and host-driver
ABI parity tests for 4-byte-aligned return buffers in both C++ and C calling
conventions.

Fixes xcl-dev#1130

Assisted-by: Antigravity (Gemini 4 Neon)
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#1139 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/1139 branch November 25, 2026 00:14
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.

D3D12.X: is_adopted() does misaligned *const usize dereference on 4-byte-aligned D3D12_HEAP_PROPERTIES return buffer

2 participants