runtime: check the CPU-SRV refresh refusals without a device #1714
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!1714
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1714/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 UTCRefs #1149.
What the header does
src/cpu_srv_upload.hdefinescpu_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 failingGetHeapPropertiesresult as it is. It returnsDXGI_ERROR_DEVICE_REMOVEDfor a fence atUINT64_MAXandDXGI_ERROR_WAS_STILL_DRAWINGwhile the fence is short of the previous value. The source is staged throughReadProcessMemoryfirst, 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}andcpu_srv_stale_{warp,hardware}(tests/descriptor_window_submissions.cpp, inoffscreen_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, aSIZE_MAXoffset and a source on an unreadable page (checked only withSUCCEEDED). Nothing checks the header without a device.Mutation probe
30 single-point mutants of the header, one at a time, rebuilding
offscreen_checkandcpu_srv_upload_checkand running^(cpu_srv_(refresh|stale)_warp|cpu_srv_upload)$. The WARP column counts a mutant as killed ifcpu_srv_refresh_warporcpu_srv_stale_warpfailed.cpu_srv_{refresh,stale}_warpcpu_srv_upload!upload!source!bytes!previous_fence && previous_valuedestination_offset > Widthto>=destination_offset > Widthbytes > Width - offsetto>=bytes > Width - offset + 1GetHeapPropertiesreturnsE_INVALIDARGGetHeapPropertiesignoredDEFAULTUINT64_MAXremoved-device checkWAS_STILL_DRAWINGdone < previous_valueto<=done < previous_valueto!=E_PENDINGReadProcessMemoryfailure returnsE_FAILcopied != bytesmemcpyfrom the source instead ofReadProcessMemoryMapreturnsS_OKMapread rangenullptrmemcpyignoresdestination_offsetUnmapwritten rangenullptrbytesUnmapmemcpyone byte shortMapWARP tests: 8 of 30 killed. With the new check: 28 of 30 killed. The two survivors:
destination_offset >= Widthis equivalent. Withdestination_offset == Width, the nonzero size is refused bybytes > Width - destination_offset.copied != bytesis not observable.ReadProcessMemoryfails withERROR_PARTIAL_COPYwhen a read crosses into an inaccessible page; it does not succeed with a short count.New cases
tests/cpu_srv_upload_check.cppdrives the header with a fake upload resource (GetDesc,GetHeapProperties,MapandUnmapover 32 bytes of sentinel storage) and a fake fence with a fixed completed value.startup_packed_target_checkfakes 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 callMaponce on subresource 0 with read range[0, 0), andUnmaponce on subresource 0 with exactly[offset, offset + bytes):Refused (15), each with its exact result, no
Unmapand unchanged bytes.Mapmay be called only when the fakeMapfails: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_FAILfrom a failingGetHeapProperties;DXGI_ERROR_WAS_STILL_DRAWINGfor a fence at 4 of 5;DXGI_ERROR_DEVICE_REMOVEDfor a fence atUINT64_MAX;E_OUTOFMEMORYfrom a failingMap;HRESULT_FROM_WIN32(ERROR_PARTIAL_COPY)for an 8-byte source whose last 4 bytes lie on aPAGE_NOACCESSpage.Negative control
cpu_srv_upload_written_range_controlrunscpu_srv_upload_check --mutate written-rangewithWILL_FAIL TRUE. The mutation expects everyUnmaprange to start at byte 0, so the check must fail:Not pinned
GetLastErrorreports afterReadProcessMemory, which the header passes through. The WARP tests already require a failure. Only the straddling case, which theReadProcessMemorydocumentation defines asERROR_PARTIAL_COPY, is pinned.E_OUTOFMEMORYfrom the staging allocation, which cannot be reached without failingnew (std::nothrow).Commands and results
cpu_srv_upload_checkprintscpu_srv_upload: PASS (5 refreshed, 15 refused).python -B tests/docs_links_check.pypasses (17 Markdown files, 364 links). No_hardwaretest 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,
devpreset (Debug). The WARP tests use Microsoft WARP. The new check uses no device.Commit:
62758977AI-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.