HLE/dstorage: a plain read the kernel refuses into guarded title memory is copied through a buffer #426

Open
YeokiNoewChi wants to merge 1 commit from upstream-pr/426 into main
YeokiNoewChi commented 2026-11-25 00:40:52 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by YeokiNoewChi on 2026-11-25T00:40:52Z.


Problem

On cold starts (fresh shader cache) the title kept stopping on its own breakpoint during the world load: 0x80000003 at +0x23d8f03, where it checks an allocator's result for null and traps. Each time, the log showed this a moment before:

WARN victory_hle::modules::dstorage: dstorage: request failed: copying options=0x0 offset=... source_size=624 destination_size=624 ... hr=0x800706f8

0x800706f8 is ERROR_INVALID_USER_BUFFER. A plain request (options 0: file source, address destination) is read with ReadFile straight into title memory. into_destination calls kernel_will_write first, which opens the write guard's blocks. However, the GPU side's check can make a block read-only again (watch::protect) before the kernel's write lands. The kernel then refuses the read, the request fails, and the title's load fails with it.

Change

dstorage.rs only, plain copies only:

  • When ReadFile returns ERROR_INVALID_USER_BUFFER or ERROR_NOACCESS for an address destination, and the whole destination is committed and not PAGE_NOACCESS or a guard page (VirtualQuery), the read goes into our own buffer instead. The bytes are then stored with plain writes, which fault into the guard's handler like the title's own writes and are noted written as usual.
  • Any other error, page destinations, memory sources, and destinations that are not committed keep the kernel's error, as before.
  • Compressed requests are not affected: they decode in user mode already.
  • It logs dstorage: a read the kernel refused into guarded title memory was copied through a buffer at the 1st, 2nd, 4th, 8th... occurrence.

Tested

RTX 3070 Ti 8 GB, Ryzen 5 5600X (6 cores), 32 GB, Windows 11, Series X profile:

  • Before: three cold starts in a row ended on that breakpoint, each right after the failed copying request above.
  • After: three runs on new builds (shaders translated afresh) reached the world and ran 7 to 12 minutes each (4 to 8 of them in the world) with no crash until I stopped them. The fallback copied one refused read in two of them (624 and 25,088 bytes); the third had none.
  • cargo test -p victory-hle dstorage: 14 passed. cargo clippy -p victory-hle -- -D warnings: clean.

The race is more likely on machines where the GPU side's checks compete with the title for CPU, like this 6-core one during shader warm-up. That may be why it shows on some machines and not others.

Related, not overlapping: #329 (diagnostics for page-destination write failures) and #403 (DirectStorage file lifetime).

AI-assisted (Claude Code); counts, offsets and hashes only, nothing from the game.

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:issue:6594443001 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/426). Originally posted by [YeokiNoewChi](https://github.com/YeokiNoewChi) on 2026-11-25T00:40:52Z. --- ## Problem On cold starts (fresh shader cache) the title kept stopping on its own breakpoint during the world load: `0x80000003` at `+0x23d8f03`, where it checks an allocator's result for null and traps. Each time, the log showed this a moment before: ``` WARN victory_hle::modules::dstorage: dstorage: request failed: copying options=0x0 offset=... source_size=624 destination_size=624 ... hr=0x800706f8 ``` `0x800706f8` is `ERROR_INVALID_USER_BUFFER`. A plain request (options 0: file source, address destination) is read with `ReadFile` straight into title memory. `into_destination` calls `kernel_will_write` first, which opens the write guard's blocks. However, the GPU side's check can make a block read-only again (`watch::protect`) before the kernel's write lands. The kernel then refuses the read, the request fails, and the title's load fails with it. ## Change `dstorage.rs` only, plain copies only: - When `ReadFile` returns `ERROR_INVALID_USER_BUFFER` or `ERROR_NOACCESS` for an address destination, and the whole destination is committed and not `PAGE_NOACCESS` or a guard page (`VirtualQuery`), the read goes into our own buffer instead. The bytes are then stored with plain writes, which fault into the guard's handler like the title's own writes and are noted written as usual. - Any other error, page destinations, memory sources, and destinations that are not committed keep the kernel's error, as before. - Compressed requests are not affected: they decode in user mode already. - It logs `dstorage: a read the kernel refused into guarded title memory was copied through a buffer` at the 1st, 2nd, 4th, 8th... occurrence. ## Tested RTX 3070 Ti 8 GB, Ryzen 5 5600X (6 cores), 32 GB, Windows 11, Series X profile: - **Before:** three cold starts in a row ended on that breakpoint, each right after the failed `copying` request above. - **After:** three runs on new builds (shaders translated afresh) reached the world and ran 7 to 12 minutes each (4 to 8 of them in the world) with no crash until I stopped them. The fallback copied one refused read in two of them (624 and 25,088 bytes); the third had none. - `cargo test -p victory-hle dstorage`: 14 passed. `cargo clippy -p victory-hle -- -D warnings`: clean. The race is more likely on machines where the GPU side's checks compete with the title for CPU, like this 6-core one during shader warm-up. That may be why it shows on some machines and not others. Related, not overlapping: #329 (diagnostics for page-destination write failures) and #403 (DirectStorage file lifetime). AI-assisted (Claude Code); counts, offsets and hashes only, nothing from the game. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/426:upstream-pr/426'
git switch 'upstream-pr/426'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/426'
git switch 'upstream-pr/426'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/426'
git switch 'upstream-pr/426'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/426'
git switch 'main'
git merge --squash 'upstream-pr/426'
git switch 'main'
git merge --ff-only 'upstream-pr/426'
git switch 'main'
git merge 'upstream-pr/426'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!426
No description provided.