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

Merged
Olima34 merged 2 commits from upstream-pr/111 into main 2026-11-26 17:16:44 +00:00
Olima34 commented 2026-11-26 16:44:14 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-26T16:44:14Z.


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
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6631216986 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/111). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-26T16:44:14Z. --- ## 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
LakshanSivakumar commented 2026-11-26 17:17:02 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T17:17:02Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7198769121 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/111#issuecomment-7198769121). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T17:17:02Z. --- Merged in 182c14f. It's off unless `VICTORY_TRACE_OWNERS` is set, it's documented, and each case fires in a test. Thanks!
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
LakshanSivakumar/Native-Victory-macOS!111
No description provided.