test(libc): check that the macOS guest arena keeps free space beside host regions #7634

Merged
imellag merged 2 commits from upstream-pr/7634 into main 2026-10-20 15:47:19 +00:00
imellag commented 2026-10-18 18:36:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-18T18:36:36Z.


What

Follow-up to #6124, from my test comment there:

  • guest_arena_gap: the existing four guest_arena tests still pass when the mach_vm_region walk is disabled, because TryReserve records every 1 GiB chunk it cannot reserve as occupied. The new test reads the host map in a static initializer that runs before the arena reserves its range. It then takes the first free 64 KiB range that shares a 1 GiB chunk with a host region (outside the system reserved range) and requires a fixed guest mapping there to be accepted. If no host region shares a chunk with free space, it says so and passes, like guest_arena_unmappable. It also checks that the map really was read before the reservation.
  • docs/dev/debt/libc.md: on macOS 27.0.1 (M4 Pro) the unmappable range starts at 0xF_C000_0000, not 0x10_0000_0000. The extra GiB lies inside the system reserved range, so placement does not change; the line now records both measurements.

Tested

Apple M4 Pro, macOS 27.0.1 (26A434), Apple clang 21.0.0, CMake 4.4.4, Ninja 1.13.2. Standalone core/libs/tests/guest_arena project, built per architecture:

Build Result Free range found by gap
x86_64 under Rosetta, Release and Debug 5/5 0x2_0000_0000, beside dyld
native arm64, Release and Debug 5/5 for example 0x75_4000_0000, beside a host region at 0x75_5E00_0000

--repeat until-fail:20 on both Release builds: no failures.

Negative control: with HostMappings starting at ApplicationAreaEnd (the walk disabled), guest_arena_gap fails on both architectures with fixed guest mapping 0x200000000+0x10000 overlaps a host region in the guest arena (x86_64) and the same at 0x7180000000 (arm64), while the other four still pass.

The guest_arena tests are not part of CI; they run in the full macOS build and in the standalone project.

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:4911723776 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7634). Originally posted by [imellag](https://github.com/imellag) on 2026-10-18T18:36:36Z. --- ### What Follow-up to #6124, from [my test comment there](https://github.com/boykopovar/AnyPS5/pull/6124#issuecomment-6250875472): - `guest_arena_gap`: the existing four `guest_arena` tests still pass when the `mach_vm_region` walk is disabled, because `TryReserve` records every 1 GiB chunk it cannot reserve as occupied. The new test reads the host map in a static initializer that runs before the arena reserves its range. It then takes the first free 64 KiB range that shares a 1 GiB chunk with a host region (outside the system reserved range) and requires a fixed guest mapping there to be accepted. If no host region shares a chunk with free space, it says so and passes, like `guest_arena_unmappable`. It also checks that the map really was read before the reservation. - `docs/dev/debt/libc.md`: on macOS 27.0.1 (M4 Pro) the unmappable range starts at 0xF_C000_0000, not 0x10_0000_0000. The extra GiB lies inside the system reserved range, so placement does not change; the line now records both measurements. ### Tested Apple M4 Pro, macOS 27.0.1 (26A434), Apple clang 21.0.0, CMake 4.4.4, Ninja 1.13.2. Standalone `core/libs/tests/guest_arena` project, built per architecture: | Build | Result | Free range found by `gap` | |---|---|---| | x86_64 under Rosetta, Release and Debug | 5/5 | 0x2_0000_0000, beside dyld | | native arm64, Release and Debug | 5/5 | for example 0x75_4000_0000, beside a host region at 0x75_5E00_0000 | `--repeat until-fail:20` on both Release builds: no failures. Negative control: with `HostMappings` starting at `ApplicationAreaEnd` (the walk disabled), `guest_arena_gap` fails on both architectures with `fixed guest mapping 0x200000000+0x10000 overlaps a host region in the guest arena` (x86_64) and the same at 0x7180000000 (arm64), while the other four still pass. The `guest_arena` tests are not part of CI; they run in the full macOS build and in the standalone project. ### 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
github-actions[bot] commented 2026-10-18 18:54:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T18:54:14Z.


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.

Pull request Shared files not compared
PR 5021 docs/dev/debt/libc.md
PR 6226 docs/dev/debt/libc.md
PR 6469 docs/dev/debt/libc.md
PR 6819 docs/dev/debt/libc.md
PR 7081 docs/dev/debt/libc.md
PR 7473 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253796882 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7634#issuecomment-6253796882). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T18:54:14Z. --- <!-- pr-overlap --> 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. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `docs/dev/debt/libc.md` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `docs/dev/debt/libc.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `docs/dev/debt/libc.md` | | [PR 6819](https://www.github.com/boykopovar/AnyPS5/pull/6819) | `docs/dev/debt/libc.md` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `docs/dev/debt/libc.md` | | [PR 7473](https://www.github.com/boykopovar/AnyPS5/pull/7473) | `docs/dev/debt/libc.md` | | [PR 7715](https://www.github.com/boykopovar/AnyPS5/pull/7715) | `docs/dev/debt/libc.md` |
jotitadev commented 2026-10-18 19:35:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T19:35:26Z.

Review: COMMENTED


Ran this on a second Apple silicon machine and macOS version.

Machine: Apple M2 Max, macOS 27.2 (26B5112a), Apple clang 21.0.0, CMake 4.4.4, Ninja. Head f67e22173 merged onto main 4b4385cb7, standalone core/libs/tests/guest_arena project, native arm64 Release only (I did not run the x86_64/Rosetta build).

Build Result gap
main (4 tests) 4/4 n/a
PR 5/5, --repeat until-fail:20 clean free range 0x7300000000 beside host region 0x7336000000-0x7336400000 accepted
PR, HostMappings starting at ApplicationAreaEnd 4/5 fails: fixed guest mapping 0x7340000000+0x10000 overlaps a host region in the guest arena

So the negative control reproduces here too: only guest_arena_gap catches the disabled walk.

On the libc.md line: walking mach_vm_region from 0x2_0000_0000 in a plain arm64 process on this machine, the max-protection-none regions start at 0xF_C000_0000 (0xfc0000000-0x1000000000, then 0x1000000000-0x7000000000), the same as your M4 Pro on 27.0.1. With an M2 Max showing it too, the difference from the M1 Pro measurement looks like macOS 26.5 vs 27.x rather than the chip, if you want the line to say that.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5564621811 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7634#pullrequestreview-5564621811). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-18T19:35:26Z. **Review:** COMMENTED --- Ran this on a second Apple silicon machine and macOS version. **Machine:** Apple M2 Max, macOS 27.2 (26B5112a), Apple clang 21.0.0, CMake 4.4.4, Ninja. Head `f67e22173` merged onto `main` `4b4385cb7`, standalone `core/libs/tests/guest_arena` project, native arm64 Release only (I did not run the x86_64/Rosetta build). | Build | Result | `gap` | |---|---|---| | `main` (4 tests) | 4/4 | n/a | | PR | 5/5, `--repeat until-fail:20` clean | `free range 0x7300000000 beside host region 0x7336000000-0x7336400000 accepted` | | PR, `HostMappings` starting at `ApplicationAreaEnd` | 4/5 | fails: `fixed guest mapping 0x7340000000+0x10000 overlaps a host region in the guest arena` | So the negative control reproduces here too: only `guest_arena_gap` catches the disabled walk. On the `libc.md` line: walking `mach_vm_region` from 0x2_0000_0000 in a plain arm64 process on this machine, the max-protection-none regions start at **0xF_C000_0000** (`0xfc0000000-0x1000000000`, then `0x1000000000-0x7000000000`), the same as your M4 Pro on 27.0.1. With an M2 Max showing it too, the difference from the M1 Pro measurement looks like macOS 26.5 vs 27.x rather than the chip, if you want the line to say that. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
adriadam10 commented 2026-10-20 15:50:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T15:50:42Z.


Checked the new gap test against the arena logic (host map read before the reservation, a free 64 KiB range sharing a 1 GiB chunk with a host region, negative control confirmed by @jotitadev on an M2 Max) and the updated debt line; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6295012905 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7634#issuecomment-6295012905). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-20T15:50:42Z. --- Checked the new gap test against the arena logic (host map read before the reservation, a free 64 KiB range sharing a 1 GiB chunk with a host region, negative control confirmed by @jotitadev on an M2 Max) and the updated debt line; merged.
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!7634
No description provided.