feat(libkernel): direct memory mappings on macOS hosts #14466
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14466"
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 oneandonlydean on 2026-11-01T14:43:35Z.
What
Carries #7631 by @mugurc, with credit.
Use named Mach memory entries for direct-memory backing on macOS and place direct and flexible mappings through the guest arena, with Mach fallbacks for hinted and fixed no-overwrite mappings. Retain current main's Apple write-watch protection and file-backed mapping implementation, Linux and Windows behavior, and Emscripten placement behavior.
Carry the original executable-mapping and descriptor-release checks, updating their two
sceKernelMunmapcalls to the current integer-address signature. The original commit isc28643f3e5; this carry is based onac26e59d9a.Tested
Linux x86-64, on main
ac26e59d9a: build OK; the focused testsguest_memory,guest_mmap_fixed_anonymous,guest_amm_placement,guest_kernel_stack_protect,guest_jit_shared_memory,guest_mprotect_unmappedandguest_memory_lifetimeall pass (7/7).guest_arena_*is registered only on Apple, so it did not run here. There is no macOSguest_memoryrun yet: full macOS qualification needs the current macOS integration stack, and relinker-only coverage does not cover these changes. Windows was not built.Source checks confirm that the selected Linux, Windows and Emscripten production source matches the base after substituting the fixed-placement local, and that
DoMprotectand file-backed mapping remain byte-identical to the base. The Apple source selects the Mach backing/map/release paths and both current write-watch protection calls. Both carried checks remain defined and called.tools/check_conventions.pyandgit diff --checkpass.Focused runtime checks requested:
guest_memory,guest_mmap_fixed_anonymous,guest_amm_placement,guest_kernel_stack_protect,guest_jit_shared_memory,guest_mprotect_unmapped,guest_memory_lifetime, andguest_arena_*. The new checks run insideguest_memory. Full macOS library qualification needs the current macOS integration stack; relinker-only macOS results do not cover these changes.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T05:49:41Z.
Review: COMMENTED
Reviewed — no blocking findings
This adds macOS host support to direct memory mappings: Mach
mach_vm_mapfor hinted and fixed mappings, a memory entry per backing, aMapFixedNoReplacehelper, and Apple branches in the arena and write-watch paths. The Apple code is compiled and run by no job on this head. The Windows run passedguest_memory, which shares the changed test file. The Apple branches were read, not compiled or run.What I ran
e6af0135e6a627bf817d89deb5b2fa936d82f36a; based8b60b46ed425b117b6fae18900fe6ab81ed6661. 2 files, +105/-11:libkernel/DirectMemory/DirectMemory.cpp(the Apple branches and the shared paths that now include__APPLE__) andcore/libs/tests/GuestMemory.cpp(+45:CheckDirectMemoryBecomesExecutable,CheckDirectMemoryReleasesHostDescriptors, and#ifndef __APPLE__guards aroundCheckGuestModuleUsesFlexibleMemory).DirectMemory.cppdiff, includingMapAtOrAbove,MapFixedNoReplace, the backing's memory entry (create, map, release),MapPlaced,AddMapping,UnmapRegisteredandUnmap, and the whole test diff.guest_memory,guest_mmap_fixed_anonymousandcheck_compile_test_the_changed_translation_units_are_taken_from_the_base. Linux and the relinker jobs are skipped on this head, so no macOS job ran.Results
MapPlacedkeepsMAP_FIXEDon Windows andMAP_FIXED_NOREPLACEon Linux, as before; only the Apple branch is newmach_vm_mapflags, memory entry lifetime,MapFixedNoReplaceerrno mapping)guest_memory(hosted, Windows)mach_error_string,MAP_MEM_NAMED_CREATE)WatchMapping,MapAligned)Read-only check output
Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: not applicable. Stack check: passed. Hosted:
gh api repos/boykopovar/AnyPS5/commits/e6af0135e6a627bf817d89deb5b2fa936d82f36a/check-runs, and the Windows job log.Negative control
Not run here. A negative control needs a macOS build and run, and code from this head is not run here.
Findings
Blocking
None.
Non-blocking
CheckDirectMemoryBecomesExecutablewrites and runs x86-64 bytes (b8 2a 00 00 00 c3, thenb8 2b ...) with no architecture guard. It passed on the Windows x86-64 runner. Run natively on an arm64 macOS host, the same bytes would not execute as the test expects. Either state which macOS architectures the guest tests target, or guard the check.Sources
github.com/boykopovar/AnyPS5@e6af0135e6/core/libs/prx/libkernel/DirectMemory/DirectMemory.cppgithub.com/boykopovar/AnyPS5@e6af0135e6/core/libs/tests/GuestMemory.cppwindowsone6af0135e6Not verified
VM_FLAGS_FIXEDwithout overwrite forMapFixedNoReplace, shared memory-entry mappings, andVM_INHERIT_SHARE.MAP_JITrequirement on Apple Silicon.To get this to a good state
guest_memoryat this head would settle the Apple paths. Also state or guard the architecture of the new execution check.