fix(libkernel): follow the thread priority ranges and POSIX attribute errors measured on a PS5 #10133
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10133"
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 orezraey on 2026-10-23T10:35:31Z.
What
Thread priority ranges and POSIX attribute errors measured on a retail PS5 (firmware 13.60) with four homebrew probes calling
libkernel_sys.sprxfrom a payload process. The sources and console logs are in this gist (pposix,pprio,pprio2,pprio3).scePthreadSetprioandpthread_setprioaccepted any value before. A sweep of every value from -4096 to 70000 on the console accepted exactly 256–767, 896–959, 65792–66303 and 66432–66495. More values outside the sweep agree with the same rule:scePthreadGetprioreturns 65792 and -65280);EINVAL(0x80020016, or 22 frompthread_setprio); both seterrnoto 22 and leave the priority alone. A null thread returnsEINVALwithout touchingerrno.A joined or finished thread returns
ESRCHfor any priority, before the range is checked, and leaveserrnoalone.pthread_setprioreturnedESRCHfor a joined thread on the console; the order andscePthreadSetpriosettingerrnofollow firmware 13.42'slibkernel, which @BunnyFl ran in an emulator below. Before, the value was stored in the ended thread's object.scePthreadAttrSetschedparamonly takes 256–767, which AnyPS5 already did.pthread_getprio(NULL)returns -1 withEINVAL. Before, it setESRCH. A joined thread keepsESRCH.pthread_attr_getinheritschedwith a null output returnsEINVAL, aspthread_attr_getscopeandpthread_attr_getstackaddrdo. Before, it threw.pthread_mutexattr_setprioceilingtakes ceilings from 256 to 767 underPTHREAD_PRIO_PROTECT. Values 0, 255, 768 and 1000 now returnEINVAL; before, any value was stored.Already matching, now recorded as measured:
setscopetaking 0 and 2 and returningEINVALfor 1, 3 and -1;setinheritschedtaking 0 and 4 and returningENOTSUP(45) otherwise;pthread_attr_setsolosched_nptaking 0 and returningENOTSUPfor 1, 2, -1 and 100;EINVALfor null, uninitialized and destroyed attributes;EINVAL), the ceiling reset to 767 when protocol 2 is set, andEINVALfor the ceiling under any other protocol.A null output of
pthread_mutexattr_getprotocolcrashed the probe and is left as it is.Tested
main(5bdda3661e, with the firmware 13.60 debt relabel from #10179):8bef063196. The only conflict waslibkernel.md: it keeps this PR's measuredpthread_mutexattr_*entry andmain's 13.60sceCoredumpSetUserDataTypeentry. The 9guest_pthread_*tests named here pass three runs in a row on Windows 11 (WinLibs GCC 15.2) and on Linux (WSL2, GCC);check_conventionspasses.mainagain (eeb7760717, with #10130 and #10105; no conflicts):da762ebf4b.guest_pthread_attr,guest_pthread_attr_errors,guest_pthread_mutexattr,guest_pthread_schedparam,guest_pthread_start,guest_pthread_join_detach,guest_pthread_mutex_errorsandguest_pthread_destroyed_objectspass three runs in a row on Windows 11 (WinLibs GCC 15.2) and on Linux (WSL2, GCC);check_conventionspasses.main(99b8446cbc, with thepthread_rwlockattr_settype_npandsceCoredumpSetUserDataTypedebt updates):60b9e7f43f. The only conflict waslibkernel.md: it keeps this PR's measuredpthread_mutexattr_*entry andmain's newpthread_rwlockattr_settype_npentry and PPSA02225 sentence. The 9guest_pthread_*tests named here pass three runs in a row on Windows 11 (WinLibs GCC 15.2) and on Linux (WSL2, GCC);check_conventionspasses.mainagain (with #9573, through #10130's refreshed branch):496d29622c.libkernel.mdkeeps this PR's measuredpthread_getprio, scePthreadSetprio and pthread_setprioentry;scePthreadAttrGetandpthread_attr_get_npkeep #9573'screateSuspendednext to the inheritance.guest_pthread_attr,guest_pthread_attr_errors,guest_pthread_mutexattr,guest_pthread_schedparam,guest_pthread_start,guest_pthread_join_detach,guest_pthread_mutex_errors,guest_pthread_destroyed_objectsandguest_pthread_create_suspendedpass three runs in a row on Windows 11 (WinLibs GCC 15.2) and on Linux (WSL2, GCC);check_conventionspasses.main(f26434afa3, with #10706):d677bc6353. The tests take their declarations from the library headers, andThread.cppgets__errorfromlibc/include/Api.hppinstead of declaring it again. The 8guest_pthread_*tests named here pass three runs in a row on Windows (MinGW) and on Linux (WSL Ubuntu, GCC);public_headersaudit andcheck_conventionspass.Windows 11, MinGW (winlibs).
guest_pthread_attrchecks rejected priorities (-1, 0, 255, 768, 895, 960, 1023, 131840) and accepted ones read back as given (256, 900, 959, 65792, -65280), andEINVALfor a nullgetinheritschedoutput.guest_pthread_mutexattrchecks the ceiling range.guest_pthread_schedparamchecksEINVALforpthread_getprio(NULL)and theerrnorules of both setters (out of range, null, and a joined thread with an out-of-range priority).guest_pthread_attr_errors,guest_pthread_start,guest_pthread_join_detach,guest_pthread_mutex_errorsandguest_pthread_destroyed_objects.293bc5dd2b(main merged;libkernel.mdkeeps main's new SCE mutex-attribute entry and this PR's measured POSIX mutex-attribute entry):guest_pthread_attr,guest_pthread_attr_errors,guest_pthread_mutexattr,guest_pthread_schedparam,guest_pthread_start,guest_pthread_join_detach,guest_pthread_mutex_errorsandguest_pthread_destroyed_objectspass three runs in a row on Windows 11 (WinLibs GCC 15.2); the first four also pass three runs in a row on Linux (WSL2 6.18, GCC 16.2).898736710e(main merged again after #7299;libkernel.mdkeeps this PR's rewrittenpthread_attr_getinheritschedentry plus main'sShared memoryand Windowsshm_open, shm_unlinkentries):guest_pthread_attr,guest_pthread_attr_errors,guest_pthread_mutexattrandguest_pthread_schedparampass three runs in a row on Windows 11 (WinLibs GCC 15.2) and on Linux (WSL2, GCC 16.2).tools/check_conventions.pypasses.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)pthread_mutexattrprotocol debt entry), #10130, #8373, #10089, #10179 (both edit the thread-attribute debt entries; this branch carries its commits until it merges); #8373, #10089, #10179 edit the same lines too (merge order only); #10706 removes the test declarations this PR adds toGuestPthreadAttr.cpp,GuestPthreadMutexattr.cppandGuestPthreadSchedparam.cpp(merge order only)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T10:50:31Z.
Review: CHANGES_REQUESTED
The firmware 13.60 probe supports the accepted low-16-bit priority ranges, exact stored priorities, errno differences, mutex ceiling range, and null-output behavior. The regression additions cover both accepted/rejected values and live-thread cases. GCC 12.2 syntax checks passed for the changed implementation and tests; conventions, diff-check, and main-sync pass (5 ahead/29 behind; merge clean). The author reports nine related Windows thread/attribute tests passing three times. Integration is blocked by open PR #10130: the current heads conflict in
docs/dev/debt/libkernel.mdon the thread-attribute entry, and the entries need one combined update. Please coordinate the wording and landing order with #10130, preserve both measured priority and inherited-attribute findings, then refresh and rerun the overlap/convention checks. AddDepends onif one must land first. Hosted policy checks pass; product jobs are skipped by the workflow.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T11:12:54Z.
Review: APPROVED
Reviewed the exact head
8c2c979aec7a0259e1819759f111b3ad7ff55c0b. The low-16-bit priority validation matches the measured accepted ranges and preserves the input value when storing; live-thread locking prevents writes to retired thread state. The POSIX wrapper distinguishes null, invalid-priority and joined-thread outcomes as documented, and the attribute changes now return measured POSIX errors instead of throwing. The probe sources/logs are linked in the description. Exact conventions/diff checks pass and merge preview is clean. Hosted conventions, eligibility, intake, labels and report pass; product jobs were skipped by path policy. The author reports nine focused Windows thread/attribute tests passing three runs each; I did not independently run them. No blocking issue found.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T12:15:37Z.
Review: APPROVED
Reviewed the current head
a99a56fe83d7fef6428e8af2fa3acf361a417426, including the post-review updates. Priority validation uses the measured low-16-bit ranges and preserves the original accepted value; the live-thread lookup preserves the measured ESRCH-before-range behavior, while null and invalid-priority errno handling remain distinct.pthread_getprio(NULL), nullgetinheritschedoutput, and the mutex ceiling range now have matching regressions. The inheritance field is captured at thread creation and reported by both attribute query paths. The PR body lists its dependency on #10130 and carries the relevant combined thread-attribute changes. Current eligibility, conventions, labels and report checks pass; product jobs are skipped by repository policy. The author reports nine focused Windows thread/attribute tests passing three runs each; I did not independently run that suite locally.