Repository navigation
feat(libkernel): map files through the guest's mmap on macOS hosts - #7974
Conversation
…st's mmap on macOS
…execute after mapping
|
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.
|
MarcZX10
left a comment
There was a problem hiding this comment.
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_EXEC for the initial file mapping, applies the requested protection with mprotect, 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.
|
Linux check of head
AI-assisted: yes |
|
Checked the macOS path in |
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. feat(libkernel): JIT shared memory on macOS hosts #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 feat(libkernel): JIT shared memory on macOS hosts #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 AGC: run mesh-path draws on devices without mesh shaders through a compute pass and an indexed draw #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)