feat(libkernel): implement sceKernelMapNamedFlexibleMemoryInternal #355

Merged
DotDebian merged 1 commit from upstream-pr/355 into main 2026-10-02 13:45:58 +00:00
DotDebian commented 2026-10-02 12:09:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DotDebian on 2026-10-02T12:09:06Z.


What

sceKernelMapNamedFlexibleMemoryInternal (NID 4h6F1LLbTiw) was not exported by libkernel. This PR adds it in core/libs/prx/libkernel/DirectMemory/Export.cpp as a forward to sceKernelMapNamedFlexibleMemory: the mapping counts against the flexible budget, gets the range name and is released by sceKernelMunmap.

Why the same signature and contract. The libc.prx bundled with an SDK 9 title (Astro Bot) calls this function at three sites as (&addr, len, 3, 0x8000, name) with addr a zeroed local, then tests eax and reads the address back from the local. An older libc.prx (Dreaming Sarah) has the same three sites with identical result handling, calling sceKernelMapNamedFlexibleMemory(&addr, len, 3, 0, name). So the function is a drop-in successor of the public one.

Flag 0x8000 still throws. Every call site I found passes 0x8000. I could not find what it means: it is in no public mmap flag list I checked (fpPS4 rtl/mmap.pas, the Mira FreeBSD headers). This PR does not touch SupportedFlags in DirectMemory.cpp, so the call still throws Unsupported memory mapping flags 0x8000, as it would through sceKernelMapNamedFlexibleMemory. The flag is listed under "Unknown function info" in docs/dev/TechnicalDebt.md.

The practical effect is therefore limited: titles that bundle the SDK 9 libc resolve the import, and the next failure names the flag instead of the missing symbol. What "Internal" changes beyond the public function, if anything, is not established either; the equivalence rests on the call-site comparison above.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, Release build with -DBUILD_TESTING=ON. No title or homebrew was run with this branch. Linux was not built or run locally; the change has no platform-specific code, so CI is the first Linux run of it.

New check CheckInternalNamedFlexibleMapping in the existing ctest guest_memory (core/libs/tests/GuestMemory.cpp):

  • flags 0 returns 0 with a non-null address;
  • sceKernelVirtualQuery reports the name passed in;
  • sceKernelAvailableFlexibleMemorySize drops by len and returns to its previous value after sceKernelMunmap;
  • flags 0x8000 throws, leaves the address null and leaves the available flexible size unchanged.

objdump -p on the built libkernel.prx lists sceKernelMapNamedFlexibleMemoryInternal in the export table. Full suite: 107/107 tests pass.

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:4716224865 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/355). Originally posted by [DotDebian](https://github.com/DotDebian) on 2026-10-02T12:09:06Z. --- ### What `sceKernelMapNamedFlexibleMemoryInternal` (NID `4h6F1LLbTiw`) was not exported by libkernel. This PR adds it in `core/libs/prx/libkernel/DirectMemory/Export.cpp` as a forward to `sceKernelMapNamedFlexibleMemory`: the mapping counts against the flexible budget, gets the range name and is released by `sceKernelMunmap`. **Why the same signature and contract.** The `libc.prx` bundled with an SDK 9 title (Astro Bot) calls this function at three sites as `(&addr, len, 3, 0x8000, name)` with `addr` a zeroed local, then tests `eax` and reads the address back from the local. An older `libc.prx` (Dreaming Sarah) has the same three sites with identical result handling, calling `sceKernelMapNamedFlexibleMemory(&addr, len, 3, 0, name)`. So the function is a drop-in successor of the public one. **Flag `0x8000` still throws.** Every call site I found passes `0x8000`. I could not find what it means: it is in no public mmap flag list I checked (fpPS4 `rtl/mmap.pas`, the Mira FreeBSD headers). This PR does not touch `SupportedFlags` in `DirectMemory.cpp`, so the call still throws `Unsupported memory mapping flags 0x8000`, as it would through `sceKernelMapNamedFlexibleMemory`. The flag is listed under "Unknown function info" in `docs/dev/TechnicalDebt.md`. The practical effect is therefore limited: titles that bundle the SDK 9 libc resolve the import, and the next failure names the flag instead of the missing symbol. What "Internal" changes beyond the public function, if anything, is not established either; the equivalence rests on the call-site comparison above. ### Tested Windows 11, MinGW-w64 GCC 15.2.0, Release build with `-DBUILD_TESTING=ON`. No title or homebrew was run with this branch. Linux was not built or run locally; the change has no platform-specific code, so CI is the first Linux run of it. New check `CheckInternalNamedFlexibleMapping` in the existing ctest `guest_memory` (`core/libs/tests/GuestMemory.cpp`): - flags 0 returns 0 with a non-null address; - `sceKernelVirtualQuery` reports the name passed in; - `sceKernelAvailableFlexibleMemorySize` drops by `len` and returns to its previous value after `sceKernelMunmap`; - flags `0x8000` throws, leaves the address null and leaves the available flexible size unchanged. `objdump -p` on the built `libkernel.prx` lists `sceKernelMapNamedFlexibleMemoryInternal` in the export table. Full suite: 107/107 tests pass. ### 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)
github-actions[bot] commented 2026-10-02 13:43:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-02T13:43:02Z.


Progress report (e1654a9 → 74fcea2)

📈 System libraries: 80.77% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel sceKernelMapNamedFlexibleMemoryInternal
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5953732659 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/355#issuecomment-5953732659). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-02T13:43:02Z. --- <!-- progress-report --> ### Progress report (e1654a9 → 74fcea2) 📈 **System libraries**: 80.77% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `sceKernelMapNamedFlexibleMemoryInternal` | </details>
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!355
No description provided.