fix(libkernel): sceKernelMapNamedSystemFlexibleMemory maps and then rejects a name of 32 characters or a null name #17718

Merged
xXPBSXx merged 3 commits from upstream-pr/17718 into main 2026-11-21 09:19:06 +00:00
xXPBSXx commented 2026-11-09 12:25:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-11-09T12:25:26Z.


What

sceKernelMapNamedSystemFlexibleMemory threw for a name of 32 or more characters and for a null name. On a PS5 the call maps the memory first and then refuses the name: a name of 32 characters returns SCE_KERNEL_ERROR_ENAMETOOLONG (0x8002003f, errno 63) and a null name returns SCE_KERNEL_ERROR_EFAULT (0x8002000e, errno 14), and in both cases the mapping exists without a name of its own; names of 8 and 31 characters are stored (cases 4.1 to 4.4, lines 36 to 39 of the raw output in the first comment). This does the same: the name is read before the mapping as before, a null name returns EFAULT after the mapping and a name of 32 or more bytes returns ENAMETOOLONG after it, and the range is left mapped and not named. A test pins the two errors and a non-null mapping, and for the 32-character name that the range is not named with the name cut to 31. The debt entry of the function states the measurement through the existing debt fragment of this function (the one entry, not a second fragment). The same run showed that the flags 0x8000 are accepted (0, the name is set) and the protection 0x800 is refused with EINVAL and no mapping (cases 4.5 and 4.6, lines 40 and 41); the entry records both and neither is changed here. A name that cannot be read still throws, which was not measured. A title process was not measured, and a name of 33 or more characters follows from the 32-character case.

sceKernelMapNamedDirectMemory has the same name checks in #16945; this change does not depend on it (different function and test file, and each pull request changes the debt in its own fragment).

Tested

Measured on a PS5 with firmware 11.60 (kernel_get_fw_version 0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-08 at 04:33 UTC (the utc in the PROBE line is the console's own clock, about 1 h 42 min ahead). A title process may differ. The calls mapped 64 KiB; the mapping was read back with sceKernelVirtualQuery. The cases are 4.1 to 4.6, lines 36 to 41 of the raw output in the first comment.

Call PS5, payload process, firmware 11.60 AnyPS5 main before here
sceKernelMapNamedSystemFlexibleMemory(64 KiB, name of 31 characters) 0, the name is stored (line 37) 0 0
sceKernelMapNamedSystemFlexibleMemory(64 KiB, name of 32 characters) 0x8002003f, mapped, no name (anon:..., line 38) throws 0x8002003f, mapped, not named
sceKernelMapNamedSystemFlexibleMemory(64 KiB, NULL name) 0x8002000e, mapped, no name (anon:..., line 39) throws 0x8002000e, mapped

Red and green on one base: Windows 10 Pro (MinGW GCC, Release, cmake -DBUILD_TESTING=ON, ninja -j4 guest_system_flexible_memory_tests, ctest -R ^guest_system_flexible_memory$, one worktree, a checkout, cmake, ninja and ctest per phase), base upstream/main dd9b766645bb: on the base guest_system_flexible_memory passes (23:41 UTC on 2026-11-19); with the test commit cf471c208974 it fails (23:43 UTC; exit code 0xc0000409, and the output shows an unhandled std::runtime_error and an abort, which is the throw of the old code; the message of the exception reads name of 32 bytes or more, which is the first new call, the 32-character name); with the fix commit 16cae035c8a9 it passes (23:44 UTC); with the documentation commit 3583d06ce82d it passes (23:46 UTC). tools/check_conventions.py --base dd9b766645bb and tools/debt_fold.py --check pass on the head, the entry is 957 characters without the list marker, and a merge into upstream/main c8eb2aac700 was checked with git merge-tree and is clean. The change is 3 files, +13/-5, with no new comments in code. Linux and macOS were not run here; CI will. Not tested: a title process and any other firmware.

Overlap: the other open pull requests that change the files of this branch (core/libs/prx/libkernel/DirectMemory/Export.cpp, core/libs/tests/GuestSystemFlexibleMemory.cpp and the existing fragment docs/dev/debt/changes/fix-libkernel-range-name-guest-copy.md, which is on main unfolded, for the entry of sceKernelMapNamedSystemFlexibleMemory in docs/dev/debt/libkernel.md), found by reading the changed files of all 2028 open pull requests at about 09:03 to 09:23 UTC on 2026-11-20, by reading what they change in every file whose path contains DirectMemory, SystemFlexible, GuestMemory or VirtualRange and in all debt files for sceKernelMapNamedSystemFlexibleMemory, NameVirtualRange, CopyRangeName and the fragment name, and by searching their titles and branch names for SystemFlexible, MapNamedSystem and range name, were checked on 2026-11-20 at about 09:32 UTC against main c8eb2aac700 together with this head: the branch is based on dd9b766645b, an ancestor of it, merges into main without a conflict, and tools/debt_fold.py --check applies the fragment together with every other fragment on main without an error. This branch replaces the earlier head f65c9ef5cac of this pull request, which is not an ancestor of the new head; the earlier head carried the three commits of the first version of #16945 in front of its own. #16945 (fix(libkernel): sceKernelMapNamedDirectMemory returns ENAMETOOLONG for a 32 character name and EFAULT for a NULL name) changes the neighbouring function in the same Export.cpp and a different test file, and merges with this head without a conflict. #21569 (fix(libkernel): bound virtual range names as the console does) and #19486 (feat(libSceNKWebKit): implement WKContextGetGeolocationManager and WKGeolocationManager functions) show NameVirtualRange or the fragment in their patches, #21569 as unchanged context of a call and #19486 as lines of an older state of main, whose head is identical to main in Export.cpp, the test and the fragment; neither changes a line of sceKernelMapNamedSystemFlexibleMemory. The other pull requests that list DirectMemory/Export.cpp (#24073, #24063, #23613, #22051, #22040, #22013, #19183, #18190, #17936 and #17553) change other functions of the file. With this branch applied to main, all 68 pull requests that list one of these files or matched a name were merged on top of it: 31 of them already conflict with main alone, and none has more conflicting files with this branch than without it. Unpublished local branches that touch these files were compared as well (150 branches); the only one that names the function or NameVirtualRange in a changed line is an earlier local copy of the first version of #16945, which this branch no longer carries. The merged result was not built or run beyond the red and green runs above.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (documentation and a host-independent memory check only)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5223822843 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17718). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-11-09T12:25:26Z. --- ### What `sceKernelMapNamedSystemFlexibleMemory` threw for a name of 32 or more characters and for a null name. On a PS5 the call maps the memory first and then refuses the name: a name of 32 characters returns `SCE_KERNEL_ERROR_ENAMETOOLONG` (0x8002003f, errno 63) and a null name returns `SCE_KERNEL_ERROR_EFAULT` (0x8002000e, errno 14), and in both cases the mapping exists without a name of its own; names of 8 and 31 characters are stored (cases 4.1 to 4.4, lines 36 to 39 of the raw output in the first comment). This does the same: the name is read before the mapping as before, a null name returns `EFAULT` after the mapping and a name of 32 or more bytes returns `ENAMETOOLONG` after it, and the range is left mapped and not named. A test pins the two errors and a non-null mapping, and for the 32-character name that the range is not named with the name cut to 31. The debt entry of the function states the measurement through the existing debt fragment of this function (the one entry, not a second fragment). The same run showed that the flags 0x8000 are accepted (0, the name is set) and the protection 0x800 is refused with `EINVAL` and no mapping (cases 4.5 and 4.6, lines 40 and 41); the entry records both and neither is changed here. A name that cannot be read still throws, which was not measured. A title process was not measured, and a name of 33 or more characters follows from the 32-character case. `sceKernelMapNamedDirectMemory` has the same name checks in #16945; this change does not depend on it (different function and test file, and each pull request changes the debt in its own fragment). ### Tested Measured on a PS5 with firmware 11.60 (`kernel_get_fw_version` 0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-08 at 04:33 UTC (the `utc` in the `PROBE` line is the console's own clock, about 1 h 42 min ahead). A title process may differ. The calls mapped 64 KiB; the mapping was read back with `sceKernelVirtualQuery`. The cases are 4.1 to 4.6, lines 36 to 41 of the raw output in the first comment. | Call | PS5, payload process, firmware 11.60 | AnyPS5 `main` before | here | |---|---|---|---| | `sceKernelMapNamedSystemFlexibleMemory(64 KiB, name of 31 characters)` | 0, the name is stored (line 37) | 0 | 0 | | `sceKernelMapNamedSystemFlexibleMemory(64 KiB, name of 32 characters)` | 0x8002003f, mapped, no name (`anon:...`, line 38) | throws | 0x8002003f, mapped, not named | | `sceKernelMapNamedSystemFlexibleMemory(64 KiB, NULL name)` | 0x8002000e, mapped, no name (`anon:...`, line 39) | throws | 0x8002000e, mapped | Red and green on one base: Windows 10 Pro (MinGW GCC, Release, `cmake -DBUILD_TESTING=ON`, `ninja -j4 guest_system_flexible_memory_tests`, `ctest -R ^guest_system_flexible_memory$`, one worktree, a checkout, cmake, ninja and ctest per phase), base `upstream/main` `dd9b766645bb`: on the base `guest_system_flexible_memory` passes (23:41 UTC on 2026-11-19); with the test commit `cf471c208974` it fails (23:43 UTC; exit code 0xc0000409, and the output shows an unhandled `std::runtime_error` and an abort, which is the throw of the old code; the message of the exception reads `name of 32 bytes or more`, which is the first new call, the 32-character name); with the fix commit `16cae035c8a9` it passes (23:44 UTC); with the documentation commit `3583d06ce82d` it passes (23:46 UTC). `tools/check_conventions.py --base dd9b766645bb` and `tools/debt_fold.py --check` pass on the head, the entry is 957 characters without the list marker, and a merge into `upstream/main` `c8eb2aac700` was checked with `git merge-tree` and is clean. The change is 3 files, +13/-5, with no new comments in code. Linux and macOS were not run here; CI will. Not tested: a title process and any other firmware. Overlap: the other open pull requests that change the files of this branch (`core/libs/prx/libkernel/DirectMemory/Export.cpp`, `core/libs/tests/GuestSystemFlexibleMemory.cpp` and the existing fragment `docs/dev/debt/changes/fix-libkernel-range-name-guest-copy.md`, which is on `main` unfolded, for the entry of `sceKernelMapNamedSystemFlexibleMemory` in `docs/dev/debt/libkernel.md`), found by reading the changed files of all 2028 open pull requests at about 09:03 to 09:23 UTC on 2026-11-20, by reading what they change in every file whose path contains `DirectMemory`, `SystemFlexible`, `GuestMemory` or `VirtualRange` and in all debt files for `sceKernelMapNamedSystemFlexibleMemory`, `NameVirtualRange`, `CopyRangeName` and the fragment name, and by searching their titles and branch names for `SystemFlexible`, `MapNamedSystem` and `range name`, were checked on 2026-11-20 at about 09:32 UTC against `main` `c8eb2aac700` together with this head: the branch is based on `dd9b766645b`, an ancestor of it, merges into `main` without a conflict, and `tools/debt_fold.py --check` applies the fragment together with every other fragment on `main` without an error. This branch replaces the earlier head `f65c9ef5cac` of this pull request, which is not an ancestor of the new head; the earlier head carried the three commits of the first version of #16945 in front of its own. #16945 (`fix(libkernel): sceKernelMapNamedDirectMemory returns ENAMETOOLONG for a 32 character name and EFAULT for a NULL name`) changes the neighbouring function in the same `Export.cpp` and a different test file, and merges with this head without a conflict. #21569 (`fix(libkernel): bound virtual range names as the console does`) and #19486 (`feat(libSceNKWebKit): implement WKContextGetGeolocationManager and WKGeolocationManager functions`) show `NameVirtualRange` or the fragment in their patches, #21569 as unchanged context of a call and #19486 as lines of an older state of `main`, whose head is identical to `main` in `Export.cpp`, the test and the fragment; neither changes a line of `sceKernelMapNamedSystemFlexibleMemory`. The other pull requests that list `DirectMemory/Export.cpp` (#24073, #24063, #23613, #22051, #22040, #22013, #19183, #18190, #17936 and #17553) change other functions of the file. With this branch applied to `main`, all 68 pull requests that list one of these files or matched a name were merged on top of it: 31 of them already conflict with `main` alone, and none has more conflicting files with this branch than without it. Unpublished local branches that touch these files were compared as well (150 branches); the only one that names the function or `NameVirtualRange` in a changed line is an earlier local copy of the first version of #16945, which this branch no longer carries. The merged result was not built or run beyond the red and green runs above. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a (documentation and a host-independent memory check only) <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
MarcZX10 commented 2026-11-20 09:58:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T09:58:56Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the reviewed implementation and regression coverage support merging.

What I ran

Reviewed head 3583d06ce82d1002daa13e98a65244fd561cacdd. No commands or tests were run in this review; the PR description reports Windows test runs, convention and debt checks, and a clean merge check, which I did not independently run.

Results

Check Result Note
Changed code and regression test passed Read all three changed files
Test execution in this review not run Author-reported runs only
Reported merge and convention checks not run Not independently confirmed

Findings

Blocking

None.

Non-blocking

None.

Not verified

I read core/libs/prx/libkernel/DirectMemory/Export.cpp, core/libs/tests/GuestSystemFlexibleMemory.cpp, and docs/dev/debt/changes/fix-libkernel-range-name-guest-copy.md; all three files listed as reviewed were read. No changed files were excluded. I did not independently run tests, check CI, verify the PS5 behavior, or build and run the merged result. The test verifies the too-long name is not retained, but does not assert the precise anonymous range name described in the PR.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5990826804 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17718#pullrequestreview-5990826804). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T09:58:56Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the reviewed implementation and regression coverage support merging. ## What I ran Reviewed head `3583d06ce82d1002daa13e98a65244fd561cacdd`. No commands or tests were run in this review; the PR description reports Windows test runs, convention and debt checks, and a clean merge check, which I did not independently run. ## Results | Check | Result | Note | |---|---|---| | Changed code and regression test | passed | Read all three changed files | | Test execution in this review | not run | Author-reported runs only | | Reported merge and convention checks | not run | Not independently confirmed | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I read `core/libs/prx/libkernel/DirectMemory/Export.cpp`, `core/libs/tests/GuestSystemFlexibleMemory.cpp`, and `docs/dev/debt/changes/fix-libkernel-range-name-guest-copy.md`; all three files listed as reviewed were read. No changed files were excluded. I did not independently run tests, check CI, verify the PS5 behavior, or build and run the merged result. The test verifies the too-long name is not retained, but does not assert the precise anonymous range name described in the PR. ## To get this to a good state Nothing is required.
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!17718
No description provided.