fix(libkernel): honour MAP_FIXED in sceKernelReserveVirtualRange and sceKernelMemoryPoolReserve #198

Merged
MichonGoddijn231849 merged 1 commit from upstream-pr/198 into main 2026-10-01 08:28:19 +00:00
MichonGoddijn231849 commented 2026-09-30 22:00:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-09-30T22:00:32Z.


What

sceKernelReserveVirtualRange and sceKernelMemoryPoolReserve ignored their flags and the requested address, and reserved wherever the arena had room. A title that reserves a range with MAP_FIXED then uses the address it asked for, not the one returned. Marvel's Wolverine passes 0x400010 (MAP_FIXED | MAP_NO_COALESCE) for its heaps and later maps and writes at those addresses, memory that was never reserved.

  • DoReserveVirtual takes the flags. With MAP_FIXED and an address, it checks the range is free (RequireAvailable, as the fixed maps do) and reserves exactly there, keeping MAP_NO_COALESCE.
  • Other reservations are placed as before, with no flags passed on, so titles that pass other bits see no change.
  • sceKernelMemoryPoolReserve starts from addr_in, as the fixed case needs.

Tested

Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0.

  • guest_memory: new CheckFixedVirtualReservation reserves a known free range with MAP_FIXED through both functions and requires the requested address back. It fails on main and passes with this change.
  • Marvel's Wolverine (PPSA03671): its fixed heap reservations land where it asked, and its first allocation no longer returns null.

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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4696495763 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/198). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-09-30T22:00:32Z. --- ### What `sceKernelReserveVirtualRange` and `sceKernelMemoryPoolReserve` ignored their flags and the requested address, and reserved wherever the arena had room. A title that reserves a range with `MAP_FIXED` then uses the address it asked for, not the one returned. Marvel's Wolverine passes 0x400010 (`MAP_FIXED | MAP_NO_COALESCE`) for its heaps and later maps and writes at those addresses, memory that was never reserved. - `DoReserveVirtual` takes the flags. With `MAP_FIXED` and an address, it checks the range is free (`RequireAvailable`, as the fixed maps do) and reserves exactly there, keeping `MAP_NO_COALESCE`. - Other reservations are placed as before, with no flags passed on, so titles that pass other bits see no change. - `sceKernelMemoryPoolReserve` starts from `addr_in`, as the fixed case needs. ### Tested Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0. - `guest_memory`: new `CheckFixedVirtualReservation` reserves a known free range with `MAP_FIXED` through both functions and requires the requested address back. It fails on `main` and passes with this change. - Marvel's Wolverine (PPSA03671): its fixed heap reservations land where it asked, and its first allocation no longer returns null. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [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. Written with Claude (Anthropic) under my direction; I reviewed and tested it. 🤖 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!198
No description provided.