dstorage: say why a read failed, retry EINTR, map errno to Win32 #130

Manually merged
github merged 2 commits from github-bot/gh-130 into main 2026-11-26 19:08:27 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-26 18:01 UTC · original
Olima34:fix/dstorage-read-errors → main · +113 −21 · 2 files · 2 commits · merged 2026-11-26 19:00 UTC

DirectStorage read failures on macOS lost their cause, and a read interrupted by a signal failed the request.

Evidence. In ItsMariusBC's run 3 on #110 (M5 Pro, Series S), 179 lines read dstorage: request failed: reading the source ... hr=0x8007001e (ERROR_READ_FAULT) right before the crash, and the log cannot say why:

  • on macOS, from_win32 mapped every io error except NotFound and PermissionDenied to ERROR_READ_FAULT;
  • the log dropped the errno;
  • read_into gave up on EINTR, which is plausible in this signal-heavy process (read_exact retries it).

What (only modules/dstorage.rs and the docs):

  1. "request failed" now logs the host error with its errno and kind, for example reading the source: Input/output error (os error 5) (Uncategorized). This covers both the raw copy and compressed sources.
  2. read_into goes through a new fill_at, as read_exact does: it retries Interrupted, continues through short reads, and treats Ok(0) as UnexpectedEof, which still becomes END_OF_FILE. read_into/read_source now return io::Result, so the error reaches the log.
  3. from_win32 (non-Windows) is the inverse of the UCRT's _dosmaperr table:
    • EBADF → ERROR_INVALID_HANDLE;
    • EMFILE/ENFILE → ERROR_TOO_MANY_OPEN_FILES;
    • ENOMEM → ERROR_NOT_ENOUGH_MEMORY;
    • EINVAL → ERROR_INVALID_PARAMETER;
    • ENOSPC → ERROR_DISK_FULL;
    • ENOENT/EACCES/EPERM as before;
    • EIO and the rest stay ERROR_READ_FAULT.
      errno values below 35 are the same on every Unix; others are matched by kind. The Windows from_win32 is unchanged. Its other caller, open_file, gets the finer codes too, and nothing relied on 0x8007001e.

Tests (both fail on main):

  • host_errors_map_to_their_win32_codes: on main, errno 12 gives 0x8007001e instead of 0x80070008.
  • reads_go_on_past_signals_and_short_reads: a test reader returns Interrupted once, then 2 bytes at a time; no real signals.

victory-hle tests on x86_64-apple-darwin (247), Windows clippy and cargo xtask policy pass. The Windows victory-hle tests also pass under Wine (161 library tests, including the 20 dstorage ones). This doesn't claim to fix the crash: it makes the next log say why those reads fail.

**@⁠Olima34** on GitHub · 2026-11-26 18:01 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/130) `Olima34:fix/dstorage-read-errors` → `main` · +113 −21 · 2 files · 2 commits · merged 2026-11-26 19:00 UTC DirectStorage read failures on macOS lost their cause, and a read interrupted by a signal failed the request. **Evidence.** In ItsMariusBC's run 3 on #110 (M5 Pro, Series S), 179 lines read `dstorage: request failed: reading the source ... hr=0x8007001e` (ERROR_READ_FAULT) right before the crash, and the log cannot say why: - on macOS, `from_win32` mapped every io error except NotFound and PermissionDenied to ERROR_READ_FAULT; - the log dropped the errno; - `read_into` gave up on `EINTR`, which is plausible in this signal-heavy process (`read_exact` retries it). **What** (only `modules/dstorage.rs` and the docs): 1. "request failed" now logs the host error with its errno and kind, for example `reading the source: Input/output error (os error 5) (Uncategorized)`. This covers both the raw copy and compressed sources. 2. `read_into` goes through a new `fill_at`, as `read_exact` does: it retries `Interrupted`, continues through short reads, and treats `Ok(0)` as `UnexpectedEof`, which still becomes `END_OF_FILE`. `read_into`/`read_source` now return `io::Result`, so the error reaches the log. 3. `from_win32` (non-Windows) is the inverse of the UCRT's `_dosmaperr` table: - EBADF → ERROR_INVALID_HANDLE; - EMFILE/ENFILE → ERROR_TOO_MANY_OPEN_FILES; - ENOMEM → ERROR_NOT_ENOUGH_MEMORY; - EINVAL → ERROR_INVALID_PARAMETER; - ENOSPC → ERROR_DISK_FULL; - ENOENT/EACCES/EPERM as before; - EIO and the rest stay ERROR_READ_FAULT. errno values below 35 are the same on every Unix; others are matched by kind. The Windows `from_win32` is unchanged. Its other caller, `open_file`, gets the finer codes too, and nothing relied on 0x8007001e. **Tests** (both fail on main): - `host_errors_map_to_their_win32_codes`: on main, errno 12 gives 0x8007001e instead of 0x80070008. - `reads_go_on_past_signals_and_short_reads`: a test reader returns `Interrupted` once, then 2 bytes at a time; no real signals. victory-hle tests on x86_64-apple-darwin (247), Windows clippy and `cargo xtask policy` pass. The Windows victory-hle tests also pass under Wine (161 library tests, including the 20 dstorage ones). This doesn't claim to fix the crash: it makes the next log say why those reads fail.
On macOS every host error but NotFound and PermissionDenied reached the
title as ERROR_READ_FAULT, and the "request failed" log line dropped the
errno. A run on #110 logged 179 such failures before a crash that the
log could not explain.

- read_into goes through fill_at, which tries Interrupted (EINTR) again
  and goes on through short reads, as read_exact does.
- The log line gives the host's error with its errno and kind.
- from_win32 maps errno the way the UCRT's _dosmaperr table does in
  reverse: EBADF, EMFILE/ENFILE, ENOMEM, EINVAL and ENOSPC get their own
  codes; EIO and the rest stay ERROR_READ_FAULT.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:04:13 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 18:56 UTC · original · approved these changes

Reviewed and tested together with the other open PRs on main (macOS x86_64 tests for shader, hle, loader and gpu, the setup shell tests, and Windows clippy). Thanks!

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 18:56 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/130#pullrequestreview-6079228637) · **approved these changes** Reviewed and tested together with the other open PRs on main (macOS x86_64 tests for shader, hle, loader and gpu, the setup shell tests, and Windows clippy). Thanks!
github manually merged commit 37d7a7135a into main 2026-11-26 19:08:27 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.