Skip to content

xmem: report allocations the host refuses - #538

Merged
Marvisak merged 1 commit into
Marvisak:mainfrom
coderanonymus:xmem-report-refusals
Nov 25, 2026
Merged

Marvisak merged 1 commit into
Marvisak:mainfrom
coderanonymus:xmem-report-refusals

Conversation

@coderanonymus

Copy link
Copy Markdown

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 Report Windows commit-limit failures in crashes.log #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

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 Marvisak#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 Marvisak#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 <noreply@anthropic.com>

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…uses

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@geiyiliyabumo

Copy link
Copy Markdown
Contributor

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants