XMem: keep allocation errors and report system commit #4317

Open
tyr0nsur wants to merge 1 commit from upstream-pr/4317 into main
tyr0nsur commented 2026-11-30 18:50:04 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tyr0nsur on 2026-11-30T18:50:04Z.


Related to #4291.

What it changes

The report showed Win32 error 8 while the title's window still had a large free gap. The tester could start with the same profile after increasing the Windows paging file. A play log with the system commit figures next to the failed allocation would help distinguish this pattern from a refusal caused by limited address space.

Capture the result of each VirtualAlloc or VirtualAlloc2 attempt before probing the window, trimming spare buffers or logging. If a retry fails, use its error. Return the final failure code to the title. For memory refusals, log the system commit in use and its limit when Windows supplies the figures. Preserve the existing crash-log path for ERROR_COMMITMENT_LIMIT and the existing retry and placement choices.

How it was tested

  • Windows 11, RTX 4060 8 GiB. Tests used synthetic allocations and no Series S/X profile or shader wave size.
  • On e1251c31, a zero-byte commit set Win32 error 87, and the logging path returned 88 after a synthetic log sink changed the thread's error. With this patch the regression keeps 87.
  • cargo test -p victory-hle --locked --lib --quiet -- --test-threads=1 passed (470 passed, 13 ignored). The staged asset-policy check passed.

Checked for overlap

  • Searched open PRs for the failure, paths and error handling. #3787 changes address placement and #3738 changes when pages are committed. This PR records the result of the existing calls.

Developed with Codex and reviewed with Claude Opus 5.5.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5571625409 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4317). Originally posted by [tyr0nsur](https://github.com/tyr0nsur) on 2026-11-30T18:50:04Z. --- Related to #4291. ## What it changes The report showed Win32 error 8 while the title's window still had a large free gap. The tester could start with the same profile after increasing the Windows paging file. A play log with the system commit figures next to the failed allocation would help distinguish this pattern from a refusal caused by limited address space. Capture the result of each `VirtualAlloc` or `VirtualAlloc2` attempt before probing the window, trimming spare buffers or logging. If a retry fails, use its error. Return the final failure code to the title. For memory refusals, log the system commit in use and its limit when Windows supplies the figures. Preserve the existing crash-log path for `ERROR_COMMITMENT_LIMIT` and the existing retry and placement choices. ## How it was tested - Windows 11, RTX 4060 8 GiB. Tests used synthetic allocations and no Series S/X profile or shader wave size. - On `e1251c31`, a zero-byte commit set Win32 error 87, and the logging path returned 88 after a synthetic log sink changed the thread's error. With this patch the regression keeps 87. - `cargo test -p victory-hle --locked --lib --quiet -- --test-threads=1` passed (470 passed, 13 ignored). The staged asset-policy check passed. ## Checked for overlap - [x] Searched open PRs for the failure, paths and error handling. #3787 changes address placement and #3738 changes when pages are committed. This PR records the result of the existing calls. Developed with Codex and reviewed with Claude Opus 5.5.
babuakhil commented 2026-11-30 19:42:17 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by babuakhil on 2026-11-30T19:42:17Z.


Checked on Windows 11 (Rust 1.98.1, pinned), on main (e1251c31), which this is based on. Not tested in the game.

The lost error is real without the synthetic sink. A throwaway test (not part of this PR) made the same refused zero-byte commit through XMemVirtualAlloc and read GetLastError() right after, with three subscribers:

subscriber main this PR
none 87 87
a plain tracing_subscriber::fmt() writing to stderr 6 (ERROR_INVALID_HANDLE) 87
a sink that sets the last error to 88 (as in your test) 88 87

So with ordinary logging, main already hands the title the logger's error instead of Windows' refusal, and the SetLastError at the end fixes that. That's the part that matters for a title deciding what to do after a null. I also checked that no path out of XMemVirtualAlloc skips it: the only early return hands back the title's own placeholder, not a failure.

cargo test -p victory-hle --lib modules::xmem: 50 passed and 1 failed, two runs out of two. The failure is a_read_by_range_waits_only_for_a_remapping_that_meets_it, which fails the same way on main (49 passed, 1 failed, two runs out of two) and passes alone on both, so it's the timing test you mentioned, not this change. Clippy's only note in xmem.rs, the unwrap_or_default match in port_on, is on main too (line 1933 there, 1956 here).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7289810124 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4317#issuecomment-7289810124). Originally posted by [babuakhil](https://github.com/babuakhil) on 2026-11-30T19:42:17Z. --- Checked on Windows 11 (Rust 1.98.1, pinned), on `main` (`e1251c31`), which this is based on. Not tested in the game. **The lost error is real without the synthetic sink.** A throwaway test (not part of this PR) made the same refused zero-byte commit through `XMemVirtualAlloc` and read `GetLastError()` right after, with three subscribers: | subscriber | `main` | this PR | |---|---|---| | none | 87 | 87 | | a plain `tracing_subscriber::fmt()` writing to stderr | **6** (`ERROR_INVALID_HANDLE`) | 87 | | a sink that sets the last error to 88 (as in your test) | 88 | 87 | So with ordinary logging, `main` already hands the title the logger's error instead of Windows' refusal, and the `SetLastError` at the end fixes that. That's the part that matters for a title deciding what to do after a null. I also checked that no path out of `XMemVirtualAlloc` skips it: the only early return hands back the title's own placeholder, not a failure. `cargo test -p victory-hle --lib modules::xmem`: 50 passed and 1 failed, two runs out of two. The failure is `a_read_by_range_waits_only_for_a_remapping_that_meets_it`, which fails the same way on `main` (49 passed, 1 failed, two runs out of two) and passes alone on both, so it's the timing test you mentioned, not this change. Clippy's only note in `xmem.rs`, the `unwrap_or_default` match in `port_on`, is on `main` too (line 1933 there, 1956 here).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/4317:upstream-pr/4317'
git switch 'upstream-pr/4317'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/4317'
git switch 'upstream-pr/4317'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/4317'
git switch 'upstream-pr/4317'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/4317'
git switch 'main'
git merge --squash 'upstream-pr/4317'
git switch 'main'
git merge --ff-only 'upstream-pr/4317'
git switch 'main'
git merge 'upstream-pr/4317'
git push origin 'main'
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
trustno1-coder/VIctory-NVIDIA!4317
No description provided.