startup: check the placement publish lock and width #1503

Manually merged
github merged 1 commit from gh-pr/1503/head into gh-pr/1503/base 2026-11-26 23:12:20 +00:00
Owner

@⁠Asimmimx on GitHub · 2026-11-24 13:13 UTC · original
Asimmimx:startup/placement-publish-check → main · +98 −1 · 3 files · 1 commits · merged 2026-11-24 13:30 UTC

Change

Refs #1149. This adds a device-free check for src/startup_stubs/placement_publish.h. Device slot 133 (d3d12_xs_device.cpp) uses it to register a placed buffer.

The binding lookup placed_buffer_range in d3d12_capture.inl takes note_lock shared and starts its search at address - max_width + 1. It therefore relies on two things:

  • publish_placement inserts the record and its index entry under the exclusive lock;
  • max_width never shrinks below the widest record published so far.

The tests that reach the header are startup_placement_alloc (CPU), startup_placed_vertex_warp and xmem_page_runs_device_warp. They check the inserted records, the ALREADY_EXISTS and out-of-memory paths and the rollback, but neither of those two properties. Three single-point mutants left all three passing:

  • dropping the lock guard;
  • taking the lock shared instead of exclusive;
  • max_width = record.bytes, which lets a later, narrower record shrink the search window. Lookups inside a wider, earlier buffer would then start too late and miss it.

startup_placement_publish includes only the header:

  • It publishes four records of 1 MiB, 128 KiB, 4 MiB and 256 KiB.
  • From inside the records accessor, and from the record's copy constructor (which runs under the lock), it checks that TryAcquireSRWLockShared fails. SRW locks are not reentrant, so this means the lock is held exclusively. It also checks that the lock is free again after the call.
  • It checks max_width after each record against hand-worked values: 0x100000, 0x100000, 0x400000, 0x400000.
  • It checks each record and its index entry.

startup_placement_publish_shrink_control runs --mutate shrink, which expects 0x20000 after the second record, and must fail (WILL_FAIL).

The change is test, CMake and docs/experiments.md only. The paragraph sits next to the existing startup_placement_alloc text, and the CMake block follows the startup_placement_alloc registration.

Verification

Commit 3c6273ac (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_placement_(alloc|publish|publish_shrink_control)|startup_placed_vertex_warp)$' -V
#   4/4 passed; the control exits 5 with "after owner 2: max_width 0x100000, expected 0x20000"

xmem_page_runs_device_warp also passed on the unmodified header. 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 the affected targets, ran the tests, then reverted. None of this is committed.

Mutant alloc / placed_vertex_warp / xmem_device_warp startup_placement_publish
control: if (!added) → if (added) killed / killed / killed fails
lock guard dropped survived fails
guard takes shared instead of exclusive survived fails
max_width = record.bytes survived fails
insert_or_assign (duplicate replaces the record) survived survives, not pinned
rollback records.erase dropped killed by alloc survives (already covered)
throw; → return S_OK; killed by alloc survives (already covered)
record.bytes - 1 killed by alloc fails
index key start + 1 killed by alloc and placed_vertex fails
length_error catch → domain_error survived survives, not pinned

Two survivors are deliberately not pinned:

  • insert_or_assign. A duplicate owner cannot come from the real caller: each owner is a freshly allocated wrapper that lives for the whole process. The ALREADY_EXISTS return is already checked.
  • domain_error catch. A std::unordered_map throws length_error only above max_size, which is not practically reachable.

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:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1503) `Asimmimx:startup/placement-publish-check` → `main` · +98 −1 · 3 files · 1 commits · merged 2026-11-24 13:30 UTC ## Change Refs #1149. This adds a device-free check for `src/startup_stubs/placement_publish.h`. Device slot 133 (`d3d12_xs_device.cpp`) uses it to register a placed buffer. The binding lookup `placed_buffer_range` in `d3d12_capture.inl` takes `note_lock` shared and starts its search at `address - max_width + 1`. It therefore relies on two things: - `publish_placement` inserts the record and its index entry under the exclusive lock; - `max_width` never shrinks below the widest record published so far. The tests that reach the header are `startup_placement_alloc` (CPU), `startup_placed_vertex_warp` and `xmem_page_runs_device_warp`. They check the inserted records, the `ALREADY_EXISTS` and out-of-memory paths and the rollback, but neither of those two properties. Three single-point mutants left all three passing: - dropping the lock guard; - taking the lock shared instead of exclusive; - `max_width = record.bytes`, which lets a later, narrower record shrink the search window. Lookups inside a wider, earlier buffer would then start too late and miss it. `startup_placement_publish` includes only the header: - It publishes four records of 1 MiB, 128 KiB, 4 MiB and 256 KiB. - From inside the records accessor, and from the record's copy constructor (which runs under the lock), it checks that `TryAcquireSRWLockShared` fails. SRW locks are not reentrant, so this means the lock is held exclusively. It also checks that the lock is free again after the call. - It checks `max_width` after each record against hand-worked values: 0x100000, 0x100000, 0x400000, 0x400000. - It checks each record and its index entry. `startup_placement_publish_shrink_control` runs `--mutate shrink`, which expects 0x20000 after the second record, and must fail (`WILL_FAIL`). The change is test, CMake and `docs/experiments.md` only. The paragraph sits next to the existing `startup_placement_alloc` text, and the CMake block follows the `startup_placement_alloc` registration. ## Verification Commit `3c6273ac` (`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_placement_(alloc|publish|publish_shrink_control)|startup_placed_vertex_warp)$' -V # 4/4 passed; the control exits 5 with "after owner 2: max_width 0x100000, expected 0x20000" ``` `xmem_page_runs_device_warp` also passed on the unmodified header. `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 the affected targets, ran the tests, then reverted. None of this is committed. | Mutant | alloc / placed_vertex_warp / xmem_device_warp | `startup_placement_publish` | |---|---|---| | control: `if (!added)` → `if (added)` | killed / killed / killed | fails | | lock guard dropped | **survived** | fails | | guard takes shared instead of exclusive | **survived** | fails | | `max_width = record.bytes` | **survived** | fails | | `insert_or_assign` (duplicate replaces the record) | survived | survives, not pinned | | rollback `records.erase` dropped | killed by alloc | survives (already covered) | | `throw;` → `return S_OK;` | killed by alloc | survives (already covered) | | `record.bytes - 1` | killed by alloc | fails | | index key `start + 1` | killed by alloc and placed_vertex | fails | | `length_error` catch → `domain_error` | survived | survives, not pinned | Two survivors are deliberately not pinned: - **`insert_or_assign`.** A duplicate owner cannot come from the real caller: each owner is a freshly allocated wrapper that lives for the whole process. The `ALREADY_EXISTS` return is already checked. - **`domain_error` catch.** A `std::unordered_map` throws `length_error` only above `max_size`, which is not practically reachable. ## 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).
src/startup_stubs/placement_publish.h adds a slot-133 buffer to the
resource records and to the start index of its placement group, and
widens the group's max_width. Binding lookup reads the same maps under
note_lock in shared mode and starts its search at the address minus
max_width plus one. The only direct check, startup_placement_alloc,
fails allocations and checks the rollback, but it adds one record whose
width is the largest and checks the lock only after the call returns.
Single-point mutants that drop the lock guard, take the guard in shared
mode, or assign max_width from the new record instead of keeping the
maximum left it, startup_placed_vertex_warp and
xmem_page_runs_device_warp passing.

startup_placement_publish includes the header without a device. It
publishes four records of 1 MiB, 128 KiB, 4 MiB and 256 KiB, probes
the lock from the records accessor and from the record copy made under
it, and checks the hand-written widths 0x100000, 0x100000, 0x400000
and 0x400000 with each record and index entry. Each of the three
mutants now fails it. The startup_placement_publish_shrink_control run
expects the narrower width after the second record and must fail.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:12:19 +00:00
github manually merged commit 2993c12c78 into gh-pr/1503/base 2026-11-26 23:12:20 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.