feat(libc): implement siginterrupt through the sigaction libkernel registers #8872

Merged
ycbuzi merged 5 commits from upstream-pr/8872 into main 2026-10-24 17:39:00 +00:00
ycbuzi commented 2026-10-21 03:54:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T03:54:07Z.


What

libc.prx exports siginterrupt (TsrS8nGDQok, a libSceLibcInternal export in the public SDK's stub table) and runs FreeBSD 11.4's lib/libc/gen/siginterrupt.c sequence: read the signal's disposition with sigaction, set or clear the signal's bit in _sigintr and SA_RESTART in the flags, install the disposition again. EINVAL for a signal outside 1 to 128 comes from the first sigaction, as there.

libc cannot call libkernel (libkernel links libc), so this follows the pattern the pthread hooks already use: libc keeps a registered sigaction and the address of the _sigintr set (RegisterSigaction_nid_no_patch in General.hpp), and libkernel registers both from a static initializer in Signals.cpp when it loads, as RegisterPthreadOnLoad does in Thread.cpp. A call before that registration throws. The set is written outside libkernel's registration lock, as FreeBSD's libc writes it without one; the libc debt entry says so, and the libkernel signal entry from #8866 now points here.

#8866, now merged, added the _sigintr export to libkernel and made signal honour it; this PR builds on it.

Refs #8846: this PR only adds siginterrupt. On main, _sigintr is exported by libkernel but not by libkernel_sys or libkernel_web, which the issue also asks for, so it should stay open.

Tested

Windows 11, MinGW GCC 15.2.0, Release, BUILD_TESTING=ON, on main 05f9995704 plus #8866:

  • guest_signals, extended: siginterrupt(30, 1) sets bit 29 and clears SA_RESTART on the installed handler, a following signal(30) registers without SA_RESTART, siginterrupt(30, 0) clears the bit and restores SA_RESTART; the same on signal 128 (bit 127) with the default disposition; 0, -1 and 129 fail with EINVAL and leave the set alone. guest_signals passes (1 of 1).
  • Revert check: with libkernel's registration commented out (everything else kept) the test fails, as siginterrupt throws; restored, it passes. It exits with 0xc0000409 and what(): siginterrupt: libkernel has not registered sigaction on the reverted build, and passes again on the restored one.
  • tools/import_audit.py on a one-line registry importing TsrS8nGDQok from libSceLibcInternal.prx against the built libraries: implemented 1, absent 0; the tool exits 1 only to note that --libs has no file named libSceLibcInternal.prx, which libc.prx serves.
  • python tools/check_conventions.py --base origin/main --head HEAD passes.
  • Not run: Linux.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4946137170 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8872). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-21T03:54:07Z. --- ### What `libc.prx` exports `siginterrupt` (`TsrS8nGDQok`, a libSceLibcInternal export in the public SDK's stub table) and runs FreeBSD 11.4's `lib/libc/gen/siginterrupt.c` sequence: read the signal's disposition with `sigaction`, set or clear the signal's bit in `_sigintr` and `SA_RESTART` in the flags, install the disposition again. `EINVAL` for a signal outside 1 to 128 comes from the first `sigaction`, as there. libc cannot call libkernel (libkernel links libc), so this follows the pattern the pthread hooks already use: libc keeps a registered `sigaction` and the address of the `_sigintr` set (`RegisterSigaction_nid_no_patch` in `General.hpp`), and libkernel registers both from a static initializer in `Signals.cpp` when it loads, as `RegisterPthreadOnLoad` does in `Thread.cpp`. A call before that registration throws. The set is written outside libkernel's registration lock, as FreeBSD's libc writes it without one; the libc debt entry says so, and the libkernel `signal` entry from #8866 now points here. #8866, now merged, added the `_sigintr` export to `libkernel` and made `signal` honour it; this PR builds on it. Refs #8846: this PR only adds `siginterrupt`. On `main`, `_sigintr` is exported by `libkernel` but not by `libkernel_sys` or `libkernel_web`, which the issue also asks for, so it should stay open. ### Tested Windows 11, MinGW GCC 15.2.0, Release, `BUILD_TESTING=ON`, on `main` 05f9995704 plus #8866: - `guest_signals`, extended: `siginterrupt(30, 1)` sets bit 29 and clears `SA_RESTART` on the installed handler, a following `signal(30)` registers without `SA_RESTART`, `siginterrupt(30, 0)` clears the bit and restores `SA_RESTART`; the same on signal 128 (bit 127) with the default disposition; 0, -1 and 129 fail with `EINVAL` and leave the set alone. `guest_signals` passes (1 of 1). - Revert check: with libkernel's registration commented out (everything else kept) the test fails, as `siginterrupt` throws; restored, it passes. It exits with `0xc0000409` and `what(): siginterrupt: libkernel has not registered sigaction` on the reverted build, and passes again on the restored one. - `tools/import_audit.py` on a one-line registry importing `TsrS8nGDQok` from `libSceLibcInternal.prx` against the built libraries: `implemented 1, absent 0`; the tool exits 1 only to note that `--libs` has no file named `libSceLibcInternal.prx`, which `libc.prx` serves. - `python tools/check_conventions.py --base origin/main --head HEAD` passes. - Not run: Linux. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-21 04:24:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T04:24:43Z.


Manual review of the overlap warning: #6565 appends a libc debt entry at the end of debt/libc.md, where this PR also appends its siginterrupt entry; retain both entries when rebasing. The Signals.cpp overlap with #3986 is in blocked-signal/raise logic, while this PR adds the registration hook and updates signal for _sigintr; #7201/#7622 touch only alarm handling. Other debt-file overlaps are unrelated entries. The code overlap is line-disjoint; the only integration change I found is keeping both appended debt entries.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6308007230 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8872#issuecomment-6308007230). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T04:24:43Z. --- Manual review of the overlap warning: #6565 appends a libc debt entry at the end of `debt/libc.md`, where this PR also appends its `siginterrupt` entry; retain both entries when rebasing. The `Signals.cpp` overlap with #3986 is in blocked-signal/raise logic, while this PR adds the registration hook and updates `signal` for `_sigintr`; #7201/#7622 touch only alarm handling. Other debt-file overlaps are unrelated entries. The code overlap is line-disjoint; the only integration change I found is keeping both appended debt entries.
ycbuzi commented 2026-10-21 04:30:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T04:30:46Z.


Thanks for the overlap check. Noted for the rebase: both libc debt entries (#6565's and the siginterrupt one here) stay, and the Signals.cpp hunks (registration at the end of the file, the _sigintr line in signal) are apart from #3986's blocked-signal and raise changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6308082127 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8872#issuecomment-6308082127). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-21T04:30:46Z. --- Thanks for the overlap check. Noted for the rebase: both libc debt entries (#6565's and the `siginterrupt` one here) stay, and the `Signals.cpp` hunks (registration at the end of the file, the `_sigintr` line in `signal`) are apart from #3986's blocked-signal and `raise` changes.
mazen320 commented 2026-10-21 20:41:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mazen320 on 2026-10-21T20:41:06Z.


Console measurement (PS5 FTP 192.168.0.144, /system/common/lib). Parsed each modules DT_SYMTAB/DT_STRTAB` (no Ghidra).

_sigintr (nQVWJEGHObc)

Module SHA-256 (prefix) st_info bind st_size storage
libkernel.sprx f89a698bf7a0… STT_OBJECT STB_GLOBAL 16 BSS (zero-init)
libkernel_sys.sprx 60921322b155… STT_OBJECT STB_GLOBAL 16 BSS
libkernel_web.sprx 4ab93ee107e8… STT_OBJECT STB_GLOBAL 16 BSS

String form in those modules is nQVWJEGHObc#I#A. That matches a 16-byte sigset_t (four uint32 words) and the FreeBSD zero-init lead in #8846.

  • libSceLibcInternal.sprx has nQVWJEGHObc#A#B as an undefined import (st_size 0, shndx 0), not a provider.
  • siginterrupt (TsrS8nGDQok) is a STT_FUNC in LibcInternal (st_size 128) and is absent from the three kernel modules` dynsym — consistent with putting the function in libc and the bitmap in libkernel (#8872 / #8866 split).

No title run. AI-assisted parse of the pulled SPRX files.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6326081323 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8872#issuecomment-6326081323). Originally posted by [mazen320](https://github.com/mazen320) on 2026-10-21T20:41:06Z. --- Console measurement (PS5 FTP `192.168.0.144`, `/system/common/lib`). Parsed each module`s `DT_SYMTAB`/`DT_STRTAB` (no Ghidra). ### `_sigintr` (`nQVWJEGHObc`) | Module | SHA-256 (prefix) | `st_info` | bind | `st_size` | storage | | --- | --- | --- | --- | --- | --- | | `libkernel.sprx` | `f89a698bf7a0…` | `STT_OBJECT` | `STB_GLOBAL` | **16** | BSS (zero-init) | | `libkernel_sys.sprx` | `60921322b155…` | `STT_OBJECT` | `STB_GLOBAL` | **16** | BSS | | `libkernel_web.sprx` | `4ab93ee107e8…` | `STT_OBJECT` | `STB_GLOBAL` | **16** | BSS | String form in those modules is `nQVWJEGHObc#I#A`. That matches a 16-byte `sigset_t` (four `uint32` words) and the FreeBSD zero-init lead in #8846. ### Related - `libSceLibcInternal.sprx` has `nQVWJEGHObc#A#B` as an **undefined** import (`st_size` 0, `shndx` 0), not a provider. - `siginterrupt` (`TsrS8nGDQok`) is a **`STT_FUNC`** in LibcInternal (`st_size` 128) and is **absent** from the three kernel modules` dynsym — consistent with putting the function in libc and the bitmap in libkernel (#8872 / #8866 split). No title run. AI-assisted parse of the pulled SPRX files.
mazen320 commented 2026-10-21 21:42:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mazen320 on 2026-10-21T21:42:44Z.


Console siginterrupt (TsrS8nGDQok) in libSceLibcInternal.sprx, Ghidra 12.1.4 headless decompile (x86:LE:64:default:gcc), plus NID resolve:

  • Function body size matches dynsym (st_size 128).
  • It imports/uses _sigintr (nQVWJEGHObc) and calls sigaddset (JUimFtKe0Kc).
  • Control flow matches FreeBSD: sigaction query → if flag==0 clear bit in _sigintr and set SA_RESTART (|= 2), else set bit and clear SA_RESTART (&= ~2) → sigaction install. Stack cookie via f7uOxY9mM1U / Ou3iL1abvng.

This is static evidence from the pulled firmware module; no title run. Aligns with #8866/#8872’s FreeBSD-shaped split (bitmap in libkernel, function in libc).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6327202262 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8872#issuecomment-6327202262). Originally posted by [mazen320](https://github.com/mazen320) on 2026-10-21T21:42:44Z. --- Console `siginterrupt` (`TsrS8nGDQok`) in `libSceLibcInternal.sprx`, Ghidra 12.1.4 headless decompile (x86:LE:64:default:gcc), plus NID resolve: - Function body size matches dynsym (`st_size` 128). - It imports/uses `_sigintr` (`nQVWJEGHObc`) and calls `sigaddset` (`JUimFtKe0Kc`). - Control flow matches FreeBSD: `sigaction` query → if `flag==0` clear bit in `_sigintr` and set `SA_RESTART` (`|= 2`), else set bit and clear `SA_RESTART` (`&= ~2`) → `sigaction` install. Stack cookie via `f7uOxY9mM1U` / `Ou3iL1abvng`. This is static evidence from the pulled firmware module; no title run. Aligns with #8866/#8872’s FreeBSD-shaped split (bitmap in libkernel, function in libc).
mazen320 commented 2026-10-21 21:43:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mazen320 on 2026-10-21T21:43:31Z.


Correction on the imported NIDs from the same Ghidra decompile (hyphens, not underscores):

  • UDCI-WazohQ → sigaction (already implemented)
  • Nd-u09VFSCA → resolve below / expected sigdelset
  • JUimFtKe0Kc → sigaddset (confirmed)
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6327215343 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8872#issuecomment-6327215343). Originally posted by [mazen320](https://github.com/mazen320) on 2026-10-21T21:43:31Z. --- Correction on the imported NIDs from the same Ghidra decompile (hyphens, not underscores): - `UDCI-WazohQ` → `sigaction` (already implemented) - `Nd-u09VFSCA` → resolve below / expected `sigdelset` - `JUimFtKe0Kc` → `sigaddset` (confirmed)
ycbuzi commented 2026-10-21 21:52:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T21:52:02Z.


Checked those NIDs by hash: Nd-u09VFSCA is sigdelset and JUimFtKe0Kc is sigaddset, as you have, but UDCI-WazohQ is _sigaction, not sigaction (KiJEPEWRyUY), which matches FreeBSD's siginterrupt calling _sigaction. #8872 calls the sigaction libkernel registers instead of importing either, with the same steps: query, set or clear the _sigintr bit with SA_RESTART cleared or set, install.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6327357704 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8872#issuecomment-6327357704). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-21T21:52:02Z. --- Checked those NIDs by hash: `Nd-u09VFSCA` is `sigdelset` and `JUimFtKe0Kc` is `sigaddset`, as you have, but `UDCI-WazohQ` is `_sigaction`, not `sigaction` (`KiJEPEWRyUY`), which matches FreeBSD's `siginterrupt` calling `_sigaction`. #8872 calls the `sigaction` libkernel registers instead of importing either, with the same steps: query, set or clear the `_sigintr` bit with `SA_RESTART` cleared or set, install.
EagleBearerYS commented 2026-10-22 00:50:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T00:50:26Z.


@ycbuzi on this one: #9499 registers libkernel's sigprocmask with libc at the end of Signals.cpp, where this PR registers sigaction. Both registrations stay. #9499 proposes going right after #8866 and before this PR, which would then rebase over it. If you'd rather this one went first, say so and #9499 will list it under Depends on.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329957978 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8872#issuecomment-6329957978). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-22T00:50:26Z. --- @ycbuzi on this one: #9499 registers libkernel's `sigprocmask` with libc at the end of `Signals.cpp`, where this PR registers `sigaction`. Both registrations stay. #9499 proposes going right after #8866 and before this PR, which would then rebase over it. If you'd rather this one went first, say so and #9499 will list it under Depends on.
ycbuzi commented 2026-10-22 01:49:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-22T01:49:39Z.


Either order works: the sigaction registration here and the sigprocmask one in #9499 are separate lines at the end of Signals.cpp, so whichever lands second rebases over the other. Going after #9499 is fine; I'll rebase this one when it lands.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6330732217 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8872#issuecomment-6330732217). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-22T01:49:39Z. --- Either order works: the `sigaction` registration here and the `sigprocmask` one in #9499 are separate lines at the end of `Signals.cpp`, so whichever lands second rebases over the other. Going after #9499 is fine; I'll rebase this one when it lands.
harisibrar1 commented 2026-10-24 13:25:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T13:25:14Z.

Review: COMMENTED


Checked against main 6cd36e6517 and FreeBSD releng/11.4 lib/libc/gen/siginterrupt.c:

  • The sequence matches siginterrupt.c: query, set or clear the bit with SA_RESTART cleared or set, then reinstall. EINVAL comes from the first sigaction before the set is touched. The struct layout matches GuestSigaction (32 bytes, flags at 8, mask at 12), and TsrS8nGDQok hashes from siginterrupt. It still merges cleanly onto main.
  • One design question. Main now has a separate libSceLibcInternal prx that links libkernel (core/libs/CMakeLists.txt:169) and already calls libkernel exports directly, e.g. utimes_nid_postfix in libSceLibcInternal/FileTime.cpp and fcntl/close in Directory.cpp. Since the console's siginterrupt is a LibcInternal function that imports _sigaction (per the decompile above), could it live there and call _sigaction_nid_postfix and _sigintr_nid_postfix directly? That would drop RegisterSigaction_nid_no_patch, the static initializer at the end of Signals.cpp (the same spot #9499 uses), the duplicated InterruptSigaction, and the throw when a call comes before registration. I haven't checked which prx the loader resolves a libSceLibcInternal import to, so if there's a reason it has to be libc.prx, please ignore this.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638405164 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8872#pullrequestreview-5638405164). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T13:25:14Z. **Review:** COMMENTED --- Checked against main 6cd36e6517 and FreeBSD releng/11.4 `lib/libc/gen/siginterrupt.c`: - The sequence matches `siginterrupt.c`: query, set or clear the bit with `SA_RESTART` cleared or set, then reinstall. `EINVAL` comes from the first `sigaction` before the set is touched. The struct layout matches `GuestSigaction` (32 bytes, flags at 8, mask at 12), and `TsrS8nGDQok` hashes from `siginterrupt`. It still merges cleanly onto main. - One design question. Main now has a separate `libSceLibcInternal` prx that links libkernel (`core/libs/CMakeLists.txt:169`) and already calls libkernel exports directly, e.g. `utimes_nid_postfix` in `libSceLibcInternal/FileTime.cpp` and `fcntl`/`close` in `Directory.cpp`. Since the console's `siginterrupt` is a LibcInternal function that imports `_sigaction` (per the decompile above), could it live there and call `_sigaction_nid_postfix` and `_sigintr_nid_postfix` directly? That would drop `RegisterSigaction_nid_no_patch`, the static initializer at the end of `Signals.cpp` (the same spot #9499 uses), the duplicated `InterruptSigaction`, and the throw when a call comes before registration. I haven't checked which prx the loader resolves a `libSceLibcInternal` import to, so if there's a reason it has to be libc.prx, please ignore this. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
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!8872
No description provided.