Skip to content

DirectStorage: a virtual destination is written without faulting - #705

Open
requiemsnkrp wants to merge 1 commit into
xcl-dev:mainfrom
requiemsnkrp:dstorage-destination-write
Open

requiemsnkrp wants to merge 1 commit into
xcl-dev:mainfrom
requiemsnkrp:dstorage-destination-write

Conversation

@requiemsnkrp

@requiemsnkrp requiemsnkrp commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

execute checks a virtual destination with writable() at its start, then reads the file or copies the source and inflates it, and only then writes the destination with copy_nonoverlapping. If the title unmapped the destination in that window (which spans the file read), the write faulted in the xcl-dstorage worker and ended the process. It is now written with write_own (NtWriteVirtualMemory on the process itself), the counterpart of the read_own that the page arrays already use, so the request fails with E_ACCESS_VIOLATION instead. Not WriteProcessMemory: it first queries the region, and in the 4 GiB coherent window that took 75–175 ms a call (measured in the title: 64 KiB and 8-byte writes alike, while ReadProcessMemory took 3–11 µs). A first version with it showed 0 frames in two 60 s regression runs, because the title's first streaming stalled. This is the destination side of #476; @brothernog found it in the review of #561. It is independent of #509 and #561 (a different hunk of execute), branched from main 91f9a5e.

What is in it

  • crates/xcl/src/hle/dstorage.rs: write_own (NtWriteVirtualMemory, raw-dylib as the other ntdll calls), used for the virtual destination's write in execute; the writable() check at the start stays (it commits lazy pages and refuses early)
  • crates/xcl/src/hle/dstorage.rs, tests: a_destination_unmapped_under_the_worker_fails_the_request runs 20000 memory-source requests while another thread decommits and recommits the destination page

Tested

  • NVIDIA GeForce RTX 3060 12 GB, driver 621.24 (32-lane waves); AMD Ryzen 5 5600X; Windows 11 Pro 26200; Rust 1.100.0 msvc; DXC 1.9.2602.17; debug for the tests, release for the regression runs
  • the new test without the fix (5 runs, --exact): 5 × 0xc0000005 STATUS_ACCESS_VIOLATION; with the fix: 10 of 10 passed; hle::dstorage tests: 14 passed
  • cargo test --workspace -- --test-threads=4 on d09f285: 693 passed, 0 failed, 41 ignored
  • SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware

Regression run

main:

xcl-smoke v1
commit: 63cdc25bc0d2b59cc2af85e6e23f619dfaf72866
gpu: NVIDIA GeForce RTX 3060
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1488 (PresentX 1488)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16363 MB

(main 63cdc25; this branch's base 91f9a5e differs from it by README.md only)

PR:

xcl-smoke v1
commit: d09f285014c6262b35f6b412d46eb4cfd70b7b2c
gpu: NVIDIA GeForce RTX 3060
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1411 (PresentX 1412)
presents per 2 s (last 3): 60 60 32
device removals: 0
crashes: 0
peak commit: 17010 MB

Not tested

AI use

  • Claude Code with Claude Opus 5.5: wrote the change, the test and this description, and ran the tests and the regression runs on the machine above; opened at my request.

`execute` checks a virtual destination with `writable()` at its start,
then reads the file or copies the source and inflates it, and only then
writes the destination with `copy_nonoverlapping`. A destination the
title unmapped in that time faulted in the xcl-dstorage worker and ended
the process (the destination side of xcl-dev#476, found by brothernog in the
review of xcl-dev#561). It is now written with `write_own`
(NtWriteVirtualMemory on the process itself), the counterpart of the
`read_own` the page arrays use: the request fails with E_ACCESS_VIOLATION
instead. Not WriteProcessMemory: it first queries the region, which in
the 4 GiB coherent window took 75-175 ms a call (measured) and stalled the
title's first streaming (0 frames in 60 s).

The test runs 20000 requests while another thread decommits and
recommits the destination page: before, the test process ended with
0xc0000005 (5 of 5 runs); after, it passes (10 of 10).

Assisted-by: Claude Code (Claude Opus 5.5)
@mastrr9

mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

Code audit + NVIDIA RTX 5080 test run on d09f285014c6262b35f6b412d46eb4cfd70b7b2c:

Review

Looks clean — NtWriteVirtualMemory (raw-dylib from ntdll) matches the x64 Win32 signature, checks at != 0, NT_SUCCESS (>= 0), and done == data.len(), avoiding WriteProcessMemory's expensive NtQueryVirtualMemory page-table walk while failing cleanly with E_ACCESS_VIOLATION if the title unmaps a virtual destination mid-request.

Tested

  • Hardware / OS / toolchain: NVIDIA GeForce RTX 5080 (driver 617.42), AMD Ryzen 7 9800X3D, Windows 11 25H2 (build 26200.9711), rustc 1.100.0 (MSVC), debug build.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 693 passed, 0 failed, 41 ignored.
  • New stress test hle::dstorage::tests::a_destination_unmapped_under_the_worker_fails_the_request: passed.
  • SKIPPED GPU/D3D12 tests: gpu_geometry_wave32_prefix_count_over_a_mask / gpu_wave32_program_in_wave64_hardware (no wave64), plus 2 D3D12 debug-layer tests (no d3d12SDKLayers.dll).

Not tested

  • Retail title / scripts/smoke.ps1 run (test suite only).
  • AMD / Intel GPUs.

AI use: code review and test run orchestrated with Antigravity (Gemini 4 Neon) on the hardware listed above.

@lordon1a

Copy link
Copy Markdown

Independent test report on d09f285:

Tested

  • Hardware: NVIDIA GeForce RTX 3070 Ti Laptop GPU (driver 616.64, SM 6.6), Intel i7-12700H, Windows 11 Home 26H2 (build 26200), rustc 1.100.0 (x86_64-pc-windows-gnullvm), debug build
  • Command: cargo test -p xcl --lib hle::dstorage::tests -- --nocapture
  • Result: 14 passed, 0 failed, 0 ignored in 0.19s (a_destination_unmapped_under_the_worker_fails_the_request ok)

Not tested

  • AMD / Intel GPU, retail title

AI use

  • Antigravity (Google DeepMind agent) — fetched d09f285 in a detached worktree, audited the diff, ran the test suite, and posted this report.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of d09f285014c6262b35f6b412d46eb4cfd70b7b2c on AMD RDNA4. I merged it onto current main f4ce27c locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 702 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 661 passed, 0 failed, 21 ignored
  • 0 SKIPPED; a_destination_unmapped_under_the_worker_fails_the_request passes.

Review: Writing the destination with write_own (NtWriteVirtualMemory on the own process) turns a destination unmapped during the file read into E_ACCESS_VIOLATION for that request instead of a fault in xcl-dstorage, the write-side counterpart of #561. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
Integrates upstream PR xcl-dev#705 while keeping Wine dirty-range notification:
- Write virtual destinations via NtWriteVirtualMemory (write_own) so a
  destination unmapped during file read/inflate fails with
  E_ACCESS_VIOLATION instead of faulting the worker thread, without
  WriteProcessMemory's page-table walk stall.
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
Integrates upstream PR xcl-dev#705 while keeping Wine dirty-range notification:
- Write virtual destinations via NtWriteVirtualMemory (write_own) so a
  destination unmapped during file read/inflate fails with
  E_ACCESS_VIOLATION instead of faulting the worker thread, without
  WriteProcessMemory's page-table walk stall.
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
Integrates upstream PR xcl-dev#705 while keeping Wine dirty-range notification:
- Write virtual destinations via NtWriteVirtualMemory (write_own) so a
  destination unmapped during file read/inflate fails with
  E_ACCESS_VIOLATION instead of faulting the worker thread, without
  WriteProcessMemory's page-table walk stall.
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
Integrates upstream PR xcl-dev#705 while keeping Wine dirty-range notification:
- Write virtual destinations via NtWriteVirtualMemory (write_own) so a
  destination unmapped during file read/inflate fails with
  E_ACCESS_VIOLATION instead of faulting the worker thread, without
  WriteProcessMemory's page-table walk stall.
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
Integrates upstream PR xcl-dev#705 while keeping Wine dirty-range notification:
- Write virtual destinations via NtWriteVirtualMemory (write_own) so a
  destination unmapped during file read/inflate fails with
  E_ACCESS_VIOLATION instead of faulting the worker thread, without
  WriteProcessMemory's page-table walk stall.
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
Integrates upstream PR xcl-dev#705 while keeping Wine dirty-range notification:
- Write virtual destinations via NtWriteVirtualMemory (write_own) so a
  destination unmapped during file read/inflate fails with
  E_ACCESS_VIOLATION instead of faulting the worker thread, without
  WriteProcessMemory's page-table walk stall.
@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
# Conflicts:
#	crates/xcl/src/hle/dstorage.rs
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main (crates/xcl/src/hle/dstorage.rs) — needs a rebase before it can be tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants