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

Closed
makmatvey wants to merge 1 commit from upstream-pr/2452 into main
makmatvey commented 2026-11-25 13:49:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by makmatvey on 2026-11-25T13:49:23Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:issue:5492607677 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2452). Originally posted by [makmatvey](https://github.com/makmatvey) on 2026-11-25T13:49:23Z. --- ## 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).
DenRakEiw commented 2026-11-25 13:55:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T13:55:22Z.

Review: APPROVED


Verified against origin/main (940d32f):

  • Opening DirectStorage files with write/delete sharing and preserving LastError is clean and well-tested.
  • cargo test -p victory-hle dstorage::: 15/15 passed (including opens_alongside_a_writer_and_keeps_not_found).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6058901122 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2452#pullrequestreview-6058901122). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T13:55:22Z. **Review:** APPROVED --- Verified against `origin/main` (`940d32f`): - Opening DirectStorage files with write/delete sharing and preserving `LastError` is clean and well-tested. - `cargo test -p victory-hle dstorage::`: 15/15 passed (including `opens_alongside_a_writer_and_keeps_not_found`). - `cargo clippy -p victory-hle --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 14:11:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T14:11:24Z.

Review: COMMENTED


HLE DirectStorage open_file shares write/delete, keeps LastError. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.

<!-- greyfinch-sync:Marvisak/VIctory:review:6059179447 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2452#pullrequestreview-6059179447). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T14:11:24Z. **Review:** COMMENTED --- HLE DirectStorage open_file shares write/delete, keeps LastError. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.
oni-swr commented 2026-11-25 15:04:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T14:13:04Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7164936008 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2452#issuecomment-7164936008). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T14:13:04Z. --- **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.
Marvisak commented 2026-11-25 16:09:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T16:00:46Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167513680 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2452#issuecomment-7167513680). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T16:00:46Z. --- <!-- 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)_
kotekompotek commented 2026-11-25 17:05:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T16:52:36Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7168664852 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2452#issuecomment-7168664852). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T16:52:36Z. --- 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.

Pull request closed

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
Marvisak/VIctory!2450
No description provided.