fix(libkernel): sceKernelReleaseDirectMemory returns 0 for a length of 0 #17553
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17553"
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-08T21:58:19Z.
What
sceKernelReleaseDirectMemoryreturnedEINVALfor a length of 0, andguest_memorypinnedRelease(0, 0)asEINVALwithout a console result. On a PS5, releasing a length of 0 at an aligned start returns 0, while a length of 1 and an unaligned start (phys + 1, 16 KiB) returnEINVAL, and releasing a block and releasing it again return 0 (cases 9.44 to 9.48, lines 48 to 52 of the raw output). This returns 0 for a length of 0 at an aligned start before the range is claimed; the twoEINVALcases and a start below 0 or unaligned are unchanged. The test now expectsRelease(0, 0)to return 0 and pins the five measured results. A debt fragment,docs/dev/debt/changes/fix-kernel-release-direct-memory-zero-length.md, changes thesceKernelReleaseDirectMemoryentry ofdocs/dev/debt/libkernel.mdto record the measurement; an unaligned start with a length of 0, a start at the end of direct memory and a title process were not measured.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 08:55 UTC. A title process may differ. The calls released a block of the probe's own 4 MiB direct memory; the cases are 9.44 to 9.48, lines 48 to 52 of the raw output in the first comment.mainbeforesceKernelReleaseDirectMemory(phys, 0)EINVALsceKernelReleaseDirectMemory(phys, 1)EINVALsceKernelReleaseDirectMemory(phys + 1, 16 KiB)EINVALsceKernelReleaseDirectMemory(phys, 16 KiB), then againOn this branch,
maineb2d16b170b, on 2026-11-17: with only the test commitb220bf30d12,guest_memoryfails on Windows (MinGW, Release, 23:01 to 23:05 UTC, one run) withGuest memory check failed at core/libs/tests/GuestMemory.cpp:1052, which isRelease(0, 0) == 0, and on Linux (WSL, Release, from 22:29 UTC, one run) withSubprocess aborted; with the fix commit81531bed9b8it passes in 3 of 3 runs on Linux, and with the docs commit15a8b0b46f8it passes in 1 run on Windows (23:04 to 23:07 UTC) and in 3 of 3 runs on Linux. The Linux commits were applied withgit amto a clean checkout ofmain.tools/check_conventions.py --base upstream/mainpasses on each of the three commits on Linux. The probe source and its raw output are in the first comment. Not tested: macOS, the CI runner, a title process and any other firmware.Overlap (2026-11-18, list of open pull requests read from 23:59 UTC on 2026-11-17 to 00:16 UTC, test-merged at 00:18 UTC against
main4568142448e, head15a8b0b46f84): of the 1786 open pull requests, 12 changecore/libs/prx/libkernel/DirectMemory/Export.cpp,core/libs/tests/GuestMemory.cpporcore/libs/prx/libkernel/DirectMemory/MemoryPool.cpp(#22051, #22040, #22013, #21569, #20349, #19183, #18293, #17936, #17718, #16945, #16372 and #12315), and each was merged with and without this branch. None conflicts only with this branch: five conflict withmainby themselves (#21569, #17718 and #16945 inDirectMemory/Export.cpp, #18293 inWindowsMappings.hpp, #12315 inlibSceLibreSsl3) and the other seven merge cleanly with and without it. None of them changessceKernelReleaseDirectMemory; #22013, #20349, #17718, #16945 and #12315 only add or keep calls of it in tests, and the hunk of #19183 sits insceKernelCheckedReleaseDirectMemory. The branch no longer editsdocs/dev/debt/libkernel.md, so the debt lines of #16869 (merged on 2026-11-12) and #16945 no longer meet this change, and no open pull request changes a debt line that namessceKernelReleaseDirectMemory.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 MarcZX10 on 2026-11-21T11:58:31Z.
Review: APPROVED
Reviewed — looks good
The change matches the documented PS5 payload observation, validates the range before returning success for zero length, and adds regression coverage for the changed behavior.
What I ran
Reviewed head
15a8b0b46f84bb8dfc86c39a63ce89e8fb1108a0against the prepared diff. No tests or builds were run. Readcore/libs/prx/libkernel/DirectMemory/Export.cpp,core/libs/tests/GuestMemory.cpp, anddocs/dev/debt/changes/fix-kernel-release-direct-memory-zero-length.md; the complete text of each changed file was available. The excluded-file list was not available as a separate artifact.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author reports PS5 firmware 11.60 behavior and host test runs; these were not independently reproduced. No tests, builds, CI, title-process behavior, or other firmware were checked. No claims are made about excluded files.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T12:20:20Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the targeted implementation and tests support the reported zero-length behavior.
What I ran
Reviewed head
b561ad37603674c3f66d52781cacbe48b8ef2ea0using the prepared diff andrepo_read.py. No commands or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests were run independently. The author reports PS5 measurements on firmware 11.60 in a payload process and host test runs; these were not independently verified. The changed files listed in the manifest were read:
core/libs/prx/libkernel/DirectMemory/Export.cpp,core/libs/tests/GuestMemory.cpp, anddocs/dev/debt/changes/fix-kernel-release-direct-memory-zero-length.md. No changed files were excluded.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:50:39Z.
Review: COMMENTED
The Linux integration build passed the registered GuestMemory CTest, including zero-length release and neighboring argument checks.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T14:08:03Z.
Review: APPROVED
I read the diff at
b561ad3760. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged intomainat6c6b29320fetogether with other open PRs (so not an isolated build).guest_memory: pass on both.main's, the same test fails too.Not checked: a console.
AI-assisted: yes (Claude Code)
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.