feat(libkernel): map files through the guest's mmap on macOS hosts #7974
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7974"
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 DavidSamir on 2026-10-19T16:31:11Z.
What
On macOS the guest's
mmapof a file descriptor throws (DoMapFileBacked_nid_no_patch: "file-backed guest mmap is not supported on this host"), andPosixMemory.cppaccepts only shared memory objects that macOS never reports. So no regular file, anonymousshm_openobject or JIT shared memory descriptor can be mapped there. Dusklight (PPSA99305) needs it for SQLite's WAL index: without it SQLite reportsdisk I/O errorand the title's shader cache fails to start.This takes the Linux path on macOS:
feat(libkernel): check file and shared memory descriptors for the guest's mmap on macOS.PosixMemory.cpppins the descriptor, checks its access mode against the protection and accepts a shared memory object or a regular file, as on Linux. An anonymousshm_openobject on macOS is already an unlinked temporary file, so it passes as a regular file.feat(libkernel): map files through the guest's mmap on macOS, adding execute after mapping.DoMapFileBackedmaps shared or private as on Linux. macOS refuses to create an executable file mapping (EPERMforPROT_READ | PROT_EXEC), so the mapping is made without execute and then given the full protection withmprotect, which macOS allows. #7937 does the same for the JIT views.test(libkernel):guest_shm_openwritesmov eax, 42; retinto an anonymous object and runs it from a read-execute mapping of it (not on Windows, where an executable shared file mapping fails by design).docs(debt): a short macOS entry next to "Regular file mappings": the same checks as Linux, execute added after mapping, Rosetta keeping an old translation for code rewritten through another view (measured in #7937), and namedshm_openobjects still throwing.Tested
Apple M2, macOS 26, MoltenVK 1.4.x (Vulkan SDK 1.4.363), x86-64 build under Rosetta 2, Release, on
mainwith @mugurc's macOS series (ci/macos-series-2, whichmainalone needs to build on macOS), #7937 (without it libkernel does not compile on macOS) and #6836.guest_shm_open(with the new executable case)mmapguest_jit_shared_memory, with #7937's macOS skip of themmapcase removedguest_msyncThe other 35 libkernel/libc memory tests (
ctest -R "mmap\|shm\|msync\|mprotect\|munmap\|jit\|mlock\|flexible\|direct\|virtual_query\|savedata\|mapping\|memory" -E agc) give the same result with and without this PR.guest_memory_lifetime,guest_kernel_app_archive_mmapandguest_flexible_memory_declaredfail on macOS on both, so they are not caused by it.Dusklight (PPSA99305), relinked with
--macos --to-rosetta,APS5_TRACE_MEMORY=1:map fileline;SQLite version 3.51.3, thenFailed to start transaction: disk I/O error,Failed to open schema check transaction,Failed to validate schema; abort after 17 s.map file 0x201400000+0x204000 offset=0x0 prot=0x3, two more file mappings,SQLite cache init succeeded, then the title runs toAGC graphics: device does not support mesh shadersafter 22 s, which the mesh fallback in #6528 is about. Nothing past that is tested on this M2.Not tested: Linux and Windows code is unchanged. Once #7937 and this PR are both in, the macOS skip of
MmapOfTheDescriptorSharesTheObjectinGuestJitSharedMemory.cppcan go; I will send that one-line follow-up.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)mainalone)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T16:42:32Z.
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/DirectMemory.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppdocs/dev/debt/libkernel.mdcore/libs/tests/GuestShmOpen.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/PosixMemory.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/PosixMemory.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppcore/libs/prx/libkernel/DirectMemory/PosixMemory.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T16:44:48Z.
Review: COMMENTED
I reviewed the macOS-specific path and its interaction with #7937. This PR adds the file-backed mapping path while #7937 covers the JIT shared-memory mapping; the dependency is called out in the description. The executable-protection fallback removes
PROT_EXECfor the initial file mapping, applies the requested protection withmprotect, and unmaps on failure before registering the allocation. The reported M2 tests exercise the new regular-file and anonymous-object cases. I did not independently run the macOS tests.Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-19T21:07:33Z.
Linux check of head
758e22d4f4merged ontomainbf2c63f85(clean merge). Ubuntu 24.04 in WSL2, i7-11700F, GCC 13.3, Ninja, Release,BUILD_TESTING=ON.guest_shm_open,guest_jit_shared_memoryandguest_msyncpass in 3 runs of 3.guest_shm_opencase is compiled into the test that ran. It writesmov eax, 42; retinto an anonymousshm_openobject and calls it through a read-executemmap, and it returns 42 on Linux. The__APPLE__paths inDirectMemory.cppandPosixMemory.cppare not compiled here, so this run covers only the shared test case.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T11:48:19Z.
Checked the macOS path in
DoMapFileBacked(map withoutPROT_EXEC, thenmprotect,Unmapon failure before registering) and the widened descriptor checks inPosixMemory.cppagainst the Linux path, the new executable case inguest_shm_open, and the debt entry. Linux and Windows behaviour is unchanged; the macOS runs are the author's (M2, Rosetta 2) and the Linux run is also theirs; merged.