fix(libkernel): refuse fixed no-overwrite mappings over live memory with ENOMEM #994

Merged
CnRJay merged 1 commit from upstream-pr/994 into main 2026-10-07 02:31:13 +00:00
CnRJay commented 2026-10-06 22:15:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-06T22:15:04Z.


What

A direct or flexible mapping with MAP_FIXED | MAP_NO_OVERWRITE (0x90) over a range that already holds an allocation threw "fixed mapping ... overlaps a registered guest allocation". The kernel refuses it with ENOMEM and leaves the existing mapping alone; fpPS4's TVirtualManager.check_fixed (kernel/mm_adr_virtual.pas) returns ENOMEM for an allocated node when MAP_NO_OVERWRITE is set, and allows it over a reservation.

DoMapDirect and DoMapAnon now return SCE_KERNEL_ERROR_ENOMEM in that case. A range entirely covered by sceKernelReserveVirtualRange reservations keeps the previous path. To test for overlap the guest allocation registry gets GuestAllocationsOverlaps (Mutation::Overlaps).

UFC 6 (PPSA23566) maps fixed no-overwrite at 0xfbffffc000 repeatedly to find a free slot and aborted on the second attempt.

Tested

  • Windows 11, bundled MinGW 15.2, Release, on edf90b16: 365/365 CTest. New CheckNoOverwriteRefusesLiveMapping in guest_memory: direct and flexible 0x90 mappings over a live direct mapping return 0x8002000c, the output address is unchanged, and the original mapping's contents and physical offset survive. The existing CheckNamedAndHintedMappings expected a throw for the same flexible case; it now expects ENOMEM.
  • PPSA23566: the address probe loop completes and startup continues.
  • Linux not built.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4765245726 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/994). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-06T22:15:04Z. --- ### What A direct or flexible mapping with `MAP_FIXED | MAP_NO_OVERWRITE` (0x90) over a range that already holds an allocation threw "fixed mapping ... overlaps a registered guest allocation". The kernel refuses it with ENOMEM and leaves the existing mapping alone; fpPS4's `TVirtualManager.check_fixed` (`kernel/mm_adr_virtual.pas`) returns ENOMEM for an allocated node when `MAP_NO_OVERWRITE` is set, and allows it over a reservation. `DoMapDirect` and `DoMapAnon` now return `SCE_KERNEL_ERROR_ENOMEM` in that case. A range entirely covered by `sceKernelReserveVirtualRange` reservations keeps the previous path. To test for overlap the guest allocation registry gets `GuestAllocationsOverlaps` (`Mutation::Overlaps`). UFC 6 (PPSA23566) maps fixed no-overwrite at `0xfbffffc000` repeatedly to find a free slot and aborted on the second attempt. ### Tested - Windows 11, bundled MinGW 15.2, Release, on `edf90b16`: 365/365 CTest. New `CheckNoOverwriteRefusesLiveMapping` in `guest_memory`: direct and flexible 0x90 mappings over a live direct mapping return `0x8002000c`, the output address is unchanged, and the original mapping's contents and physical offset survive. The existing `CheckNamedAndHintedMappings` expected a throw for the same flexible case; it now expects ENOMEM. - PPSA23566: the address probe loop completes and startup continues. - Linux not built. ### 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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!994
No description provided.