fix(memory): a title's physical pages are numbered by their first 4 KiB frame, as the console numbers them #10

Open
github-bot wants to merge 1 commit from github-bot/gh-10 into main AGit
Owner

@⁠arugerdev on GitHub · 2026-11-23 21:02 UTC · original
arugerdev:fix/physical-page-frames → main · +97 −10 · 3 files · 1 commits · open

XValkyrie gave a title's physical pages consecutive numbers, one per 64 KiB page (87120, 87121, ...). A title numbers physical memory in 4 KiB frames instead. Windows' AllocateUserPhysicalPages gives page frame numbers in system pages, and the console's kernel does the same, so a 64 KiB page is 16 frames: 87120, 87136, ...

A title that only hands the numbers back never noticed. A later-kit Series title does arithmetic on them. It keeps each page's frame shifted right by 4, and shifts it back ((v << 4) & 0x1fffff0) to map the page at another address through XMemMapPhysicalPagesScatter. With consecutive numbers, 16 pages shifted down to the same value, so one physical page was mapped at 16 addresses at once. Whatever the title wrote at one of them appeared at the other 15. In that title this overwrote the shader code it had just read, and 1,215 of the 1,234 passes of its effects came out empty. It then stopped on a null pass, reading 0x68, the crash other people report with that title.

This change:

  • hands the title the first 4 KiB frame of each page it allocates;
  • takes frames back in XMemMapPhysicalPages, XMemMapPhysicalPagesScatter, XMemFreePhysicalPages and their kernelx names. A frame that is not the first of a page, or that is past the section, is refused as an invalid parameter, as a page past the section already was.

Pages, sections and views are unchanged. A title that only passes back the numbers it was given maps the same pages as before.

Where it comes from

  • Windows' AllocateUserPhysicalPages documentation: the page array is page frame numbers of system (4 KiB) pages.
  • The title's disassembly, which has no symbols: it computes each frame it passes to XMemMapPhysicalPagesScatter as (v << 4) & 0x1fffff0 from a value it stored shifted right by 4.
  • A trace of the calls in that title: it allocates 99,776 pages and maps them in one range. It then scatters 6,720 of them elsewhere with each number repeated 16 times (87120 ×16, 87136 ×16, ...), which mapped page 87120 at 16 consecutive addresses.

Testing

  • build.cmd --test passes. A new case in tests/memory.cpp allocates pages, maps them, and maps two of them again from their numbers shifted right and left by 4, as the title does. It checks that each frame is a multiple of 16, that each page comes back with its own bytes, and that a frame within a page is refused. The case fails on main and passes with this change.
  • clang-format 18.1.8, run as the format job runs it, leaves the tree as it is.
  • With that title, no page is mapped at more than one address in the scattered range, its effects' passes are made, and it goes on past the null pass to its audio processor, decoder and DSP. It stops later, when the host removes the Direct3D 12 device, which this change does not address.
**@⁠arugerdev** on GitHub · 2026-11-23 21:02 UTC · [original](https://github.com/sammwyy/xvalkyrie/pull/10) `arugerdev:fix/physical-page-frames` → `main` · +97 −10 · 3 files · 1 commits · open XValkyrie gave a title's physical pages consecutive numbers, one per 64 KiB page (87120, 87121, ...). A title numbers physical memory in 4 KiB frames instead. Windows' `AllocateUserPhysicalPages` gives page frame numbers in system pages, and the console's kernel does the same, so a 64 KiB page is 16 frames: 87120, 87136, ... A title that only hands the numbers back never noticed. A later-kit Series title does arithmetic on them. It keeps each page's frame shifted right by 4, and shifts it back (`(v << 4) & 0x1fffff0`) to map the page at another address through `XMemMapPhysicalPagesScatter`. With consecutive numbers, 16 pages shifted down to the same value, so one physical page was mapped at 16 addresses at once. Whatever the title wrote at one of them appeared at the other 15. In that title this overwrote the shader code it had just read, and 1,215 of the 1,234 passes of its effects came out empty. It then stopped on a null pass, reading `0x68`, the crash other people report with that title. This change: - hands the title the first 4 KiB frame of each page it allocates; - takes frames back in `XMemMapPhysicalPages`, `XMemMapPhysicalPagesScatter`, `XMemFreePhysicalPages` and their kernelx names. A frame that is not the first of a page, or that is past the section, is refused as an invalid parameter, as a page past the section already was. Pages, sections and views are unchanged. A title that only passes back the numbers it was given maps the same pages as before. **Where it comes from** - Windows' `AllocateUserPhysicalPages` documentation: the page array is page frame numbers of system (4 KiB) pages. - The title's disassembly, which has no symbols: it computes each frame it passes to `XMemMapPhysicalPagesScatter` as `(v << 4) & 0x1fffff0` from a value it stored shifted right by 4. - A trace of the calls in that title: it allocates 99,776 pages and maps them in one range. It then scatters 6,720 of them elsewhere with each number repeated 16 times (87120 ×16, 87136 ×16, ...), which mapped page 87120 at 16 consecutive addresses. **Testing** - `build.cmd --test` passes. A new case in `tests/memory.cpp` allocates pages, maps them, and maps two of them again from their numbers shifted right and left by 4, as the title does. It checks that each frame is a multiple of 16, that each page comes back with its own bytes, and that a frame within a page is refused. The case fails on `main` and passes with this change. - clang-format 18.1.8, run as the format job runs it, leaves the tree as it is. - With that title, no page is mapped at more than one address in the scattered range, its effects' passes are made, and it goes on past the null pass to its audio processor, decoder and DSP. It stops later, when the host removes the Direct3D 12 device, which this change does not address.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 02:46:22 +00:00
Author
Owner

@⁠arugerdev on GitHub · 2026-11-23 21:06 UTC · original

With this change the window stays open for about 12–15 s here, against about 6 s before. The title gets past the crash at image+0xb5a5f8 and reaches its audio setup, then stops when the host removes the Direct3D 12 device (DXGI_ERROR_INVALID_CALL), which this PR does not address.

image
**@⁠arugerdev** on GitHub · 2026-11-23 21:06 UTC · [original](https://github.com/sammwyy/xvalkyrie/pull/10#issuecomment-7114021897) With this change the window stays open for about 12–15 s here, against about 6 s before. The title gets past the crash at `image+0xb5a5f8` and reaches its audio setup, then stops when the host removes the Direct3D 12 device (`DXGI_ERROR_INVALID_CALL`), which this PR does not address. <img width="1276" height="748" alt="image" src="https://github.com/user-attachments/assets/fbf2ea64-4efd-4f7f-a076-f8be7d5b58bc" />
Author
Owner

@⁠sammwyy on GitHub · 2026-11-23 21:08 UTC · original

The next version of XValkyrie already has that fixed. Regardless, I’m going to evaluate your implementation.

**@⁠sammwyy** on GitHub · 2026-11-23 21:08 UTC · [original](https://github.com/sammwyy/xvalkyrie/pull/10#issuecomment-7114057255) The next version of XValkyrie already has that fixed. Regardless, I’m going to evaluate your implementation.
This pull request has changes conflicting with the target branch.
  • src/runtime/modules/memory.cpp
  • tests/CMakeLists.txt
  • tests/memory.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/10/head:github-bot/gh-10'
git switch 'github-bot/gh-10'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-10'
git switch 'github-bot/gh-10'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-10'
git switch 'github-bot/gh-10'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-10'
git switch 'main'
git merge --squash 'github-bot/gh-10'
git switch 'main'
git merge --ff-only 'github-bot/gh-10'
git switch 'main'
git merge 'github-bot/gh-10'
git push origin 'main'
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/sammwyy--xvalkyrie!10
No description provided.