Repository navigation
Conversation
…-protected title pages
5 tasks
Contributor
|
Review (head 1b6f674, diff read, not a merge-check):
Fine: with the switch off the default path is unchanged ( AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
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.
Adds opt-in
XCL_GUEST_WRITE_GUARD=1(off by default: zero behavior change) so XCL and Windows kernel-mode writes (ReadFile,NtWriteVirtualMemory,recv/recvfrom, and XCL's own writability pre-checks) remain safe when XCL protects title pages asPAGE_READONLYorPAGE_NOACCESS(forXCL_PAGE_ALIAS=1guarded views or future read-only/no-access page protectors).TL;DR — Before vs After (RX 6650 XT 8 GB,
origin/amd-dev41aa60ce)XCL_GUEST_WRITE_GUARDoff)XCL_GUEST_WRITE_GUARD=1)NtWriteVirtualMemory/ReadFile) into XCL-protected RO/NA pageguest_write_probe& unit tests)ERROR_NOACCESS/STATUS_PARTIAL_COPY, 0 faults, 0 bytes landed)recv/recvfrom) into XCL-protected orMEM_WRITE_WATCHpageWSAEFAULTon RO/NA; TCPrecvmissesMEM_WRITE_WATCH1b6f6748, default off vsmaind8bd9a38)main)1b6f6748, opt-in on)=1)Motivation & empirical OS probe (
crates/xcl/tests/guest_write_probe.rs)User-mode stores into a
PAGE_READONLYorPAGE_NOACCESSpage raise an access violation that a vectored handler can repair, but Windows kernel-mode writes do not fault in user mode:ReadFile(buffered,NO_BUFFERING, andOVERLAPPED) fails synchronously withERROR_NOACCESS(998), writing 0 bytes;NtReadFilefails withSTATUS_ACCESS_VIOLATION,WriteProcessMemorywithERROR_NOACCESS,NtWriteVirtualMemorywithSTATUS_PARTIAL_COPY;recv/recvfromfail withWSAEFAULT(and TCPrecvalso bypassesMEM_WRITE_WATCHdirty tracking even onPAGE_READWRITEpages);gpu_copy_into_an_imported_heap) documents thatOpenExistingHeapFromAddressrequiresPAGE_READWRITEon entry (0x80070057otherwise) anddxgkrnlsecures imported VADs so laterVirtualProtectdowngrades fail with Win32 error 87 (ERROR_INVALID_PARAMETER).What is in it
crates/xcl/src/hle/kernelx/guest_write.rs(new):enabled()(XCL_GUEST_WRITE_GUARD=1, default off).register/unregister/is_pinned/xcl_protectedrange & pin registry for page protectors (fast-path single atomic load when no ranges are registered).writable(p, n): treats committed pages protected by XCL (registered ranges orguards::is_view) as writable for XCL's own pre-checks while still rejecting uncommitted pages andPAGE_GUARD.open(p, n)→Bracket: runslazy::ensure, pins pages in registered ranges, and performs a no-op user-modeAtomicU8::fetch_add(0)on protected pages so the protector's fault handler opens them before a kernel call writes. Overlapped reads callBracket::keep_until_done(ov)to keep pins live untilOVERLAPPEDleavesSTATUS_PENDING.kernel_write(what, p, n, write): brackets a status-returning kernel write (NtWriteVirtualMemory) withopen, retries once if it failed over XCL-protected pages, and logs the first 8 repairs/failures.bounce(buf, n, call)&install(): hooksws2_32!recvandws2_32!recvfrom(only whenXCL_GUEST_WRITE_GUARD=1) to bounce receives over XCL-protected pages through an XCL buffer followed by a user-mode store.writablerules,NtWriteVirtualMemoryintoPAGE_READONLYandPAGE_NOACCESS, pin refcounting, overlapped pin lifetime, andrecvbounce.XCL_GUEST_WRITE_GUARDis off):crates/xcl/src/eh.rs:CLZEROis_writablepre-check.crates/xcl/src/hle/d3d12x/cpu_writes.rs: fence/label writability pre-checks (write_now_in,u64_writable_now,writable).crates/xcl/src/hle/d3d12x/frame.rs:note_signaledoutput index writability check.crates/xcl/src/hle/dstorage.rs&crates/xcl/src/hle/dstorage/parallel.rs: DirectStoragewrite_title,writable, andwrite_destination.crates/xcl/src/vfs_hooks.rs:hk_read_fileusesguest_write::openandkeep_until_doneforERROR_IO_PENDING.crates/xcl/src/hle/kernelx/guards.rs: exposeis_view()andpub(super) fn still_pending().crates/xcl/src/hle/kernelx.rs&crates/xcl/src/host.rs: register module and install socket hooks when enabled.crates/xcl/tests/guest_write_probe.rs(new): integration test proving the Windows kernel-write & write-watch behavior matrix plus ignored D3D12 imported-heap probe.Tested
32.0.21045.29003), AMD Ryzen 7 5700X, Windows 11,rustc 1.100.0 (0ef1bc386 2026-11-09).cargo test -p xcl --lib -- hle::kernelx::guest_write hle::d3d12x::frame::tests hle::d3d12x::cpu_writes::tests hle::dstorage::tests hle::kernelx::guards::tests --test-threads=1(debug): 53 passed, 0 failed, 0 ignored, 0 skipped (including all 6guest_writeunit tests).cargo test -p xcl --test guest_write_probe -- --test-threads=1(debug): 1 passed, 0 failed, 1 ignored; plus--ignored: 1 passed (gpu_copy_into_an_imported_heap), 0 failed.1b6f6748withXCL_GUEST_WRITE_GUARD=1:1,657frames (60 60 60per 2 s),16,226 MBpeak commit,exit: 0x0,0device removals,0crashes (vs1,655frames /16,648 MBwith switch off).Regression run
Baseline (
main):PR head (
1b6f6748, default off):Not tested
DeviceIoControlandWSARecvoverlapped scatter-gather socket I/O (not used by tested titles).AI use
guest_writemodule, call sites, and probe test; Antigravity (Gemini) audited and rebased it ontoorigin/amd-dev(41aa60ce), resolvedframe.rs::writableintegration, added overflow/volatile fixes, and ran all unit, probe, and smoke verifications.