fix(libkernel): return ESRCH from signalto for a handle that is not a thread #13832

Merged
zaryabzip merged 1 commit from upstream-pr/13832 into main 2026-11-01 03:28:11 +00:00
zaryabzip commented 2026-10-31 08:44:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-31T08:44:34Z.


What

scePthreadCondSignalto and pthread_cond_signalto_np returned EPERM for a handle that is not a thread. A PS5 returns ESRCH there. @orezraey measured it in a payload process on firmware 13.60 (probe and log, from #11263):

Thread argument scePthreadCondSignalto pthread_cond_signalto_np main before
null 0x80020016 22 same
0x12345 0x80020003 3 0x80020001 / 1
a live thread that isn't waiting 0x80020001 1 same

The debt entry already recorded the difference. The new check sits between the null check and the not-waiting check, as the console orders them. It uses GuestThreadIsLive, the lookup pthread_getprio, sched_setparam and pthread_setaffinity_np already use to answer ESRCH. It compares the handle with the registered threads without dereferencing it. A thread that has finished but hasn't been joined wasn't tried on the console; like those calls, it now gets ESRCH here, and the debt entry says so. No function changes count.

GuestCondTimedwait.cpp's SignalTo() adds the 0x12345 case for both exports. Its existing checks still require EPERM for the calling thread, which isn't waiting.

Overlap: #13725 also changes Cond.cpp and the debt line above, in other places; git merge-tree merges the two cleanly.

Tested

Windows 11 (WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2) and Ubuntu 24.04 on WSL2 (GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1), both with the head 0a5c3be283 merged into main e8c25dd3ba.

  • No warnings in Cond.cpp or GuestCondTimedwait.cpp.
  • ctest -R "cond|pthread" -E "^agc_|^secondary_output": 69 of 69 pass on both hosts, covering the guest_cond_*, guest_pthread_*, guest_kernel_sys_pthread* and guest_ult_condition_* tests. guest_cond_timedwait passes 3 of 3 on --repeat until-fail:3. The existing checks that the calling thread gets EPERM still pass.
  • Baseline: on that main with only the test change, guest_cond_timedwait builds and then aborts at the first 0x12345 check (line 153), where main returns EPERM (Windows exit 0xc0000409, Linux SIGABRT).
  • tools/check_conventions.py passes.

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5096035623 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13832). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-10-31T08:44:34Z. --- ### What `scePthreadCondSignalto` and `pthread_cond_signalto_np` returned `EPERM` for a handle that is not a thread. A PS5 returns `ESRCH` there. @orezraey measured it in a payload process on firmware 13.60 ([probe and log](https://gist.github.com/orezraey/c423a99dcf8b8775bf116eba2d41fca1), from #11263): | Thread argument | `scePthreadCondSignalto` | `pthread_cond_signalto_np` | `main` before | |---|---|---|---| | null | `0x80020016` | 22 | same | | `0x12345` | `0x80020003` | 3 | `0x80020001` / 1 | | a live thread that isn't waiting | `0x80020001` | 1 | same | The debt entry already recorded the difference. The new check sits between the null check and the not-waiting check, as the console orders them. It uses `GuestThreadIsLive`, the lookup `pthread_getprio`, `sched_setparam` and `pthread_setaffinity_np` already use to answer `ESRCH`. It compares the handle with the registered threads without dereferencing it. A thread that has finished but hasn't been joined wasn't tried on the console; like those calls, it now gets `ESRCH` here, and the debt entry says so. No function changes count. `GuestCondTimedwait.cpp`'s `SignalTo()` adds the `0x12345` case for both exports. Its existing checks still require `EPERM` for the calling thread, which isn't waiting. Overlap: #13725 also changes `Cond.cpp` and the debt line above, in other places; `git merge-tree` merges the two cleanly. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 (WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2) and Ubuntu 24.04 on WSL2 (GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1), both with the head 0a5c3be283 merged into `main` e8c25dd3ba. - No warnings in `Cond.cpp` or `GuestCondTimedwait.cpp`. - `ctest -R "cond|pthread" -E "^agc_|^secondary_output"`: 69 of 69 pass on both hosts, covering the `guest_cond_*`, `guest_pthread_*`, `guest_kernel_sys_pthread*` and `guest_ult_condition_*` tests. `guest_cond_timedwait` passes 3 of 3 on `--repeat until-fail:3`. The existing checks that the calling thread gets `EPERM` still pass. - Baseline: on that `main` with only the test change, `guest_cond_timedwait` builds and then aborts at the first `0x12345` check (line 153), where `main` returns `EPERM` (Windows exit 0xc0000409, Linux SIGABRT). - `tools/check_conventions.py` passes. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
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!13832
No description provided.