Repository navigation
startup: copy guest memory with guarded_memcpy in ring_copy - #3469
Merged
Merged
Conversation
This was referenced Nov 29, 2026
# Conflicts: # src/startup_stubs/d3d12_xs_device.cpp
5 tasks done
lukaslw-lab
approved these changes
Nov 30, 2026
lukaslw-lab
left a comment
Contributor
There was a problem hiding this comment.
Reviewed 766f1e30 by 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.
- Outputs are cleared on entry and set only after
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. - Test seam:
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. - SHOULD: the body describes an older head. Tests ran "on 7259bea", before
c8e24e1dadded 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_fault covers a fault on a never-readable page, a fault after a 16-byte readable prefix (so guarded_memcpy really starts copying), and that neither output is published. The std::memcpy mutation shows the guard is needed. CI did not run it: it is not in the pr preset's list, and /O2 was skipped on the PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 7259bea (base cf0c30a):
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.