xmem: name both owners when allocations come to share pages (VICTORY_TRACE_OWNERS) #111

Manually merged
github merged 2 commits from github-bot/gh-111 into main 2026-11-26 17:21:09 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-26 16:44 UTC · original
Olima34:feat/xmem-trace-owners → main · +394 −3 · 4 files · 2 commits · merged 2026-11-26 17:16 UTC

What this changes

Refs #15 ("Needed: finding which allocations in xmem_posix share pages"). VICTORY_TRACE_OWNERS=1 logs a warning naming both owners at the moment two allocations come to share title memory:

  • C1: a new physical-page view (XMemMapPhysicalPages, …Scatter, map_alias / CopyPageMappings, back_with_pool) lands over an existing view.
  • C2: XMemAllocatePhysicalPages hands out page numbers past what the title keeps (number >> 4 in 21 bits), so truncated numbers would land on other allocations.
  • C3: VirtualFree(MEM_DECOMMIT) on a range that still has pool views. Since #108, MEM_RELEASE gives the views back, so it no longer fires for a normal release.
  • C4: a map or alias into a destination outside every known region.

For each owner the log gives the call that made it, its base and length, the pool id and page index, a sequence number, and the title's return address (image+off) when on a title thread.

Off by default, documented under "Bring-up diagnostics". Turned off, the cost is one LazyLock<bool> read per call: every write to the owner bookkeeping is behind the switch.

How it was tested

  • Each case fires at least once in a test, counted through a cfg(test) counter. The tests compare pool ids rather than addresses, so parallel tests can't make them flaky; C2 is checked through a pure function.
  • cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory, arm64 cargo test --workspace
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings, also with --all-features; clippy for macOS reports nothing new in the files touched
  • cargo xtask policy
  • Ran the game: not done, no copy of it here. A story-load run with it on should name the colliding allocations.

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • No guesses about console behaviour
  • New diagnostics are behind a VICTORY_* variable and documented
**@⁠Olima34** on GitHub · 2026-11-26 16:44 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/111) `Olima34:feat/xmem-trace-owners` → `main` · +394 −3 · 4 files · 2 commits · merged 2026-11-26 17:16 UTC ## What this changes Refs #15 ("Needed: finding which allocations in xmem_posix share pages"). `VICTORY_TRACE_OWNERS=1` logs a warning naming **both** owners at the moment two allocations come to share title memory: - **C1:** a new physical-page view (`XMemMapPhysicalPages`, `…Scatter`, `map_alias` / CopyPageMappings, `back_with_pool`) lands over an existing view. - **C2:** `XMemAllocatePhysicalPages` hands out page numbers past what the title keeps (`number >> 4` in 21 bits), so truncated numbers would land on other allocations. - **C3:** `VirtualFree(MEM_DECOMMIT)` on a range that still has pool views. Since #108, `MEM_RELEASE` gives the views back, so it no longer fires for a normal release. - **C4:** a map or alias into a destination outside every known region. For each owner the log gives the call that made it, its base and length, the pool id and page index, a sequence number, and the title's return address (`image+off`) when on a title thread. Off by default, documented under "Bring-up diagnostics". Turned off, the cost is one `LazyLock<bool>` read per call: every write to the owner bookkeeping is behind the switch. ## How it was tested - [x] Each case fires at least once in a test, counted through a `cfg(test)` counter. The tests compare pool ids rather than addresses, so parallel tests can't make them flaky; C2 is checked through a pure function. - [x] `cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory`, arm64 `cargo test --workspace` - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`, also with `--all-features`; clippy for macOS reports nothing new in the files touched - [x] `cargo xtask policy` - [ ] Ran the game: not done, no copy of it here. A story-load run with it on should name the colliding allocations. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] No guesses about console behaviour - [x] New diagnostics are behind a `VICTORY_*` variable and documented
VICTORY_TRACE_OWNERS=1 (off by default) logs, when it happens, a physical page view mapped over another, page numbers past the 25 bits the title keeps, VirtualFree (MEM_RELEASE or MEM_DECOMMIT) of a range that still shows views, and a title mapping outside every region VirtualAlloc or XMemVirtualAlloc made. Each side names the public call that made it, its range, pool id and page index, a sequence number and the title's return address. Off, it costs one read of the switch. For #15.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 16:46:38 +00:00
Windows maps a view only over a placeholder, so mapping one over another
fails there before any bookkeeping and the case cannot arise.
github manually merged commit 94c6b56167 into main 2026-11-26 17:21:09 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 17:17 UTC · original

Merged in 182c14f. It's off unless VICTORY_TRACE_OWNERS is set, it's documented, and each case fires in a test. Thanks!

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 17:17 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/111#issuecomment-7198769121) Merged in 182c14f. It's off unless `VICTORY_TRACE_OWNERS` is set, it's documented, and each case fires in a test. Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.