Skip to content

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

Merged
oneandonlydean merged 4 commits into
boykopovar:mainfrom
YossiYad:feat/kernel-sys-thread-defaults
Oct 22, 2026
Merged

oneandonlydean merged 4 commits into
boykopovar:mainfrom
YossiYad:feat/kernel-sys-thread-defaults

Conversation

@YossiYad

Copy link
Copy Markdown
Contributor

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. feat(libkernel_sys): implement the scePthread scope, atfork and setconcurrency forms #9141 rewrites scePthreadSetconcurrency right after the scePthreadSetName stub this removes, so whichever merges second needs a small rebase. feat(libkernel_sys): identify the initial pthread #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

@github-actions

Copy link
Copy Markdown

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

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

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

@xXPBSXx

xXPBSXx commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

@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

Copy link
Copy Markdown
Collaborator

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

@oneandonlydean
oneandonlydean merged commit d6eafa5 into boykopovar:main Oct 22, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants