Skip to content

[Memory] Hold the split arena's address from selection until it is mapped - #75

Open
xnetcat wants to merge 2 commits into
mainfrom
fix/split-arena-reserve
Open

xnetcat wants to merge 2 commits into
mainfrom
fix/split-arena-reserve

Conversation

@xnetcat

@xnetcat xnetcat commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Before submitting

Please read our contribution guidelines before opening a pull request:

➡️ CONTRIBUTING.md

By opening this pull request, you confirm that you have read and agree to follow the contribution guidelines.

Testing

No game was run (no games on the test machine).

What changed: PR #71 chose the split guest allocator arena's address at startup and told the GPU process, but the arena was mapped only at the first guest allocation. Anything mapped in between (the malloc nano zone growing, dyld, a host library) could take the range, and the arena then stayed private, so the GPU process could not see the VideoOut labels or HLE data in it. The mapping was lazy only because the guest allocator has been lazy since it was added (08b315b), long before the split; Clear at each load also releases the arena. The chosen range is now held as a no-access reservation of the backing's owner from the moment it is chosen. The arena's view replaces that reservation at the first allocation, and Clear holds the range again at the same address. If the hold fails at selection, the code probes and tries again, up to 4 times, and then logs the existing loud private-arena error. The address the GPU process is told and the address mapped stay the same. The protocol is unchanged.

  • New test SplitGuestMemoryTests.AnArenaTakenBetweenSelectionAndFirstUseStaysBacked: something maps into the arena's range after selection and before first use (exact placement without overwrite, as mach_vm_allocate fixed does), once at startup and once after Clear. Without the change it fails with one arena map failure and a private arena. With the change the outsider cannot land and the arena stays backed. It replaces AnArenaThatCannotBeMappedAtFirstUseIsCountedAndPrivate, whose scenario (taken after selection) can no longer happen.
  • Nano zone growth, checked with an x86_64 program under Rosetta with MallocNanoZone unset: 640 MB of 128-byte mallocs grew the zone upward from 0x600000000000 in contiguous 0x20000000 regions to 0x600280000000 (about 9.5 GiB of address space). With a page already mapped at 0x600020000000, the zone skipped that region and kept growing above it. The relocated arena (preferred + 1 TiB, 0x610000000000) would need roughly 60 GB of live small allocations before the zone reached it, and it is now held anyway.
  • Synthetic guests through the built app, default split mode, MallocNanoZone unset (as a user launch): 9 runs (wakeping x5, tbbburst x4). 9 of 9 printed [VMEM] Split layout: 0x0000600000000000 is taken ... with the arena at 0x0000610000000000. 0 of 9 printed any "could not be mapped" or "could not be held" line. The GPU process connected with the guest allocator arena at 0x610000000000 in every run, all runs exited 0, and tbbburst printed verdict ok 4 of 4.
  • uvx reuse lint: compliant. Release build: 0 errors. dotnet test SharpEmu.slnx -c Release: 0 failures in all 12 test projects (Libs.Tests 12638 passed, 162 skipped; the known SeatbeltSandboxProbeTests audio failure did not occur this time). The targeted run (SplitGuestMemoryTests, PhysicalVirtualMemory*, GuestSpaceOwner*): 93 passed, 0 failed.
  • Not verified: a tester run from the app on a real title. The private-arena error path (a hold that fails at selection) has no direct test now, because no stock host can make the hold fail on purpose.

Checklist

By submitting this pull request, you confirm that:

  • I have read and followed CONTRIBUTING.md.
  • I tested my changes or marked the testing section as N/A.
  • I wrote this pull request description myself and did not paste AI-generated explanations.
  • I listed the game(s) I tested (or marked the testing section as N/A).

…aps it

The split layout chose the guest allocator arena's address at startup (and told
the GPU process) but mapped it only at the first guest allocation, so anything
mapped in between (the malloc nano zone growing, dyld, a host library) could take
it and leave the arena private. The chosen range is now held as a no-access
reservation of the backing's owner, which the arena's view replaces; Clear holds
it again at the same address. A hold that fails at selection probes again (up to
4 times) before the loud private-arena error.
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

📦 Build artifacts — 679f6e8

Platform Download
macOS (osx-x64) sharpemu-osx-x64-59c029f
macOS app bundle (osx-x64) sharpemu-osx-x64-app-59c029f

From build run #568. Downloads require a GitHub login and expire after 90 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant