DStorage: preserve GetLastError across heap allocation in open_file and permit shared write/delete #1932
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!1932
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1932/head"
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?
@ashrafsdrop on GitHub · 2026-11-25 01:10 UTC · original
ashrafsdrop:dstorage/open-file-share-error→main· +28 −2 · 1 files · 1 commits · closed without mergingResolves VIC-BT-037 from #1249:
Summary
Preserve OS Error Code:
In \crates/victory-hle/src/modules/dstorage.rs:open_file, previously \String::from_utf16_lossy\ was executed before \std::io::Error::last_os_error()\ when \CreateFileW\ failed. Because UTF-16 decoding performs heap allocations which can make Win32 calls resetting or mutating the thread-local error state, \GetLastError()\ could be clobbered before being mapped by \rom_win32. Captures \last_os_error()\ immediately after the failure check.
Permit Concurrent Write and Delete Access:
Adds \FILE_SHARE_WRITE\ and \FILE_SHARE_DELETE\ to \FILE_SHARE_READ\ in \CreateFileW. Matches Windows DirectStorage behavior permitting concurrent streaming or file replacements without encountering \ERROR_SHARING_VIOLATION.
Tests:
Adds unit test \open_file_preserves_error_and_allows_shared_access\ asserting that opening a missing file accurately returns \
@AgneyaK on GitHub · 2026-11-25 02:27 UTC · original
Tested
ce91efamerged ontomain940d32f(clean), Windows 11 26300, Rust 1.98.1 MSVC.main'sdstorage.rs,open_file_preserves_error_and_allows_shared_accessfails at the first open with-2147024864(0x80070020,ERROR_SHARING_VIOLATION):mainopens withFILE_SHARE_READonly, and the test holds a write handle. With the PR it passes.GetLastErrorordering half isn't really tested. Themissing.binassertion (0x80070002) is the resultmaingives too:from_utf16_lossyallocating didn't change the last error in this run. The reorder is still the safer order. It just isn't shown by a failing test.cargo test -p victory-hle --lib --locked5 runs,144 passedeach.cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean.Not tested: the title. Its DirectStorage files are package archives opened read-only, so I'd expect no change there.
AI use: Claude Code (Claude Opus 5.5) ran these checks and wrote this; the results are from the runs described.
@Marvisak on GitHub · 2026-11-25 08:18 UTC · original · edited 2026-11-25 11:22 UTC
Automated triage for the maintainers.
Merge candidate. A small hardening change. Recommending a look, not approving.
crates/victory-hle/src/modules/dstorage.rs,open_file: the OS error is now read right afterCreateFileWfails, before the path is decoded withString::from_utf16_lossy. The path is decoded once for both branches. The share mode is back toFILE_SHARE_READalone, so the behaviour change from the earlier head is gone. By my reading the result is the same asmainin every case seen so far, and only the order is safer.open_file_reports_missing_file_errorchecks that a missing file maps to0x80070002. That also passes onmain, so it guards the error mapping, not the reorder. Small nit: the test never releases the file object it opens, so the handle stays open until the process exits.CI:
checkpassing.On your reply: both requested changes are in (error captured first with one decode, share-mode change dropped), so the verdict moves from needs-work.
Generated by Claude Code
@ashrafsdrop on GitHub · 2026-11-25 11:03 UTC · original
Updated in head
9325572:Immediate Error Capture & Single-Pass Decode:
let err = (handle as isize == -1).then(std::io::Error::last_os_error);captures the OS error immediately before path decoding, preventing heap allocations from clobbering thread-local error state.Retain Read-Only Share Mode:
FILE_SHARE_WRITE | FILE_SHARE_DELETE, keepingFILE_SHARE_READto prevent torn reads on title package archives.Rebased on Main:
origin/main(940d32f), picking up the GPU-less CI test runner fixes.@Marvisak on GitHub · 2026-11-25 22:04 UTC · original
Automated triage for the maintainers, second look (a review against current
main, with builds and tests where they could change the verdict).Closing because it changes nothing observable: the allocator's
HeapAllocdoes not touch the last error on success, and the new test passes onmaintoo, as noted in the thread. The share-mode change in the title is no longer part of the diff.If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.
Pull request closed