Repository navigation
Conversation
|
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.
|
…macOS hosts (@mugurc) Records that the fork carries mugurc's split-out direct memory pull request: its code was already here through his macOS series, so the merge changes no file, and the fork and the open pull request now share history for whichever is merged first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…macOS hosts (@mugurc) Records that the branch carries mugurc's split-out direct memory pull request, whose code it already had through his macOS series. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ba322f9 to
dccdf09
Compare
…macOS hosts (@mugurc) This branch already carried an earlier head of this PR; mugurc has pushed newer commits since, and this merge brings the branch up to them. The file-backed mapping takes the PR's layout, with its explicit error on hosts that are neither Linux, macOS nor Windows. In DoMprotect the PR would leave macOS a plain mprotect; this branch keeps mapping a host stack's unmapped pages before protecting them on macOS as on Linux (c3cdbe1), so main's host stack guard keeps working there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Direct memory, flexible memory and the mmap family map guest memory with Linux-only calls. On macOS: - the backing of a direct memory pool is a named Mach memory entry (mach_make_memory_entry_64 with MAP_MEM_NAMED_CREATE), mapped with mach_vm_map. macOS has no memfd, and a POSIX shared memory object does not work for guest code: an mprotect that adds execute to its mapping fails with EACCES, and code mapped executable from it does not run under Rosetta (SIGBUS). The entry is a Mach port, so a pool holds no file descriptor; - mappings are placed in the guest arena that macOS now reserves, as on Linux: a fixed mapping has to lie inside it, a mapping with a hint is allocated from the hint and one without an address from the arena's start, and an unmapped range goes back to the arena reserved. The fallbacks Linux has for a process without the arena use mach_vm_map: with VM_FLAGS_ANYWHERE, whose search starts at the hint, for a mapping above a hint, and without VM_FLAGS_OVERWRITE, which refuses an occupied range, for a fixed mapping that must not replace another (MAP_FIXED_NOREPLACE does not exist); - mprotect finds the guest module that holds a range through the emulated dl_iterate_phdr of macOS, as Linux finds it through the host one; - a protection change on a host thread's stack protects it directly: macOS maps the whole stack of a thread, the main thread's included, so it has no unmapped pages for the Linux retry to map first; - the mappings are tracked by the write watch and the physical span index, as on Linux; - a file-backed mapping is still refused with ENOTSUP: the Windows implementation now has its own branch instead of the one every host other than Linux took. guest_memory checks that direct memory made executable with sceKernelMprotect runs, and that allocating and releasing direct memory leaves no host descriptor open.
dccdf09 to
c28643f
Compare
|
Checked on Apple M2, macOS 27.2, x86_64 Release. Merged onto main 61ad086 plus the other macOS build fixes (#4627, #10362, #10366, #10369): |
imellag
left a comment
There was a problem hiding this comment.
Tested head c28643f3e5 on Apple M4 Pro, macOS 27.0.1, Apple clang, x86-64 Release under Rosetta 2.
Alone on main 3fcb5e4d76: DirectMemory/DirectMemory.cpp now compiles. The other 19 steps that fail on main on macOS still fail, and there are no new failures.
With the other open macOS build PRs (#10562, #10641, #10366, #10419, #7804, #10552, #4630, #10659, #10660; I resolved the conflicts of #10552 and #4630 with main locally), libkernel links and the guest tests run:
guest_mmap_fixed_anonymous,guest_amm_placement,guest_jit_shared_memory,guest_shm_open,guest_arena_available,guest_mprotect_unmapped,guest_memory_lifetimeandguest_flexible_memory_declaredpass.guest_memoryruns the two checks this PR adds without a failure. It then aborts later, inCheckMlock(GuestMemory.cpp:1695):sceKernelMlockon asceKernelReserveVirtualRangerange does not returnENOMEM.guest_mlock,guest_system_configuration,guest_kernel_is_stackandguest_credentialsabort too. Inguest_system_configuration,kern.proc.vmmapleaveserrnoat 2 becausesceKernelVirtualQueryfalls back to/proc/self/maps.
All five pass once your f66a4df741 (feat(libkernel): guest memory protection and VirtualQuery on macOS hosts, branch feat/libkernel-memory-protection-macos) is added on top; it applies cleanly to this stack. Apart from #7201, I couldn't find an open PR that carries it. Do you plan to open it? It seems to be the part of the series these tests still need on macOS.
guest_kernel_stack_protect still aborts with it: the child re-executes /proc/self/exe (GuestKernelStackProtect.cpp:529), which macOS doesn't have.
AI-assisted: yes
|
Since #10706 was merged, They are Checked on AI-assisted: yes |
|
After rebasing on main, GuestMemory.cpp no longer builds: With that change, plus a separate macOS fix for mlock on PROT_NONE ranges, AI-assisted: yes (Claude Code) |
What
Maps guest memory on macOS hosts. Direct memory, flexible memory and the mmap family used Linux-only calls (
memfd_create,MAP_FIXED_NOREPLACE, a hintedmmapthat searches upward), and placed mappings in the guest arena only on Linux. Part of the macOS series announced on #1 (#1 (comment)).mach_make_memory_entry_64withMAP_MEM_NAMED_CREATE), mapped withmach_vm_map. macOS has nomemfd, and a POSIX shared memory object does not work for guest code: anmprotectthat adds execute to its mapping fails withEACCES, and code mapped executable from it does not run under Rosetta (SIGBUS). The entry is a Mach port, so a pool holds no file descriptor.ArenaAvailable,ArenaCommit,ArenaForget, and theGuestArenaAllocateFromHintandGuestArenaAllocatebranches ofMapPlaced). Without them a mapping with no address came back from a plainmmapoutside the arena: @DavidSamir found that ccleste (PPSA59322) needs its 16 MiB ring fromsceKernelMapDirectMemoryinside 0x2_0000_0000-0x3_0000_0000 and stops before device creation otherwise (macOS support #1 (comment)), and that ten radv-based titles report no Vulkan device for the same reason (macOS support #1 (comment)).mach_vm_mapon macOS: withVM_FLAGS_ANYWHERE, whose search starts at the hint, for a mapping above a hint, and withoutVM_FLAGS_OVERWRITE, which refuses an occupied range, for a fixed mapping that must not replace another.mprotectfinds the guest module that holds a range through the emulateddl_iterate_phdrof macOS, as Linux finds it through the host one. The mappings are registered with the write watch (fix(libc): track never-collected pages in the macOS write watch #3703) and the physical span index, as on Linux.mprotectfails withENOMEM, stays Linux-only (MapUnmappedPagesis): macOS maps the whole stack of a thread. Under Rosetta, the main thread's stack at 8 MiB and at the 64 MiB limit and pthread stacks of 512 KiB and 64 MiB have no unmapped page, andmprotectover each whole stack succeeds.ENOTSUPon macOS. feat(libkernel): map regular files with mmap on Windows #6542 gave the Windows implementation the branch that every host other than Linux took; it now has its own, and the others keep the refusal.CheckGuestModuleUsesFlexibleMemoryis skipped on macOS: its module is a host-built library, which macOS's emulateddl_iterate_phdr(it lists relinked images only) does not show.Tested
macOS 26.5.1, Apple M5 Max, Apple clang 21, x86-64 build under Rosetta 2.
main7e2ba73 with the rest of the macOS series (ci/macos-series-2on my fork, which now includes #7937) and the libSceSsl change of #7332. The libraries do not link on macOS without the series.main7e2ba73. The one conflict was the Windows branch of~PhysicalBacking, which perf(libkernel): reuse released direct-memory sections that never held data #8857 gave a section pool; the macOS branch after it is unchanged.guest_memorywith the two checks this PR adds,guest_mmap_fixed_anonymous,guest_amm_placement,guest_kernel_stack_protectandguest_jit_shared_memorypass, and so doesguest_shm_opennow that the series carries feat(libkernel): JIT shared memory on macOS hosts #7937.ninja,ninja libsandctest -j4: 1798 tests, 1123 passed, 25 failed, the rest skipped (no Vulkan loader in the environment). Of the memory tests among them,guest_memory_lifetime,guest_flexible_memory_declaredandguest_kernel_app_archive_mmapfailed the same way before this rebase. The others failed before as well, or are new since my last run onmain3fd1cc3: tests and checksmainadded since then, andagc_driver_graphics, which now times out. I have not looked into the new ones yet.Earlier runs of this pull request:
main218aa8f, with feat(libc): reserve the guest arena on macOS #6124's arena reserved and the mapping paths of this PR left Linux-only,guest_memory(CheckReservationHintWithoutRoomAbove: a reservation hinted above the arena is not placed inside it),guest_mmap_fixed_anonymous(CheckPosixFixedAnonymousMapping: a fixedmmapinto a reservation fails) andguest_amm_placementfail. With them all three pass, andguest_memoryruns every arena check on macOS.guest_ampr_markers,guest_ampr_threads,guest_arena_available,guest_arena_unmappable,guest_arena_host,guest_arena_commit,guest_mlockandguest_mprotect_unmappedpass either way.guest_memorypass: direct memory mapped read-write, filled with code and made executable withsceKernelMprotectruns it, and 64 rounds of allocating, mapping and releasing direct memory leave no host descriptor open. With ashm_openbacking the first fails withEACCESand the second leaks one descriptor a round.sceKernelMapDirectMemorywithout an address, as ccleste's ring (onmain218aa8f): in six launches it was placed at 0x2_0000_0000 five times and at 0x2_00CB_0000 once, inside the window ccleste needs.mainc1ca834,libkerneldoes not compile on macOS with the earlier version of this PR (MapUnmappedPagesis undeclared, and the Windows file mapping code of feat(libkernel): map regular files with mmap on Windows #6542 is compiled); with this one it does, andguest_kernel_stack_protectpasses.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)