macOS boot hang after "Relocate program": ProtectGuestMemory applies guest-only protection to the host mapping (regression from #135) #148
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!148
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/148/head"
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?
@Stepz97 on GitHub · 2026-08-01 15:40 UTC · original
Stepz97:fix-protect-guest-memory-host-clamp→main· +11 −1 · 1 files · 1 commits · closed without mergingSymptom
Since the guest memory rework (#135, first bad commit
2f5396c, found by bisect betweenf6e01e5anda65d17awith a validated good/bad oracle), nothing boots on macOS: both homebrew samples and games freeze right after--- Relocate program: ... ---, with one thread spinning at 100% CPU and no further output. Before #135 (f6e01e5), the same binaries execute guest code normally.This looks related to the Raiden III regression reported around #136 — same first bad commit territory, and #136 (signal dispatch) does not fix this hang.
Root cause
#135 establishes the invariant that guest-visible protection lives in the virtual range tracker while host mappings stay writable, and applies exactly that clamp in
SetProgramMemoryProtection:But
ProtectGuestMemorystill applies the requested guest mode verbatim to the host mapping. The broken sequence on every boot:InstallRelocateHandlercallsProtectGuestMemory(pltgot, Write, &old_mode).old_modeis read from the range tracker, so for the pltgot (inside a read-only RELRO segment) it comes back asRead.pltgot[1]/pltgot[2], it restoresold_mode— and the restore mprotects the host page to read-only.RelocateRecords(PatchGuestMemory64, a plain store) faults. The GPU fault handler path finds the page inside a GPU-mapped range, runs an invalidate that is a no-op (no GPU resources exist at boot), returns "handled" without changing any protection, and the retried store faults again. Infinite fault livelock.Measured on macOS: 8,000+ identical faults (rip =
RelocateRecords, fault addr = pltgot+0x18, page-fault error code 0x6 = user-mode write) with the handler returning "resolved" every time. Windows presumably survives because its fault path resolves the write differently, but the defect itself is platform-independent code.Fix
Clamp the host mode in
ProtectGuestMemoryexactly likeSetProgramMemoryProtectionalready does, preservingNoAccessso guard pages still trap. The tracker keeps recording the requested guest mode.Validation
a65d17a+ this patch alone: guest code executes again on macOS (unresolved-import stub calls resume, where before the process never leftRelocate).memory_tracker/page_manager), and the Mandelbrot homebrew sample renders byte-identical to its pre-#135 reference dump.Two adjacent notes (no patch attached, maintainer's call)
KernelMprotecthas the same shape (applies the guest mode verbatim to the host mapping). Since that one is the guest-facing syscall, faithfully applying guest protection may be intentional — but any guest that mprotects its own memory read-only and later gets patched by the runtime linker will hit the same livelock. Possibly the actual Raiden III mechanism.KernelMapNamedFlexibleMemory's accepted flags to the sce namespace and reused bit0x400(previously accepted as POSIXMAP_STACK) asMAP_DMEM_COMPAT. That silently breaks any POSIX-style mmap shim written against the old contract (MAP_PRIVATE|MAP_ANON= 0x1002 now returns EINVAL). Worth a mention in the changelog if the narrowing is intentional.Disclosure (README § AI Use): this fix was developed with AI assistance. I reviewed the analysis and the code, ran the validation on my machine, and take responsibility for this submission.
Pull request closed