startup: check the title heap allocation that succeeds #1556

Manually merged
github merged 1 commit from gh-pr/1556/head into gh-pr/1556/base 2026-11-26 23:16:17 +00:00
Owner

@⁠Asimmimx on GitHub · 2026-11-24 13:53 UTC · original
Asimmimx:tests/title-heap-memory-check → main · +21 −1 · 2 files · 1 commits · merged 2026-11-24 14:38 UTC

Change

Refs #1149. This extends startup_title_heap, the check for src/startup_stubs/title_heap_memory.h. When a descriptor heap's desktop CPU start is not usable as an address (any CBV/SRV/UAV heap, or a heap whose start is tagged), the wrapper allocates plain memory of NumDescriptors × increment bytes. It gives that memory to the executable as the heap's CPU start.

No existing test takes the path where this allocation succeeds:

  • startup_title_heap uses only an allocator that returns 0 and ignores the size it is asked for.
  • startup_title_heap_device_warp creates no view heap. On WARP the sampler, render-target and depth heaps have aligned starts.
  • startup_view_heap_* and startup_null_views_* pass memory of their own.
  • d3d12x_descriptor_*_warp get a plain desktop device.

So three mutants left all of these passing:

  • discarding the allocated address, which would make every view heap created without its own memory fail with E_OUTOFMEMORY;
  • allocate(1);
  • allocate(bytes / 2).

This adds four expectations to the existing rule(). An allocator that succeeds returns 0x20000 and records the size it is asked for. Two cases use hand-worked sizes:

  • an aligned view heap, 1024 × 32 = 0x8000 bytes;
  • a tagged sampler heap, 128 × 32 = 0x1000 bytes.

Each call must return true, store 0x20000, ask for exactly that size, and advance the allocation count to 2 and then 3.

Only tests/startup_title_heap_check.cpp (+18 lines) and two sentences in the existing title-heap bullet of docs/startup-runtime.md change. There is no CMake change and no new CTest. The existing startup_title_heap_tags_control still fails as intended.

A behaviour I did not pin. WARP's CreateDescriptorHeap accepts NumDescriptors = 0 for all four heap types; I checked this with a scratch probe that is not committed. Such a heap is therefore reachable from the real caller. When it needs memory and has none of its own, title_heap_memory skips the allocation and returns false, so the wrapper returns E_OUTOFMEMORY although the desktop call succeeded. Should a zero-count heap be refused, or accepted without memory? I left it untested; tell me which you want and I will add the case.

Verification

Commit 309cfede (main) plus this change, dev preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260, Windows SDK 10.0.26100.0, WARP 10.0.26100.9818.

ctest --preset dev --no-tests=error -R '^startup_title_heap(_tags_control|_device_warp)?$' -V
#   3/3 passed (the tags control fails with 3 FAILs, as WILL_FAIL expects)

tests/docs_links_check.py, tests/bidi_controls_check.py and git diff --check passed.

Mutation probe

I applied each mutation to the header alone, rebuilt, and ran the following tests, then reverted. None of this is committed.

  • startup_title_heap
  • startup_title_heap_tags_control
  • startup_title_heap_device_warp
  • startup_null_views_warp
  • d3d12x_descriptor_{heap,table,negative}_warp
Mutant Existing With the new cases
control: drop the CBV_SRV_UAV clause killed killed
alignment mask alignof(int) - 1 killed killed
|| → && in the rule killed killed
ignore caller memory in the early return killed killed
every type except samplers needs memory killed killed
allocated address discarded survived killed
allocate(1) survived killed
allocate(bytes / 2) survived killed
drop the if (bytes) guard survived survived (zero-count question above)
return title_memory != 0 || !bytes survived survived (zero-count question above)

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

**@⁠Asimmimx** on GitHub · 2026-11-24 13:53 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1556) `Asimmimx:tests/title-heap-memory-check` → `main` · +21 −1 · 2 files · 1 commits · merged 2026-11-24 14:38 UTC ## Change Refs #1149. This extends `startup_title_heap`, the check for `src/startup_stubs/title_heap_memory.h`. When a descriptor heap's desktop CPU start is not usable as an address (any CBV/SRV/UAV heap, or a heap whose start is tagged), the wrapper allocates plain memory of `NumDescriptors × increment` bytes. It gives that memory to the executable as the heap's CPU start. No existing test takes the path where this allocation succeeds: - `startup_title_heap` uses only an allocator that returns 0 and ignores the size it is asked for. - `startup_title_heap_device_warp` creates no view heap. On WARP the sampler, render-target and depth heaps have aligned starts. - `startup_view_heap_*` and `startup_null_views_*` pass memory of their own. - `d3d12x_descriptor_*_warp` get a plain desktop device. So three mutants left all of these passing: - discarding the allocated address, which would make every view heap created without its own memory fail with `E_OUTOFMEMORY`; - `allocate(1)`; - `allocate(bytes / 2)`. This adds four expectations to the existing `rule()`. An allocator that succeeds returns `0x20000` and records the size it is asked for. Two cases use hand-worked sizes: - an aligned view heap, 1024 × 32 = `0x8000` bytes; - a tagged sampler heap, 128 × 32 = `0x1000` bytes. Each call must return true, store `0x20000`, ask for exactly that size, and advance the allocation count to 2 and then 3. Only `tests/startup_title_heap_check.cpp` (+18 lines) and two sentences in the existing title-heap bullet of `docs/startup-runtime.md` change. There is no CMake change and no new CTest. The existing `startup_title_heap_tags_control` still fails as intended. **A behaviour I did not pin.** WARP's `CreateDescriptorHeap` accepts `NumDescriptors = 0` for all four heap types; I checked this with a scratch probe that is not committed. Such a heap is therefore reachable from the real caller. When it needs memory and has none of its own, `title_heap_memory` skips the allocation and returns false, so the wrapper returns `E_OUTOFMEMORY` although the desktop call succeeded. Should a zero-count heap be refused, or accepted without memory? I left it untested; tell me which you want and I will add the case. ## Verification Commit `309cfede` (`main`) plus this change, `dev` preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260, Windows SDK 10.0.26100.0, WARP 10.0.26100.9818. ```powershell ctest --preset dev --no-tests=error -R '^startup_title_heap(_tags_control|_device_warp)?$' -V # 3/3 passed (the tags control fails with 3 FAILs, as WILL_FAIL expects) ``` `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `git diff --check` passed. ## Mutation probe I applied each mutation to the header alone, rebuilt, and ran the following tests, then reverted. None of this is committed. - `startup_title_heap` - `startup_title_heap_tags_control` - `startup_title_heap_device_warp` - `startup_null_views_warp` - `d3d12x_descriptor_{heap,table,negative}_warp` | Mutant | Existing | With the new cases | |---|---|---| | control: drop the `CBV_SRV_UAV` clause | killed | killed | | alignment mask `alignof(int) - 1` | killed | killed | | `\|\|` → `&&` in the rule | killed | killed | | ignore caller memory in the early return | killed | killed | | every type except samplers needs memory | killed | killed | | allocated address discarded | **survived** | killed | | `allocate(1)` | **survived** | killed | | `allocate(bytes / 2)` | **survived** | killed | | drop the `if (bytes)` guard | survived | survived (zero-count question above) | | `return title_memory != 0 \|\| !bytes` | survived | survived (zero-count question above) | ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Claude Code).
ensure_title_heap_memory() gives a descriptor heap without memory of
its own plain memory from the allocator. startup_title_heap tested it
only with an allocator that always fails and ignores the requested
size, and startup_title_heap_device_warp creates no view heap and gets
aligned sampler starts on WARP, so the success path was never taken.
Three single-point mutants left startup_title_heap, its tags control,
startup_title_heap_device_warp and startup_null_views_warp passing:
discarding the allocated address (every view heap without memory then
fails with E_OUTOFMEMORY), and asking for 1 byte or half of the heap.

Add an aligned view heap of 0x8000 bytes and a tagged sampler heap of
0x1000 bytes with an allocator that succeeds. Each must return true,
store the allocated address and pass the whole size to the allocator.
Each of the three mutants now fails the test. Five further mutants (no
view-heap clause, a 4-byte alignment mask, && for ||, ignoring caller
memory, and every non-sampler type needing memory) were already caught.
A heap of zero bytes is left unpinned: it gets no allocation and is
refused, and whether that is intended is not settled here.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:16:14 +00:00
github manually merged commit f9fc9800d6 into gh-pr/1556/base 2026-11-26 23:16:17 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.