fix(libkernel): sceKernelMapNamedDirectMemory returns ENAMETOOLONG for a 32 character name and EFAULT for a NULL name #16945
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16945"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-11-08T00:08:57Z.
What
sceKernelMapNamedDirectMemoryreturned 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 returnsSCE_KERNEL_ERROR_ENAMETOOLONG(0x8002003f, errno 63) for a name of 32 characters andSCE_KERNEL_ERROR_EFAULT(0x8002000e, errno 14) for a NULL name; the range stays mapped and has no name of its own (it readsanon: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 returnsENAMETOOLONGand a NULL name returnsEFAULT, 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 thatsceKernelMapNamedFlexibleMemoryis unchanged. The debt entry indocs/dev/debt/libkernel.mdstates 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) : 0in the probe source in the first comment). The first version of this pull request returnedEFAULTfor 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 reportsanon:and hex digits; that is not changed.git grepfinds no call ofsceKernelMapNamedDirectMemoryin 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 currentmainand no longer depends on it.Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-07 at 19:25 UTC (theutcin thePROBEline 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 withsceKernelVirtualQuery. The probe source and its raw output are in the first comment.mainbeforeanon:..., line 58)anon:..., line 59)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), baseupstream/mainfd6d6f4a8498: on the baseguest_memorypasses (21:13 UTC on 2026-11-19); with the test commitee6651cb08cfit 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 onmain); with the fix commit528371df05c6it passes (21:18 UTC); with the documentation commitccde1e977bd0it passes (21:21 UTC).tools/check_conventions.py --base fd6d6f4a8498andtools/debt_fold.py --checkpass on the head, and a merge intoupstream/maina410f24ddadwas checked withgit merge-treeand 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.cppand the fragmentdocs/dev/debt/changes/fix-kernel-map-named-direct-memory-null-name.md, a new file, for the entry ofsceKernelMapNamedDirectMemoryindocs/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 containsDirectMemory,GuestMemory,VirtualRangeorNamedDirectand in all debt files forsceKernelMapNamedDirectMemory,NameMappedRange,CopyRangeNameandMapNamedFlexibleMemory, and by searching their titles and branch names for the same names, were checked on 2026-11-19 at about 23:06 UTC againstmaina410f24ddadtogether with this head: the branch is based onfd6d6f4a849, an ancestor of it, merges intomainwithout a conflict, andtools/debt_fold.py --checkapplies the fragment together with every other fragment onmainwithout an error. This branch replaces the earlier head344e54d0f5bof 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 inExport.cppandGuestMemory.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 toGuestMemory.cppand changesExport.cpp, and does not change a line that names these functions; it already conflicts withmaininExport.cpp, and with this branch applied it also conflicts inGuestMemory.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 callsceKernelMapNamedDirectMemoryandsceKernelMapNamedFlexibleMemorywith short names inGuestMemory.cpp, #18585 callssceKernelMapNamedDirectMemoryinGuestKernelDirectMemoryMapping.cppwith 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 tomaininExport.cppandGuestMemory.cpp. With this branch applied tomain, 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 withmainalone, 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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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:
{0x33, 0, 64 * KB, 0}: the name argument is NULL, not"". What the console measured is NULL name →0x8002000ewith the range mapped and unnamed.Export.cpp:360,if (result == 0 && name)) and returnsEFAULTfor"", 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:
""argument and keepEFAULTif the console returns it, orEFAULTafter the mapping as measured, drop the""claim, and say NULL in the body, test and debt entry (check that no internal caller ofsceKernelMapNamedDirectMemorypasses NULL).Please also say that names longer than 32 characters are inferred from the 32 character case, or add a 33 character probe.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T05:00:20Z.
Review: APPROVED
Reviewed — looks good
The change at head
ccde1e977bd0ba6279ce7e41b8607f416b395c70matches 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
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests were run. The PR description reports Windows
guest_memoryand 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 inmanifest.jsonwere read:core/libs/prx/libkernel/DirectMemory/Export.cpp,core/libs/tests/GuestMemory.cpp, anddocs/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.
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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.