fix(libkernel): block guest signals by FreeBSD's bit n - 1 #1652

Merged
SleglJan merged 1 commit from upstream-pr/1652 into main 2026-10-10 04:40:26 +00:00
SleglJan commented 2026-10-08 15:44:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-08T15:44:29Z.


What

Dispatch in System/src/Signals.cpp tested the blocked mask with 1u << guest, bit n. sigprocmask keeps the first word of the title's set as it is, and FreeBSD keeps signal n at bit n − 1 (_SIG_BIT), which is what FreeBSD's sigaddset (and #1641's) produces. So a title that blocked SIGTERM (bit 14) was not protected, and a set with bit 15 blocked SIGTERM instead of SIGURG.

Dispatch now tests 1u << (guest - 1). The stored mask and the set sigprocmask returns are unchanged, so they keep the title's layout. Nothing else interprets the mask's bits; sigprocmask only combines and returns it.

Found while adding the sigset functions in #1641: with them a title can build such a set without importing anything else, so the mismatch stops being latent. The two are independent changes; #1641 lists this one under Depends on so they land in order.

Tested

  • Linux (CachyOS, kernel 7.2.9, GCC 16.2.1), full build with BUILD_TESTING=ON and ANYPS5_ENABLE_SPIRV_TOOLS=ON on this branch (based on main 4b005b22): ctest --repeat until-fail:3 466/466; tools/check_conventions.py --base upstream/main passes.
  • guest_signals gains two cases: block {1u << 14} with SIG_BLOCK, raise(15) is not delivered, SIG_UNBLOCK, raise(15) is delivered; and block {1u << 15}, raise(15) is still delivered. The first was written before the change: on main it aborts (the raise is delivered through the block); it passes with the change. The existing round-trip assertions are untouched.
  • Windows: run by @hikazey on Windows 11 with the CI toolchain (comment below): guest_signals 5/5 with this change, 5/5 failures with main's Signals.cpp and the new cases, full suite 457/457. Pending delivery of a blocked signal after unblocking is not implemented here or on main; this only corrects which bit is tested.
  • Also the same Build workflow run on this commit in the fork's Actions (merged onto main 6b56175a), run 37822080210: guest_signals passes its three repeats on Windows, full suite 473/473. Linux passed on a rerun after agc_driver_buffer_format hit its 120 s limit on the software Vulkan runner (the test takes 92 to 108 s on main's own runs; #1744).

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 TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4789301556 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1652). Originally posted by [SleglJan](https://github.com/SleglJan) on 2026-10-08T15:44:29Z. --- ### What `Dispatch` in `System/src/Signals.cpp` tested the blocked mask with `1u << guest`, bit n. `sigprocmask` keeps the first word of the title's set as it is, and FreeBSD keeps signal n at bit n − 1 ([`_SIG_BIT`](https://github.com/freebsd/freebsd-src/blob/stable/11/sys/sys/_sigset.h)), which is what FreeBSD's `sigaddset` (and #1641's) produces. So a title that blocked SIGTERM (bit 14) was not protected, and a set with bit 15 blocked SIGTERM instead of SIGURG. `Dispatch` now tests `1u << (guest - 1)`. The stored mask and the set `sigprocmask` returns are unchanged, so they keep the title's layout. Nothing else interprets the mask's bits; `sigprocmask` only combines and returns it. Found while adding the sigset functions in #1641: with them a title can build such a set without importing anything else, so the mismatch stops being latent. The two are independent changes; #1641 lists this one under Depends on so they land in order. ### Tested - Linux (CachyOS, kernel 7.2.9, GCC 16.2.1), full build with `BUILD_TESTING=ON` and `ANYPS5_ENABLE_SPIRV_TOOLS=ON` on this branch (based on `main` 4b005b22): `ctest --repeat until-fail:3` 466/466; `tools/check_conventions.py --base upstream/main` passes. - `guest_signals` gains two cases: block `{1u << 14}` with `SIG_BLOCK`, `raise(15)` is not delivered, `SIG_UNBLOCK`, `raise(15)` is delivered; and block `{1u << 15}`, `raise(15)` is still delivered. The first was written before the change: on `main` it aborts (the raise is delivered through the block); it passes with the change. The existing round-trip assertions are untouched. - Windows: run by @hikazey on Windows 11 with the CI toolchain (comment below): `guest_signals` 5/5 with this change, 5/5 failures with `main`'s `Signals.cpp` and the new cases, full suite 457/457. Pending delivery of a blocked signal after unblocking is not implemented here or on `main`; this only corrects which bit is tested. - Also the same Build workflow run on this commit in the fork's Actions (merged onto `main` 6b56175a), [run 37822080210](https://github.com/SleglJan/AnyPS5/actions/runs/37822080210): `guest_signals` passes its three repeats on Windows, full suite 473/473. Linux passed on a rerun after `agc_driver_buffer_format` hit its 120 s limit on the software Vulkan runner (the test takes 92 to 108 s on `main`'s own runs; #1744). ### Checklist - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
hikazey commented 2026-10-08 17:18:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hikazey on 2026-10-08T17:18:20Z.


Windows run, since the description says it wasn't tested there: Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7, the CI build), Release, configured like CI, Ryzen 9 5900X. This commit merged onto main 7995d657, which merges cleanly.

build guest_signals
this PR 5/5 passed
Signals.cpp from main, new cases kept 5/5 failed
full suite with this PR 457/457 passed

So the bit n − 1 check also holds on the CRT signal/raise path that Dispatch uses on Windows: SIGTERM blocked through bit 14 isn't delivered, and bit 15 no longer blocks it.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6065252490 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1652#issuecomment-6065252490). Originally posted by [hikazey](https://github.com/hikazey) on 2026-10-08T17:18:20Z. --- Windows run, since the description says it wasn't tested there: Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7, the CI build), Release, configured like CI, Ryzen 9 5900X. This commit merged onto `main` `7995d657`, which merges cleanly. | build | `guest_signals` | | --- | --- | | this PR | 5/5 passed | | `Signals.cpp` from `main`, new cases kept | 5/5 failed | | full suite with this PR | 457/457 passed | So the bit `n − 1` check also holds on the CRT `signal`/`raise` path that `Dispatch` uses on Windows: SIGTERM blocked through bit 14 isn't delivered, and bit 15 no longer blocks it. AI-assisted: yes (Claude Code).
SleglJan commented 2026-10-08 17:24:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-08T17:24:29Z.


Thanks for the Windows run; the description now points to it, so the CRT path is covered on both hosts.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6065355685 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1652#issuecomment-6065355685). Originally posted by [SleglJan](https://github.com/SleglJan) on 2026-10-08T17:24:29Z. --- Thanks for the Windows run; the description now points to it, so the CRT path is covered on both hosts.
SleglJan commented 2026-10-09 23:54:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-09T23:54:47Z.


Rebased onto main ff8961df (head c26c1cae). #1916 (sigaction) and this PR both append cases to GuestSignals.cpp; both are kept, this PR's 12 lines after #1916's, with its two set variables renamed because term was taken. The Signals.cpp change is the same one line, and main still tests 1u << guest.

Linux (CachyOS, kernel 7.2.9, GCC 16.2.1), Release, BUILD_TESTING=ON, ANYPS5_ENABLE_SPIRV_TOOLS=ON, on this head:

  • guest_signals and guest_signal_sets pass three repeats; check_conventions.py --base upstream/main passes.
  • Full ctest on the RTX 3080 (615.71.09): 563 passed, 2 skipped, 1 failed of 566; the failure is agc_driver_dcc_keys_first_write (#2188, NVIDIA proprietary driver), which passes three repeats on RADV.
  • Fork Build workflow on this head merged into main ff8961df, run 38005245415: relinker green on all three platforms; linux 536 passed, 29 skipped, 1 failed of 566 with guest_signals and guest_signal_sets among the passed, the failure guest_video_out_resolution_status (#1714) aborting on the runner's offscreen SDL driver without Vulkan; windows stops at libSceVideoOut.prx with #2462's duplicate export. The fork's build of main ff8961df alone, run 38004711062, fails the same two ways with the same 29 skips.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6091280948 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1652#issuecomment-6091280948). Originally posted by [SleglJan](https://github.com/SleglJan) on 2026-10-09T23:54:47Z. --- Rebased onto `main` ff8961df (head c26c1cae). #1916 (sigaction) and this PR both append cases to `GuestSignals.cpp`; both are kept, this PR's 12 lines after #1916's, with its two set variables renamed because `term` was taken. The `Signals.cpp` change is the same one line, and `main` still tests `1u << guest`. Linux (CachyOS, kernel 7.2.9, GCC 16.2.1), Release, `BUILD_TESTING=ON`, `ANYPS5_ENABLE_SPIRV_TOOLS=ON`, on this head: - `guest_signals` and `guest_signal_sets` pass three repeats; `check_conventions.py --base upstream/main` passes. - Full ctest on the RTX 3080 (615.71.09): 563 passed, 2 skipped, 1 failed of 566; the failure is `agc_driver_dcc_keys_first_write` (#2188, NVIDIA proprietary driver), which passes three repeats on RADV. - Fork Build workflow on this head merged into `main` ff8961df, [run 38005245415](https://github.com/SleglJan/AnyPS5/actions/runs/38005245415): relinker green on all three platforms; linux 536 passed, 29 skipped, 1 failed of 566 with `guest_signals` and `guest_signal_sets` among the passed, the failure `guest_video_out_resolution_status` (#1714) aborting on the runner's offscreen SDL driver without Vulkan; windows stops at `libSceVideoOut.prx` with #2462's duplicate export. The fork's build of `main` ff8961df alone, [run 38004711062](https://github.com/SleglJan/AnyPS5/actions/runs/38004711062), fails the same two ways with the same 29 skips. AI-assisted: yes (Claude Code)
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!1652
No description provided.