HLE: DirectStorage open_file shares write/delete and keeps LastError #2452

Open
github-bot wants to merge 1 commit from github-bot/gh-2452 into main AGit
Owner

@⁠makmatvey on GitHub · 2026-11-25 13:49 UTC · original
makmatvey:cursor/hle-dstorage-open-share-0835 → main · +58 −3 · 1 files · 1 commits · open

What’s wrong

IDStorageFactoryX::OpenFile opened with FILE_SHARE_READ only. A path already held open for write (share read|write) then failed with ERROR_SHARING_VIOLATION. On failure, the path was also turned into a String before last_os_error(), so a heap allocation could overwrite GetLastError and the returned HRESULT_FROM_WIN32 was wrong (VIC-BT-037 in #1249).

What the change does

  • Pass FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE to CreateFileW.
  • Capture std::io::Error::last_os_error() immediately after a failed open, before any heap work for the path string.

Tests

  • opens_alongside_a_writer_and_keeps_not_found — opens while another handle holds the file for write; missing path returns HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND).
  • Linux agent: cargo xtask policy (pass). Full victory-hle tests need Windows CI.

Asset policy

No game data used.

Fixes part of #1249 (VIC-BT-037).

**@⁠makmatvey** on GitHub · 2026-11-25 13:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2452) `makmatvey:cursor/hle-dstorage-open-share-0835` → `main` · +58 −3 · 1 files · 1 commits · open ## What’s wrong `IDStorageFactoryX::OpenFile` opened with `FILE_SHARE_READ` only. A path already held open for write (share read|write) then failed with `ERROR_SHARING_VIOLATION`. On failure, the path was also turned into a `String` before `last_os_error()`, so a heap allocation could overwrite `GetLastError` and the returned `HRESULT_FROM_WIN32` was wrong (VIC-BT-037 in #1249). ## What the change does - Pass `FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE` to `CreateFileW`. - Capture `std::io::Error::last_os_error()` immediately after a failed open, before any heap work for the path string. ## Tests - `opens_alongside_a_writer_and_keeps_not_found` — opens while another handle holds the file for write; missing path returns `HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)`. - Linux agent: `cargo xtask policy` (pass). Full `victory-hle` tests need Windows CI. ## Asset policy No game data used. Fixes part of #1249 (VIC-BT-037).
open_file used FILE_SHARE_READ only, so a path already open for write
failed with ERROR_SHARING_VIOLATION. It also formatted the path before
reading last_os_error(), which can clobber GetLastError on failure.

Share FILE_SHARE_READ|WRITE|DELETE and capture the OS error before any
heap work. Test opens alongside a writer and checks HRESULT_FROM_WIN32
for a missing path.

Co-authored-by: Matsvey Makushenka <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:06:20 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 14:13 UTC · original

Independent verification of #2452 at 67ea174 (pure CPU)

Commands: cargo test -p victory-hle --lib, cargo clippy -p victory-hle --all-targets -- -D warnings, cargo xtask policy; merges cleanly with origin/main 940d32f.

  • lib tests: 144 passed, 0 failed (plus 1 in another target); clippy clean; policy OK.
  • Negative control: dstorage.rs reverted to origin/main with the new test kept -> opens_alongside_a_writer_and_keeps_not_found FAILS.
  • The test is Windows-only (std::os::windows), like the surrounding module.

AI-assisted verification by Claude Code (Claude Sonnet 5.5). No game files, dumps or hashes.

**@⁠oni-swr** on GitHub · 2026-11-25 14:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2452#issuecomment-7164936008) **Independent verification of #2452 at `67ea174`** (pure CPU) Commands: `cargo test -p victory-hle --lib`, `cargo clippy -p victory-hle --all-targets -- -D warnings`, `cargo xtask policy`; merges cleanly with `origin/main` `940d32f`. - lib tests: 144 passed, 0 failed (plus 1 in another target); clippy clean; policy OK. - Negative control: `dstorage.rs` reverted to `origin/main` with the new test kept -> `opens_alongside_a_writer_and_keeps_not_found` FAILS. - The test is Windows-only (`std::os::windows`), like the surrounding module. AI-assisted verification by Claude Code (Claude Sonnet 5.5). No game files, dumps or hashes.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 16:00 UTC · original

Automated triage for the maintainers.

Needs work. In open_file (crates/victory-hle/src/modules/dstorage.rs), keeping the error from the failed open is fine, but the wider sharing flags change what the title sees and come with no evidence of the console's behaviour (public documentation, or a title code path that needs it). Please add that evidence, or split the error part into its own PR. CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 16:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/2452#issuecomment-7167513680) <!-- victory-triage v1 head=67ea174cad20ddcc82aa380d2dc070f1bf577734 verdict=needs-work at=2026-11-25T15:58:47Z --> Automated triage for the maintainers. Needs work. In `open_file` (`crates/victory-hle/src/modules/dstorage.rs`), keeping the error from the failed open is fine, but the wider sharing flags change what the title sees and come with no evidence of the console's behaviour (public documentation, or a title code path that needs it). Please add that evidence, or split the error part into its own PR. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 16:52 UTC · original

Both parts are real fixes: FILE_SHARE_WRITE|DELETE lets DirectStorage open a file another handle already holds for write (ERROR_SHARING_VIOLATION was fatal here), and capturing last_os_error before from_utf16_lossy's allocation is the right order — an intervening heap call can clobber LastError. The test exercises exactly the writer-held-open case that previously failed.

**@⁠kotekompotek** on GitHub · 2026-11-25 16:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2452#issuecomment-7168664852) Both parts are real fixes: `FILE_SHARE_WRITE|DELETE` lets DirectStorage open a file another handle already holds for write (ERROR_SHARING_VIOLATION was fatal here), and capturing `last_os_error` before `from_utf16_lossy`'s allocation is the right order — an intervening heap call can clobber LastError. The test exercises exactly the writer-held-open case that previously failed.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2452/head:github-bot/gh-2452'
git switch 'github-bot/gh-2452'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2452'
git switch 'github-bot/gh-2452'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2452'
git switch 'github-bot/gh-2452'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2452'
git switch 'main'
git merge --squash 'github-bot/gh-2452'
git switch 'main'
git merge --ff-only 'github-bot/gh-2452'
git switch 'main'
git merge 'github-bot/gh-2452'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2452
No description provided.