fix(libkernel): let signal() record every valid signal number like sigaction #2760

Closed
husseinkad wants to merge 2 commits from upstream-pr/2760 into main
husseinkad commented 2026-10-10 13:11:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-10T13:11:26Z.


What

signal() returned SIG_ERR with EINVAL for every guest signal that has no host equivalent: only 2, 4, 6, 8, 11 and 15 worked, so signal(SIGPIPE, SIG_IGN), signal(SIGHUP, h) or signal(SIGUSR1, h) failed while sigaction() in the same file accepted the same numbers. FreeBSD's signal() is sigaction() with SA_RESTART and an empty mask (never SA_RESETHAND), and the kernel's kern_sigaction rejects only numbers outside 1..128 and SIGKILL/SIGSTOP with a handler other than SIG_DFL.

signal_nid_postfix now does the same: EINVAL for numbers outside 1..128 and for SIGKILL/SIGSTOP with a non-default handler (signal(SIGKILL, SIG_DFL) succeeds, as in FreeBSD), the disposition of every other number is recorded in the table sigaction uses, and the previous handler is returned. The rejection of a SIG_ERR handler value, which FreeBSD does not have, is removed.

Delivery is unchanged: only the six signals with host equivalents take effect or can be raised, and raise/kill of the others still fail with EINVAL. In particular signal(SIGPIPE, SIG_IGN) is now recorded and succeeds but does not stop the host SIGPIPE on Linux. TechnicalDebt (the SIGPIPE and the sigaction/signal entries) is updated to say exactly that.

Tested

Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release:

  • guest_signals gains: every unmapped number 1..128 accepted with SIG_IGN, a handler and SIG_DFL with the previous handler returned, errno left alone on success, the stored mask and flags replaced by SA_RESTART and 0 after an earlier sigaction, 9 and 17 accepting SIG_DFL and rejecting a handler or SIG_IGN, and out-of-range numbers failing. It fails without the change (exit 0xc0000409) and passes with it. ctest -R "guest_(signal|kill|sigaltstack)" passes (4 of 4).
  • Outside the repo, main's and this branch's libkernel side by side with 155 signal numbers (-5 to 140 and the integer extremes) x 5 handler-chain scenarios (4,992 signal() calls, read back through sigaction): the six mapped numbers and all invalid numbers are byte-identical; only the 120 previously rejected numbers change, and each now behaves exactly like mapped signal 15; real delivery of the six mapped signals in 8 modes (48 runs per build, in separate processes) is identical; 4 to 8 threads for 2 seconds on private and shared numbers show no corruption of the table.
  • tools/check_conventions.py --base origin/main passes; tools/pr_overlap.py --branch reports no overlap.
  • Linux not run.

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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4811446811 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2760). Originally posted by [husseinkad](https://github.com/husseinkad) on 2026-10-10T13:11:26Z. --- ### What `signal()` returned `SIG_ERR` with `EINVAL` for every guest signal that has no host equivalent: only 2, 4, 6, 8, 11 and 15 worked, so `signal(SIGPIPE, SIG_IGN)`, `signal(SIGHUP, h)` or `signal(SIGUSR1, h)` failed while `sigaction()` in the same file accepted the same numbers. FreeBSD's [`signal()`](https://github.com/freebsd/freebsd-src/blob/releng/11.4/lib/libc/gen/signal.c) is `sigaction()` with `SA_RESTART` and an empty mask (never `SA_RESETHAND`), and the kernel's `kern_sigaction` rejects only numbers outside 1..128 and `SIGKILL`/`SIGSTOP` with a handler other than `SIG_DFL`. `signal_nid_postfix` now does the same: `EINVAL` for numbers outside 1..128 and for `SIGKILL`/`SIGSTOP` with a non-default handler (`signal(SIGKILL, SIG_DFL)` succeeds, as in FreeBSD), the disposition of every other number is recorded in the table `sigaction` uses, and the previous handler is returned. The rejection of a `SIG_ERR` handler value, which FreeBSD does not have, is removed. Delivery is unchanged: only the six signals with host equivalents take effect or can be raised, and `raise`/`kill` of the others still fail with `EINVAL`. In particular `signal(SIGPIPE, SIG_IGN)` is now recorded and succeeds but does not stop the host `SIGPIPE` on Linux. TechnicalDebt (the SIGPIPE and the sigaction/signal entries) is updated to say exactly that. ### Tested Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release: - `guest_signals` gains: every unmapped number 1..128 accepted with `SIG_IGN`, a handler and `SIG_DFL` with the previous handler returned, `errno` left alone on success, the stored mask and flags replaced by `SA_RESTART` and 0 after an earlier `sigaction`, 9 and 17 accepting `SIG_DFL` and rejecting a handler or `SIG_IGN`, and out-of-range numbers failing. It fails without the change (exit `0xc0000409`) and passes with it. `ctest -R "guest_(signal|kill|sigaltstack)"` passes (4 of 4). - Outside the repo, `main`'s and this branch's `libkernel` side by side with 155 signal numbers (-5 to 140 and the integer extremes) x 5 handler-chain scenarios (4,992 `signal()` calls, read back through `sigaction`): the six mapped numbers and all invalid numbers are byte-identical; only the 120 previously rejected numbers change, and each now behaves exactly like mapped signal 15; real delivery of the six mapped signals in 8 modes (48 runs per build, in separate processes) is identical; 4 to 8 threads for 2 seconds on private and shared numbers show no corruption of the table. - `tools/check_conventions.py --base origin/main` passes; `tools/pr_overlap.py --branch` reports no overlap. - Linux not run. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [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
github-actions[bot] commented 2026-10-10 13:11:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T13:11:35Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6097853002 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2760#issuecomment-6097853002). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T13:11:35Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

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