feat(libkernel_sys): implement pthread_set_defaultstacksize_np, scePthreadSetDefaultstacksize and scePthreadSetName #9279

Merged
YossiYad merged 4 commits from upstream-pr/9279 into main 2026-10-22 06:16:31 +00:00
YossiYad commented 2026-10-21 17:24:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-21T17:24:16Z.


What

Three libkernel_sys exports threw. They now follow fpPS4's libkernel (LGPL-2.1):

  • pthread_set_defaultstacksize_np(size) sets the stack size used by scePthreadAttrInit and by scePthreadCreate without attributes. A size of 16384 bytes or less returns EINVAL and keeps the old default. scePthreadSetDefaultstacksize is the same call returning 0x80020016 instead.
  • scePthreadSetName(thread, name) returns nothing and renames the thread through the existing pthread_set_name_np, so a null name clears it (fpPS4).

The default used to be a constexpr of 1 MiB written twice, in Attr.cpp and Thread.cpp. It is now one atomic in Attr.cpp, read by both, still starting at 1 MiB. Attributes initialised before a change keep their size.

Not measured on a PS5; the debt entry says where the rule comes from.

Tested

Linux (Fedora 44, GCC, Ninja, -DBUILD_TESTING=ON), based on main d34da5d694:

  • New guest_kernel_sys_thread_defaults (core/libs/tests/GuestKernelSysThreadDefaults.cpp): sizes 0 and 16384 are refused by both forms and leave the default alone, 16385 is taken, a new attribute and a thread created without attributes report the new size, and scePthreadSetName sets and clears the name read back with scePthreadGetname. It aborts on main. Each of these changes made it fail: accepting 16384, scePthreadAttrInit or scePthreadCreate keeping 1 MiB, scePthreadSetName doing nothing, and the sce form returning the errno.
  • Full ctest: 1795 of 1803 pass. The 8 failures fail the same way on main on this machine and do not use these exports: application_heap_scripting, application_heap_lazy, agc_driver_guest_memory_lifetime, agc_driver_image_array_window_past_layer_limit, agc_driver_tessellation and the three net_dontwait_blocking_* cases.
  • tools/progress.py --compare: libraries +0.03%, 3 functions implemented, none lost.
  • tools/check_conventions.py --base upstream/main passes.
  • tools/pr_overlap.py: no open PR implements these three. #9141 rewrites scePthreadSetconcurrency right after the scePthreadSetName stub this removes, so whichever merges second needs a small rebase. #9160 adds lines near the removed DEFAULT_STACK_SIZE in Thread.cpp, separated by unchanged lines.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4955613113 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9279). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-21T17:24:16Z. --- ### What Three libkernel_sys exports threw. They now follow [fpPS4's libkernel](https://github.com/red-prig/fpPS4/blob/04cefd4/kernel/ps4_pthread_attr.pas#L89-L102) (LGPL-2.1): - `pthread_set_defaultstacksize_np(size)` sets the stack size used by `scePthreadAttrInit` and by `scePthreadCreate` without attributes. A size of 16384 bytes or less returns `EINVAL` and keeps the old default. `scePthreadSetDefaultstacksize` is the same call returning `0x80020016` instead. - `scePthreadSetName(thread, name)` returns nothing and renames the thread through the existing `pthread_set_name_np`, so a null name clears it ([fpPS4](https://github.com/red-prig/fpPS4/blob/04cefd4/kernel/ps4_pthread.pas#L579-L593)). The default used to be a `constexpr` of 1 MiB written twice, in `Attr.cpp` and `Thread.cpp`. It is now one atomic in `Attr.cpp`, read by both, still starting at 1 MiB. Attributes initialised before a change keep their size. Not measured on a PS5; the debt entry says where the rule comes from. ### Tested Linux (Fedora 44, GCC, Ninja, `-DBUILD_TESTING=ON`), based on `main` `d34da5d694`: - New `guest_kernel_sys_thread_defaults` (`core/libs/tests/GuestKernelSysThreadDefaults.cpp`): sizes 0 and 16384 are refused by both forms and leave the default alone, 16385 is taken, a new attribute and a thread created without attributes report the new size, and `scePthreadSetName` sets and clears the name read back with `scePthreadGetname`. It aborts on `main`. Each of these changes made it fail: accepting 16384, `scePthreadAttrInit` or `scePthreadCreate` keeping 1 MiB, `scePthreadSetName` doing nothing, and the sce form returning the errno. - Full `ctest`: 1795 of 1803 pass. The 8 failures fail the same way on `main` on this machine and do not use these exports: `application_heap_scripting`, `application_heap_lazy`, `agc_driver_guest_memory_lifetime`, `agc_driver_image_array_window_past_layer_limit`, `agc_driver_tessellation` and the three `net_dontwait_blocking_*` cases. - `tools/progress.py --compare`: libraries +0.03%, 3 functions implemented, none lost. - `tools/check_conventions.py --base upstream/main` passes. - `tools/pr_overlap.py`: no open PR implements these three. #9141 rewrites `scePthreadSetconcurrency` right after the `scePthreadSetName` stub this removes, so whichever merges second needs a small rebase. #9160 adds lines near the removed `DEFAULT_STACK_SIZE` in `Thread.cpp`, separated by unchanged lines. ### 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
github-actions[bot] commented 2026-10-21 17:25:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T17:25:07Z.


Progress report (99844c7 → 5cca233)

📈 System libraries: 42.13% (+0.03%, +3 implemented functions)

✅ 3 implemented
Library Name
libkernel_sys pthread_set_defaultstacksize_np_nid_postfix
libkernel_sys scePthreadSetDefaultstacksize
libkernel_sys scePthreadSetName
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6322220981 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9279#issuecomment-6322220981). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T17:25:07Z. --- <!-- progress-report --> ### Progress report (99844c7 → 5cca233) 📈 **System libraries**: 42.13% (+0.03%, +3 implemented functions) <details> <summary>✅ 3 implemented</summary> | Library | Name | | - | - | | libkernel_sys | `pthread_set_defaultstacksize_np_nid_postfix` | | libkernel_sys | `scePthreadSetDefaultstacksize` | | libkernel_sys | `scePthreadSetName` | </details>
github-actions[bot] commented 2026-10-21 17:49:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T17:49:06Z.


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
PR 4563 core/libs/prx/libkernel/Pthread/src/Thread.cpp L827-828
PR 8457 docs/dev/debt/libkernel_sys.md L20
PR 8531 docs/dev/debt/libkernel_sys.md L20
PR 8987 core/libs/CMakeLists.txt L311, L317
docs/dev/debt/libkernel_sys.md L20
PR 9019 core/libs/prx/libkernel_sys/Export.cpp L25
PR 9103 docs/dev/debt/libkernel_sys.md L20
PR 9141 core/libs/CMakeLists.txt L311, L317
core/libs/prx/libkernel_sys/Export.Discovery.cpp L2431-2443
docs/dev/debt/libkernel_sys.md L20
PR 9382 core/libs/prx/libkernel_sys/Export.cpp L25
PR 9632 core/libs/prx/libkernel_sys/Export.Discovery.cpp L481-490

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 3986 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 5021 core/libs/CMakeLists.txt
core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
core/libs/prx/libkernel_sys/Export.cpp
PR 5528 core/libs/prx/libkernel_sys/Export.cpp
PR 6044 core/libs/CMakeLists.txt
PR 6525 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 6740 core/libs/prx/libkernel/Pthread/include/Pthread.hpp
PR 6879 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 7149 core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 7201 core/libs/CMakeLists.txt
core/libs/prx/libkernel/Pthread/src/Thread.cpp
core/libs/prx/libkernel_sys/Export.cpp
PR 7275 core/libs/CMakeLists.txt
PR 7565 core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 7622 core/libs/CMakeLists.txt
PR 8285 core/libs/CMakeLists.txt
PR 8592 core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 8650 core/libs/CMakeLists.txt
PR 9063 core/libs/CMakeLists.txt
PR 9095 core/libs/prx/libkernel_sys/Export.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6322699589 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9279#issuecomment-6322699589). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T17:49:06Z. --- <!-- 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 | |---|---|---|---| | [PR 4563](https://www.github.com/boykopovar/AnyPS5/pull/4563) | `core/libs/prx/libkernel/Pthread/src/Thread.cpp` [L827-828](https://github.com/boykopovar/AnyPS5/blob/da54c652e30b59cdc54087e9c1fc9e46237964ca/core/libs/prx/libkernel/Pthread/src/Thread.cpp#L827-L828) | | | | [PR 8457](https://www.github.com/boykopovar/AnyPS5/pull/8457) | `docs/dev/debt/libkernel_sys.md` [L20](https://github.com/boykopovar/AnyPS5/blob/da54c652e30b59cdc54087e9c1fc9e46237964ca/docs/dev/debt/libkernel_sys.md#L20) | | | | [PR 8531](https://www.github.com/boykopovar/AnyPS5/pull/8531) | `docs/dev/debt/libkernel_sys.md` [L20](https://github.com/boykopovar/AnyPS5/blob/da54c652e30b59cdc54087e9c1fc9e46237964ca/docs/dev/debt/libkernel_sys.md#L20) | | | | [PR 8987](https://www.github.com/boykopovar/AnyPS5/pull/8987) | `core/libs/CMakeLists.txt` [L311](https://github.com/boykopovar/AnyPS5/blob/da54c652e30b59cdc54087e9c1fc9e46237964ca/core/libs/CMakeLists.txt#L311), [L317](https://github.com/boykopovar/AnyPS5/blob/da54c652e30b59cdc54087e9c1fc9e46237964ca/core/libs/CMakeLists.txt#L317)<br>`docs/dev/debt/libkernel_sys.md` [L20](https://github.com/boykopovar/AnyPS5/blob/da54c652e30b59cdc54087e9c1fc9e46237964ca/docs/dev/debt/libkernel_sys.md#L20) | | | | [PR 9019](https://www.github.com/boykopovar/AnyPS5/pull/9019) | `core/libs/prx/libkernel_sys/Export.cpp` [L25](https://github.com/boykopovar/AnyPS5/blob/da54c652e30b59cdc54087e9c1fc9e46237964ca/core/libs/prx/libkernel_sys/Export.cpp#L25) | | | | [PR 9103](https://www.github.com/boykopovar/AnyPS5/pull/9103) | `docs/dev/debt/libkernel_sys.md` [L20](https://github.com/boykopovar/AnyPS5/blob/da54c652e30b59cdc54087e9c1fc9e46237964ca/docs/dev/debt/libkernel_sys.md#L20) | | | | [PR 9141](https://www.github.com/boykopovar/AnyPS5/pull/9141) | `core/libs/CMakeLists.txt` [L311](https://github.com/boykopovar/AnyPS5/blob/da54c652e30b59cdc54087e9c1fc9e46237964ca/core/libs/CMakeLists.txt#L311), [L317](https://github.com/boykopovar/AnyPS5/blob/da54c652e30b59cdc54087e9c1fc9e46237964ca/core/libs/CMakeLists.txt#L317)<br>`core/libs/prx/libkernel_sys/Export.Discovery.cpp` [L2431-2443](https://github.com/boykopovar/AnyPS5/blob/da54c652e30b59cdc54087e9c1fc9e46237964ca/core/libs/prx/libkernel_sys/Export.Discovery.cpp#L2431-L2443)<br>`docs/dev/debt/libkernel_sys.md` [L20](https://github.com/boykopovar/AnyPS5/blob/da54c652e30b59cdc54087e9c1fc9e46237964ca/docs/dev/debt/libkernel_sys.md#L20) | | | | [PR 9382](https://www.github.com/boykopovar/AnyPS5/pull/9382) | `core/libs/prx/libkernel_sys/Export.cpp` [L25](https://github.com/boykopovar/AnyPS5/blob/da54c652e30b59cdc54087e9c1fc9e46237964ca/core/libs/prx/libkernel_sys/Export.cpp#L25) | | | | [PR 9632](https://www.github.com/boykopovar/AnyPS5/pull/9632) | `core/libs/prx/libkernel_sys/Export.Discovery.cpp` [L481-490](https://github.com/boykopovar/AnyPS5/blob/da54c652e30b59cdc54087e9c1fc9e46237964ca/core/libs/prx/libkernel_sys/Export.Discovery.cpp#L481-L490) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 3986](https://www.github.com/boykopovar/AnyPS5/pull/3986) | `core/libs/prx/libkernel/Pthread/src/Thread.cpp` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/CMakeLists.txt`<br>`core/libs/prx/libkernel/Pthread/include/Pthread.hpp`<br>`core/libs/prx/libkernel/Pthread/src/Thread.cpp`<br>`core/libs/prx/libkernel_sys/Export.cpp` | | [PR 5528](https://www.github.com/boykopovar/AnyPS5/pull/5528) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/CMakeLists.txt` | | [PR 6525](https://www.github.com/boykopovar/AnyPS5/pull/6525) | `core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 6740](https://www.github.com/boykopovar/AnyPS5/pull/6740) | `core/libs/prx/libkernel/Pthread/include/Pthread.hpp` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libkernel/Pthread/src/Thread.cpp` | | [PR 7149](https://www.github.com/boykopovar/AnyPS5/pull/7149) | `core/libs/prx/libkernel/Pthread/include/Pthread.hpp`<br>`core/libs/prx/libkernel/Pthread/src/Thread.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/CMakeLists.txt`<br>`core/libs/prx/libkernel/Pthread/src/Thread.cpp`<br>`core/libs/prx/libkernel_sys/Export.cpp` | | [PR 7275](https://www.github.com/boykopovar/AnyPS5/pull/7275) | `core/libs/CMakeLists.txt` | | [PR 7565](https://www.github.com/boykopovar/AnyPS5/pull/7565) | `core/libs/prx/libkernel/Pthread/include/Pthread.hpp`<br>`core/libs/prx/libkernel/Pthread/src/Thread.cpp` | | [PR 7622](https://www.github.com/boykopovar/AnyPS5/pull/7622) | `core/libs/CMakeLists.txt` | | [PR 8285](https://www.github.com/boykopovar/AnyPS5/pull/8285) | `core/libs/CMakeLists.txt` | | [PR 8592](https://www.github.com/boykopovar/AnyPS5/pull/8592) | `core/libs/prx/libkernel/Pthread/include/Pthread.hpp`<br>`core/libs/prx/libkernel/Pthread/src/Thread.cpp` | | [PR 8650](https://www.github.com/boykopovar/AnyPS5/pull/8650) | `core/libs/CMakeLists.txt` | | [PR 9063](https://www.github.com/boykopovar/AnyPS5/pull/9063) | `core/libs/CMakeLists.txt` | | [PR 9095](https://www.github.com/boykopovar/AnyPS5/pull/9095) | `core/libs/prx/libkernel_sys/Export.cpp` |
xXPBSXx commented 2026-10-21 19:43:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T19:43:47Z.


Independent Windows run of this PR (data only).

Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against main is clean. I built only guest_kernel_sys_thread_defaults_tests; ctest -N -R guest_kernel_sys_thread_defaults lists exactly one test.

PR head tested: 5cca233e989d2ef5fc6a26172a0a7c23ba0db4d1.

Results (3 runs each):

  • PR head: guest_kernel_sys_thread_defaults passes 3/3.
  • Baseline: I kept the PR's test and replaced only these production files: core/libs/prx/libkernel/Pthread/include/Pthread.hpp, core/libs/prx/libkernel/Pthread/src/Attr.cpp, core/libs/prx/libkernel/Pthread/src/Thread.cpp, core/libs/prx/libkernel_sys/Export.Discovery.cpp, core/libs/prx/libkernel_sys/Export.cpp with the version from the PR's merge base (99844c7eef), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards.

Not run: other platforms, the other tests in the same family, the full repository CTest, and any title or console run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6324969191 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9279#issuecomment-6324969191). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T19:43:47Z. --- Independent Windows run of this PR (data only). **Environment:** Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against `main` is clean. I built only `guest_kernel_sys_thread_defaults_tests`; `ctest -N -R guest_kernel_sys_thread_defaults` lists exactly one test. **PR head tested:** `5cca233e989d2ef5fc6a26172a0a7c23ba0db4d1`. **Results (3 runs each):** - PR head: `guest_kernel_sys_thread_defaults` passes 3/3. - Baseline: I kept the PR's test and replaced only these production files: `core/libs/prx/libkernel/Pthread/include/Pthread.hpp`, `core/libs/prx/libkernel/Pthread/src/Attr.cpp`, `core/libs/prx/libkernel/Pthread/src/Thread.cpp`, `core/libs/prx/libkernel_sys/Export.Discovery.cpp`, `core/libs/prx/libkernel_sys/Export.cpp` with the version from the PR's merge base (`99844c7eef`), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards. **Not run:** other platforms, the other tests in the same family, the full repository CTest, and any title or console run. AI-assisted (Claude Code).
YossiYad commented 2026-10-22 05:34:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-22T05:34:50Z.


@oneandonlydean @adriadam10 ready from my side: CI is green, it merges cleanly, and xXPBSXx's Windows run shows the test passing here and failing with main's library code.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6333572172 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9279#issuecomment-6333572172). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-22T05:34:50Z. --- @oneandonlydean @adriadam10 ready from my side: CI is green, it merges cleanly, and xXPBSXx's Windows run shows the test passing here and failing with `main`'s library code.
oneandonlydean commented 2026-10-22 06:02:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-22T06:02:00Z.


@YossiYad thanks, it's in my review queue now. I'll come back here with the result.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6333938514 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9279#issuecomment-6333938514). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-22T06:02:00Z. --- @YossiYad thanks, it's in my review queue now. I'll come back here with the result.
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!9279
No description provided.