feat(libkernel): implement msync #1857
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1857"
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 hikazey on 2026-10-08T22:10:21Z.
What
Adds
msyncto libkernel, next tommap,munmapandmprotectinDirectMemory/PosixMemory.cpp. It follows FreeBSD 11'skern_msyncandvm_map_syncover the guest's mappings assceKernelVirtualQueryreports them:kern_msync. A range whose end wraps isEINVAL.MS_ASYNC | MS_INVALIDATEisEINVAL. Other flag bits are not checked, as in FreeBSD.ENOMEM. Length 0 checks the mapping that holds the address (vm_map_syncwidensstart == endto that entry). Reservations count as mapped, since FreeBSD has a map entry for them.mmaponly creates private anonymous mappings, so there are no file mappings to sync.MS_INVALIDATEon a mapped range throws. FreeBSD returnsEBUSYthere when the range holdsmlocked pages, and locked pages are not tracked. TheENOMEMcheck comes first, as invm_map_sync.One limitation is recorded in TechnicalDebt with the rest: a page
munmaped from inside a larger mapping still counts as mapped, becausesceKernelVirtualQuerykeeps reporting the whole mapping after a partial unmap (onmaintoo).EVO-PLAYER PPSA99039 v0.11.0 (sainsaji/EVO-PLAYER-PS5) imports it for a mapped-file benchmark (
projects/evoplayer/src/evo_iobench.c,msync(p, len, MS_SYNC)). It's also in the absent lists of other titles in #1578, where it was claimed.Tested
687c0f0f…5349,eboot.binand the bundledlibc.prxunwrapped from their SELFs), relinked with--windowson Windows 11. Onmain364a56b6with #1838, #1634, #1714 and #1641 merged locally (its earlier stops):FAIL: unresolved ELF import tZY4+SZNFhA from libkernel.prx(msync);KiJEPEWRyUY(sigaction, #1431).guest_msynctest (Windows and Linux): success for the whole range,MS_ASYNC, an unaligned address inside the mapping, a range crossing a page boundary, length 0, an unknown flag bit and a reserved range, with errno untouched on success;EINVALforMS_ASYNC | MS_INVALIDATEand a wrapping range;ENOMEMaftermunmapfor the start, a range, length 0 andMS_INVALIDATE; theMS_INVALIDATEthrow on a mapped range.guest_msync5/5; full suite 482/482. Mutations, each with the test kept, all fail: the mapped check removed, theMS_ASYNC | MS_INVALIDATEcheck removed, the throw moved before the mapped check, and the wrap check removed.guest_msync5/5; full suite 488/488; the mapped-check mutation fails.mainae91d978:guest_msync3/3 on Windows;tools/check_conventions.py --base origin/mainpasses.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-08T22:10:43Z.
Progress report (
8d47cfb→0bff6da)➖ System libraries: 85.46% (+0.0%, +1 implemented functions)
✅ 1 implemented
msync_nid_postfixImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T22:21:07Z.
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/DirectMemory/PosixMemory.cppL1-2, L17, L115core/libs/prx/libkernel/DirectMemory/PosixMemory.cppL17Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T21:53:07Z.
Checked
msyncagainst FreeBSD 11kern_msync/vm_map_sync(page rounding, wrap andMS_ASYNC | MS_INVALIDATEgiveEINVAL, unmapped range givesENOMEM,MS_INVALIDATEon a mapped range throws).The branch conflicted with
mainonly by adjacency (mlock/munlockinPosixMemory.cpp, the test block inlibkernel/CMakeLists.txt). I rebased it keeping both sides, no logic changes. Full build and ctest on the rebased head: 525/525,guest_msyncpasses, and without the change it doesn't link, so it does exercise the code.