feat(libkernel): add missing pthread attribute accessors #8373
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8373"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by slider on 2026-10-20T11:32:49Z.
What
Adds 15 missing pthread attribute accessors to libkernel. Most are the
scePthread*counterparts of POSIX functions that already exist.pthread_mutexattr_setkind_npandpthread_mutexattr_getkind_np, following FreeBSD 11.4 libthr (thr_mutexattr.c): an invalid attribute sets errno toEINVALand returns -1, and the kind is the mutex type. A kind outside 1 to 4 throws, becausepthread_mutex_inithere does not reject it withEINVALas FreeBSD'smutex_check_attrdoes. AlsoscePthreadMutexattrGettype,Getprotocol,Setprioceiling,Getprioceiling,SetpsharedandGetpshared.scePthreadMutexattrSetprotocolnow stores the protocol throughpthread_mutexattr_setprotocol, soscePthreadMutexattrGetprotocolreports it. It keeps the 0 to 2 range and theEINVALresults measured on a PS5 (firmware 13.60).pthread_cond_signalto_npover the existingscePthreadCondSignalto;scePthreadCondattrSetpsharedandscePthreadCondattrGetpshared.pthread_rwlockattr_gettype_npandscePthreadRwlockattrGettype, which report whatscePthreadRwlockattrSettypestored;scePthreadRwlockattrSetpsharedandscePthreadRwlockattrGetpshared.0x8002xxxx(newPosixThread::ToSce, the inverse ofToErrno), matching how shadPS4 registers these NIDs (ORBIS(posix_...)insrc/core/libraries/kernel/threads/{mutex,condvar,rwlock}.cpp).docs/dev/debt/libkernel.md):scePthreadMutexattrSetprotocol's entry is cut to what is still open, and the remaining gaps are recorded: thesetkind_npthrow,signaltowaking every waiter, and the unapplied rwlock type.Left out on purpose:
pthread_condattr_getclockandscePthreadCondattrGetclock, which boykopovar/AnyPS5#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):
guest_pthread_mutexattr,guest_pthread_condattr,guest_pthread_rwlockandguest_cond_timedwait. Thesignaltocase has a waiter woken bypthread_cond_signalto_npfrom another thread.guest_pthread_mutex_errors,guest_kernel_errors(measuredscePthreadMutexattrSetprotocolresults) andguest_pthread_destroyed_objectspass.ToSceor the stored value makes the new tests fail.tools/check_conventions.py --base origin/mainpasses.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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T13:56:17Z.
Review: APPROVED
Checked against main
522e32e3b6and FreeBSD 11.4 libthr (thr_mutexattr.c L108-133, thr_mutex.c L207-218):pthread_mutexattr_setkind_np/getkind_npmatch FreeBSD: errno EINVAL with -1 for a null or uninitialized attribute, getkind by value. The throw for kinds outside 1-4 stands in formutex_check_attr's later EINVAL and is recorded in libkernel.md, which seems the right call.522e32e3b6. The only file shared with #9156 is libkernel.md (#9156 only addspthread_attr_*thread-attribute forms), so the two don't overlap.ToSceinvertsToErrnofor every value the wrapped POSIX functions return (0 or 22), andscePthreadMutexattrSetprotocolkeeps the 13.60-measured 0-2 range and EINVAL results while now storing the protocol.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.