Skip to content

feat(libkernel): add missing pthread attribute accessors - #8373

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
slider:feat/libkernel-pthread-attr-accessors
Oct 24, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
slider:feat/libkernel-pthread-attr-accessors

Conversation

@slider

@slider slider commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

What

Adds 15 missing pthread attribute accessors to libkernel. Most are the scePthread* counterparts of POSIX functions that already exist.

  • Mutex attributes: pthread_mutexattr_setkind_np and pthread_mutexattr_getkind_np, following FreeBSD 11.4 libthr (thr_mutexattr.c): an invalid attribute sets errno to EINVAL and returns -1, and the kind is the mutex type. A kind outside 1 to 4 throws, because pthread_mutex_init here does not reject it with EINVAL as FreeBSD's mutex_check_attr does. Also scePthreadMutexattrGettype, Getprotocol, Setprioceiling, Getprioceiling, Setpshared and Getpshared.
  • scePthreadMutexattrSetprotocol now stores the protocol through pthread_mutexattr_setprotocol, so scePthreadMutexattrGetprotocol reports it. It keeps the 0 to 2 range and the EINVAL results measured on a PS5 (firmware 13.60).
  • Condition variables: pthread_cond_signalto_np over the existing scePthreadCondSignalto; scePthreadCondattrSetpshared and scePthreadCondattrGetpshared.
  • Read-write locks: pthread_rwlockattr_gettype_np and scePthreadRwlockattrGettype, which report what scePthreadRwlockattrSettype stored; scePthreadRwlockattrSetpshared and scePthreadRwlockattrGetpshared.
  • Each SCE variant calls its POSIX function and returns the error as 0x8002xxxx (new PosixThread::ToSce, the inverse of ToErrno), matching how shadPS4 registers these NIDs (ORBIS(posix_...) in src/core/libraries/kernel/threads/{mutex,condvar,rwlock}.cpp).
  • Debt (docs/dev/debt/libkernel.md): scePthreadMutexattrSetprotocol's entry is cut to what is still open, and the remaining gaps are recorded: the setkind_np throw, signalto waking every waiter, and the unapplied rwlock type.

Left out on purpose:

  • pthread_condattr_getclock and scePthreadCondattrGetclock, which feat(libkernel): implement pthread_condattr_getclock #8010 implements.
  • pthread_rwlockattr_settype_np: the lock never applies the type, so it would be a new silent stub.
  • scePthreadMutexattrGetkind/Setkind/Getgen/Setgen: their console behaviour is undocumented.

Tested

Linux (Ubuntu 24.04, GCC 13.3, Release):

  • New cases pass in guest_pthread_mutexattr, guest_pthread_condattr, guest_pthread_rwlock and guest_cond_timedwait. The signalto case has a waiter woken by pthread_cond_signalto_np from another thread.
  • The existing guest_pthread_mutex_errors, guest_kernel_errors (measured scePthreadMutexattrSetprotocol results) and guest_pthread_destroyed_objects pass.
  • Breaking ToSce or the stored value makes the new tests fail.
  • tools/check_conventions.py --base origin/main passes.

Windows: every changed source and test file passes a syntax-only check with MinGW-w64 GCC 13 (not the supported 15.2); not built or run.

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

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Progress report (9446779 → bb403de)

📈 System libraries: 45.68% (+0.07%, +15 implemented functions)

✅ 15 implemented
Library Name
libkernel pthread_cond_signalto_np_nid_postfix
libkernel pthread_mutexattr_getkind_np_nid_postfix
libkernel pthread_mutexattr_setkind_np_nid_postfix
libkernel pthread_rwlockattr_gettype_np_nid_postfix
libkernel scePthreadCondattrGetpshared
libkernel scePthreadCondattrSetpshared
libkernel scePthreadMutexattrGetprioceiling
libkernel scePthreadMutexattrGetprotocol
libkernel scePthreadMutexattrGetpshared
libkernel scePthreadMutexattrGettype
libkernel scePthreadMutexattrSetprioceiling
libkernel scePthreadMutexattrSetpshared
libkernel scePthreadRwlockattrGetpshared
libkernel scePthreadRwlockattrGettype
libkernel scePthreadRwlockattrSetpshared

@github-actions

github-actions Bot commented Oct 20, 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 10061 docs/dev/debt/libkernel.md L261

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 4630 docs/dev/debt/libkernel.md
PR 5021 docs/dev/debt/libkernel.md
PR 6149 docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6830 docs/dev/debt/libkernel.md
PR 6936 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7090 docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7192 docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md
PR 7511 docs/dev/debt/libkernel.md
PR 8010 core/libs/prx/libkernel/Pthread/Posix/Cond.cpp
core/libs/tests/GuestPthreadCondattr.cpp
docs/dev/debt/libkernel.md
PR 8605 docs/dev/debt/libkernel.md
PR 9160 docs/dev/debt/libkernel.md
PR 9199 docs/dev/debt/libkernel.md
PR 9284 docs/dev/debt/libkernel.md
PR 9293 docs/dev/debt/libkernel.md
PR 9297 docs/dev/debt/libkernel.md
PR 9302 docs/dev/debt/libkernel.md
PR 9509 docs/dev/debt/libkernel.md
PR 9557 docs/dev/debt/libkernel.md
PR 9561 docs/dev/debt/libkernel.md
PR 9566 docs/dev/debt/libkernel.md
PR 9575 docs/dev/debt/libkernel.md
PR 9669 docs/dev/debt/libkernel.md
PR 9693 docs/dev/debt/libkernel.md
PR 9947 docs/dev/debt/libkernel.md
PR 10350 docs/dev/debt/libkernel.md

@adriadam10 adriadam10 self-assigned this Oct 21, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 22, 2026
@slider
slider force-pushed the feat/libkernel-pthread-attr-accessors branch from b99eaee to bb403de Compare October 23, 2026 06:29
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 23, 2026
@EagleBearerYS

Copy link
Copy Markdown
Contributor

@slider a note on order with #10173 (ours, which makes scePthreadRwlockattrSettype store only types 1 and 2, from BunnyFl's measurement on firmware 13.42). The two PRs conflict only in tests/GuestPthreadRwlock.cpp, where both add a check function before main(). #10173 goes second and keeps both functions.

One thing it changes for CheckAttrType here: the {1, 2, 0} loop sets type 0 and expects SCE_OK, but on firmware 13.42 type 0 returns 0x80020016 (EINVAL) and isn't stored. When #10173 merges after this PR, it drops 0 from that loop; the checks of the initial type 0 after pthread_rwlockattr_init stay as they are. Nothing needed on your side.

@harisibrar1 harisibrar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked against main 522e32e and FreeBSD 11.4 libthr (thr_mutexattr.c L108-133, thr_mutex.c L207-218):

  • pthread_mutexattr_setkind_np/getkind_np match FreeBSD: errno EINVAL with -1 for a null or uninitialized attribute, getkind by value. The throw for kinds outside 1-4 stands in for mutex_check_attr's later EINVAL and is recorded in libkernel.md, which seems the right call.
  • None of the 15 functions exist on current main, and the branch still merges cleanly into 522e32e. The only file shared with #9156 is libkernel.md (#9156 only adds pthread_attr_* thread-attribute forms), so the two don't overlap.
  • ToSce inverts ToErrno for every value the wrapped POSIX functions return (0 or 22), and scePthreadMutexattrSetprotocol keeps the 13.60-measured 0-2 range and EINVAL results while now storing the protocol.
  • Looks good to me; the #10173 ordering note above covers the only interaction I found.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

@adriadam10
adriadam10 merged commit c9b7582 into boykopovar:main Oct 24, 2026
10 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the new accessors against FreeBSD 11.4 libthr and the existing POSIX/SCE pairs: ToSce is the inverse of ToErrno, scePthreadMutexattrSetprotocol keeps the measured 0 to 2 range and EINVAL results while now storing the value, the new tests pin stored values and error codes, and the throw/unverified cases are recorded in docs/dev/debt/libkernel.md; merged.

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.

4 participants