fix(libkernel): sceKernelMapNamedDirectMemory returns ENAMETOOLONG for a 32 character name and EFAULT for a NULL name #16945

Open
xXPBSXx wants to merge 3 commits from upstream-pr/16945 into main
xXPBSXx commented 2026-11-08 00:08:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-11-08T00:08:57Z.


What

sceKernelMapNamedDirectMemory returned 0 for a name of 32 or more characters and named the range with the name cut to 31, and returned 0 for a NULL name. On a PS5 the mapping succeeds in both cases and the call returns SCE_KERNEL_ERROR_ENAMETOOLONG (0x8002003f, errno 63) for a name of 32 characters and SCE_KERNEL_ERROR_EFAULT (0x8002000e, errno 14) for a NULL name; the range stays mapped and has no name of its own (it reads anon: and hex digits), and a name of 31 characters is stored (lines 57 to 59 of the output in the first comment). This does the same: after a successful mapping, a name of 32 or more bytes returns ENAMETOOLONG and a NULL name returns EFAULT, and neither names the range. A test pins the three results, a non-null mapping in each case, and the name read back; it also pins that sceKernelMapNamedFlexibleMemory is unchanged. The debt entry in docs/dev/debt/libkernel.md states the measurement through a debt fragment.

The NULL is what the probe passed. The probe's case 6.8 is labelled "name of 0 chars", but its table entry is {0x33, 0, 64 * KB, 0}, so the name argument is a NULL pointer, and the label comes from printing 0 for a NULL name (mp[i].name ? strlen(mp[i].name) : 0 in the probe source in the first comment). The first version of this pull request returned EFAULT for an empty string and called that measured; the review pointed out that no probe case passes an empty string, so that is removed. An empty string is not measured and is unchanged here, and the entry says so.

Not measured: a name of 33 or more characters (it follows from the 32-character case and from sceKernelSetVirtualRangeName, whose limit is the same 31 characters), an empty string, sceKernelMapNamedFlexibleMemory (unchanged, and it still cuts a longer name to 31 characters here), a title process, and other firmware. The range without a name reads as empty here where the console reports anon: and hex digits; that is not changed. git grep finds no call of sceKernelMapNamedDirectMemory in this repository outside its definition, its declaration and tests, and no test other than the new one passes NULL. #16869 is merged, so this branch is rebuilt on current main and no longer depends on it.

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-07 at 19:25 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 of an own 4 MiB direct memory block with protection 0x33 and alignment 0x10000, and the name was read back with sceKernelVirtualQuery. The probe source and its raw output are in the first comment.

Call PS5, payload process, firmware 11.60 AnyPS5 main before here
name of 31 characters 0, the name is stored (line 57) 0 0
name of 32 characters 0x8002003f, mapped, no name (anon:..., line 58) 0, the name is cut to 31 0x8002003f, mapped, no name
NULL name 0x8002000e, mapped, no name (anon:..., line 59) 0 0x8002000e, mapped, no name
empty string not measured 0, stored as an empty name unchanged

Red and green on one base: Windows 10 Pro (MinGW GCC, Release, cmake -DBUILD_TESTING=ON, ninja -j4 guest_memory_tests, ctest -R ^guest_memory$, one worktree, a checkout, cmake, ninja and ctest per phase), base upstream/main fd6d6f4a8498: on the base guest_memory passes (21:13 UTC on 2026-11-19); with the test commit ee6651cb08cf it fails (21:15 UTC; exit code 0xc0000409 and "Guest memory check failed at core/libs/tests/GuestMemory.cpp:286", the check of the call's result in the loop over the cases; the message does not name the case, and that it is the 32-character one follows from the order of the cases, where the first returns 0 on main); with the fix commit 528371df05c6 it passes (21:18 UTC); with the documentation commit ccde1e977bd0 it passes (21:21 UTC). tools/check_conventions.py --base fd6d6f4a8498 and tools/debt_fold.py --check pass on the head, and a merge into upstream/main a410f24ddad was checked with git merge-tree and is clean. The change is 3 files, +46/-2, 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/GuestMemory.cpp and the fragment docs/dev/debt/changes/fix-kernel-map-named-direct-memory-null-name.md, a new file, for the entry of sceKernelMapNamedDirectMemory in docs/dev/debt/libkernel.md), found by reading the changed files of all 2028 open pull requests at about 22:31 to 22:50 UTC on 2026-11-19, by reading what they change in every file whose path contains DirectMemory, GuestMemory, VirtualRange or NamedDirect and in all debt files for sceKernelMapNamedDirectMemory, NameMappedRange, CopyRangeName and MapNamedFlexibleMemory, and by searching their titles and branch names for the same names, were checked on 2026-11-19 at about 23:06 UTC against main a410f24ddad together with this head: the branch is based on fd6d6f4a849, 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 344e54d0f5b of this pull request, which is not an ancestor of the new head. Two other pull requests carry changes to the same function: #17718 (fix(libkernel): sceKernelMapNamedSystemFlexibleMemory maps and then rejects a name of 32 characters or a null name) contains an earlier copy of the commits of this pull request (ab942cf2991, 03ccc499427, de6c7c5e3dc, the variant with the empty-name result) in front of its own three commits, and so conflicts with this head in Export.cpp and GuestMemory.cpp; it has to be rebased onto the new head once this one is pushed. #21569 (fix(libkernel): bound virtual range names as the console does) adds a test function to GuestMemory.cpp and changes Export.cpp, and does not change a line that names these functions; it already conflicts with main in Export.cpp, and with this branch applied it also conflicts in GuestMemory.cpp (both add a check function in the same place), so whichever of the two is merged second needs a rebase of that test file. Four further pull requests show these names only as unchanged context or as other calls: #19183 and #23770 call sceKernelMapNamedDirectMemory and sceKernelMapNamedFlexibleMemory with short names in GuestMemory.cpp, #18585 calls sceKernelMapNamedDirectMemory in GuestKernelDirectMemoryMapping.cpp with the names "bad" and "test_dmem_named" (3 and 15 characters, so none is affected), and #19486 shows the definitions in its patch, but its head is identical to main in Export.cpp and GuestMemory.cpp. With this branch applied to main, all 71 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 apart from #17718 and #21569 (and the old head of this pull request) none has more conflicting files with this branch than without it. 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:5207087529 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16945). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-11-08T00:08:57Z. --- ### What `sceKernelMapNamedDirectMemory` returned 0 for a name of 32 or more characters and named the range with the name cut to 31, and returned 0 for a NULL name. On a PS5 the mapping succeeds in both cases and the call returns `SCE_KERNEL_ERROR_ENAMETOOLONG` (0x8002003f, errno 63) for a name of 32 characters and `SCE_KERNEL_ERROR_EFAULT` (0x8002000e, errno 14) for a NULL name; the range stays mapped and has no name of its own (it reads `anon:` and hex digits), and a name of 31 characters is stored (lines 57 to 59 of the output in the first comment). This does the same: after a successful mapping, a name of 32 or more bytes returns `ENAMETOOLONG` and a NULL name returns `EFAULT`, and neither names the range. A test pins the three results, a non-null mapping in each case, and the name read back; it also pins that `sceKernelMapNamedFlexibleMemory` is unchanged. The debt entry in `docs/dev/debt/libkernel.md` states the measurement through a debt fragment. The NULL is what the probe passed. The probe's case 6.8 is labelled "name of 0 chars", but its table entry is `{0x33, 0, 64 * KB, 0}`, so the name argument is a NULL pointer, and the label comes from printing 0 for a NULL name (`mp[i].name ? strlen(mp[i].name) : 0` in the probe source in the first comment). The first version of this pull request returned `EFAULT` for an empty string and called that measured; the review pointed out that no probe case passes an empty string, so that is removed. An empty string is not measured and is unchanged here, and the entry says so. Not measured: a name of 33 or more characters (it follows from the 32-character case and from `sceKernelSetVirtualRangeName`, whose limit is the same 31 characters), an empty string, `sceKernelMapNamedFlexibleMemory` (unchanged, and it still cuts a longer name to 31 characters here), a title process, and other firmware. The range without a name reads as empty here where the console reports `anon:` and hex digits; that is not changed. `git grep` finds no call of `sceKernelMapNamedDirectMemory` in this repository outside its definition, its declaration and tests, and no test other than the new one passes NULL. #16869 is merged, so this branch is rebuilt on current `main` and no longer depends on it. ### 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-07 at 19:25 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 of an own 4 MiB direct memory block with protection 0x33 and alignment 0x10000, and the name was read back with `sceKernelVirtualQuery`. The probe source and its raw output are in the first comment. | Call | PS5, payload process, firmware 11.60 | AnyPS5 `main` before | here | |---|---|---|---| | name of 31 characters | 0, the name is stored (line 57) | 0 | 0 | | name of 32 characters | 0x8002003f, mapped, no name (`anon:...`, line 58) | 0, the name is cut to 31 | 0x8002003f, mapped, no name | | NULL name | 0x8002000e, mapped, no name (`anon:...`, line 59) | 0 | 0x8002000e, mapped, no name | | empty string | not measured | 0, stored as an empty name | unchanged | Red and green on one base: Windows 10 Pro (MinGW GCC, Release, `cmake -DBUILD_TESTING=ON`, `ninja -j4 guest_memory_tests`, `ctest -R ^guest_memory$`, one worktree, a checkout, cmake, ninja and ctest per phase), base `upstream/main` `fd6d6f4a8498`: on the base `guest_memory` passes (21:13 UTC on 2026-11-19); with the test commit `ee6651cb08cf` it fails (21:15 UTC; exit code 0xc0000409 and "Guest memory check failed at core/libs/tests/GuestMemory.cpp:286", the check of the call's result in the loop over the cases; the message does not name the case, and that it is the 32-character one follows from the order of the cases, where the first returns 0 on `main`); with the fix commit `528371df05c6` it passes (21:18 UTC); with the documentation commit `ccde1e977bd0` it passes (21:21 UTC). `tools/check_conventions.py --base fd6d6f4a8498` and `tools/debt_fold.py --check` pass on the head, and a merge into `upstream/main` `a410f24ddad` was checked with `git merge-tree` and is clean. The change is 3 files, +46/-2, 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/GuestMemory.cpp` and the fragment `docs/dev/debt/changes/fix-kernel-map-named-direct-memory-null-name.md`, a new file, for the entry of `sceKernelMapNamedDirectMemory` in `docs/dev/debt/libkernel.md`), found by reading the changed files of all 2028 open pull requests at about 22:31 to 22:50 UTC on 2026-11-19, by reading what they change in every file whose path contains `DirectMemory`, `GuestMemory`, `VirtualRange` or `NamedDirect` and in all debt files for `sceKernelMapNamedDirectMemory`, `NameMappedRange`, `CopyRangeName` and `MapNamedFlexibleMemory`, and by searching their titles and branch names for the same names, were checked on 2026-11-19 at about 23:06 UTC against `main` `a410f24ddad` together with this head: the branch is based on `fd6d6f4a849`, 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 `344e54d0f5b` of this pull request, which is not an ancestor of the new head. Two other pull requests carry changes to the same function: #17718 (`fix(libkernel): sceKernelMapNamedSystemFlexibleMemory maps and then rejects a name of 32 characters or a null name`) contains an earlier copy of the commits of this pull request (`ab942cf2991`, `03ccc499427`, `de6c7c5e3dc`, the variant with the empty-name result) in front of its own three commits, and so conflicts with this head in `Export.cpp` and `GuestMemory.cpp`; it has to be rebased onto the new head once this one is pushed. #21569 (`fix(libkernel): bound virtual range names as the console does`) adds a test function to `GuestMemory.cpp` and changes `Export.cpp`, and does not change a line that names these functions; it already conflicts with `main` in `Export.cpp`, and with this branch applied it also conflicts in `GuestMemory.cpp` (both add a check function in the same place), so whichever of the two is merged second needs a rebase of that test file. Four further pull requests show these names only as unchanged context or as other calls: #19183 and #23770 call `sceKernelMapNamedDirectMemory` and `sceKernelMapNamedFlexibleMemory` with short names in `GuestMemory.cpp`, #18585 calls `sceKernelMapNamedDirectMemory` in `GuestKernelDirectMemoryMapping.cpp` with the names "bad" and "test_dmem_named" (3 and 15 characters, so none is affected), and #19486 shows the definitions in its patch, but its head is identical to `main` in `Export.cpp` and `GuestMemory.cpp`. With this branch applied to `main`, all 71 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 apart from #17718 and #21569 (and the old head of this pull request) none has more conflicting files with this branch than without it. 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 -->
adriadam10 commented 2026-11-12 16:09:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-12T16:09:56Z.

Review: CHANGES_REQUESTED


Thanks, the 31 and 32 character results match probe cases 6.6 and 6.7. One measured claim does not match the probe, as @oneandonlydean noted:

  • Probe case 6.8 is labelled "name of 0 chars", but its table entry is {0x33, 0, 64 * KB, 0}: the name argument is NULL, not "". What the console measured is NULL name → 0x8002000e with the range mapped and unnamed.
  • This PR keeps NULL returning 0 (Export.cpp:360, if (result == 0 && name)) and returns EFAULT for "", which no probe case covers. The PR body, the test (GuestMemory.cpp:254) and the debt entry (libkernel.md:209) all present that as measured.

To fix, either:

  • re-measure with a real "" argument and keep EFAULT if the console returns it, or
  • make a NULL name return EFAULT after the mapping as measured, drop the "" claim, and say NULL in the body, test and debt entry (check that no internal caller of sceKernelMapNamedDirectMemory passes NULL).

Please also say that names longer than 32 characters are inferred from the 32 character case, or add a 33 character probe.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5877841583 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16945#pullrequestreview-5877841583). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-11-12T16:09:56Z. **Review:** CHANGES_REQUESTED --- Thanks, the 31 and 32 character results match probe cases 6.6 and 6.7. One measured claim does not match the probe, as @oneandonlydean noted: - Probe case 6.8 is labelled "name of 0 chars", but its table entry is `{0x33, 0, 64 * KB, 0}`: the name argument is NULL, not `""`. What the console measured is NULL name → `0x8002000e` with the range mapped and unnamed. - This PR keeps NULL returning 0 (`Export.cpp:360`, `if (result == 0 && name)`) and returns `EFAULT` for `""`, which no probe case covers. The PR body, the test (`GuestMemory.cpp:254`) and the debt entry (`libkernel.md:209`) all present that as measured. To fix, either: - re-measure with a real `""` argument and keep `EFAULT` if the console returns it, or - make a NULL name return `EFAULT` after the mapping as measured, drop the `""` claim, and say NULL in the body, test and debt entry (check that no internal caller of `sceKernelMapNamedDirectMemory` passes NULL). Please also say that names longer than 32 characters are inferred from the 32 character case, or add a 33 character probe.
MarcZX10 commented 2026-11-20 05:00:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T05:00:20Z.

Review: APPROVED


Reviewed — looks good

The change at head ccde1e977bd0ba6279ce7e41b8607f416b395c70 matches its stated behavior; I found no verified blocking defects in the changed code.

What I ran

Read the prepared diff and all three changed files at the pinned head, plus the relevant name-copying helper and its existing virtual-range-name caller. No commands or tests were run during this review; test results in the PR description are author-reported.

Results

Check Result Note
Changed code review passed All three changed files were read
Tests in this review not run Reported test runs were not reproduced
Other platforms and console behavior not run See Not verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests were run. The PR description reports Windows guest_memory and convention/debt checks passing, and PS5 firmware 11.60 payload measurements; these reports were not independently verified. Title-process behavior, other firmware, and Linux/macOS were not tested in this review. All files listed as reviewed in manifest.json were read: core/libs/prx/libkernel/DirectMemory/Export.cpp, core/libs/tests/GuestMemory.cpp, and docs/dev/debt/changes/fix-kernel-map-named-direct-memory-null-name.md. No files were excluded by the manifest.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5987743103 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16945#pullrequestreview-5987743103). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T05:00:20Z. **Review:** APPROVED --- # Reviewed — looks good The change at head `ccde1e977bd0ba6279ce7e41b8607f416b395c70` matches its stated behavior; I found no verified blocking defects in the changed code. ## What I ran Read the prepared diff and all three changed files at the pinned head, plus the relevant name-copying helper and its existing virtual-range-name caller. No commands or tests were run during this review; test results in the PR description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | All three changed files were read | | Tests in this review | not run | Reported test runs were not reproduced | | Other platforms and console behavior | not run | See Not verified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests were run. The PR description reports Windows `guest_memory` and convention/debt checks passing, and PS5 firmware 11.60 payload measurements; these reports were not independently verified. Title-process behavior, other firmware, and Linux/macOS were not tested in this review. All files listed as reviewed in `manifest.json` were read: `core/libs/prx/libkernel/DirectMemory/Export.cpp`, `core/libs/tests/GuestMemory.cpp`, and `docs/dev/debt/changes/fix-kernel-map-named-direct-memory-null-name.md`. No files were excluded by the manifest. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 13:50:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:50:37Z.

Review: COMMENTED


The Linux integration build passed the registered GuestMemory CTest, including the added named-memory mapping cases.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6171071137 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16945#pullrequestreview-6171071137). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T13:50:37Z. **Review:** COMMENTED --- The Linux integration build passed the registered GuestMemory CTest, including the added named-memory mapping cases. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/16945:upstream-pr/16945'
git switch 'upstream-pr/16945'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/16945'
git switch 'upstream-pr/16945'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/16945'
git switch 'upstream-pr/16945'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/16945'
git switch 'main'
git merge --squash 'upstream-pr/16945'
git switch 'main'
git merge --ff-only 'upstream-pr/16945'
git switch 'main'
git merge 'upstream-pr/16945'
git push origin 'main'
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!16945
No description provided.