feat(libkernel): implement pthread_kill #3047

Merged
babyhuey merged 2 commits from upstream-pr/3047 into main 2026-10-11 05:44:03 +00:00
babyhuey commented 2026-10-10 21:09:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-10T21:09:32Z.


What

Implements pthread_kill (yH-uQW3LbX0) in libkernel. Like FreeBSD's, it returns the error number instead of setting errno: EINVAL for a signal outside 0 to 128 and ESRCH for a null thread. Signal 0 only checks the handle. A signal to the calling thread goes through raise, so it uses the same handlers and limits as raise and kill. A signal to another thread throws NotImplemented, since guest signals are not delivered to a chosen thread yet (#1431). TechnicalDebt records both limits.

Ruffle (PPSA68091) stops at it on main (catalog build, eboot.bin and sce_module/libc.prx unwrapped as #2605 requires; tracked in #1578):

  • main 56fb1b3b, Linux: app.elf: symbol lookup error: app.elf: undefined symbol: yH-uQW3LbX0
  • with this PR, Linux (on 262c0316): app.elf: symbol lookup error: app.elf: undefined symbol: 04AjkP0jO9U (_umtx_op, #1482)

With #1482's wait/wake also in place, Ruffle goes on to 0Ma-LQjv6So without calling pthread_kill during start-up, so it only needs the export to be there for now.

Tested

Linux (Ubuntu 24.04, GCC 13, Release) on 262c0316: guest_signals passes 5/5 (--repeat until-fail:5). The new cases deliver signal 15 to the calling thread through its handler, check that signal 0 delivers nothing, check EINVAL for 200 and -1 and ESRCH for a null thread, and check that a signal to another thread throws without delivering. check_conventions.py passes. Windows 11 (MinGW-w64 GCC 15.2 from WinLibs, Release) on 262c0316: guest_signals 5/5 with no warnings and no crash dialog; Ruffle stops at FAIL: unresolved ELF import yH-uQW3LbX0 (pthread_kill) from libkernel.prx on main and at FAIL: unresolved ELF import 04AjkP0jO9U (_umtx_op) from libkernel.prx with this PR.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4814452996 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3047). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-10T21:09:32Z. --- ### What Implements `pthread_kill` (`yH-uQW3LbX0`) in libkernel. Like FreeBSD's, it returns the error number instead of setting `errno`: `EINVAL` for a signal outside 0 to 128 and `ESRCH` for a null thread. Signal 0 only checks the handle. A signal to the calling thread goes through `raise`, so it uses the same handlers and limits as `raise` and `kill`. A signal to another thread throws `NotImplemented`, since guest signals are not delivered to a chosen thread yet (#1431). TechnicalDebt records both limits. Ruffle (PPSA68091) stops at it on `main` (catalog build, `eboot.bin` and `sce_module/libc.prx` unwrapped as #2605 requires; tracked in #1578): - `main` 56fb1b3b, Linux: `app.elf: symbol lookup error: app.elf: undefined symbol: yH-uQW3LbX0` - with this PR, Linux (on 262c0316): `app.elf: symbol lookup error: app.elf: undefined symbol: 04AjkP0jO9U` (`_umtx_op`, #1482) With #1482's wait/wake also in place, Ruffle goes on to `0Ma-LQjv6So` without calling `pthread_kill` during start-up, so it only needs the export to be there for now. ### Tested Linux (Ubuntu 24.04, GCC 13, Release) on 262c0316: `guest_signals` passes 5/5 (`--repeat until-fail:5`). The new cases deliver signal 15 to the calling thread through its handler, check that signal 0 delivers nothing, check `EINVAL` for 200 and -1 and `ESRCH` for a null thread, and check that a signal to another thread throws without delivering. `check_conventions.py` passes. Windows 11 (MinGW-w64 GCC 15.2 from WinLibs, Release) on 262c0316: `guest_signals` 5/5 with no warnings and no crash dialog; Ruffle stops at `FAIL: unresolved ELF import yH-uQW3LbX0 (pthread_kill) from libkernel.prx` on `main` and at `FAIL: unresolved ELF import 04AjkP0jO9U (_umtx_op) from libkernel.prx` with this PR. ### 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
github-actions[bot] commented 2026-10-10 21:09:55 +00:00 (Migrated from github.com)

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


Progress report (77bd928 → 0e88f30)

📉 System libraries: 85.94% (-0.03%, +1 declared functions)

🆕 1 declared as stubs
Library Name
libkernel pthread_kill_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102205949 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3047#issuecomment-6102205949). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T21:09:55Z. --- <!-- progress-report --> ### Progress report (77bd928 → 0e88f30) 📉 **System libraries**: 85.94% (-0.03%, +1 declared functions) <details> <summary>🆕 1 declared as stubs</summary> | Library | Name | | - | - | | libkernel | `pthread_kill_nid_postfix` | </details>
Dextroid17 commented 2026-10-10 22:59:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-10T22:59:25Z.

Review: COMMENTED


The semantics here are right and better sourced than most: returning the error number rather than setting errno is what FreeBSD does, routing a self-signal through raise means it inherits the same handlers and limits as kill, and the test's received == 0 check after the other-thread throw proves no signal leaked while the not-implemented path was taken. The title is named and both limits are in the debt entry, which is the whole package this tree asks for.

One small thing I would change: both return values already have names in this tree. Pthread/Posix/Common.hpp defines GUEST_ESRCH = 3, GUEST_EINVAL = 22, GUEST_EFAULT = 14 and GUEST_ETIMEDOUT = 60 — precisely because a pthread_* function returns a guest errno rather than a SceKernelError, and that distinction is invisible inside a bare literal. Using GUEST_ESRCH and GUEST_EINVAL would say which family is meant without the reader having to go and check.

And the boundary is unpinned. MaxSignal is 128 and the test is guest > MaxSignal, so 128 is a valid signal and 129 is not — but the test covers 200 and -1 rather than either side of the line. A case each way is a line apiece and stops the next reader re-deriving it.

One practical note in case it is not on your radar: GitHub reports this PR as conflicting, so it needs a rebase onto main. The conflict is a doc-line collision in docs/dev/TechnicalDebt.md — Signals.cpp is byte-identical between your base and current main, which I checked before writing it down.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5481114868 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3047#pullrequestreview-5481114868). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-10T22:59:25Z. **Review:** COMMENTED --- The semantics here are right and better sourced than most: returning the error number rather than setting `errno` is what FreeBSD does, routing a self-signal through `raise` means it inherits the same handlers and limits as `kill`, and the test's `received == 0` check after the other-thread throw proves no signal leaked while the not-implemented path was taken. The title is named and both limits are in the debt entry, which is the whole package this tree asks for. **One small thing I would change: both return values already have names in this tree.** `Pthread/Posix/Common.hpp` defines `GUEST_ESRCH = 3`, `GUEST_EINVAL = 22`, `GUEST_EFAULT = 14` and `GUEST_ETIMEDOUT = 60` — precisely because a `pthread_*` function returns a *guest errno* rather than a `SceKernelError`, and that distinction is invisible inside a bare literal. Using `GUEST_ESRCH` and `GUEST_EINVAL` would say which family is meant without the reader having to go and check. **And the boundary is unpinned.** `MaxSignal` is 128 and the test is `guest > MaxSignal`, so 128 is a valid signal and 129 is not — but the test covers 200 and -1 rather than either side of the line. A case each way is a line apiece and stops the next reader re-deriving it. **One practical note in case it is not on your radar:** GitHub reports this PR as conflicting, so it needs a rebase onto `main`. The conflict is a doc-line collision in `docs/dev/TechnicalDebt.md` — `Signals.cpp` is byte-identical between your base and current `main`, which I checked before writing it down. Written with AI assistance.
babyhuey commented 2026-10-10 23:25:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-10T23:25:03Z.


Thanks @Dextroid17, all three done. Rebased onto main 2b5d119f (the only conflict was the TechnicalDebt line next to kill, kept both), and a new commit on top returns PosixThread::GUEST_EINVAL and GUEST_ESRCH and adds the edge cases pthread_kill(nullptr, 128) == ESRCH and pthread_kill(nullptr, 129) == EINVAL. guest_signals still passes on Linux and Ruffle still goes on to _umtx_op.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103292126 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3047#issuecomment-6103292126). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-10T23:25:03Z. --- Thanks @Dextroid17, all three done. Rebased onto `main` 2b5d119f (the only conflict was the TechnicalDebt line next to `kill`, kept both), and a new commit on top returns `PosixThread::GUEST_EINVAL` and `GUEST_ESRCH` and adds the edge cases `pthread_kill(nullptr, 128) == ESRCH` and `pthread_kill(nullptr, 129) == EINVAL`. `guest_signals` still passes on Linux and Ruffle still goes on to `_umtx_op`.
oneandonlydean commented 2026-10-11 01:08:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T01:08:23Z.


Conflicts with main in Signals.cpp after the alarm changes (e5ae8dfc); please rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104053051 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3047#issuecomment-6104053051). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T01:08:23Z. --- Conflicts with main in `Signals.cpp` after the `alarm` changes (e5ae8dfc); please rebase.
babyhuey commented 2026-10-11 01:14:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T01:14:20Z.


Rebased onto main 77bd928a (0e88f301). The only conflict was the include list in Signals.cpp, where I kept both <string> and <thread>. guest_signals passes 5/5 on Linux, and Ruffle (PPSA68091) still gets past pthread_kill to _umtx_op (#1482).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104095351 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3047#issuecomment-6104095351). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-11T01:14:20Z. --- Rebased onto `main` 77bd928a (0e88f301). The only conflict was the include list in `Signals.cpp`, where I kept both `<string>` and `<thread>`. `guest_signals` passes 5/5 on Linux, and Ruffle (PPSA68091) still gets past `pthread_kill` to `_umtx_op` (#1482).
github-actions[bot] commented 2026-10-11 03:39:13 +00:00 (Migrated from github.com)

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


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
#3152 docs/dev/TechnicalDebt.md L519
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105097134 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3047#issuecomment-6105097134). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T03:39:13Z. --- <!-- 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 | |---|---|---|---| | #3152 | `docs/dev/TechnicalDebt.md` [L519](https://github.com/boykopovar/AnyPS5/blob/90f26c996cb9b4ad48453e407c2026e088117d87/docs/dev/TechnicalDebt.md#L519) | | |
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!3047
No description provided.