feat(libkernel): direct memory mappings on macOS hosts #14466

Merged
oneandonlydean merged 1 commit from upstream-pr/14466 into main 2026-11-02 22:37:13 +00:00
oneandonlydean commented 2026-11-01 14:43:35 +00:00 (Migrated from github.com)

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 sceKernelMunmap calls to the current integer-address signature. The original commit is c28643f3e5; this carry is based on ac26e59d9a.

Tested

Linux x86-64, on main ac26e59d9a: build OK; the focused tests guest_memory, guest_mmap_fixed_anonymous, guest_amm_placement, guest_kernel_stack_protect, guest_jit_shared_memory, guest_mprotect_unmapped and guest_memory_lifetime all pass (7/7). guest_arena_* is registered only on Apple, so it did not run here. There is no macOS guest_memory run 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 DoMprotect and 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.py and git diff --check pass.

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, and guest_arena_*. The new checks run inside guest_memory. Full macOS library qualification needs the current macOS integration stack; relinker-only macOS results do not cover these changes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5108417137 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14466). Originally posted by [oneandonlydean](https://github.com/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 `sceKernelMunmap` calls to the current integer-address signature. The original commit is c28643f3e5da3fbcea3d14da334096a3f88fab84; this carry is based on ac26e59d9abf03805477b593f4d31294c185f442. ### Tested Linux x86-64, on main ac26e59d9a: build OK; the focused tests `guest_memory`, `guest_mmap_fixed_anonymous`, `guest_amm_placement`, `guest_kernel_stack_protect`, `guest_jit_shared_memory`, `guest_mprotect_unmapped` and `guest_memory_lifetime` all pass (7/7). `guest_arena_*` is registered only on Apple, so it did not run here. There is no macOS `guest_memory` run 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 `DoMprotect` and 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.py` and `git diff --check` pass. 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`, and `guest_arena_*`. The new checks run inside `guest_memory`. Full macOS library qualification needs the current macOS integration stack; relinker-only macOS results do not cover these changes. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-02 05:49:41 +00:00 (Migrated from github.com)

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_map for hinted and fixed mappings, a memory entry per backing, a MapFixedNoReplace helper, 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 passed guest_memory, which shares the changed test file. The Apple branches were read, not compiled or run.

What I ran

  • Head e6af0135e6a627bf817d89deb5b2fa936d82f36a; base d8b60b46ed425b117b6fae18900fe6ab81ed6661. 2 files, +105/-11: libkernel/DirectMemory/DirectMemory.cpp (the Apple branches and the shared paths that now include __APPLE__) and core/libs/tests/GuestMemory.cpp (+45: CheckDirectMemoryBecomesExecutable, CheckDirectMemoryReleasesHostDescriptors, and #ifndef __APPLE__ guards around CheckGuestModuleUsesFlexibleMemory).
  • Read the whole DirectMemory.cpp diff, including MapAtOrAbove, MapFixedNoReplace, the backing's memory entry (create, map, release), MapPlaced, AddMapping, UnmapRegistered and Unmap, and the whole test diff.
  • Read-only checks from the trusted main checkout: diff check, conventions and PR template, and the stack check all passed. The ABI audit is not applicable.
  • Hosted: the Windows CTest run passed 3 of 3 cases: guest_memory, guest_mmap_fixed_anonymous and check_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.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed conventions check from the main checkout
Mergeability and dependencies passed stack check passed
Shared placement logic (Windows and Linux) passed by reading MapPlaced keeps MAP_FIXED on Windows and MAP_FIXED_NOREPLACE on Linux, as before; only the Apple branch is new
Apple mapping logic (mach_vm_map flags, memory entry lifetime, MapFixedNoReplace errno mapping) passed by reading not compiled or run on macOS
guest_memory (hosted, Windows) passed the shared test file, including the new unguarded execution check, passed on the Windows x86-64 runner
Apple build (SDK headers, mach_error_string, MAP_MEM_NAMED_CREATE) not verified no macOS build
Write-watch registration on Apple (WatchMapping, MapAligned) not verified the Apple write-watch backend was not read
New macOS tests not run no macOS job runs guest tests on this head
ABI audit not applicable no export changed
Build and runtime tests (Linux) not run Linux is skipped on pull requests
Negative controls not run no local build
Hosted CI passed (Windows) windows passed (3/3 cases); linux, register-context, relinkers and write-watch skipped
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

  • No hosted job compiles or runs the Apple branches on this head, so they are unverified until a macOS build runs them.
  • CheckDirectMemoryBecomesExecutable writes and runs x86-64 bytes (b8 2a 00 00 00 c3, then b8 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

Not verified

  • Whether the Apple branches compile against the macOS SDK.
  • The Mach semantics the code relies on: VM_FLAGS_FIXED without overwrite for MapFixedNoReplace, shared memory-entry mappings, and VM_INHERIT_SHARE.
  • Executable mappings under Apple's W^X rules, and any MAP_JIT requirement on Apple Silicon.
  • The Apple write-watch backend.

To get this to a good state

  • Nothing blocking. A macOS build and run of guest_memory at this head would settle the Apple paths. Also state or guard the architecture of the new execution check.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5732561082 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14466#pullrequestreview-5732561082). Originally posted by [MarcZX10](https://github.com/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_map` for hinted and fixed mappings, a memory entry per backing, a `MapFixedNoReplace` helper, 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 passed `guest_memory`, which shares the changed test file. The Apple branches were read, not compiled or run. ## What I ran - Head `e6af0135e6a627bf817d89deb5b2fa936d82f36a`; base `d8b60b46ed425b117b6fae18900fe6ab81ed6661`. 2 files, +105/-11: `libkernel/DirectMemory/DirectMemory.cpp` (the Apple branches and the shared paths that now include `__APPLE__`) and `core/libs/tests/GuestMemory.cpp` (+45: `CheckDirectMemoryBecomesExecutable`, `CheckDirectMemoryReleasesHostDescriptors`, and `#ifndef __APPLE__` guards around `CheckGuestModuleUsesFlexibleMemory`). - Read the whole `DirectMemory.cpp` diff, including `MapAtOrAbove`, `MapFixedNoReplace`, the backing's memory entry (create, map, release), `MapPlaced`, `AddMapping`, `UnmapRegistered` and `Unmap`, and the whole test diff. - Read-only checks from the trusted main checkout: diff check, conventions and PR template, and the stack check all passed. The ABI audit is not applicable. - Hosted: the Windows CTest run passed 3 of 3 cases: `guest_memory`, `guest_mmap_fixed_anonymous` and `check_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. - No MarcZX10 review at this head. ## Results | Check | Result | Note | | --- | --- | --- | | Diff check | passed | | | Conventions and PR template | passed | conventions check from the main checkout | | Mergeability and dependencies | passed | stack check passed | | Shared placement logic (Windows and Linux) | passed by reading | `MapPlaced` keeps `MAP_FIXED` on Windows and `MAP_FIXED_NOREPLACE` on Linux, as before; only the Apple branch is new | | Apple mapping logic (`mach_vm_map` flags, memory entry lifetime, `MapFixedNoReplace` errno mapping) | passed by reading | not compiled or run on macOS | | `guest_memory` (hosted, Windows) | passed | the shared test file, including the new unguarded execution check, passed on the Windows x86-64 runner | | Apple build (SDK headers, `mach_error_string`, `MAP_MEM_NAMED_CREATE`) | not verified | no macOS build | | Write-watch registration on Apple (`WatchMapping`, `MapAligned`) | not verified | the Apple write-watch backend was not read | | New macOS tests | not run | no macOS job runs guest tests on this head | | ABI audit | not applicable | no export changed | | Build and runtime tests (Linux) | not run | Linux is skipped on pull requests | | Negative controls | not run | no local build | | Hosted CI | passed (Windows) | windows passed (3/3 cases); linux, register-context, relinkers and write-watch skipped | <details><summary>Read-only check output</summary> 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. </details> ## 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** - No hosted job compiles or runs the Apple branches on this head, so they are unverified until a macOS build runs them. - `CheckDirectMemoryBecomesExecutable` writes and runs x86-64 bytes (`b8 2a 00 00 00 c3`, then `b8 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 - Production: https://github.com/boykopovar/AnyPS5/blob/e6af0135e6a627bf817d89deb5b2fa936d82f36a/core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp - Test: https://github.com/boykopovar/AnyPS5/blob/e6af0135e6a627bf817d89deb5b2fa936d82f36a/core/libs/tests/GuestMemory.cpp - Windows job log: check-run `windows` on e6af0135e6a627bf817d89deb5b2fa936d82f36a ## Not verified - Whether the Apple branches compile against the macOS SDK. - The Mach semantics the code relies on: `VM_FLAGS_FIXED` without overwrite for `MapFixedNoReplace`, shared memory-entry mappings, and `VM_INHERIT_SHARE`. - Executable mappings under Apple's W^X rules, and any `MAP_JIT` requirement on Apple Silicon. - The Apple write-watch backend. ## To get this to a good state - Nothing blocking. A macOS build and run of `guest_memory` at this head would settle the Apple paths. Also state or guard the architecture of the new execution check.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!14466
No description provided.