feat(libkernel): implement mlock and munlock #1673
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1673"
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 SleglJan on 2026-10-08T16:11:35Z.
What
Adds the POSIX
mlockexport to libkernel as a wrapper over the existingsceKernelMlock(#359), besidemunmapandmprotectinDirectMemory/PosixMemory.cpp: 0 on success, otherwise -1 with the guest errno taken from the kernel error code the sce form returns (EINVALfor a range that wraps around zero,ENOMEMfor an unmapped or reserved-only range,EPERMandEAGAINwhen the host refuses the lock), as FreeBSD 11'smlock(2)lists them. The signature is FreeBSD's,int mlock(const void *addr, size_t len); page rounding and a zero length at a page-aligned address returning 0 come fromsceKernelMlock. An unexpected host error still throws there.Second commit, asked for below:
munlock(OG4RsDwLguo) andsceKernelMunlock(xQIIfJ860sk, listed in aerolib), the same pair for unlocking. The host unlock ismunlockon Linux andVirtualUnlockper committed region on Windows, where pages that are not locked count as unlocked. Results follow FreeBSD 11'ssys_munlockandvm_map_unwire(vm_mmap.c,vm_map.c): 0 for a mapped range whether or not it is locked, a reserved-only range included,EINVALfor a range that wraps around zero,ENOMEMfor an unmapped range; an unexpected host error throws.sceKernelMlockshares the page rounding with it.Overlap: #1633 (
madvise) and #1857 (msync) add functions at the same place inPosixMemory.cpp; adjacent additions, whichever merges second needs a one-line rebase.In the Linux audit of the homebrew catalog (#1578),
mlockwas absent for 14 of the 34 relinked titles. A bundledlibChakraCore.prximports bothmlockandmunlock(@EdouardSence below).Tested
BUILD_TESTING=ONandANYPS5_ENABLE_SPIRV_TOOLS=ONon this branch rebased ontomaind70b8998:guest_mlockandguest_memorypass--repeat until-fail:3;tools/check_test_registration.pyandtools/check_conventions.py --base upstream/mainpass.guest_mlock: thesceKernelMlockcases ofguest_memorythrough the POSIX form (without the Windows working-set check): zero length at an aligned address with errno untouched, an unaligned start inside a flexible mapping (on LinuxVmLckgrows by the rounded length), locking twice; -1 with errno 22 for a range wrapping around zero, errno 12 for a reserved-only range and for the mapping aftersceKernelMunmap. Written before the implementation; it failed on the unresolved export and passes with it.munlockcases in the same test, written first and failing on the unresolved export: zero length with errno untouched; an unaligned start whose rounded range unlocks the whole mapping (VmLckback to its starting value on Linux); unlocking an already unlocked range returns 0 with errno untouched; lock one page, unlock it (VmLckup by one page, then back); -1 with errno 22 for a range wrapping around zero; 0 for a reserved-only range; -1 with errno 12 for the mapping aftersceKernelMunmap.libkernel.prxexports the four NIDs (mTBZfEal2Bw,OG4RsDwLguo,3k6kx-zOOSQ,xQIIfJ860sk).tools/import_audit.pyon five of the 14 catalog titles, absent imports onmain4b005b22→ the mlock commit: PPSA17641 SymphonyStation5 35 → 34, PPSA74126 Stremio Plus 49 → 48, PPSA97510 PSXS5 72 → 71, PPSA99000 ProsperoStore 40 → 39, PPSA99001 ProsperoRadio 64 → 63. None of them loads yet; the remaining imports are listed in #1578.main6b56175a, run 37822087281:guest_mlockpasses its three repeats, full suite 474/474. hikazey ran it merged ontomain6b56175aon Windows 11 with MinGW-w64 GCC 15.2.0 (the CI toolchain):guest_mlock5/5, the full suite 474/474, and the test fails 5/5 whenSetErroris given thesceKernelMlockresult without the& 0xffff(comment).maind70b8998, run 37935576283:guest_mlockandguest_memorypass, full suite 508/508; Linux and the relinker matrix pass in the same run..Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T17:08:37Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libkernel/CMakeLists.txtL438core/libs/prx/libkernel/DirectMemory/PosixMemory.cppL7, L99Imported from boykopovar/AnyPS5. Originally posted by hikazey on 2026-10-08T18:21:40Z.
Windows run (the description lists Linux only): Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7, the CI build), Release, configured like CI, Ryzen 9 5900X. This commit merged onto
main6b56175a, which merges cleanly.guest_mlockSetError(result)without& 0xffff, test keptSo the POSIX form works on top of the Windows
sceKernelMlockpath (VirtualLock) as well: zero length, the unaligned start inside a flexible mapping, locking twice, and errno 22/12 for the wrapping, reserved-only and unmapped ranges.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-08T18:27:18Z.
Thanks for the Windows run, especially the mutation check. Added to the Tested section.
Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-09T10:37:42Z.
Title evidence: Ratchet & Clank: Rift Apart (PPSA01474) needs
mlock.On
main43972e69the relinked title doesn't start:mTBZfEal2Bwismlock, imported by the title's bundledlibChakraCore.prx. The same module also importsmunlock(OG4RsDwLguo), which nothing exports either, so it fails on that symbol next. With this PR plus a local placeholder formunlock, the title loads and runs until a later, unrelated stop.Since
munlockis the counterpart of what this PR adds, would you add it here? Otherwise I can open a separate PR once this one is merged.Measured on Linux, RX 9070 XT. Tested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T13:16:00Z.
Progress report (
d70b899→1078608)📈 System libraries: 84.71% (+0.02%, +3 implemented functions)
✅ 3 implemented
mlock_nid_postfixmunlock_nid_postfixsceKernelMunlock_nid_postfixImported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-09T13:29:04Z.
Thanks for adding
munlock. Confirmed on Ratchet & Clank: Rift Apart (PPSA01474) with head10786087, on Linux with an RX 9070 XT.munlockplaceholder removed, the relinked title has no undefined imports left, and its bundledlibChakraCore.prxloads.guest_mlockpasses here.Tested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-09T13:36:45Z.
Thanks for the ChakraCore log line and for confirming the head.
munlock(OG4RsDwLguo) andsceKernelMunlock(xQIIfJ860sk, listed in aerolib) are in the second commit, so the pair matchesmlock/sceKernelMlock; the POSIX form wraps the sce form asmlockdoes. The host unlock ismunlockon Linux andVirtualUnlockon Windows, where a region that is only partly locked is unlocked page by page and an unmapped guest range is told apart from a reservation through libkernel's own registries, since both read as a reserved placeholder there. Results follow FreeBSD 11'ssys_munlockandvm_map_unwire: 0 for a mapped range whether or not it is locked, a reserved-only range included,EINVALfor a range that wraps around zero,ENOMEMfor an unmapped range.guest_mlockcovers them, on Linux withVmLckreturning to its starting value. Windows: the fork's Build workflow on head10786087merged ontomaind70b8998, run 37935576283:guest_mlockandguest_memorypass, full suite 508/508; Linux and the relinker matrix pass in the same run. Title and description updated.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T21:15:17Z.
Checked on Linux,
main+ this head: full build, ctest 521/521 (guest_mlockpasses; without the change it doesn't link, so the test needs it). The four NIDs match aerolib, and the errno mapping follows the cited FreeBSDsys_munlock/vm_map_unwire. The Windows path is covered by the fork run and @hikazey's run; thelinux/windowsjobs are skipped upstream by the current manual-build policy. Merging.Overlap with #1633 and #1857 in
PosixMemory.cppis adjacent only; whichever lands second needs a one-line rebase.