Repository navigation
Conversation
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Dukestar69
left a comment
There was a problem hiding this comment.
LGTM — verified on Windows against origin/main (63bcca4).
- Opt-in guarded writes for title
memcpy/memsetare cleanly isolated behind the switch and well-covered across concurrent writes, armed aliases, straddling ranges, and host import policy. cargo test -p victory-gpu --lib watch:: -- --test-threads=1: 19 passed, 0 failed (1 ignored).cargo test -p victory-hle --lib host:: -- --test-threads=1: 3 passed, 0 failed (includingcrt_copy_imports_follow_the_switch_and_host_policy).cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal
left a comment
There was a problem hiding this comment.
Clean, well-contained opt-in experiment (VICTORY_COPY_BESIDE=1), keeping default host CRT resolution and section layout unchanged. Verified merged onto origin/main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090, VICTORY_D3D12_DEBUG=1):
- Lock ordering & lifetime safety:
- Lock acquisition forms a strict cycle-free DAG (
PHYSICAL -> BESIDE_VIEWS -> GUARDS -> Changed):xmem::map(crates/victory-hle/src/modules/xmem.rs:861-866) andxmem::unmap(xmem.rs:998-1005) holdPHYSICALwhile updatingBESIDE_VIEWS/GUARDS,watch::bulk_chunk(crates/victory-gpu/src/watch.rs:941-955) holdsBESIDE_VIEWS.read()->GUARDS, andGUARDSnever calls back intoBESIDE_VIEWSorPHYSICAL. xmem::unmapcallstitle_memory_beside_gone(at, size)before unmapping or dropping theSlice/Arc<Section>, soSection.1cannot be unmapped while abulk_chunkwrite is in flight.- Confirmed live on Windows 11 with a
SEC_RESERVEsection (XMemAllocatePhysicalPages+XMemMapPhysicalPageswithVICTORY_COPY_BESIDE=1, and a standaloneSEC_RESERVEwatch.rstest) that committing the title view commits the shared backing pages inSection.1as well (ours_state = MEM_COMMIT,PAGE_READWRITE), andtracked_memseton a guardedSEC_RESERVEpage succeeds without faulting.
- Lock acquisition forms a strict cycle-free DAG (
- Verification:
cargo xtask policy(191 files ok) andcargo clippy --locked -p victory-gpu -p victory-hle --all-targets -- -D warnings(both default and--features victory-gpu/diagnostics) pass cleanly.victory-gpuwatch::tests::*(19/19 passed, 1 ignored benchmark) andvictory-hlehost::+xmem::(17/17 withVICTORY_COPY_BESIDEunset and 17/17 withVICTORY_COPY_BESIDE=1) all pass.- Additional adversarial checks passed: zero-length and self-copy (
dst == src) no-ops do not dirty pages; multiple consecutive redirected writes followed by a native write fault on an armed page preserve the original pre-first-writesavedbytes; forward (dst > src) and backward (dst < src) overlappingtracked_memcpyacross guarded pages preserve exact bytes and dirty ranges; misaligned multi-page copies spanning 3 guarded pages match byte-for-byte.
Minor non-blocking observation if this ever graduates past opt-in: bulk_chunk executes the caller's write closure while holding BESIDE_VIEWS.read() and guards(). Read faults on src won't deadlock on_write (since on_write returns EXCEPTION_CONTINUE_SEARCH when ExceptionInformation[0] != WRITE), though if a title ever caught a fault inside memcpy via SEH __try/__except, unwinding past an extern "C" frame would skip Rust guard drops. Completely fine for an opt-in experiment.
LGTM!
On Windows, a title import of
memcpyormemsetfromVCRUNTIME140.dllcan write through a writable view of the same physical section while its title mapping stays read-only. Enable the experiment withVICTORY_COPY_BESIDE=1. The default keeps the host CRT bindings and the existing section layout.The hook processes one 64 KiB destination page at a time. It pins the view registration, verifies protection, marks the page and its aliases dirty, and lets armed trackers save the old bytes before writing under the guard lock. Ordinary writes run after releasing those locks. A small bit table skips registry lookups for ordinary address regions. A stale bit only causes another lookup. Remapping unregisters the view before unmapping it. The resolver still checks the host allow-list and the presence of the actual export.
Measurements
On a Ryzen 7 2700X, the ignored
guarded_crt_copy_benchmarkalternates 3,200 native and redirected 4 KiB writes per sample on the same 32 freshly guarded pages, including the tracker take. Every round checks the dirty range, and every sample verifies the final bytes. On the standalone branch the three native samples measured 7.36, 9.17 and 9.37 µs/copy. The redirected samples measured 0.70, 0.70 and 0.75 µs/copy.On a separate RTX 2080 integration stack, two five-minute runs used the same diagnostic executable with the BVH builder held back. The enabled run logged a redirected CRT write. Both runs reached the world and ended at the cutoff without device removal. Medians below use complete reporting intervals after world entry with at least 500 draws per frame.
Streaming and draw counts differed. An earlier pair, before the region filter, also varied substantially. These runs establish that the title uses the path and show lower guard overhead in the final pair. They do not establish higher world FPS.
Verification against main
Integration
#3069 targets marked GPU copy-back and has independent evidence about readers overlapping a write. This change targets title CRT calls. It holds the guard lock from the dirty mark through the page chunk's write. A refresh that already obtained its dirty ranges can still overlap title activity. A multi-page CRT copy has ordinary CRT visibility. If #3035 lands, its optimistic snapshot validation will need to account for writes through retained guards and their aliases.
The CRT interception idea follows avatarmanz's VIctory work.
AI-assisted (Codex).