Skip to content

feat(libc): support x86-64 unwind register contexts on macOS - #1499

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
yabanana:codex/macos-unwind-register-context
Oct 10, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
yabanana:codex/macos-unwind-register-context

Conversation

@yabanana

@yabanana yabanana commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What

On macOS x86-64, LibcCaptureRegisters and LibcRestoreRegisters currently take the unsupported-platform branch and call abort(). This prevents the guest unwinder from capturing its starting frame or installing a landing-pad context once the macOS unwind path is enabled.

Reuse the existing System V x86-64 instruction sequence on Apple hosts, with Mach-O symbol spelling and private visibility instead of ELF assembler directives. The Linux instruction sequence and the Windows implementation are unchanged.

Add behavioral tests for all captured general registers, the caller's stack and return address, and a restore that abandons a nested stack frame and transfers the exception/selector registers and callee-saved registers to a landing pad. The probes also run concurrently on four threads. They build independently of the prx libraries, are registered in the full Linux test suite, and get Debug/Release CI on Linux and Intel macOS.

This is a register-transfer prerequisite for the macOS work in #1 and complements #927. It does not implement frame discovery, Mach-O relinking, or the complete exception runtime. No graphics changes.

Tested

Current head fbce6710 is rebased onto main at 745b775e, which includes #2099 and #2151. The previous SPIRV-Headers build blocker is resolved in this base. git range-diff confirms the register-transfer source and probes are unchanged; only workflow integration context changed.

  • Mach-O x86-64 through Rosetta on Apple M5 Max/macOS 27.2/AppleClang 21: capture, restore and four-thread probes pass in Debug and Release, each repeated three times on this head. Registration, conventions and whitespace checks pass.
  • Previous rebased head 9bdcc027 passed all four Linux/Intel macOS register-context jobs and all three relinker jobs; its full builds failed on the now-resolved upstream header issue. These earlier results are not current-head full-build validation.
  • Upstream now runs full Linux/Windows PR builds only through maintainer-authorized workflow_dispatch with a PR number. Please dispatch Build with pr=1499 for this head. Automatic register-context/relinker checks may run separately; skipped full-build jobs do not count as passes.
  • No commercial title or complete guest exception runtime was tested.

Standalone reproduction commands remain in docs/dev/BUILD.md.

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 in docs/dev/TechnicalDebt.md
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

@klosixgaming-arch klosixgaming-arch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent addition of comprehensive register context capture and restore tests for x86-64 on both Linux and macOS. This is important for verifying the correctness of the unwinder's register transfer operations.

Strengths:

  • Comprehensive test coverage including capture, restore, and multi-threaded scenarios (256 iterations per thread)
  • Proper handling of platform-specific symbol naming (macOS vs Linux) with appropriate asm directives
  • Clean separation into a standalone test target that can be built without submodules or prx libraries
  • Good documentation in BUILD.md about how to run the tests on both platforms

Technical notes:

  • The approach of using inline assembly probes to verify register capture/restore is correct and thorough
  • Proper validation of guard values to ensure no out-of-bounds writes
  • Test properly verifies all 17 registers including stack pointer and instruction pointer
  • Multi-threaded testing ensures thread-safety of the register context operations

This will improve confidence in the unwinder's correctness across platforms. Ready to merge.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 8, 2026
@yabanana
yabanana force-pushed the codex/macos-unwind-register-context branch from ee57930 to 6e8058f Compare October 8, 2026 13:58
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 8, 2026
@github-actions github-actions Bot mentioned this pull request Oct 8, 2026
9 tasks done
@yabanana
yabanana force-pushed the codex/macos-unwind-register-context branch from 6e8058f to 9bdcc02 Compare October 9, 2026 08:12
@yabanana

yabanana commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@adriadam10 Could you review the updated register-context prerequisite? Head 9bdcc027 is rebased onto 6cc0503d; the register-transfer implementation and probes are unchanged. Debug/Release capture, restore and four-thread tests pass locally, each repeated three times, and conventions/test registration pass. #1603 is included in the base, so the old formatting-registration blocker is resolved. Fresh upstream validation: https://github.com/boykopovar/AnyPS5/actions/runs/37903526054.

@yabanana
yabanana force-pushed the codex/macos-unwind-register-context branch from 9bdcc02 to de230c3 Compare October 9, 2026 10:05
@yabanana

yabanana commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

@adriadam10 Current head fbce6710 is rebased onto main 745b775e, including merged #2099 and #2151. Both previous upstream CI blockers (SPIRV headers and Windows Clang without AMDGPU support) are addressed in this base. The unchanged register-context probes pass locally in Debug/Release, three repetitions per mode. Under the new policy, could you dispatch Build on main with input pr=1499 for full Linux/Windows validation, and review the current head? Skipped full-build jobs are not counted as passes.

@yabanana
yabanana force-pushed the codex/macos-unwind-register-context branch from de230c3 to fbce671 Compare October 9, 2026 10:22
@popcoder565

Copy link
Copy Markdown
Contributor

Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head fbce6710, merged onto main 8b393b6 in one build with 31 other PRs that had no Windows run.

  • The change is macOS-only, and its test isn't registered on Windows, so this only checks that the Windows build is unaffected.
  • Full ctest in that build: 520 of 521. The one failure is guest_offline_imports, broken by feat(libSceRudp): implement sceRudpGetStatus #2359 (reported there).

No title was run.

🤖 Addressed by Claude Code

@adriadam10

Copy link
Copy Markdown
Collaborator

Checked on Linux x86-64: build and register_context_{capture,restore,threads} pass; the register-context jobs (Linux and Intel macOS, Debug/Release) are green on this head, and popcoder565's Windows run shows the Windows build is unaffected. The production change is __APPLE__-only and the Linux sequence is unchanged. Merging.

@adriadam10
adriadam10 merged commit 0eb7f09 into boykopovar:main Oct 10, 2026
13 checks passed
SleglJan pushed a commit to SleglJan/AnyPS5 that referenced this pull request Oct 10, 2026
…egister-context

feat(libc): support x86-64 unwind register contexts on macOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants