build(libkernel): compile Exception on macOS #11249

Closed
iamthehimansh wants to merge 1 commit from upstream-pr/11249 into main
iamthehimansh commented 2026-10-25 22:35:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by iamthehimansh on 2026-10-25T22:35:20Z.


What

Next part of splitting #8658: libkernel's System/src/Exception.cpp does not compile on macOS. The change is macOS-only; Linux and Windows compile the same code as before.

It converts the host signal context to and from the guest machine context through Linux's gregs array and fpregs pointer. On macOS the general registers are named fields of mcontext_t->__ss, and the x87/SSE state is an FXSAVE-layout block inside mcontext_t->__fs. macOS now copies those fields directly. A static_assert checks that the Darwin float state has the FXSAVE layout (MXCSR at 24, XMM0 at 160) that the copy relies on, so a header change fails the build instead of corrupting registers.

Overlap

@marion909's #7201 ("Macos port", 100 files, needs a rebase) also converts the Darwin machine context in this file, and 46 of this PR's 56 added lines appear there too. This PR carries only Exception.cpp, so it can land on its own. It differs in one place: it copies the full 512-byte FXSAVE image from __fs into the guest state, checks the Darwin layout with a static_assert at MXCSR, XMM0 and the end of XMM15, and writes back only the 416 register bytes. #7201 copies 416 bytes in both directions. If #7201 lands first, I'll close this or rebase it onto that.

Tested

macOS 26 on an Apple M2 Pro, x86_64 under Rosetta 2, Release with Ninja, on main at b90d009d9: System/src/Exception.cpp.o compiles, where main fails it. The libkernel tests cannot run on macOS until the rest of libkernel builds (#10552, #7804, #10898 and follow-ups), so this is a compile check only. In #8658's full macOS run (1,960 tests) the same code passed guest_exception_handler, guest_raise_exception, guest_signals, guest_signal_sets and guest_signal_list. For Linux and Windows, I checked the file's view under unifdef -U__APPLE__, with -D__linux__ and with -D_WIN32: it equals main. python3 tools/check_conventions.py --base origin/main passes.

Checklist

  • Based on current main; #7201 also implements this conversion (see Overlap)
  • 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 (Cana)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5009401549 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11249). Originally posted by [iamthehimansh](https://github.com/iamthehimansh) on 2026-10-25T22:35:20Z. --- ### What Next part of splitting #8658: `libkernel`'s `System/src/Exception.cpp` does not compile on macOS. The change is macOS-only; Linux and Windows compile the same code as before. It converts the host signal context to and from the guest machine context through Linux's `gregs` array and `fpregs` pointer. On macOS the general registers are named fields of `mcontext_t->__ss`, and the x87/SSE state is an FXSAVE-layout block inside `mcontext_t->__fs`. macOS now copies those fields directly. A `static_assert` checks that the Darwin float state has the FXSAVE layout (MXCSR at 24, XMM0 at 160) that the copy relies on, so a header change fails the build instead of corrupting registers. ### Overlap @marion909's #7201 ("Macos port", 100 files, needs a rebase) also converts the Darwin machine context in this file, and 46 of this PR's 56 added lines appear there too. This PR carries only `Exception.cpp`, so it can land on its own. It differs in one place: it copies the full 512-byte FXSAVE image from `__fs` into the guest state, checks the Darwin layout with a `static_assert` at MXCSR, XMM0 and the end of XMM15, and writes back only the 416 register bytes. #7201 copies 416 bytes in both directions. If #7201 lands first, I'll close this or rebase it onto that. ### Tested macOS 26 on an Apple M2 Pro, x86_64 under Rosetta 2, Release with Ninja, on `main` at `b90d009d9`: `System/src/Exception.cpp.o` compiles, where `main` fails it. The `libkernel` tests cannot run on macOS until the rest of `libkernel` builds (#10552, #7804, #10898 and follow-ups), so this is a compile check only. In #8658's full macOS run (1,960 tests) the same code passed `guest_exception_handler`, `guest_raise_exception`, `guest_signals`, `guest_signal_sets` and `guest_signal_list`. For Linux and Windows, I checked the file's view under `unifdef -U__APPLE__`, with `-D__linux__` and with `-D_WIN32`: it equals `main`. `python3 tools/check_conventions.py --base origin/main` passes. ### Checklist - [x] Based on current `main`; #7201 also implements this conversion (see Overlap) - [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 ([Cana](https://cana.build))
MarcZX10 commented 2026-10-25 22:36:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T22:36:54Z.

Review: APPROVED


I reviewed the full macOS conversion. The general registers map field-for-field between Darwin __ss and GuestMcontext, and the FXSAVE offsets are checked at MXCSR, XMM0, and the end of XMM15 before copying the state image. The 512-byte host read fits the guest state assertion; the reverse path copies the same 416 bytes as the Linux implementation. The Apple branch is isolated from the existing Linux conversion.

git diff --check and current-main conventions pass. Hosted eligibility, conventions, intake, labels and report pass; product/build jobs are skipped by policy. I did not run the macOS runtime test locally. The author reports this same code passed the named guest exception/signal tests in the previous full macOS run (1,960 tests), and the changed translation unit compiles on the current branch. No concrete defect found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645705424 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11249#pullrequestreview-5645705424). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T22:36:54Z. **Review:** APPROVED --- I reviewed the full macOS conversion. The general registers map field-for-field between Darwin `__ss` and `GuestMcontext`, and the FXSAVE offsets are checked at MXCSR, XMM0, and the end of XMM15 before copying the state image. The 512-byte host read fits the guest state assertion; the reverse path copies the same 416 bytes as the Linux implementation. The Apple branch is isolated from the existing Linux conversion. `git diff --check` and current-main conventions pass. Hosted eligibility, conventions, intake, labels and report pass; product/build jobs are skipped by policy. I did not run the macOS runtime test locally. The author reports this same code passed the named guest exception/signal tests in the previous full macOS run (1,960 tests), and the changed translation unit compiles on the current branch. No concrete defect found.
MarcZX10 commented 2026-10-26 06:38:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T06:38:36Z.

Review: CHANGES_REQUESTED


I am updating my earlier approval after checking the exact overlap against current open #7201. #7201 is still open and contains this same Exception.cpp context conversion; this PR itself says 46 of its 56 added lines also appear there. CONTRIBUTING requires the authors to agree which overlapping change lands first and record any prerequisite on Depends on. The current description says this PR can land independently, but does not show coordination with #7201’s author. Please record the agreed merge order and list a dependency if #7201 must land first, or coordinate that this focused PR is the replacement for this portion of #7201. The technical review of this head remains sound; this request is specifically for the documented overlap/merge-order rule.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5648231091 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11249#pullrequestreview-5648231091). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T06:38:36Z. **Review:** CHANGES_REQUESTED --- I am updating my earlier approval after checking the exact overlap against current open #7201. #7201 is still open and contains this same `Exception.cpp` context conversion; this PR itself says 46 of its 56 added lines also appear there. CONTRIBUTING requires the authors to agree which overlapping change lands first and record any prerequisite on `Depends on`. The current description says this PR can land independently, but does not show coordination with #7201’s author. Please record the agreed merge order and list a dependency if #7201 must land first, or coordinate that this focused PR is the replacement for this portion of #7201. The technical review of this head remains sound; this request is specifically for the documented overlap/merge-order rule.

Pull request closed

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!11249
No description provided.