fix(libkernel): replace partly overlapped allocations with a fixed mapping #1370

Merged
gjonn merged 1 commit from upstream-pr/1370 into main 2026-10-08 09:35:54 +00:00
gjonn commented 2026-10-08 00:35:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-08T00:35:29Z.


What

A fixed mapping (MAP_FIXED, without no-overwrite) replaces existing mappings on the console, as on FreeBSD. sceKernelMapDirectMemory and the anonymous/flexible paths already did that when the new range lay entirely inside registered allocations (RemapFixedIntoRegistered), but threw fixed mapping ... overlaps a registered guest allocation when it only partly overlapped them. They now unmap the overlapped registered pieces (the same path as sceKernelMunmap, factored into UnmapRegistered) and then map. Fixed no-overwrite mappings are unchanged (#994: ENOMEM over live memory).

A title maps 32 MiB of direct memory at 0xf410000000, releases the physical memory without unmapping, places a fixed 6 MiB mapping inside the old range, and then a fixed 0xa600000-byte mapping at 0xf410e00000, which starts on the remaining 18 MiB of the old allocation and extends past its end. This aborted the title intermittently 13-20 s after start.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0: new CheckFixedMappingReplacesPartialOverlap in GuestMemory.cpp (a fixed 3-page mapping over a live 1-page allocation and two free pages). It fails on main with fixed mapping 0x200000000+0xc000 overlaps a registered guest allocation 0x200000000+0x4000 and passes with this change; guest_memory and guest_ampr_markers pass.
  • A title that does this: three 90 s runs without the abort; the title gets further into rendering.

Not addressed here: GuestAllocationsUnmap still throws when the range crosses a hole inside one allocation (for example a reservation whose tail was already unmapped); that is a separate topic.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4780181583 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1370). Originally posted by [gjonn](https://github.com/gjonn) on 2026-10-08T00:35:29Z. --- ### What A fixed mapping (`MAP_FIXED`, without no-overwrite) replaces existing mappings on the console, as on FreeBSD. `sceKernelMapDirectMemory` and the anonymous/flexible paths already did that when the new range lay entirely inside registered allocations (`RemapFixedIntoRegistered`), but threw `fixed mapping ... overlaps a registered guest allocation` when it only partly overlapped them. They now unmap the overlapped registered pieces (the same path as `sceKernelMunmap`, factored into `UnmapRegistered`) and then map. Fixed no-overwrite mappings are unchanged (#994: `ENOMEM` over live memory). A title maps 32 MiB of direct memory at `0xf410000000`, releases the physical memory without unmapping, places a fixed 6 MiB mapping inside the old range, and then a fixed `0xa600000`-byte mapping at `0xf410e00000`, which starts on the remaining 18 MiB of the old allocation and extends past its end. This aborted the title intermittently 13-20 s after start. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0: new `CheckFixedMappingReplacesPartialOverlap` in `GuestMemory.cpp` (a fixed 3-page mapping over a live 1-page allocation and two free pages). It fails on `main` with `fixed mapping 0x200000000+0xc000 overlaps a registered guest allocation 0x200000000+0x4000` and passes with this change; `guest_memory` and `guest_ampr_markers` pass. - A title that does this: three 90 s runs without the abort; the title gets further into rendering. Not addressed here: `GuestAllocationsUnmap` still throws when the range crosses a hole inside one allocation (for example a reservation whose tail was already unmapped); that is a separate topic. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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
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!1370
No description provided.