feat(libkernel): JIT shared memory on macOS hosts #7937
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7937"
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-19T15:04:59Z.
What
JIT shared memory (
sceKernelJitCreateSharedMemory,sceKernelJitCreateAliasOfSharedMemory,sceKernelJitMapSharedMemory) on macOS hosts. Onmain,Jit.cppcreates its object withmemfd_create, so libkernel does not compile on macOS (use of undeclared identifier 'MFD_CLOEXEC'). XPSemu (PPSA97358) maps QEMU's translation buffer through these calls.feat(libkernel): back JIT shared memory with an unlinked temporary file on macOS. The object is anmkstempfile in the temporary directory, unlinked at once and marked close-on-exec, the wayshm_openalready makes its anonymous objects on macOS (File/src/SharedMemory.cpp).fix(libkernel): make JIT shared memory views executable after mapping them on macOS. macOS refuses to create an executable shared file mapping (mmapreturnsEPERMforPROT_READ | PROT_EXECand for read-write-execute), butmprotectadds execute to the same mapping.DoMapShared, whose only caller is the JIT map, maps without execute and then applies the full protection on macOS.test(libkernel):guest_jit_shared_memoryruns on macOS. The case that maps a JIT descriptor through the guest'smmapis skipped there: file-backed guestmmapthrows on macOS (DoMapFileBacked_nid_no_patch), which is a separate topic.docs(debt): a macOS entry next to the JIT entry: the backing, the execute-after-map step, the Rosetta behaviour below, and the unsupportedmmapof a descriptor.Measured under Rosetta 2 with a standalone x86-64 program (the probe is attached below, not added): code written through a read-write view runs from a read-execute view of the same object the first time, but rewriting it after it has run leaves the old translation in place (the old value is returned again) until the read-execute view's protection changes. A single read-write-execute view sees its own rewrites. XPSemu and VLC map one read-write-execute view (
__wrap_mmapin theirps5/compat/mmap.c), so they are not affected. A title that writes through an alias and executes through another view after rewriting would run stale code; the debt entry says so.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) and #6836.guest_jit_shared_memory_tests: before this change libkernel does not compile on macOS; with it, the test passes: write through an alias and run through the executable view, one read-write-execute view,dup,dup2keeping the descriptor table in step, and the invalid arguments. Themmapcase is skipped on macOS.--macos --to-rosetta --macos-fixed-base 0x400000),APS5_TRACE_MEMORY=1: the title maps its 128 MiB translation buffer,map shared 0x7400000000+0x8000000 prot=0x7, runs 16 s, prepares and draws its first shaders, then stops at the MoltenVK pipeline error #6235 covers (output of type float4 is not compatible with a MTLPixelFormatR8Uint color attachment). Nothing past that is tested.picker/picker.bin).The probe (
clang -arch x86_64 probe.c && ./a.outon the M2):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)mainon macOS needs @mugurc's macOS series, as for the other macOS host changes)Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T18:41:55Z.
Rebase handoff — rebased onto current
main(authorship unchanged). One docs-debt conflict, unioned.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the four knownmainregressions (#5444 Mesa, #7584 BDA, #7766, #7784), none from this PR (the JIT shared-memory path is macOS-gated).To pick it up:
Head is
66df8ce42.Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-19T21:18:15Z.
Linux check of head
84746e14d8merged ontomainbf2c63f85. 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. This includes the newguest_shm_opencase, which runsmov eax, 42; retfrom an anonymousshm_openobject through a read-executemmap.__APPLE__branches are not compiled on Linux, so this run covers the shared test and the Linux paths only.AI-assisted: yes