feat(libkernel): add munlockall export #5663
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5663"
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 al3w0f205 on 2026-10-14T05:16:20Z.
What
Adds the munlockall export (NpLBpgVV7PU, aerolib line 79270) following merged mlockall (#4386) for XPSemu (PPSA97358, QEMU os-posix.c), which imports both functions. Predicted stop on main:
FAIL: unresolved ELF import NpLBpgVV7PU from libkernel.prxImplementation follows FreeBSD 11.4 sys/vm/vm_mmap.c sys_munlockall (commit 8c639945a44588f6cfdddfb057bb5aad88735da0): checks PRIV_VM_MUNLOCK, clears wire state and returns 0. To match, munlockall unlocks ranges locked by mlock (VirtualUnlock on Windows, tolerating ERROR_NOT_LOCKED for pages never locked, and munlockall on Linux).
Tested
Checklist
Imported from boykopovar/AnyPS5. Originally posted by AlexOfTheForest on 2026-10-14T06:05:08Z.
munlockall returns 0 without touching memory, and the debt entry says that's fine because mlockall keeps no locked state. But mlock does lock pages: sceKernelMlock_nid_postfix calls LockHostPages (host mlock / VirtualLock), and guest_mlock checks VmLck after it. So after mlock(range) followed by munlockall(), the range stays locked on the host.
FreeBSD 11.4 sys_munlockall unwires the whole user map (vm_map_unwire over vm_map_min..vm_map_max with VM_MAP_WIRE_HOLESOK), which includes ranges wired by mlock. To match, munlockall would need to unlock what mlock locked, either by tracking those ranges or by walking the guest mappings and unlocking each one (Windows VirtualUnlock fails with ERROR_NOT_LOCKED on pages that were never locked, so that error has to be tolerated there).
A test that does mlock → munlockall → LockedKilobytes() == lockedBefore would catch this. Also, sys_munlockall checks PRIV_VM_MUNLOCK first; returning 0 assumes a privileged process, like the madvise MADV_PROTECT entry says. Worth stating that in the debt entry too.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T12:43:36Z.
Progress report (
6239cef→e03e6f7)📈 System libraries: 88.7% (+0.01%, +2 implemented functions)
✅ 2 implemented
munlockall_nid_postfixsceKernelMunlockall_nid_postfixImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T12:45:30Z.
Review: CHANGES_REQUESTED
Thanks for the PR. One correctness problem, also raised by @AlexOfTheForest and still unanswered:
core/libs/prx/libkernel/DirectMemory/PosixMemory.cpp:227:munlockallreturns 0 without touching anything, on the premise thatmlockallkeeps no locked state. Butmlockdoes lock host pages (sceKernelMlock_nid_postfix→LockHostPages), somlock(range); munlockall();leaves the range locked. FreeBSD 11.4sys_munlockallunwires the whole user map, including ranges wired bymlock. It needs to unlock whatmlocklocked, either by tracking those ranges or by walking the guest mappings (on WindowsVirtualUnlockfails withERROR_NOT_LOCKEDfor pages never locked, so tolerate that).core/libs/tests/GuestMlock.cpp:143: the test only callsmunlockallwith nothing locked, so it passes with a no-op. Addmlock→munlockall→ check the locked amount (as the file already does aftermlock) is back to what it was before.docs/dev/debt/libkernel.md:165:sys_munlockallchecksPRIV_VM_MUNLOCKfirst; returning 0 assumes a privileged process, like themadviseMADV_PROTECTentry says. State that, and drop "sincemlockallkeeps no locked state" once the above is fixed.Also, the overlap bot lists #5643 touching the same debt lines; check it conflicts only by adjacency after you rebase.
Imported from boykopovar/AnyPS5. Originally posted by al3w0f205 on 2026-10-14T23:08:59Z.
Thanks @AlexOfTheForest and @adriadam10 for the thorough review and guidance!
All points addressed:
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T11:51:13Z.
Review: APPROVED
Re-checked the three points against the new head:
munlockallnow unlocks the rangesmlocklocked (tracked acrossLockHostPages/UnlockHostPages/sceKernelMunmap;::munlockall()on Linux,VirtualUnlocktoleratingERROR_NOT_LOCKEDon Windows),GuestMlockcoversmlock→munlockall→ locked amount back to the baseline, and the debt entry states thePRIV_VM_MUNLOCKassumption. Build and ctest (172 tests in libs/libkernel) pass,guest_mlockincluded; merging.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:08:27Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/Export.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/PosixMemory.cppdocs/dev/debt/libkernel.mdcore/libs/tests/GuestMlock.cppcore/libs/prx/libkernel/DirectMemory/Export.cppcore/libs/prx/libkernel/DirectMemory/PosixMemory.cppdocs/dev/debt/libkernel.md