feat(libkernel): implement scePthreadAttrGetschedpolicy and scePthreadAttrGetinheritsched #7611
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7611"
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 Lindamea1 on 2026-10-18T16:57:28Z.
What
No library exported
scePthreadAttrGetschedpolicy(NIDNMyIQ9WgWbU) orscePthreadAttrGetinheritsched(lpMP8HhkBbg). libkernel exports their setters,scePthreadAttrSetschedpolicy(4+h9EzwKF4I) andscePthreadAttrSetinheritsched(eXbUSpEaTsA), and the POSIX getters. The relinker emits a title's NID imports as global symbols unless the title marks them weak, and Linux output binds them at load unless--lazy-bindingis given. So a title that imports either getter stops before it starts: on Linux the loader fails withsymbol lookup error: ... undefined symbol: NMyIQ9WgWbU, and on Windows the entry stub printsFAIL: unresolved ELF importfor it and stops with0xc0000139(WindowsEntryStubBuilder.cpp).Dragon Ball Xenoverse 2 (PPSA08587) imports both. In #6591 (Windows, AnyPS5
31cbb55d7), LuisAguilarDev lists them under "Local changes, not yet submitted": "libkernel:scePthreadAttrGetschedpolicyandscePthreadAttrGetinheritsched. These are imported but missing. The title has not called them yet." This PR adds them. Onmainthe title stops earlier, at the module #6592 adds ("Without it the title fails to load:Failed to load module: libSceNpTus.prx GetLastError: 126"). Of the other imports the thread lists as missing,sceNpSessionSignalingGetGroupInfois onmainsince #7125, andsceNetCtlGetInfoV6, still missing onmain, is declared by #7612. With #6592, this PR and #7612, every library and import the thread lists as missing is provided. With #6592 and those local changes, the thread reports that the title reaches its logos and then stops in AGC (stencil clear requires a writable stencil plane).FreeBSD 11.4 libthr:
_pthread_attr_getinheritschedreturnsEINVALwhenattror*attris null and otherwise stores the attribute'ssched_inherit; it does not check the output pointer._pthread_attr_getschedpolicyreturnsEINVALwhenattr,*attrorpolicyis null and otherwise storessched_policy. libkernel's sce calls return0x80020000 | errno, soEINVALis0x80020016. #4153 measured the neighbouring getters on a PS5 (firmware 13.60): a null or uninitialized attribute returnsEINVAL, and so does a null output ofscePthreadAttrGetstacksize,scePthreadAttrGetdetachstateandscePthreadAttrGetschedparam, whose libthr twins check it (L332, L182, L240). The two calls #4153 found to crash the console, a null attribute pointer toscePthreadAttrInitand a null output ofscePthreadAttrGetaffinity, are ones where libthr writes through that pointer unchecked (L361, L649-L652), so every null case measured there follows libthr. The two getters added here were not measured on a console.This PR adds both getters to
Pthread/src/Attr.cpp, next to the other getters, and they follow libthr. They return0x80020016for a null or uninitialized attribute, andscePthreadAttrGetschedpolicyalso returns it for a null output. Otherwise they store the attribute's policy or inheritance and return 0. A new attribute reports policy 1 (SCHED_FIFO) and inheritance 4 (PTHREAD_INHERIT_SCHED), the valuesscePthreadAttrInitstores. The values the setters accept (policies 1 and 3, inheritances 0 and 4) read back as set.Where this still differs from FreeBSD:
scePthreadAttrGetinheritschedthrows instead of faulting, since libthr writes through it unchecked.pthread_attr_getinheritsched(technical debt) andscePthreadAttrGetsoloschedthrow the same way, and so do the two calls that crashed the console (technical debt). This PR adds to that entry that the two getters were not measured and follow libthr, and that this case throws.scePthreadAttrGetstill fills in policy 1 and inheritance 4 for every thread (Attr.cppL84-L85). FreeBSD'spthread_attr_get_npinstead copies the thread's own attribute, whichpthread_createtook from the creation attribute. So afterscePthreadAttrGet, these getters report 1 and 4 for a thread created with explicit inheritance andSCHED_RR, whichscePthreadGetschedparamreports as 3. That belongs to a different function, and #6893 changes the same function, so it is left for a separate PR.Tested
Gentoo Linux, kernel 7.2.8, GCC 16.2.1, glibc 2.43, Release,
BUILD_TESTING=ON, onmain889cee5f9.guest_pthread_attr_errors, extended:scePthreadAttrSetschedpolicy(-1, 0, 2, 4) andscePthreadAttrSetinheritsched(-1, 1, 2, 8), the getters still report 1 and 4. After each accepted set (policies 3 then 1, inheritances 0 then 4), they report the value just set.scePthreadAttrGetschedpolicywith a null output returns0x80020016, andscePthreadAttrGetinheritschedwith a null output throwsstd::runtime_error. Both return0x80020016for a null and for an uninitialized attribute.Attr.cppreverted tomain, the test does not link (undefined reference to 'scePthreadAttrGetschedpolicy'and'scePthreadAttrGetinheritsched'). With the change it passes.nm -Don the NID-patched libraries: with the change,libkernel.prxexportsNMyIQ9WgWbUandlpMP8HhkBbg, at the addresses ofscePthreadAttrGetschedpolicyandscePthreadAttrGetinheritschedin the unpatched build. None of the other 126 NID-patched.prxfiles inbuild/core/libs/libsexports either NID. Onmain,libkernel.prxexports neither.FUNCimport of the NID,DT_NEEDEDlibkernel.prx,BIND_NOW), run against the builtlibkernel.prx. Onmain, importingNMyIQ9WgWbUstops in the loader withsymbol lookup error: ./load_NMyIQ9WgWbU: undefined symbol: NMyIQ9WgWbU(exit 127), and importinglpMP8HhkBbgfails the same way; importing the setter'seXbUSpEaTsAreachesmain. With the change, all three reachmain.pthread_attr_setschedpolicyreads back as 2.scePthreadGetschedparamreports 3, whilescePthreadAttrGetfollowed by the new getters reports 1 and 4 (the difference described above).tools/select_tests.pyas CI selects them: 1202 tests, 0 failed, 13 skipped. Fullctest -j6 --timeout 300: 1452 tests, 0 failed, 13 skipped (12 VideoOut tests andagc_driver_stencil_ref_export, which skip onmainon this machine too).Attr.cppandGuestPthreadAttrErrors.cppcompile withx86_64-w64-mingw32-g++16.2 (-fsyntax-only -Wall -Wextra). This is a syntax check, not a Windows build or run.tools/check_conventions.pypasses againstmain.tools/pr_overlap.py --branchreports no overlapping lines with other pull requests. It could not compare 20 pull requests that conflict withmainand share a file with this branch: #6044 (GuestPthreadAttrErrors.cpp) and 19 that changedocs/dev/debt/libkernel.md. Merged with this branch, each has exactly the conflicts it has withmain. Of the files in those conflicts, this branch changes onlydocs/dev/debt/libkernel.md, and its line there merges cleanly. #6044 movesGuestPthreadAttrErrors.cpptocore/libs/tests/threads/, and this branch's test changes are carried into the moved file. #6893 adds a line toscePthreadAttrGetinAttr.cppand merges with this branch without a conflict.Not run on Windows, macOS or a console.
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T16:58:04Z.
Progress report (
e1338ff→2514ead)📈 System libraries: 90.25% (+0.01%, +2 implemented functions)
✅ 2 implemented
scePthreadAttrGetinheritschedscePthreadAttrGetschedpolicyImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T17:22:59Z.
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.
docs/dev/debt/libkernel.mdcore/libs/tests/GuestPthreadAttrErrors.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T18:06:16Z.
Windows run, since the description lists Windows as not run. Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON. Build:mainc3591adf9with #7623, #7612, #7611, #7603, #7579, #7563 and #7541 merged together (each merge clean, built once).The build is clean and
guest_pthread_attr_errorspasses 3 runs of 3.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by LuisAguilarDev on 2026-10-19T02:09:49Z.
Supporting this one. Dragon Ball Xenoverse 2 (PPSA08587, #6591) needs both getters to load.
I had the same two getters on my fork since 2026-10-15 (3cb3fef): the getters return the values the existing setters store and reject a null attribute or output with
EINVAL, as the other attribute getters do. With it, the title loads and reaches the Conton City hub (Windows 11, RTX 3070 Ti). I won't open a duplicate.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T23:24:05Z.
Merged: checked diff against libthr 11.4 refs, setters' fields, test pins values; Windows run by @LeandroLP23 passes; merged.