Skip to content

startup: keep the object receiver for 8-byte struct returns when rdx holds a wrapper - #2774

Merged
tedin7 merged 1 commit into
R0Y00:mainfrom
MasterDomino:startup/small-result-receiver
Nov 26, 2026
Merged

tedin7 merged 1 commit into
R0Y00:mainfrom
MasterDomino:startup/small-result-receiver

Conversation

@MasterDomino

Copy link
Copy Markdown
Collaborator

Refs #2379. Fixes the Release-only crash in startup_resource_retire_title reported on #2768.

Problem

Since #2719, all six startup_resource_retire_title variants segfault in Release (--preset release) on main; Debug passes. A bisect puts it at #2719: its parent 41cd090b passes 6/6 in Release, and 33004fa1 fails 6/6. The test change only exposed it. The defect is older, in the shim.

Descriptor heap slot 9 (GetCPUDescriptorHandleForHeapStart) returns an 8-byte structure. A title-ABI call passes only this in rcx and reads rax, so the second register holds whatever the caller left there. small_result took the (return buffer, object) form whenever that second argument was a live wrapper. It then wrote the handle over the first argument, the heap object's vtable, and returned the heap's address as the "handle".

Case 9 nests the slot 9 call inside a slot 20 call: invoke<void>(guest, 20, resource, &rtv, invoke<UINT64>(heap, 9)). At /O2, rdx still holds the resource wrapper at the inner call. The RTV is therefore written to an untracked slot, which fails the case-9 check, and the heap's next Release jumps to the handle value. A crash filter showed exception 0xc0000005 with access kind 8 (execute) at a data address, reached from case9_view_slot_fallback.

Change

  • small_result now takes its object from receiver(), the rule the larger struct-returning slots already use:

    • a wrapper in the first argument is the object;
    • only when both arguments look like wrappers does the one on this thread's stack become the result buffer.

    It writes through the first argument only in the (return buffer, object) form.

  • New case 10 in startup_resource_retire_title. It calls slot 9 three ways:

    1. with a second live heap wrapper in the second argument;
    2. through the hidden-pointer form with a stack buffer;
    3. once more, to confirm the heap is intact.

    It runs first, in all six variants. On failure it detaches the heap, so the negative control fails cleanly instead of crashing.

Verification

Windows 11 build 26300; AMD Radeon RX 9070 XT (driver 32.0.32029.2010); WARP 10.0.26100.9818.

  • Release, this head (85087eab, on cd5fb38b): ctest --preset release --no-tests=error -j1 -R '^startup_resource_retire_title' gives 6/6 passed (was 6/6 SEGFAULT on main f1a8db63).
  • Dev, this head: the same selection gives 6/6 passed.
  • Dev, on f1a8db63 plus this change: ctest --preset dev --no-tests=error -j6 -R '^startup_' -E 'gfx2hlsl|image_sample|vertex_fetch' gives 763/763 passed. Eight tests were not run, all capability skips, as on main: startup_view_heap_* and startup_logical_view_* ("adapter accepts 1245184 descriptors directly"), startup_sharedexp_target_*, startup_small_texture_4k_addrlib and startup_run_sh.
  • Negative control (the test kept, the shim change reverted, Release): case 10 fails in every variant, for example FAIL: heap start with a live object in the second argument: got 0x2659c32e970, expected 0x2659de204a0 (heap 000002659C32E970). The returned "handle" is the heap object's own address.
  • Reverse control: the shim change alone, with the test unchanged, also turns the six Release segfaults into passes.

Not covered

The CI /O2 job is skipped on PRs, which is why this Release regression wasn't caught there. Case 10 passes the stray wrapper explicitly instead of relying on register allocation, so it should fail without the fix under any optimization level. I ran the negative control in Release only.

AI-assisted; commands listed were executed locally.

🤖 Generated with Claude Code

…holds a wrapper

small_result chose the (return buffer, object) form whenever its second
argument was a live wrapper. A title-ABI call to descriptor heap slot 9
(GetCPUDescriptorHandleForHeapStart) passes only `this`, so the second
register holds whatever the caller left there. When that was another live
wrapper, the shim wrote the handle over the heap object's vtable and
returned the heap's address as the handle.

Case 9 of startup_resource_retire_title (R0Y00#2719) nests the slot 9 call in a
slot 20 call; at /O2 rdx still held the resource wrapper, so the RTV went to
an untracked slot and the heap's next Release jumped into data. All six
variants segfaulted in Release since R0Y00#2719.

small_result now takes its object from receiver(), the rule the larger
struct-returning slots already use: a wrapper first is the object, and only
when both look like wrappers does the one on this thread's stack become the
result buffer. Case 10 calls slot 9 with a live wrapper in the second
argument and through a return buffer; it fails in Debug and Release without
the shim change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Review + Win2025 WARP receipt for head 85087eab (comment review, no approval).

Reviewed: small_result now takes its object from receiver(), the same rule the larger struct-returning slots use. It writes through the first argument only in the (return buffer, object) form. The new case 10 covers a live second wrapper (rax form), the hidden-pointer form, and a heap-intact check. On failure it detaches the heap, so the negative control fails cleanly. It runs first in all six variants. No sibling small_result callsite is left on the old rule. The PR fixes a test crash; it does not claim game-startup progress, and I made no executable claims.

Commands run: git diff --check origin/main...HEAD (clean), 0 commits behind main.

Win2025 result: dev and release each show 100% tests passed out of 6 for ctest -R '^startup_resource_retire_title': 4 passed, 2 skipped (startup_resource_retire_title_warp_debug1, startup_resource_retire_title_hardware_debug1, debug-layer capability, not counted as passes). Release no longer crashes (this crash is the one on main since #2719).

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 85087eab072bd1a578a4ce92254c844ed1762cc1:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_resource_retire_title -- -j 2): 41.76s (configure 2.54s)
    • Test (ctest --preset dev -R '^startup_resource_retire_title' --parallel 6 --no-tests=error --output-on-failure): 4/6 passed (0.23s: startup_resource_retire_title_warp_debug1 0.03s, startup_resource_retire_title_hardware_debug1 0.03s, startup_resource_retire_title_off_hardware 0.07s, startup_resource_retire_title_off_warp 0.08s, startup_resource_retire_title_hardware_debug0 0.09s, startup_resource_retire_title_warp_debug0 0.10s); skipped (capability, not a pass): startup_resource_retire_title_warp_debug1, startup_resource_retire_title_hardware_debug1
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_resource_retire_title -- -j 2): 50.61s (configure 2.42s)
    • Test (ctest --preset release -R '^startup_resource_retire_title' --parallel 6 --no-tests=error --output-on-failure): 4/6 passed (0.34s: startup_resource_retire_title_hardware_debug1 0.06s, startup_resource_retire_title_warp_debug1 0.06s, startup_resource_retire_title_off_warp 0.10s, startup_resource_retire_title_off_hardware 0.10s, startup_resource_retire_title_hardware_debug0 0.11s, startup_resource_retire_title_warp_debug0 0.16s); skipped (capability, not a pass): startup_resource_retire_title_hardware_debug1, startup_resource_retire_title_warp_debug1
  • sccache: 0/14 hits; wall 108.9s

AI-assisted; commands listed were executed locally.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review + Win2025 WARP receipt for head 85087eab (comment review, no approval).

Reviewed: small_result now takes its object from receiver(), the same rule the larger struct-returning slots use. It writes through the first argument only in the (return buffer, object) form. The new case 10 covers a live second wrapper (rax form), the hidden-pointer form, and a heap-intact check. On failure it detaches the heap, so the negative control fails cleanly. It runs first in all six variants. No sibling small_result callsite is left on the old rule. The PR fixes a test crash; it does not claim game-startup progress, and I made no executable claims.

Commands run: git diff --check origin/main...HEAD (clean), 0 commits behind main.

Win2025 result: dev and release each show 100% tests passed out of 6 for ctest -R '^startup_resource_retire_title': 4 passed, 2 skipped (startup_resource_retire_title_warp_debug1, startup_resource_retire_title_hardware_debug1, debug-layer capability, not counted as passes). Release no longer crashes (this crash is the one on main since #2719).

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 85087eab072bd1a578a4ce92254c844ed1762cc1:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_resource_retire_title -- -j 2): 41.76s (configure 2.54s)
    • Test (ctest --preset dev -R '^startup_resource_retire_title' --parallel 6 --no-tests=error --output-on-failure): 4/6 passed (0.23s: startup_resource_retire_title_warp_debug1 0.03s, startup_resource_retire_title_hardware_debug1 0.03s, startup_resource_retire_title_off_hardware 0.07s, startup_resource_retire_title_off_warp 0.08s, startup_resource_retire_title_hardware_debug0 0.09s, startup_resource_retire_title_warp_debug0 0.10s); skipped (capability, not a pass): startup_resource_retire_title_warp_debug1, startup_resource_retire_title_hardware_debug1
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_resource_retire_title -- -j 2): 50.61s (configure 2.42s)
    • Test (ctest --preset release -R '^startup_resource_retire_title' --parallel 6 --no-tests=error --output-on-failure): 4/6 passed (0.34s: startup_resource_retire_title_hardware_debug1 0.06s, startup_resource_retire_title_warp_debug1 0.06s, startup_resource_retire_title_off_warp 0.10s, startup_resource_retire_title_off_hardware 0.10s, startup_resource_retire_title_hardware_debug0 0.11s, startup_resource_retire_title_warp_debug0 0.16s); skipped (capability, not a pass): startup_resource_retire_title_hardware_debug1, startup_resource_retire_title_warp_debug1
  • sccache: 0/14 hits; wall 108.9s

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 merged commit 475bb73 into R0Y00:main Nov 26, 2026
5 checks passed
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.

2 participants