xmem: report allocations the host refuses #538

Manually merged
github merged 1 commit from gh-pr/538/head into gh-pr/538/base 2026-11-26 04:07:36 +00:00
Owner

@⁠coderanonymus on GitHub · 2026-11-24 04:39 UTC · original
coderanonymus:xmem-report-refusals → main · +40 −10 · 1 files · 1 commits · merged 2026-11-25 00:08 UTC

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

**@⁠coderanonymus** on GitHub · 2026-11-24 04:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/538) `coderanonymus:xmem-report-refusals` → `main` · +40 −10 · 1 files · 1 commits · merged 2026-11-25 00:08 UTC 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)
A refused XMemVirtualAlloc or XMemAllocDefault handed the title a null in
silence, and the title then writes at null plus an offset, which reads
like a title bug. In #289 the faulting write is at 0x217800, the
request's length 0x2173a0 rounded up to 2 KiB, so the base it built on
was most likely such a null.

At the commit limit, XMemVirtualAlloc now writes the same crashes.log
report the physical-page commit writes since #51 (the shared part is
`commit_refused`); other refusals, and a host heap out of memory, are
warnings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:07:34 +00:00
github manually merged commit 65062e133c into gh-pr/538/base 2026-11-26 04:07:36 +00:00
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 11:47 UTC · original

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.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 11:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/538#issuecomment-7130554058) 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.*
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!538
No description provided.