startup: copy guest memory with guarded_memcpy in ring_copy #3469
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3469"
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 Leyukaka on 2026-11-29T16:11:44Z.
Fixes #3468.
Change
ring_copy(src/startup_stubs/d3d12_xs_device.cpp:2885) copied guest memory with a plainstd::memcpy. A page decommitted or protected after the caller'sreadable_windowprobe faulted inside the stand-in.x2w_local::guarded_memcpy(..., false), which returns false on an access violation or an in-page error.*offsetand*resourceare cleared on entry and written only after the copy succeeds, so a refused copy never publishes a partially copied range.No default changes.
Callers
All three already handle a false return, and none is modified:
src/startup_stubs/d3d12_draw.inl:2065, texture uploadstate.done = false, the upload is retried latersrc/startup_stubs/d3d12_draw.inl:2686, compute input snapshotrefuse(...), the existing "could not be copied" pathsrc/startup_stubs/d3d12_xs_device.cpp:2906,upload_from_titleFixture
offscreen_check --ring-copy-faultreserves one page withMEM_RESERVE/PAGE_NOACCESSand callsx2w_test_ring_copy(compiled underX2W_RING_COPY_TEST). The fixture callsring_copydirectly, without the callers' probe, so the copy faults inside the guard. The fixture does three 1-byte snapshot copies into a 1536-byte chunk:offsetstays 0;It is registered as
startup_ring_copy_faultintests/cmake/startup_ring_copy.cmake; the rootCMakeLists.txtis unchanged.Tests
On
7259bea9(basecf0c30af):startup_ring_copy_fault: passed.startup_local_log*(7): passed.upload_reservation,startup_upload_arena_{warp,hardware},startup_upload_lifetime_{warp,hardware},startup_input_view_token,stream_root_srv_{warp,hardware}: passed.Mutations, each restored afterwards:
startup_ring_copy_faultguarded_memcpyreplaced bystd::memcpy*offset = reservation.offsetmoved before the copyNot covered
resourceasnullptr, so only theoffsetpublication is checked.Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T08:54:11Z.
Review: APPROVED
Reviewed
766f1e30by reading the diff; not built or run.Verdict: approve. A fault now refuses the copy instead of crashing, and no partial range is published. One SHOULD, on the PR body only. No MUST.
guarded_memcpysucceeds (d3d12_xs_device.cpp:2887-2898). All three callers treat false as a refusal and never read the cleared values (d3d12_draw.inl:2079,:2700,d3d12_xs_device.cpp:2906). #3481 moves the:2700call into its deferred loop with the same|| !view.resourcecheck, so the two combine cleanly.X2W_RING_COPY_TESTgoes ond3d12_xs_device_obj, which only the test executables link (offscreen_check,cpu_placed_dxr_provider,startup_present_log). Theelsebranch matches theOFFSCREEN_AGILITY_620_DIRbuild, whereoffscreen_checkcompiles the file itself (CMakeLists.txt:2181-2187). So the fixture always links the seam, and the shipped DLL never contains it.7259bea9", beforec8e24e1dadded the straddling-prefix refusal and theresourcechecks, and before the merge. The fixture section lists three copies with the last at offset 1024, while the code makes four and checks 1536 (:8188). "Not covered" still saysresourceis passed asnullptr, whichc8e24e1dfixed. Please rerun at766f1e30and update the counts.Tests:
startup_ring_copy_faultcovers a fault on a never-readable page, a fault after a 16-byte readable prefix (soguarded_memcpyreally starts copying), and that neither output is published. Thestd::memcpymutation shows the guard is needed. CI did not run it: it is not in theprpreset's list, and/O2was skipped on the PR.