fix(libkernel): map non-fixed hints inside a reserved range in place #2667

Closed
ps54all wants to merge 1 commit from upstream-pr/2667 into main
ps54all commented 2026-10-10 10:30:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-10T10:30:34Z.


What

sceKernelMapDirectMemory and the flexible/anonymous map path treat an address without MAP_FIXED as a pure hint. Ratchet & Clank: Rift Apart (PPSA01474) reserves 64 GiB with sceKernelReserveVirtualRange (0x12c3000000+0x1000000000) and then maps its heaps inside that range with a hint and no MAP_FIXED (0x1307000000+0x204000, prot 0x42, flags NO_COALESCE). The hint was not honoured: the range was mapped past the end of the reservation (0x22c3100000), the title kept using 0x1307000000, and sceAmprCommandBufferSetBuffer faulted writing a command buffer object at 0x1307200000.

A map whose hint lies wholly inside a range that is still reserved is now placed there, as a fixed map into the reservation would be (PlaceHintInReservation, called from DoMapDirect and DoMapAnon). Hints outside reservations, and hints over a range that is partly mapped, keep their current behaviour.

That a hint inside a reservation is taken as is comes from the title's behaviour, not from a console measurement; it is listed in TechnicalDebt.md.

Tested

  • Windows 11, GCC 15.2.0, Release, BUILD_TESTING=ON, on main a29ef592.
  • New guest_memory case CheckHintInsideReservation: reserve four pages, map direct memory at the second and flexible memory at the third with hints and no MAP_FIXED; both land at their hints, the fourth page stays reserved and uncommitted. A hint over the two mapped pages still moves and leaves their contents intact. Without the DirectMemory.cpp change the case fails at the first address check.
  • guest_memory as a whole aborts later, at the existing read-only sceKernelPread check (CheckReadsIntoSharedWriteTracking); it fails at the same check on unmodified main on this machine, so it is not caused by this change. The new case runs before it and passes.
  • Non-GPU ctest (-E "^agc_|^video_out|^guest_video"): 375/378. The other failures: guest_file_vector (/dev/urandom reads, also unrelated) and guest_sce_net (DNS timeout on this machine).
  • tools/check_conventions.py --base origin/main and tools/check_test_registration.py pass.
  • PPSA01474 (earlier, on a local integration branch with the same two-line change): without it the title faults in libSceAmpr on its first command buffer; with it the title runs for 150 s and issues draws. Not re-run on this exact branch.
  • Not tested: Linux, macOS.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Claude Code). I reviewed and take responsibility for every line.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4810534533 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2667). Originally posted by [ps54all](https://github.com/ps54all) on 2026-10-10T10:30:34Z. --- ### What `sceKernelMapDirectMemory` and the flexible/anonymous map path treat an address without `MAP_FIXED` as a pure hint. Ratchet & Clank: Rift Apart (PPSA01474) reserves 64 GiB with `sceKernelReserveVirtualRange` (`0x12c3000000+0x1000000000`) and then maps its heaps inside that range with a hint and no `MAP_FIXED` (`0x1307000000+0x204000`, prot 0x42, flags `NO_COALESCE`). The hint was not honoured: the range was mapped past the end of the reservation (`0x22c3100000`), the title kept using `0x1307000000`, and `sceAmprCommandBufferSetBuffer` faulted writing a command buffer object at `0x1307200000`. A map whose hint lies wholly inside a range that is still reserved is now placed there, as a fixed map into the reservation would be (`PlaceHintInReservation`, called from `DoMapDirect` and `DoMapAnon`). Hints outside reservations, and hints over a range that is partly mapped, keep their current behaviour. That a hint inside a reservation is taken as is comes from the title's behaviour, not from a console measurement; it is listed in `TechnicalDebt.md`. ### Tested - Windows 11, GCC 15.2.0, Release, `BUILD_TESTING=ON`, on `main` `a29ef592`. - New `guest_memory` case `CheckHintInsideReservation`: reserve four pages, map direct memory at the second and flexible memory at the third with hints and no `MAP_FIXED`; both land at their hints, the fourth page stays reserved and uncommitted. A hint over the two mapped pages still moves and leaves their contents intact. Without the `DirectMemory.cpp` change the case fails at the first address check. - `guest_memory` as a whole aborts later, at the existing read-only `sceKernelPread` check (`CheckReadsIntoSharedWriteTracking`); it fails at the same check on unmodified `main` on this machine, so it is not caused by this change. The new case runs before it and passes. - Non-GPU ctest (`-E "^agc_|^video_out|^guest_video"`): 375/378. The other failures: `guest_file_vector` (`/dev/urandom` reads, also unrelated) and `guest_sce_net` (DNS timeout on this machine). - `tools/check_conventions.py --base origin/main` and `tools/check_test_registration.py` pass. - PPSA01474 (earlier, on a local integration branch with the same two-line change): without it the title faults in `libSceAmpr` on its first command buffer; with it the title runs for 150 s and issues draws. Not re-run on this exact branch. - Not tested: Linux, macOS. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Claude Code). I reviewed and take responsibility for every line. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-10 10:30:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T10:30:44Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096583448 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2667#issuecomment-6096583448). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T10:30:44Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

Pull request closed

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
boykopovar/AnyPS5!2667
No description provided.