runtime: check the CPU-SRV refresh refusals without a device #1707
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1714"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T17:37:41Z.
Refs #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).