Skip to content

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 into
fxceless:mainfrom
YeokiNoewChi:dstorage-guarded-read-fallback
Open

YeokiNoewChi wants to merge 1 commit into
fxceless:mainfrom
YeokiNoewChi:dstorage-guarded-read-fallback

Conversation

@YeokiNoewChi

Copy link
Copy Markdown

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

…ry is copied through a buffer

A plain DirectStorage read (options 0, file source, address destination)
lands through ReadFile into title memory. `kernel_will_write` opens the
write guard's blocks first, but the GPU side's check can make a block
read-only again before the read lands; ReadFile then fails with
ERROR_INVALID_USER_BUFFER (0x800706f8), the request fails, and the title
stops on its own breakpoint shortly after (int3 at +0x23d8f03 here: an
allocator result checked for null).

On those two errors (and ERROR_NOACCESS), when the destination is
committed and accessible, read into our own buffer and store the bytes
with plain writes, which fault into the guard's handler like the title's
own. Anything else keeps the kernel's error.

RTX 3070 Ti 8 GB, Ryzen 5 5600X, Windows 11, Series X profile: three cold
starts (fresh shader cache) in a row ended on that breakpoint, each right
after "dstorage: request failed: copying ... hr=0x800706f8"; with this
change three runs on new builds (shaders translated afresh) reached the world;
the fallback copied one refused read in two of them, the third had none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant