libkernel: signal() fails with EINVAL for every signal without a host equivalent (SIGPIPE, SIGHUP, SIGUSR1, ...) while sigaction() accepts them #3076

Closed
opened 2026-10-10 21:46:11 +00:00 by husseinkad · 0 comments
husseinkad commented 2026-10-10 21:46:11 +00:00 (Migrated from github.com)
Contributor

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


What

signal() (core/libs/prx/libkernel/System/src/Signals.cpp) returns SIG_ERR with EINVAL for every guest signal that has no host equivalent: only 2, 4, 6, 8, 11 and 15 work, so signal(SIGPIPE, SIG_IGN), signal(SIGHUP, h) and signal(SIGUSR1, h) all fail, while sigaction() in the same file accepts the same numbers and records the disposition. A title that ignores SIGPIPE the traditional way sees a failure it did not expect.

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 (so signal(SIGKILL, SIG_DFL) succeeds there).

Fix

A tested fix is on my fork: husseinkad:fix/kernel-signal-unmapped-numbers (two commits on main; PR #2760, closed by the intake check): signal fails only for numbers outside 1..128 and for SIGKILL/SIGSTOP with a non-default handler, records the disposition of every other number in the table sigaction uses, and returns the previous handler. 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 recorded and succeeds but does not stop the host SIGPIPE on Linux. TechnicalDebt is updated to say exactly that.

guest_signals gains all the unmapped numbers, 9 and 17 with SIG_DFL and with a handler, errno left alone on success and the stored mask and flags replaced as FreeBSD does; it fails without the change. Checked against main's libkernel with 155 signal numbers (-5 to 140 and the integer extremes) x 5 handler-chain scenarios (4,992 signal() calls): the six mapped numbers and all invalid numbers are byte-identical, only the 120 previously rejected numbers change, real delivery of the six mapped signals in 8 modes is identical, and 4 to 8 threads for 2 seconds show no corruption of the table. Windows 11, WinLibs GCC 15.2.0 r7; Linux not run.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5795557169 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3076). Originally posted by [husseinkad](https://github.com/husseinkad) on 2026-10-10T21:46:11Z. --- ### What `signal()` (`core/libs/prx/libkernel/System/src/Signals.cpp`) returns `SIG_ERR` with `EINVAL` for every guest signal that has no host equivalent: only 2, 4, 6, 8, 11 and 15 work, so `signal(SIGPIPE, SIG_IGN)`, `signal(SIGHUP, h)` and `signal(SIGUSR1, h)` all fail, while `sigaction()` in the same file accepts the same numbers and records the disposition. A title that ignores `SIGPIPE` the traditional way sees a failure it did not expect. 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` (so `signal(SIGKILL, SIG_DFL)` succeeds there). ### Fix A tested fix is on my fork: [`husseinkad:fix/kernel-signal-unmapped-numbers`](https://github.com/husseinkad/AnyPS5/tree/fix/kernel-signal-unmapped-numbers) (two commits on `main`; PR #2760, closed by the intake check): `signal` fails only for numbers outside 1..128 and for `SIGKILL`/`SIGSTOP` with a non-default handler, records the disposition of every other number in the table `sigaction` uses, and returns the previous handler. 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 recorded and succeeds but does not stop the host `SIGPIPE` on Linux. TechnicalDebt is updated to say exactly that. `guest_signals` gains all the unmapped numbers, 9 and 17 with `SIG_DFL` and with a handler, `errno` left alone on success and the stored mask and flags replaced as FreeBSD does; it fails without the change. Checked against `main`'s `libkernel` with 155 signal numbers (-5 to 140 and the integer extremes) x 5 handler-chain scenarios (4,992 `signal()` calls): the six mapped numbers and all invalid numbers are byte-identical, only the 120 previously rejected numbers change, real delivery of the six mapped signals in 8 modes is identical, and 4 to 8 threads for 2 seconds show no corruption of the table. Windows 11, WinLibs GCC 15.2.0 r7; Linux not run. AI-assisted: yes.
Sign in to join this conversation.
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#3076
No description provided.