fix(libkernel): return the console's errors from the scePthreadAttr calls #4153

Merged
hugodearaujo merged 1 commit from upstream-pr/4153 into main 2026-10-12 08:41:31 +00:00
hugodearaujo commented 2026-10-12 00:06:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-12T00:06:15Z.


What

The scePthreadAttr setters and getters threw on a null or uninitialized attribute, threw on an invalid detach state, and stored any policy, inheritance and priority. I called the console's exports from a homebrew payload on a PS5 (firmware 13.60):

Call Console main
any setter or getter below, null or zeroed attribute EINVAL (0x80020016) throws
scePthreadAttrDestroy, null or zeroed attribute EINVAL throws
Getstacksize, Getdetachstate, Getschedparam, null output EINVAL throws
Setstacksize below 16384 EINVAL EINVAL
Setdetachstate other than 0 and 1 EINVAL throws
Setschedpolicy other than 1 (SCHED_FIFO) and 3 (SCHED_RR) ENOTSUP (0x8002002D) 0, stored
Setinheritsched other than 0 (explicit) and 4 (inherit) ENOTSUP 0, stored
Setschedparam priority outside 256 to 767, or a null parameter ENOTSUP 0, stored / throws
Setaffinity, any mask 0 0

Values tried: stack sizes 0, 1, 16383, 16384, 0x10000 and 2^47 - 1; detach states -1 to 3 and 100; policies and inheritances -1 to 4 and 8; priorities -1, 0, 255, 256, 767, 768, 900 and 960; masks 0, 1, 0x7f, 0xff, 0x100 and all bits. Unlike pthread_setschedparam on a thread, the attribute rejects 896 to 959.

So these calls now return those errors. Two cases still throw because the console crashed the payload on them: a null pointer to scePthreadAttrInit and a null output to scePthreadAttrGetaffinity. A new attribute's 64 KiB default stack size on the console is not copied; the host code that runs on guest threads needs the current 1 MiB. TechnicalDebt has a new entry for all of this.

Titles: Hollow Knight: Silksong (PPSA12544) and Hades (PPSA03355) import these calls. Silksong checks the result of each one and gives up creating the thread when it is non-zero (eboot.bin 0xadd93b, 0x17264d4, 0x1bbe95c); the values it passes (policies 1 and 3, explicit inheritance, priorities 0x100, 0x104 and 0x109) are accepted both on the console and here. libSceJobManager builds worker attributes with priorities it has already checked against 0x100 to 0x2ff, so it is unaffected.

Tested

  • PS5 firmware 13.60: the table above.
  • Linux: full CTest 916/916. The new guest_pthread_attr_errors covers each row; it aborts on main.
  • Windows Server 2025 VM, WinLibs GCC 15.2, CI configure flags: 916/918, guest_pthread_attr_errors and guest_pthread_attr pass. agc_write_tracking and guest_kernel_stack_protect fail the same way on current main in this VM.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4823393284 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4153). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-12T00:06:15Z. --- ### What The `scePthreadAttr` setters and getters threw on a null or uninitialized attribute, threw on an invalid detach state, and stored any policy, inheritance and priority. I called the console's exports from a homebrew payload on a PS5 (firmware 13.60): | Call | Console | `main` | |---|---|---| | any setter or getter below, null or zeroed attribute | **`EINVAL`** (`0x80020016`) | throws | | `scePthreadAttrDestroy`, null or zeroed attribute | **`EINVAL`** | throws | | `Getstacksize`, `Getdetachstate`, `Getschedparam`, null output | **`EINVAL`** | throws | | `Setstacksize` below 16384 | `EINVAL` | `EINVAL` | | `Setdetachstate` other than 0 and 1 | **`EINVAL`** | throws | | `Setschedpolicy` other than 1 (`SCHED_FIFO`) and 3 (`SCHED_RR`) | **`ENOTSUP`** (`0x8002002D`) | 0, stored | | `Setinheritsched` other than 0 (explicit) and 4 (inherit) | **`ENOTSUP`** | 0, stored | | `Setschedparam` priority outside 256 to 767, or a null parameter | **`ENOTSUP`** | 0, stored / throws | | `Setaffinity`, any mask | 0 | 0 | Values tried: stack sizes 0, 1, 16383, 16384, 0x10000 and 2^47 - 1; detach states -1 to 3 and 100; policies and inheritances -1 to 4 and 8; priorities -1, 0, 255, 256, 767, 768, 900 and 960; masks 0, 1, 0x7f, 0xff, 0x100 and all bits. Unlike `pthread_setschedparam` on a thread, the attribute rejects 896 to 959. So these calls now return those errors. Two cases still throw because the console crashed the payload on them: a null pointer to `scePthreadAttrInit` and a null output to `scePthreadAttrGetaffinity`. A new attribute's 64 KiB default stack size on the console is not copied; the host code that runs on guest threads needs the current 1 MiB. TechnicalDebt has a new entry for all of this. Titles: Hollow Knight: Silksong (PPSA12544) and Hades (PPSA03355) import these calls. Silksong checks the result of each one and gives up creating the thread when it is non-zero (`eboot.bin` `0xadd93b`, `0x17264d4`, `0x1bbe95c`); the values it passes (policies 1 and 3, explicit inheritance, priorities 0x100, 0x104 and 0x109) are accepted both on the console and here. `libSceJobManager` builds worker attributes with priorities it has already checked against 0x100 to 0x2ff, so it is unaffected. ### Tested - PS5 firmware 13.60: the table above. - Linux: full CTest 916/916. The new `guest_pthread_attr_errors` covers each row; it aborts on `main`. - Windows Server 2025 VM, WinLibs GCC 15.2, CI configure flags: 916/918, `guest_pthread_attr_errors` and `guest_pthread_attr` pass. `agc_write_tracking` and `guest_kernel_stack_protect` fail the same way on current `main` in this VM. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [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)
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!4153
No description provided.