HLE: share DirectStorage file opens and keep the host's error code #3018
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3018
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3018"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Halfect on GitHub · 2026-11-26 03:30 UTC · original
Halfect:fix/dstorage-open-file-share→main· +98 −6 · 2 files · 3 commits · openFixes VIC-BT-037 from #1249.
What
IDStorageFactoryX::OpenFile(open_fileincrates/victory-hle/src/modules/dstorage.rs) asked forFILE_SHARE_READalone. A file the title's own tools or a mod hold open for writing (sharing reads and writes, not deletes) then fails withERROR_SHARING_VIOLATION, even though the emulator only reads it. The open now shares read, write and delete, the usual mode for a read-only consumer.It also read
std::io::Error::last_os_error()only after formatting the path into aString. The host keeps that code in thread-local storage, which a heap allocation may overwrite, so the failure could return (and log) the wrong error. The error is now captured immediately after the call, before anything allocates; the log keeps the path.Testing
open_file_shares_writes_and_deletes(Windows): a file held open for read+write with share read|write (no delete-share) still opens. On the previous code it fails theS_OKassertion with the sharing violation (verified as a negative control).open_file_reports_the_os_error: a missing path returnsHRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)(0x80070002).cargo test --locked -p victory-hle: 154 passed, 0 failed.cargo clippy --locked -p victory-hle --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.git diff --check: clean.cargo fmt --checkshows only the same pre-existing diffs unmodified63bcca4shows.Limitations
Windows-only behavior, verified on Windows; the change is inside the Windows-only module. Not run against a real title's DirectStorage workload. The error-capture reorder is not separately observable in a deterministic test (the clobbering is intermittent by nature); it is covered by review and the failure-path test.
No game data. AI-assisted (Kimi).
@futurepro62 on GitHub · 2026-11-26 04:22 UTC · original
Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head
39297b8(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 868 passed, 0 failed, 10 ignored.open_file_shares_writes_and_deletes,open_file_reports_the_os_error.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
@Halfect on GitHub · 2026-11-26 04:32 UTC · original
Thanks @futurepro62 for the full-suite run on the RTX 5070 Ti — 868 passed / 0 failed on the exact head
39297b8, with both new tests (open_file_shares_writes_and_deletes,open_file_reports_the_os_error) passing and the skips accounted for by pre-existing main-side issues (#2571, #1835/#2317, #1744), is exactly the coverage this change needed. Nothing further from my side; ready for review.@Marvisak on GitHub · 2026-11-26 06:16 UTC · original · edited 2026-11-26 07:20 UTC
Automated triage for the maintainers.
Still a merge candidate. The new commit
f8a7c3cdoes two things:Releasewith its real signature and checks that it returns 0.files::CreateFileWsavesGetLastErrorright after the host call, drops the translated path, and restores the error withSetLastError. A new test,open_file_preserves_the_os_error_on_virtual_drives, checks thatERROR_FILE_NOT_FOUNDsurvives on a mounted drive.The save-and-restore is harmless but mostly defensive. Freeing the path buffer normally doesn't change the last error, so the new test would likely pass on
maintoo. No other wrapper infiles.rsdoes this, which the maintainer may want to keep consistent or drop.The point from before still stands:
open_file_shares_writes_and_deletesdoesn't actually test delete-sharing.CI: passing.
Recommending a look, not approving.
Generated by Claude Code
@Halfect on GitHub · 2026-11-26 07:03 UTC · original
@fuzeofficlal Thanks for the careful review. Both points are addressed in
f8a7c3c:open_file_shares_writes_and_deletesnow uses the correctextern "system" fn(*mut c_void) -> u32signature forReleaseand asserts that the returned reference count is0.files::CreateFileWnow capturesGetLastErrorimmediately after the host call, explicitly drops the translated path buffer, and restores the saved value withSetLastErrorbefore returning. This applies to both success and failure. Addedopen_file_preserves_the_os_error_on_virtual_drives, which opens a missing file through a mounted virtual drive and verifiesERROR_FILE_NOT_FOUNDsurvives.Validation completed locally on Windows:
cargo test --locked -p victory-hle open_file -- --nocapture: 3 passed.cargo test --locked -p victory-hle: 155 unit tests and 2 integration tests passed.cargo clippy --locked -p victory-hle --all-targets -- -D warnings: passed.cargo xtask policy: passed, 191 files checked.git diff --check: passed.Could you please take another look?
@Halfect on GitHub · 2026-11-26 11:09 UTC · original
The delete-sharing point was real — the test opened the file beside a writer but never checked the delete half of the share mode. Fixed in
79b44e0.open_file_shares_writes_and_deletesnow opens the file withDELETEaccess (share mode0x7) beside the title's handle; that open only succeeds becauseopen_filepassesFILE_SHARE_DELETE. A negative control againstheld(which shares reads/writes but no deletes) must fail withERROR_SHARING_VIOLATIONfirst, so the check demonstrably has teeth.FILE_SHARE_DELETEfromopen_filemakes the new assertion fail with exactly that sharing violation (OS error 32); with the flag restored it passes.Validation on
79b44e0(Windows, CPU-only):cargo test --locked -p victory-hle open_file: 3 passed, 0 failed.cargo test --locked -p victory-hle: 155 unit tests and all integration suites passed.cargo clippy --locked -p victory-hle --all-targets -- -D warnings: passed.cargo xtask policy: passed, 191 files checked.git diff --check: passed.@fuzeofficlal on GitHub · 2026-11-26 03:43 UTC · original · requested changes
Code review on
39297b84(static source inspection; no runtime Windows tests executed):open_file_shares_writes_and_deletescallsReleasethrough a mismatched function signature (crates/victory-hle/src/modules/dstorage.rs:1282):void(file, 0x10)invokes vtable slot0x10(release::<File>, which returnsu32) viaextern "system" fn(*mut c_void)returning(). Calling through a transmuted function pointer with a mismatched return type is Rust UB even if the x64 caller ignoreseax; suggest invoking it with a-> u32signature and asserting the returned refcount is0.GetLastErrorbeforeopen_filereads it (crates/victory-hle/src/modules/dstorage.rs:129-148,crates/victory-hle/src/modules/files.rs:188-207, 263-282):files::CreateFileWowns aWidetranslation buffer that is dropped beforefiles::CreateFileWreturns, so any heap deallocation during drop runs beforedstorage::open_filereadsstd::io::Error::last_os_error(). Capturing or preserving the Win32 error insidefiles::CreateFileWacross theWidedrop (and testing a missing file on a mounted drive) ensures translated paths never lose the host error code.FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETEshare mode change itself looks good.@kotekompotek on GitHub · 2026-11-26 04:38 UTC · original · approved these changes
LGTM — sharing WRITE|DELETE matches the title's real usage (its own tools hold files open); capturing last_os_error before the UTF-16 alloc is the right order since heap alloc can clobber TLS. The share_mode(3) test discriminates the fix.
@Dukestar69 on GitHub · 2026-11-26 07:30 UTC · original · approved these changes
Tested locally merged onto
origin/main(63bcca4) on Windows 11 x64:cargo test -p victory-hle dstorage: all tests passed.cargo clippy -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 on GitHub · 2026-11-26 11:39 UTC · original · approved these changes
Reviewed
79b44e0a(git merge-treeagainstmain63bcca43is clean):crates/victory-hle/src/modules/dstorage.rs:117-137) still requestGENERIC_READ+OPEN_EXISTING, while widening sharing toFILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETEso compatible writers and delete-access handles can coexist.GetLastErrorcaptures are ordered ahead ofWidedrop / diagnostic string allocation (files.rs:264-291preservesGetLastErroracrossdrop(wide)on both error and success paths such asERROR_ALREADY_EXISTS;dstorage.rs:138-154capturesError::last_os_error()beforeString::from_utf16_lossy/ logging).Verified locally on Windows 11 (Rust 1.98.1 MSVC):
xtask policy(191 files ok) andcargo clippy -p victory-hle --all-targets -- -D warnings(default and--all-features): clean.cargo test -p victory-hle --locked: full suite 157/157 passed (includingdstorage::tests18/18,files::tests7/7, and the newopen_fileshare/error tests 3/3).Non-blocking note for a follow-up: the virtual-drive
CreateFileAbranch (files.rs:303-314) andCreateFile2(files.rs:337-345) still drop theirWideconversion buffers after calling into the host API without saving/restoringGetLastError.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.