feat(libkernel): implement sigaction #1916

Merged
johnmaia merged 3 commits from upstream-pr/1916 into main 2026-10-09 23:20:55 +00:00
johnmaia commented 2026-10-08 23:36:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-08T23:36:31Z.


What

Implements sigaction (libkernel, NID KiJEPEWRyUY). @hikazey reports in #1578 that EVO-PLAYER PPSA99039 v0.11.0 stops here once its earlier imports resolve (#1838, #1634, #1714, #1641, #1857 merged locally). At start-up, projects/evoplayer/main.cpp installs:

  • a crash handler for SIGSEGV, SIGBUS and SIGABRT (SA_SIGINFO | SA_NODEFER);
  • a quit handler for SIGTERM, SIGINT and SIGHUP (flags 0).
int sigaction(int sig, const struct sigaction* act, struct sigaction* oact);
  • Layout: FreeBSD's struct sigaction, which is the handler union at 0, sa_flags at 8, the 128-bit sa_mask at 12, and 32 bytes in all. static_asserts pin it.
  • Recording: the handler, flags and mask of every signal from 1 to 128 are recorded and returned through oact.
    • As FreeBSD's kern_sigaction does, other signal numbers return EINVAL, and so does any handler but SIG_DFL on SIGKILL or SIGSTOP.
    • signal now shares this table and records SA_RESTART, as FreeBSD's libc signal does, so mixing the two calls reports consistent results.
  • Delivery: handlers without SA_SIGINFO on the six signals signal already delivers (SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, SIGTERM) run exactly as signal handlers do. SIG_IGN and SIG_DFL are applied to the host signal as before.
  • Recorded only: SA_SIGINFO handlers and the other signals (SIGBUS, SIGHUP, ...) are recorded but never called. Calling them needs FreeBSD's siginfo_t and ucontext_t; #1431 builds the context for sceKernelRaiseException. For a signal like that, raise throws instead of terminating the process. sa_mask and the flags are not applied to delivery. All of this is in TechnicalDebt.

Overlap: none on exports. #1431 changes signal masks and exception delivery in other files (Exception.cpp, Thread.cpp), not Signals.cpp.

Tested

  • guest_signals, extended:
    • oact after signal(SIGTERM, SIG_DFL) reports SA_RESTART.
    • A plain SIGTERM handler with a mask in words 0 and 3 is delivered by raise, and round-trips through oact.
    • signal returns the handler sigaction set, and the reverse.
    • SA_SIGINFO handlers on 10, 1, 64 and 128 round-trip.
    • raise(SIGABRT) with an SA_SIGINFO handler throws.
    • Signals 0 and 129, and handlers on 9 and 17, return -1 with errno 22, while SIG_DFL on 9 and 17 succeeds.
    • Null act and oact are accepted.
  • Linux (Ubuntu 24.04.5, GCC 13.3, RX 7600): full ctest passes, 497/497.
  • Windows 11 (WinLibs GCC 15.2.0 r7): the signal and exception tests pass, 5/5.
  • No title was run here; EVO-PLAYER is a prebuilt release, and I don't run those on these machines.

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

https://claude.ai/code/session_01DwFnKjMxmwGDWiuYYf1v4D

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4794062752 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1916). Originally posted by [johnmaia](https://github.com/johnmaia) on 2026-10-08T23:36:31Z. --- ### What Implements `sigaction` (libkernel, NID `KiJEPEWRyUY`). @hikazey reports in #1578 that EVO-PLAYER PPSA99039 v0.11.0 stops here once its earlier imports resolve (#1838, #1634, #1714, #1641, #1857 merged locally). At start-up, `projects/evoplayer/main.cpp` installs: - a crash handler for `SIGSEGV`, `SIGBUS` and `SIGABRT` (`SA_SIGINFO | SA_NODEFER`); - a quit handler for `SIGTERM`, `SIGINT` and `SIGHUP` (flags 0). ```c int sigaction(int sig, const struct sigaction* act, struct sigaction* oact); ``` - **Layout:** FreeBSD's `struct sigaction`, which is the handler union at 0, `sa_flags` at 8, the 128-bit `sa_mask` at 12, and 32 bytes in all. `static_assert`s pin it. - **Recording:** the handler, flags and mask of every signal from 1 to 128 are recorded and returned through `oact`. - As FreeBSD's `kern_sigaction` does, other signal numbers return `EINVAL`, and so does any handler but `SIG_DFL` on `SIGKILL` or `SIGSTOP`. - `signal` now shares this table and records `SA_RESTART`, as FreeBSD's libc `signal` does, so mixing the two calls reports consistent results. - **Delivery:** handlers without `SA_SIGINFO` on the six signals `signal` already delivers (`SIGINT`, `SIGILL`, `SIGABRT`, `SIGFPE`, `SIGSEGV`, `SIGTERM`) run exactly as `signal` handlers do. `SIG_IGN` and `SIG_DFL` are applied to the host signal as before. - **Recorded only:** `SA_SIGINFO` handlers and the other signals (`SIGBUS`, `SIGHUP`, ...) are recorded but never called. Calling them needs FreeBSD's `siginfo_t` and `ucontext_t`; #1431 builds the context for `sceKernelRaiseException`. For a signal like that, `raise` throws instead of terminating the process. `sa_mask` and the flags are not applied to delivery. All of this is in TechnicalDebt. **Overlap:** none on exports. #1431 changes signal masks and exception delivery in other files (`Exception.cpp`, `Thread.cpp`), not `Signals.cpp`. ### Tested - `guest_signals`, extended: - `oact` after `signal(SIGTERM, SIG_DFL)` reports `SA_RESTART`. - A plain `SIGTERM` handler with a mask in words 0 and 3 is delivered by `raise`, and round-trips through `oact`. - `signal` returns the handler `sigaction` set, and the reverse. - `SA_SIGINFO` handlers on 10, 1, 64 and 128 round-trip. - `raise(SIGABRT)` with an `SA_SIGINFO` handler throws. - Signals 0 and 129, and handlers on 9 and 17, return -1 with errno 22, while `SIG_DFL` on 9 and 17 succeeds. - Null `act` and `oact` are accepted. - Linux (Ubuntu 24.04.5, GCC 13.3, RX 7600): full ctest passes, 497/497. - Windows 11 (WinLibs GCC 15.2.0 r7): the signal and exception tests pass, 5/5. - No title was run here; EVO-PLAYER is a prebuilt release, and I don't run those on these machines. ### 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) https://claude.ai/code/session_01DwFnKjMxmwGDWiuYYf1v4D
github-actions[bot] commented 2026-10-08 23:36:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T23:36:54Z.


Progress report (c9d4261 → ab658fc)

➖ System libraries: 85.63% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel sigaction_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6071170362 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1916#issuecomment-6071170362). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T23:36:54Z. --- <!-- progress-report --> ### Progress report (c9d4261 → ab658fc) ➖ **System libraries**: 85.63% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `sigaction_nid_postfix` | </details>
rmz-24 commented 2026-10-08 23:57:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rmz-24 on 2026-10-08T23:57:28Z.


Ran this on a title, since the PR says no title was run.

Windows 11, WinLibs GCC 15.2.0 r7, Release, --windows relink. EVO-PLAYER PPSA99039 v0.11.0 (release zip, SHA256 checked against the release's SHA256SUMS.txt). Base is main f1451396 with #1838, #1634, #1714, #1641 and #1857 merged locally, the same set as in #1578.

  • Without this PR: FAIL: unresolved ELF import KiJEPEWRyUY from libkernel.prx (sigaction).
  • With this PR: start-up gets past it and stops at FAIL: unresolved ELF import DRGXpDDh8Ng from libkernel.prx (lstat).

guest_signals passes on the same build.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6071404148 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1916#issuecomment-6071404148). Originally posted by [rmz-24](https://github.com/rmz-24) on 2026-10-08T23:57:28Z. --- Ran this on a title, since the PR says no title was run. Windows 11, WinLibs GCC 15.2.0 r7, Release, `--windows` relink. EVO-PLAYER PPSA99039 v0.11.0 (release zip, SHA256 checked against the release's `SHA256SUMS.txt`). Base is `main` f1451396 with #1838, #1634, #1714, #1641 and #1857 merged locally, the same set as in #1578. - Without this PR: `FAIL: unresolved ELF import KiJEPEWRyUY from libkernel.prx` (`sigaction`). - With this PR: start-up gets past it and stops at `FAIL: unresolved ELF import DRGXpDDh8Ng from libkernel.prx` (`lstat`). `guest_signals` passes on the same build. AI-assisted: yes
johnmaia commented 2026-10-09 00:14:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-09T00:14:20Z.


Checked with EVO-PLAYER v0.11.0 built from source (sainsaji/EVO-PLAYER-PS5 9715f6e: PS5 Payload SDK v0.42, pacbrew recipes and EVO's own FFmpeg 7.1.1, all from source), relinked on Linux (Ubuntu 24.04.5, RX 7600). The base was main f1451396 plus this PR, #1838, #1634, #1714, #1641, #1857 and #1529. EVO gets past KiJEPEWRyUY and stops later, while bringing up its resident decoders and before it opens a video output:

EVO boot: INFO  EVO boot: main() entry
EVO boot: INFO  EVO boot: Application::initialize entry
EVO boot: INFO  EVO vdec native: RESIDENT AVC decoder up  1920x1088 ...
EVO boot: INFO  EVO vdec native: HEVC config codec_type=974921 profile=1 max_level=123 max=1920x1088 dpb=auto depth=4
EVO boot: INFO  EVO vdec native: HEVC 1920x1088 [CreateDecoder]
terminate called after throwing an instance of 'std::runtime_error'
  what():  Videodec2: unsupported codec

As a control, preloading an abort-on-call stub for KiJEPEWRyUY over this PR's export stops it at sigaction after main() entry, so the call is made at start-up and this PR is what gets it through.

On Linux the title has 21 further unresolved imports (atoll, lstat, socketpair, tcgetattr, madvise, mkstemp, ...) that Windows only resolves on first call. I covered those with abort-on-call stubs for this run; none was called before the Videodec2 stop.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6071594618 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1916#issuecomment-6071594618). Originally posted by [johnmaia](https://github.com/johnmaia) on 2026-10-09T00:14:20Z. --- Checked with EVO-PLAYER v0.11.0 built from source (sainsaji/EVO-PLAYER-PS5 `9715f6e`: PS5 Payload SDK v0.42, pacbrew recipes and EVO's own FFmpeg 7.1.1, all from source), relinked on Linux (Ubuntu 24.04.5, RX 7600). The base was `main` `f1451396` plus this PR, #1838, #1634, #1714, #1641, #1857 and #1529. EVO gets past `KiJEPEWRyUY` and stops later, while bringing up its resident decoders and before it opens a video output: ``` EVO boot: INFO EVO boot: main() entry EVO boot: INFO EVO boot: Application::initialize entry EVO boot: INFO EVO vdec native: RESIDENT AVC decoder up 1920x1088 ... EVO boot: INFO EVO vdec native: HEVC config codec_type=974921 profile=1 max_level=123 max=1920x1088 dpb=auto depth=4 EVO boot: INFO EVO vdec native: HEVC 1920x1088 [CreateDecoder] terminate called after throwing an instance of 'std::runtime_error' what(): Videodec2: unsupported codec ``` As a control, preloading an abort-on-call stub for `KiJEPEWRyUY` over this PR's export stops it at `sigaction` after `main()` entry, so the call is made at start-up and this PR is what gets it through. On Linux the title has 21 further unresolved imports (`atoll`, `lstat`, `socketpair`, `tcgetattr`, `madvise`, `mkstemp`, ...) that Windows only resolves on first call. I covered those with abort-on-call stubs for this run; none was called before the Videodec2 stop.
klosixgaming-arch commented 2026-10-09 00:39:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-09T00:39:18Z.

Review: APPROVED


Excellent, careful implementation. The POSIX contract is handled correctly: signal range validated (EINVAL outside 1–128), SIGKILL/SIGSTOP reject a non-default handler, and the disposition (handler + flags + mask) is recorded and reported back for all 128 signals even when only a subset are natively deliverable. The boundary is exactly right — SA_SIGINFO handlers and non-signal()-delivered signals are recorded but raise of them throws (rather than a silent no-op or wrong teardown), and the limitation is spelled out in TechnicalDebt instead of being hidden. The signal() path is refactored onto the same Install()/disposition store so signal and sigaction can't drift apart, and the struct layout is pinned with static_assert. The test matrix (query, set, raise, SIGKILL/SIGSTOP, SA_SIGINFO throw, error codes, signal↔sigaction interop) is thorough.

One robustness note: handlers[] is sized 32 while dispositions[] is sized 129, and Install indexes handlers[guest] directly. That's safe today only because NativeSignal returns 0 for every guest signal at/above that bound; a future NativeSignal case added past index 31 would be an out-of-bounds write. An assert(native && guest < (int)(sizeof handlers / sizeof handlers[0])) (or sizing handlers to MaxSignal+1) would make the invariant explicit.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5464480417 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1916#pullrequestreview-5464480417). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-09T00:39:18Z. **Review:** APPROVED --- Excellent, careful implementation. The POSIX contract is handled correctly: signal range validated (EINVAL outside 1–128), SIGKILL/SIGSTOP reject a non-default handler, and the disposition (handler + flags + mask) is recorded and reported back for all 128 signals even when only a subset are natively deliverable. The boundary is exactly right — SA_SIGINFO handlers and non-`signal()`-delivered signals are recorded but `raise` of them throws (rather than a silent no-op or wrong teardown), and the limitation is spelled out in TechnicalDebt instead of being hidden. The `signal()` path is refactored onto the same `Install()`/disposition store so `signal` and `sigaction` can't drift apart, and the struct layout is pinned with `static_assert`. The test matrix (query, set, raise, SIGKILL/SIGSTOP, SA_SIGINFO throw, error codes, signal↔sigaction interop) is thorough. One robustness note: `handlers[]` is sized 32 while `dispositions[]` is sized 129, and `Install` indexes `handlers[guest]` directly. That's safe today only because `NativeSignal` returns 0 for every guest signal at/above that bound; a future `NativeSignal` case added past index 31 would be an out-of-bounds write. An `assert(native && guest < (int)(sizeof handlers / sizeof handlers[0]))` (or sizing `handlers` to `MaxSignal+1`) would make the invariant explicit. Written with AI assistance.
johnmaia commented 2026-10-09 00:51:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-09T00:51:47Z.


Thanks @klosixgaming-arch. handlers is now sized MaxSignal + 1, like dispositions (0c35d91c), so the bound no longer depends on which signals NativeSignal maps. guest_signals passes on Linux. And thanks @rmz-24 for the Windows run with the release build.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6072002579 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1916#issuecomment-6072002579). Originally posted by [johnmaia](https://github.com/johnmaia) on 2026-10-09T00:51:47Z. --- Thanks @klosixgaming-arch. `handlers` is now sized `MaxSignal + 1`, like `dispositions` (`0c35d91c`), so the bound no longer depends on which signals `NativeSignal` maps. `guest_signals` passes on Linux. And thanks @rmz-24 for the Windows run with the release build.
adriadam10 commented 2026-10-09 21:53:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T21:53:24Z.


Checked on a build of the PR merged onto current main: full ctest 527/527, guest_signals passes, and without the change the test doesn't link, so it exercises it. Layout and EINVAL cases match FreeBSD's kern_sigaction. Confirmed on EVO-PLAYER by @rmz-24 (Windows) and the author (Linux).

Added one commit: the TechnicalDebt line said raise of any recorded-only signal throws, but for signals without a native mapping (SIGBUS, SIGHUP, ...) it still returns EINVAL as on main; only SA_SIGINFO handlers on the six delivered signals throw. Worth fixing the same sentence in the PR description. The red relinker (windows) job is hardware_oracle, which this PR doesn't touch. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089883547 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1916#issuecomment-6089883547). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T21:53:24Z. --- Checked on a build of the PR merged onto current `main`: full ctest 527/527, `guest_signals` passes, and without the change the test doesn't link, so it exercises it. Layout and `EINVAL` cases match FreeBSD's `kern_sigaction`. Confirmed on EVO-PLAYER by @rmz-24 (Windows) and the author (Linux). Added one commit: the TechnicalDebt line said `raise` of any recorded-only signal throws, but for signals without a native mapping (`SIGBUS`, `SIGHUP`, ...) it still returns `EINVAL` as on `main`; only `SA_SIGINFO` handlers on the six delivered signals throw. Worth fixing the same sentence in the PR description. The red `relinker (windows)` job is `hardware_oracle`, which this PR doesn't touch. Merging.
github-actions[bot] commented 2026-10-09 22:59:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:59:22Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1619 docs/dev/TechnicalDebt.md L387
#1652 core/libs/tests/GuestSignals.cpp L48
#1926 docs/dev/TechnicalDebt.md L387
#2500 docs/dev/TechnicalDebt.md L387
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090699812 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1916#issuecomment-6090699812). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T22:59:22Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #1619 | `docs/dev/TechnicalDebt.md` [L387](https://github.com/boykopovar/AnyPS5/blob/5cb747c146c67ffd498ab7ebaced9395035a50f6/docs/dev/TechnicalDebt.md#L387) | | | | #1652 | `core/libs/tests/GuestSignals.cpp` [L48](https://github.com/boykopovar/AnyPS5/blob/5cb747c146c67ffd498ab7ebaced9395035a50f6/core/libs/tests/GuestSignals.cpp#L48) | | | | #1926 | `docs/dev/TechnicalDebt.md` [L387](https://github.com/boykopovar/AnyPS5/blob/5cb747c146c67ffd498ab7ebaced9395035a50f6/docs/dev/TechnicalDebt.md#L387) | | | | #2500 | `docs/dev/TechnicalDebt.md` [L387](https://github.com/boykopovar/AnyPS5/blob/5cb747c146c67ffd498ab7ebaced9395035a50f6/docs/dev/TechnicalDebt.md#L387) | | |
adriadam10 commented 2026-10-09 23:20:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T23:20:51Z.


Checked on a build of the PR merged onto current main: full ctest 553/553, guest_signals passes, and without the change the test doesn't link. Layout and EINVAL cases match FreeBSD's kern_sigaction; confirmed on EVO-PLAYER by @rmz-24 (Windows) and the author (Linux). Merging once CI is green on this head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090927405 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1916#issuecomment-6090927405). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T23:20:51Z. --- Checked on a build of the PR merged onto current `main`: full ctest 553/553, `guest_signals` passes, and without the change the test doesn't link. Layout and `EINVAL` cases match FreeBSD's `kern_sigaction`; confirmed on EVO-PLAYER by @rmz-24 (Windows) and the author (Linux). Merging once CI is green on this head.
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!1916
No description provided.