fix(libc): forward non-write faults from watched macOS pages #12117

Merged
plexerPK merged 1 commit from upstream-pr/12117 into main 2026-10-29 20:20:53 +00:00
plexerPK commented 2026-10-27 21:43:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by plexerPK on 2026-10-27T21:43:19Z.


What

The macOS write-watch handler treated any fault in a watched writable page as a write. Calling a non-executable watched page, or reading a watched file mapping after its backing was truncated, repeatedly returned to the same fault instead of delivering it to the previous handler/default action. This occurs both before and after collection and during a host-write scope.

Classify the saved CPU exception before recording a write: an x86-64 page fault with the write bit set, or an arm64 data abort with WnR set. Non-write faults follow the existing forwarding path. The writable-state retry remains available for concurrent writes whose first fault has already restored the page.

The constants follow Apple's XNU x86 trap definitions and arm64 ESR definitions. No third-party source is copied.

Add native subprocess regressions for execute and backing-read faults across fresh/collected pages and active/inactive host writes (eight cases). A child alarm bounds the old infinite retry; a successful case must terminate with SIGBUS/SIGSEGV. Document the separate existing limitation for write faults after backing truncation; this change does not resolve them.

Ownership preflight covered all 1,383 open PRs and 243 open issues. #11801 adds default re-raising for user-generated signals; #7192 exposes an address-based hook for fault delivery. Neither implements CPU access classification. No author coordination message has been sent.

Tested

macOS 27.0.1 (26A434), arm64, Apple clang 21.0.0, standalone actual production core/libs/tests/write_watch component, Release:

  • Unmodified main f5fefb982c53672bda23767304f97aac2eec5207: existing 10/10 tests pass. The two new regression tests fail at their child alarm (2.25 s / 2.01 s). A bounded diagnostic probe independently observes eight repeated faults for both NX-page states and both backing-read states, while normal writes succeed.
  • With the fix: 12/12 tests pass; the complete suite also passes --repeat until-fail:3. The four-thread concurrent-write test passes 20 additional repetitions.
  • macOS x86-64: the complete standalone test executable builds successfully with -DCMAKE_OSX_ARCHITECTURES=x86_64. Compile only: no Intel/Rosetta execution is available on this host.
  • python3 tools/check_conventions.py --base origin/main and git diff --check pass. Official tools/pr_overlap.py --branch codex/macos-write-watch-nonwrite-faults --repo boykopovar/AnyPS5 reports no confirmed line/export conflicts. It reports 19 comparisons unavailable because those PRs conflict with main: 18 touch unrelated libc debt entries; #7192 adds the hook described above. Their authored diffs were inspected manually; none changes this classification or the new backing-lifetime debt entry.

No full libc/libkernel build, title/guest execution, Linux/Windows runtime or GPU claim. The production change is confined to the macOS backend. Hosted CI remains separate from these local results.

Additional verification of the same head

  • Hosted write-watch (macos-15-intel) and write-watch (macos-15) jobs now report SUCCESS for head e295dbaa362a5fdd90c7315b875f066fd1b78a5b; the relinker matrix is also green. This is separate from the local arm64 evidence above.
  • tkcm01 reports an x86_64 Rosetta 2 run of this head on Apple M4/macOS 27.0.1/Apple clang 21: all 12 tests pass five repetitions each. The same fixture without the fix fails both new fault tests at the alarm while the ten existing modes pass. This is contributor-reported runtime evidence, not a local run by this author.
  • The separately documented write-after-truncation limitation has a dependent follow-up in #12435. Its new implementation is not covered by the Rosetta report above.

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:5041574250 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12117). Originally posted by [plexerPK](https://github.com/plexerPK) on 2026-10-27T21:43:19Z. --- ### What The macOS write-watch handler treated any fault in a watched writable page as a write. Calling a non-executable watched page, or reading a watched file mapping after its backing was truncated, repeatedly returned to the same fault instead of delivering it to the previous handler/default action. This occurs both before and after collection and during a host-write scope. Classify the saved CPU exception before recording a write: an x86-64 page fault with the write bit set, or an arm64 data abort with WnR set. Non-write faults follow the existing forwarding path. The writable-state retry remains available for concurrent writes whose first fault has already restored the page. The constants follow Apple's XNU [x86 trap definitions](https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/osfmk/i386/trap.h#L75-L105) and [arm64 ESR definitions](https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/osfmk/arm64/proc_reg.h#L2260-L2443). No third-party source is copied. Add native subprocess regressions for execute and backing-read faults across fresh/collected pages and active/inactive host writes (eight cases). A child alarm bounds the old infinite retry; a successful case must terminate with SIGBUS/SIGSEGV. Document the separate existing limitation for **write** faults after backing truncation; this change does not resolve them. Ownership preflight covered all 1,383 open PRs and 243 open issues. #11801 adds default re-raising for user-generated signals; #7192 exposes an address-based hook for fault delivery. Neither implements CPU access classification. No author coordination message has been sent. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> macOS 27.0.1 (26A434), arm64, Apple clang 21.0.0, standalone **actual production** `core/libs/tests/write_watch` component, Release: - Unmodified main `f5fefb982c53672bda23767304f97aac2eec5207`: existing 10/10 tests pass. The two new regression tests fail at their child alarm (2.25 s / 2.01 s). A bounded diagnostic probe independently observes eight repeated faults for both NX-page states and both backing-read states, while normal writes succeed. - With the fix: 12/12 tests pass; the complete suite also passes `--repeat until-fail:3`. The four-thread concurrent-write test passes 20 additional repetitions. - macOS x86-64: the complete standalone test executable builds successfully with `-DCMAKE_OSX_ARCHITECTURES=x86_64`. **Compile only:** no Intel/Rosetta execution is available on this host. - `python3 tools/check_conventions.py --base origin/main` and `git diff --check` pass. Official `tools/pr_overlap.py --branch codex/macos-write-watch-nonwrite-faults --repo boykopovar/AnyPS5` reports no confirmed line/export conflicts. It reports 19 comparisons unavailable because those PRs conflict with main: 18 touch unrelated libc debt entries; #7192 adds the hook described above. Their authored diffs were inspected manually; none changes this classification or the new backing-lifetime debt entry. No full libc/libkernel build, title/guest execution, Linux/Windows runtime or GPU claim. The production change is confined to the macOS backend. Hosted CI remains separate from these local results. ### Additional verification of the same head - Hosted `write-watch (macos-15-intel)` and `write-watch (macos-15)` jobs now report SUCCESS for head `e295dbaa362a5fdd90c7315b875f066fd1b78a5b`; the relinker matrix is also green. This is separate from the local arm64 evidence above. - [tkcm01 reports an x86_64 Rosetta 2 run](https://github.com/boykopovar/AnyPS5/pull/12117#issuecomment-6461020880) of this head on Apple M4/macOS 27.0.1/Apple clang 21: all 12 tests pass five repetitions each. The same fixture without the fix fails both new fault tests at the alarm while the ten existing modes pass. This is contributor-reported runtime evidence, not a local run by this author. - The separately documented write-after-truncation limitation has a dependent follow-up in #12435. Its new implementation is not covered by the Rosetta report above. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
MarcZX10 commented 2026-10-28 15:53:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T15:53:12Z.

Review: APPROVED


Reviewed exact head e295dbaa362a5fdd90c7315b875f066fd1b78a5. The fault classifier accepts only the synchronous SIGSEGV/SIGBUS codes below SI_USER, then recognizes x86-64 page-fault writes from trap 14/error bit 1 and arm64 data-abort writes from EC 0x24/WnR. Non-write faults and unavailable context continue through the pre-existing forwarding path. The focused tests cover execute and missing-backing read faults across fresh/collected pages and active/inactive host-write scopes; the author and independent reviewers report native arm64 and x86-64-under-Rosetta runs, repeated red controls, and clean ASan/UBSan runs with the documented signal-handler options. The hosted macOS write-watch matrix and repository checks are green. I independently verified the exact diff is 72 lines across the implementation, focused tests, CMake registrations and debt entry; current-main merge-tree and git diff --check are clean. I did not run the macOS-specific tests locally, and this review makes no console behavior claim. I found no blocking issue.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5685612680 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12117#pullrequestreview-5685612680). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T15:53:12Z. **Review:** APPROVED --- Reviewed exact head `e295dbaa362a5fdd90c7315b875f066fd1b78a5`. The fault classifier accepts only the synchronous SIGSEGV/SIGBUS codes below `SI_USER`, then recognizes x86-64 page-fault writes from trap 14/error bit 1 and arm64 data-abort writes from EC 0x24/WnR. Non-write faults and unavailable context continue through the pre-existing forwarding path. The focused tests cover execute and missing-backing read faults across fresh/collected pages and active/inactive host-write scopes; the author and independent reviewers report native arm64 and x86-64-under-Rosetta runs, repeated red controls, and clean ASan/UBSan runs with the documented signal-handler options. The hosted macOS write-watch matrix and repository checks are green. I independently verified the exact diff is 72 lines across the implementation, focused tests, CMake registrations and debt entry; current-main merge-tree and `git diff --check` are clean. I did not run the macOS-specific tests locally, and this review makes no console behavior claim. I found no blocking issue.
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!12117
No description provided.