runtime: check the CPU-SRV refresh refusals without a device #1714

Manually merged
github merged 1 commit from gh-pr/1714/head into gh-pr/1714/base 2026-11-26 23:28:15 +00:00
Owner

@⁠Asimmimx on GitHub · 2026-11-24 17:37 UTC · original
Asimmimx:tests/cpu-srv-upload-check → main · +329 −0 · 3 files · 1 commits · merged 2026-11-24 17:45 UTC

Refs #1149.

What the header does

src/cpu_srv_upload.h defines cpu_srv::refresh. Before a submission that reads the SRV, it copies a CPU source into a caller-owned upload buffer. It refuses a null upload or source, a zero size, and a null fence with a nonzero value (E_INVALIDARG). It also refuses a resource that is not a buffer, a range outside the buffer and a heap that is not an upload heap. It returns a failing GetHeapProperties result as it is. It returns DXGI_ERROR_DEVICE_REMOVED for a fence at UINT64_MAX and DXGI_ERROR_WAS_STILL_DRAWING while the fence is short of the previous value. The source is staged through ReadProcessMemory first, so a source on an unreadable page is refused before the live upload changes. Finally it maps subresource 0 with an empty read range, copies the bytes and unmaps exactly the written range.

Tests that reach it

Only cpu_srv_refresh_{warp,hardware} and cpu_srv_stale_{warp,hardware} (tests/descriptor_window_submissions.cpp, in offscreen_check). They refresh a real 20-byte upload buffer with an exact fit at byte 16, then refuse an outstanding fence, a refresh one byte past the end, a SIZE_MAX offset and a source on an unreadable page (checked only with SUCCEEDED). Nothing checks the header without a device.

Mutation probe

30 single-point mutants of the header, one at a time, rebuilding offscreen_check and cpu_srv_upload_check and running ^(cpu_srv_(refresh|stale)_warp|cpu_srv_upload)$. The WARP column counts a mutant as killed if cpu_srv_refresh_warp or cpu_srv_stale_warp failed.

Mutant cpu_srv_{refresh,stale}_warp with cpu_srv_upload
drop !upload survived killed (crash)
drop !source survived killed
drop !bytes survived killed
drop !previous_fence && previous_value survived killed
drop the buffer-dimension check survived killed
destination_offset > Width to >= survived survived (equivalent)
drop destination_offset > Width killed killed
bytes > Width - offset to >= killed killed
bytes > Width - offset + 1 killed killed
failed GetHeapProperties returns E_INVALIDARG survived killed
failed GetHeapProperties ignored survived killed
drop the upload-heap check survived killed
heap check refuses only DEFAULT survived killed
drop the UINT64_MAX removed-device check survived killed
removed device returns WAS_STILL_DRAWING survived killed
done < previous_value to <= killed killed
done < previous_value to != survived killed
still drawing returns E_PENDING killed killed
ReadProcessMemory failure returns E_FAIL survived killed
drop copied != bytes survived survived (not observable)
memcpy from the source instead of ReadProcessMemory killed killed
failed Map returns S_OK survived killed
Map read range nullptr survived killed
memcpy ignores destination_offset killed killed
Unmap written range nullptr survived killed
written range starts at 0 survived killed
written range ends at bytes survived killed
drop Unmap survived killed
memcpy one byte short killed killed
heap refusal after a Map survived killed

WARP tests: 8 of 30 killed. With the new check: 28 of 30 killed. The two survivors:

  • destination_offset >= Width is equivalent. With destination_offset == Width, the nonzero size is refused by bytes > Width - destination_offset.
  • Dropping copied != bytes is not observable. ReadProcessMemory fails with ERROR_PARTIAL_COPY when a read crosses into an inaccessible page; it does not succeed with a short count.

New cases

tests/cpu_srv_upload_check.cpp drives the header with a fake upload resource (GetDesc, GetHeapProperties, Map and Unmap over 32 bytes of sentinel storage) and a fake fence with a fixed completed value. startup_packed_target_check fakes a texture the same way. Expected values are worked by hand.

Refreshed (5), each on a 24-byte upload. Each must return S_OK, write exactly the source bytes and leave every other byte at the sentinel. It must call Map once on subresource 0 with read range [0, 0), and Unmap once on subresource 0 with exactly [offset, offset + bytes):

  • first use with no fence, an exact fit at byte 16;
  • 8 bytes from byte 0;
  • a fence completed at the value (5 of 5);
  • a fence completed past the value (9 of 5);
  • a fence with value 0.

Refused (15), each with its exact result, no Unmap and unchanged bytes. Map may be called only when the fake Map fails:

  • E_INVALIDARG: null upload, null source, zero bytes, no fence with value 1, a 1D texture, offset 24 (the end) with 1 byte, offset 25, offset 17 with 8 bytes, a default heap, a readback heap;
  • E_FAIL from a failing GetHeapProperties;
  • DXGI_ERROR_WAS_STILL_DRAWING for a fence at 4 of 5;
  • DXGI_ERROR_DEVICE_REMOVED for a fence at UINT64_MAX;
  • E_OUTOFMEMORY from a failing Map;
  • HRESULT_FROM_WIN32(ERROR_PARTIAL_COPY) for an 8-byte source whose last 4 bytes lie on a PAGE_NOACCESS page.

Negative control

cpu_srv_upload_written_range_control runs cpu_srv_upload_check --mutate written-range with WILL_FAIL TRUE. The mutation expects every Unmap range to start at byte 0, so the check must fail:

FAIL first use, exact fit at byte 16: hr=0x00000000 contents=1 maps=1 unmaps=1 read=1[0,0) written=1[16,24), expected S_OK, one map with read [0,0) and written [0,24)
...
cpu_srv_upload: 4 FAILED

Not pinned

  • The exact error for a source that is entirely unreadable. It is whatever GetLastError reports after ReadProcessMemory, which the header passes through. The WARP tests already require a failure. Only the straddling case, which the ReadProcessMemory documentation defines as ERROR_PARTIAL_COPY, is pinned.
  • E_OUTOFMEMORY from the staging allocation, which cannot be reached without failing new (std::nothrow).
  • The order of the argument checks relative to each other. Each refusal is checked alone.
  • The two survivors above.

Commands and results

cmake --preset dev
cmake --build --preset dev --target cpu_srv_upload_check offscreen_check
ctest --preset dev --no-tests=error -R '^(cpu_srv_(refresh|stale)_warp|cpu_srv_upload(_written_range_control)?)$'
1/4 Test #106: cpu_srv_upload .........................   Passed    0.01 sec
2/4 Test #107: cpu_srv_upload_written_range_control ...   Passed    0.01 sec
3/4 Test #251: cpu_srv_refresh_warp ...................   Passed    0.09 sec
4/4 Test #252: cpu_srv_stale_warp .....................   Passed    0.08 sec
100% tests passed, 0 tests failed out of 4

cpu_srv_upload_check prints cpu_srv_upload: PASS (5 refreshed, 15 refused). python -B tests/docs_links_check.py passes (17 Markdown files, 364 links). No _hardware test was run for this change, and no capability skips occurred.

Environment

Windows 11 Pro 26300.9974, MSVC from Visual Studio, Windows SDK 10.0.26100.0, dev preset (Debug). The WARP tests use Microsoft WARP. The new check uses no device.

Commit: 62758977

AI-assisted (Claude Code).

**@⁠Asimmimx** on GitHub · 2026-11-24 17:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1714) `Asimmimx:tests/cpu-srv-upload-check` → `main` · +329 −0 · 3 files · 1 commits · merged 2026-11-24 17:45 UTC Refs #1149. ## What the header does `src/cpu_srv_upload.h` defines `cpu_srv::refresh`. Before a submission that reads the SRV, it copies a CPU source into a caller-owned upload buffer. It refuses a null upload or source, a zero size, and a null fence with a nonzero value (`E_INVALIDARG`). It also refuses a resource that is not a buffer, a range outside the buffer and a heap that is not an upload heap. It returns a failing `GetHeapProperties` result as it is. It returns `DXGI_ERROR_DEVICE_REMOVED` for a fence at `UINT64_MAX` and `DXGI_ERROR_WAS_STILL_DRAWING` while the fence is short of the previous value. The source is staged through `ReadProcessMemory` first, so a source on an unreadable page is refused before the live upload changes. Finally it maps subresource 0 with an empty read range, copies the bytes and unmaps exactly the written range. ## Tests that reach it Only `cpu_srv_refresh_{warp,hardware}` and `cpu_srv_stale_{warp,hardware}` (`tests/descriptor_window_submissions.cpp`, in `offscreen_check`). They refresh a real 20-byte upload buffer with an exact fit at byte 16, then refuse an outstanding fence, a refresh one byte past the end, a `SIZE_MAX` offset and a source on an unreadable page (checked only with `SUCCEEDED`). Nothing checks the header without a device. ## Mutation probe 30 single-point mutants of the header, one at a time, rebuilding `offscreen_check` and `cpu_srv_upload_check` and running `^(cpu_srv_(refresh|stale)_warp|cpu_srv_upload)$`. The WARP column counts a mutant as killed if `cpu_srv_refresh_warp` or `cpu_srv_stale_warp` failed. | Mutant | `cpu_srv_{refresh,stale}_warp` | with `cpu_srv_upload` | |---|---|---| | drop `!upload` | survived | killed (crash) | | drop `!source` | survived | killed | | drop `!bytes` | survived | killed | | drop `!previous_fence && previous_value` | survived | killed | | drop the buffer-dimension check | survived | killed | | `destination_offset > Width` to `>=` | survived | survived (equivalent) | | drop `destination_offset > Width` | killed | killed | | `bytes > Width - offset` to `>=` | killed | killed | | `bytes > Width - offset + 1` | killed | killed | | failed `GetHeapProperties` returns `E_INVALIDARG` | survived | killed | | failed `GetHeapProperties` ignored | survived | killed | | drop the upload-heap check | survived | killed | | heap check refuses only `DEFAULT` | survived | killed | | drop the `UINT64_MAX` removed-device check | survived | killed | | removed device returns `WAS_STILL_DRAWING` | survived | killed | | `done < previous_value` to `<=` | killed | killed | | `done < previous_value` to `!=` | survived | killed | | still drawing returns `E_PENDING` | killed | killed | | `ReadProcessMemory` failure returns `E_FAIL` | survived | killed | | drop `copied != bytes` | survived | survived (not observable) | | `memcpy` from the source instead of `ReadProcessMemory` | killed | killed | | failed `Map` returns `S_OK` | survived | killed | | `Map` read range `nullptr` | survived | killed | | `memcpy` ignores `destination_offset` | killed | killed | | `Unmap` written range `nullptr` | survived | killed | | written range starts at 0 | survived | killed | | written range ends at `bytes` | survived | killed | | drop `Unmap` | survived | killed | | `memcpy` one byte short | killed | killed | | heap refusal after a `Map` | survived | killed | WARP tests: 8 of 30 killed. With the new check: 28 of 30 killed. The two survivors: - `destination_offset >= Width` is equivalent. With `destination_offset == Width`, the nonzero size is refused by `bytes > Width - destination_offset`. - Dropping `copied != bytes` is not observable. `ReadProcessMemory` fails with `ERROR_PARTIAL_COPY` when a read crosses into an inaccessible page; it does not succeed with a short count. ## New cases `tests/cpu_srv_upload_check.cpp` drives the header with a fake upload resource (`GetDesc`, `GetHeapProperties`, `Map` and `Unmap` over 32 bytes of sentinel storage) and a fake fence with a fixed completed value. `startup_packed_target_check` fakes a texture the same way. Expected values are worked by hand. Refreshed (5), each on a 24-byte upload. Each must return `S_OK`, write exactly the source bytes and leave every other byte at the sentinel. It must call `Map` once on subresource 0 with read range `[0, 0)`, and `Unmap` once on subresource 0 with exactly `[offset, offset + bytes)`: - first use with no fence, an exact fit at byte 16; - 8 bytes from byte 0; - a fence completed at the value (5 of 5); - a fence completed past the value (9 of 5); - a fence with value 0. Refused (15), each with its exact result, no `Unmap` and unchanged bytes. `Map` may be called only when the fake `Map` fails: - `E_INVALIDARG`: null upload, null source, zero bytes, no fence with value 1, a 1D texture, offset 24 (the end) with 1 byte, offset 25, offset 17 with 8 bytes, a default heap, a readback heap; - `E_FAIL` from a failing `GetHeapProperties`; - `DXGI_ERROR_WAS_STILL_DRAWING` for a fence at 4 of 5; - `DXGI_ERROR_DEVICE_REMOVED` for a fence at `UINT64_MAX`; - `E_OUTOFMEMORY` from a failing `Map`; - `HRESULT_FROM_WIN32(ERROR_PARTIAL_COPY)` for an 8-byte source whose last 4 bytes lie on a `PAGE_NOACCESS` page. ## Negative control `cpu_srv_upload_written_range_control` runs `cpu_srv_upload_check --mutate written-range` with `WILL_FAIL TRUE`. The mutation expects every `Unmap` range to start at byte 0, so the check must fail: ``` FAIL first use, exact fit at byte 16: hr=0x00000000 contents=1 maps=1 unmaps=1 read=1[0,0) written=1[16,24), expected S_OK, one map with read [0,0) and written [0,24) ... cpu_srv_upload: 4 FAILED ``` ## Not pinned - The exact error for a source that is entirely unreadable. It is whatever `GetLastError` reports after `ReadProcessMemory`, which the header passes through. The WARP tests already require a failure. Only the straddling case, which the `ReadProcessMemory` documentation defines as `ERROR_PARTIAL_COPY`, is pinned. - `E_OUTOFMEMORY` from the staging allocation, which cannot be reached without failing `new (std::nothrow)`. - The order of the argument checks relative to each other. Each refusal is checked alone. - The two survivors above. ## Commands and results ```powershell cmake --preset dev cmake --build --preset dev --target cpu_srv_upload_check offscreen_check ctest --preset dev --no-tests=error -R '^(cpu_srv_(refresh|stale)_warp|cpu_srv_upload(_written_range_control)?)$' ``` ``` 1/4 Test #106: cpu_srv_upload ......................... Passed 0.01 sec 2/4 Test #107: cpu_srv_upload_written_range_control ... Passed 0.01 sec 3/4 Test #251: cpu_srv_refresh_warp ................... Passed 0.09 sec 4/4 Test #252: cpu_srv_stale_warp ..................... Passed 0.08 sec 100% tests passed, 0 tests failed out of 4 ``` `cpu_srv_upload_check` prints `cpu_srv_upload: PASS (5 refreshed, 15 refused)`. `python -B tests/docs_links_check.py` passes (17 Markdown files, 364 links). No `_hardware` test was run for this change, and no capability skips occurred. ## Environment Windows 11 Pro 26300.9974, MSVC from Visual Studio, Windows SDK 10.0.26100.0, `dev` preset (Debug). The WARP tests use Microsoft WARP. The new check uses no device. Commit: `62758977` AI-assisted (Claude Code).
cpu_srv::refresh (src/cpu_srv_upload.h) copies a CPU source into a
caller-owned upload buffer once the previous GPU readers have retired.
It is reached only by cpu_srv_refresh_{warp,hardware} and
cpu_srv_stale_{warp,hardware}, which refresh a real upload buffer: an
exact fit at byte 16, an outstanding fence, a refresh one byte past the
end, a SIZE_MAX offset and a source on an unreadable page. 22 of 30
single-point mutants of the header left the two WARP tests passing:
the null upload, null source, zero-size and fence/value guards, the
buffer-dimension and upload-heap checks, the propagated
GetHeapProperties and Map results, the removed-device check and its
code, a fence that completed past the value, the ReadProcessMemory
error code, the empty read range given to Map, the written range given
to Unmap, a dropped Unmap, and a heap refusal that maps first.

Add cpu_srv_upload_check, which drives the header with a fake upload
resource and fence (as startup_packed_target_check fakes a texture).
It accepts 5 refreshes and checks the bytes written, a single Map of
subresource 0 with read range [0, 0) and a single Unmap with exactly
the written range. It refuses 15 cases with their exact result: each
invalid argument, a 1D texture, a default and a readback heap, offsets
at and past the end, one byte too many, a failing GetHeapProperties or
Map, a fence one short of the value, a removed device, and a source
whose last 4 bytes lie on an inaccessible page, which must return
HRESULT_FROM_WIN32(ERROR_PARTIAL_COPY). No refusal may unmap or change
the upload. 28 of the 30 mutants now fail the check. Changing
destination_offset > Width to >= is equivalent, because the nonzero
size is then refused by the next check. Dropping the copied != bytes
test is not observable: ReadProcessMemory fails on a partial copy
instead of reporting a short count.

Register cpu_srv_upload_written_range_control with WILL_FAIL:
--mutate written-range expects the written range to start at byte 0
and must fail.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:28:14 +00:00
github manually merged commit 62758977b8 into gh-pr/1714/base 2026-11-26 23:28:15 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.