xmem: report allocations the host refuses #538

Merged
coderanonymus merged 1 commit from upstream-pr/538 into main 2026-11-25 00:08:46 +00:00
coderanonymus commented 2026-11-24 04:39:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by coderanonymus on 2026-11-24T04:39:23Z.


Related to #289 (and the commit-limit reports of #23 / #51).

Why

If the host refuses XMemVirtualAlloc or XMemAllocDefault, the title gets a null and nothing is logged. A title that builds on that base then faults at null plus an offset, and the crash looks like a title bug.

#289 looks like this case. The faulting memset writes to 0x217800, with length 0x2173a0. 0x2173a0 rounded up to 2 KiB is exactly 0x217800. So the destination is most likely a null base plus one aligned block, not a real pointer and not an APU device address. Which allocation returned the null can't be told from the report. With this change, the log would show it.

What

  • XMemVirtualAlloc returning null:
    • At the Windows commit limit (error 1455), it writes the same crashes.log report that the physical-page commit has written since #51 (request size, system commit, the paging-file advice).
    • Any other refusal logs a warning with the size, kind, flags and OS error.
  • XMemAllocDefault with the host heap out of memory: a warning with the size.
  • The report code moves into commit_refused(len, what, error), now shared by both commit paths. commit_limit_message takes what ("physical pages" or "virtual memory"). Its test now checks both wordings.
  • In passing, clippy's field_reassign_with_default on the moved PERFORMANCE_INFORMATION setup is fixed.

The OS error is read right after VirtualAlloc2, before any logging can change it.

Verification

  • cargo clippy -p victory-hle --tests --target x86_64-pc-windows-msvc: no warnings (one fewer than main).
  • rustfmt: no diffs in xmem.rs.
  • Not run against the title or on Windows. The test I changed (commit_limit_report_includes_request_and_system_commit) was type-checked but not executed.

No game data used.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6574742013 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/538). Originally posted by [coderanonymus](https://github.com/coderanonymus) on 2026-11-24T04:39:23Z. --- Related to #289 (and the commit-limit reports of #23 / #51). ## Why If the host refuses `XMemVirtualAlloc` or `XMemAllocDefault`, the title gets a null and nothing is logged. A title that builds on that base then faults at null plus an offset, and the crash looks like a title bug. #289 looks like this case. The faulting `memset` writes to `0x217800`, with length `0x2173a0`. `0x2173a0` rounded up to 2 KiB is exactly `0x217800`. So the destination is most likely a null base plus one aligned block, not a real pointer and not an APU device address. Which allocation returned the null can't be told from the report. With this change, the log would show it. ## What - `XMemVirtualAlloc` returning null: - At the Windows commit limit (error 1455), it writes the same `crashes.log` report that the physical-page commit has written since #51 (request size, system commit, the paging-file advice). - Any other refusal logs a warning with the size, kind, flags and OS error. - `XMemAllocDefault` with the host heap out of memory: a warning with the size. - The report code moves into `commit_refused(len, what, error)`, now shared by both commit paths. `commit_limit_message` takes `what` ("physical pages" or "virtual memory"). Its test now checks both wordings. - In passing, clippy's `field_reassign_with_default` on the moved `PERFORMANCE_INFORMATION` setup is fixed. The OS error is read right after `VirtualAlloc2`, before any logging can change it. ## Verification - `cargo clippy -p victory-hle --tests --target x86_64-pc-windows-msvc`: no warnings (one fewer than `main`). - `rustfmt`: no diffs in `xmem.rs`. - Not run against the title or on Windows. The test I changed (`commit_limit_report_includes_request_and_system_commit`) was type-checked but not executed. No game data used. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
mercuryVM commented 2026-11-24 09:05:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T08:55:46Z.

Review: APPROVED


Tested 65062e1 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (264 passed, 0 failed).

  • Reporting a refused VirtualAlloc2 at the call that failed is a clear win. The reasoning about #289's 0x217800 = round-up(0x2173a0, 2 KiB) makes the "null + one block" reading convincing. Reusing the #51 commit-limit report for MEM_COMMIT keeps the paging-file advice in one place. last_os_error() is read right after the call, before anything else can overwrite it.
  • Nit: some titles probe for a free range by asking for a fixed base and handling the failure. Those refusals are expected, and now each one logs a warn!. If logs turn out noisy, logging the first refusal per (kind, size) or demoting reserve-only failures to debug! would keep the signal.
  • The PERFORMANCE_INFORMATION struct-update hunk is the same as #405, which is already in our fork. It merges cleanly.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6036250818 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/538#pullrequestreview-6036250818). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T08:55:46Z. **Review:** APPROVED --- Tested 65062e1 on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (264 passed, 0 failed). - Reporting a refused `VirtualAlloc2` at the call that failed is a clear win. The reasoning about #289's `0x217800` = round-up(`0x2173a0`, 2 KiB) makes the "null + one block" reading convincing. Reusing the #51 commit-limit report for `MEM_COMMIT` keeps the paging-file advice in one place. `last_os_error()` is read right after the call, before anything else can overwrite it. - Nit: some titles probe for a free range by asking for a fixed base and handling the failure. Those refusals are expected, and now each one logs a `warn!`. If logs turn out noisy, logging the first refusal per `(kind, size)` or demoting reserve-only failures to `debug!` would keep the signal. - The `PERFORMANCE_INFORMATION` struct-update hunk is the same as #405, which is already in our fork. It merges cleanly. AI-assisted (Claude Code).
geiyiliyabumo commented 2026-11-24 12:04:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T11:47:29Z.


Independent verification & code review on Windows 11 Pro (build 26100, Rust 1.98.1), cleanly merged onto main (ffe310e):

  • cargo xtask policy: PASS (154 files ok)
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings: PASS
  • cargo clippy -p victory-hle --all-targets --features diagnostics --locked -- -D warnings: PASS
  • cargo test -p victory-hle --locked: 94 passed + 1 integration test (no_dll_planting), 0 failed (including updated commit_limit_report_includes_request_and_system_commit)

Diff review (crates/victory-hle/src/modules/xmem.rs): clean, minimal, and very useful diagnostics for OOM/commit-limit failures.

  • Minor non-blocking note: in XMemVirtualAlloc, calling commit_refused (K32GetPerformanceInfo + log_crash file I/O) or tracing::warn! before returning NULL can overwrite the thread's Win32 last-error code; restoring SetLastError from error.raw_os_error() before returning at would preserve GetLastError() for title callers that inspect it after a failed allocation.

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7130554058 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/538#issuecomment-7130554058). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T11:47:29Z. --- Independent verification & code review on Windows 11 Pro (build 26100, Rust `1.98.1`), cleanly merged onto `main` (`ffe310e`): - `cargo xtask policy`: PASS (`154 files ok`) - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings`: PASS - `cargo clippy -p victory-hle --all-targets --features diagnostics --locked -- -D warnings`: PASS - `cargo test -p victory-hle --locked`: **94 passed + 1 integration test (`no_dll_planting`), 0 failed** (including updated `commit_limit_report_includes_request_and_system_commit`) Diff review (`crates/victory-hle/src/modules/xmem.rs`): clean, minimal, and very useful diagnostics for OOM/commit-limit failures. - Minor non-blocking note: in `XMemVirtualAlloc`, calling `commit_refused` (`K32GetPerformanceInfo` + `log_crash` file I/O) or `tracing::warn!` before returning `NULL` can overwrite the thread's Win32 last-error code; restoring `SetLastError` from `error.raw_os_error()` before returning `at` would preserve `GetLastError()` for title callers that inspect it after a failed allocation. *AI-assisted; synthetic tests only, no game files.*
catminou4 commented 2026-11-24 13:01:32 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Static review only — victory-hle doesn't build on macOS (it depends on victory-gpu, which has the known host_resource cfg issue on non-Windows, fixed by #235/#523), so I could not compile or run the updated commit_limit_message tests here.

The change itself reads well: commit_refused centralizes the commit-limit reporting (crash log at the Windows commit limit, warning otherwise) and is now reused by both the virtual-memory path (XMemVirtualAlloc null result) and the physical-page path (commit), with the alloc-default heap OOM getting a warning too. The message wording gained the what parameter consistently, and the unit test updates match the new signature and assert the new wording.

One check for whoever runs Windows: the XMemVirtualAlloc early-return structure — the new at.is_null() block sits before the existing base.is_null() debug log, so a refused commit now warns and still falls through to the null-return path. That looks intended (report once, return null as before), but worth a smoke run of a commit-limit scenario.

<!-- greyfinch-sync:Marvisak/VIctory:review:6039403044 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/538#pullrequestreview-6039403044). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T12:44:25Z. **Review:** COMMENTED --- Static review only — `victory-hle` doesn't build on macOS (it depends on `victory-gpu`, which has the known `host_resource` cfg issue on non-Windows, fixed by #235/#523), so I could not compile or run the updated `commit_limit_message` tests here. The change itself reads well: `commit_refused` centralizes the commit-limit reporting (crash log at the Windows commit limit, warning otherwise) and is now reused by both the virtual-memory path (`XMemVirtualAlloc` null result) and the physical-page path (`commit`), with the alloc-default heap OOM getting a warning too. The message wording gained the `what` parameter consistently, and the unit test updates match the new signature and assert the new wording. One check for whoever runs Windows: the `XMemVirtualAlloc` early-return structure — the new `at.is_null()` block sits before the existing `base.is_null()` debug log, so a refused commit now warns *and* still falls through to the null-return path. That looks intended (report once, return null as before), but worth a smoke run of a commit-limit scenario.
upstream-sync closed this pull request 2026-11-25 01:04:08 +00:00
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!538
No description provided.