startup: copy guest memory with guarded_memcpy in ring_copy #3471
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!3471
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@Leyukaka on GitHub · 2026-11-29 16:11 UTC · original
Leyukaka:runtime-ring-copy-guarded→main· +78 −3 · 3 files · 4 commits · merged 2026-11-30 19:58 UTCFixes #3470.
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.github-bot referenced this pull request2026-11-30 03:51:51 +00:00
github-bot referenced this pull request2026-11-30 03:58:37 +00:00
github-bot referenced this pull request2026-11-30 06:13:57 +00:00
@lukaslw-lab on GitHub · 2026-11-30 08:54 UTC · original · approved these changes
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). #3483 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.github-bot referenced this pull request2026-11-30 20:05:22 +00:00