Repository navigation
feat(libkernel): JIT shared memory on macOS hosts - #7937
adriadam10 merged 8 commits into
Conversation
|
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.
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.
|
|
Rebase handoff — rebased onto current Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, To pick it up: Head is |
…ared-memory-macos # Conflicts: # docs/dev/debt/libkernel.md
|
Linux check of head
AI-assisted: yes |
…ared-memory-macos # Conflicts: # docs/dev/debt/libkernel.md
Test report: the macOS JIT mapping on an M1 Pro with macOS 27The probe from the description, run on different hardware and a newer macOS: Apple M1 Pro, macOS 27.0.1, x86-64 under Rosetta 2 (
So the execute-after-map step also holds on macOS 27, and the stale-translation behaviour the debt entry describes is the same there. Two side observations from the same host, for the debt entry if useful:
Not run: this PR's AI-assisted: yes (Claude Code ran the probe and wrote the report). |
|
Re-checked after the red Linux run: the failing test ( |
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 fix(shader): preserve raw fragment exports for integer attachments #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)