Repository navigation
feat(libkernel): implement scePthreadAttrGetschedpolicy and scePthreadAttrGetinheritsched - #7611
Conversation
…dAttrGetinheritsched libkernel exported scePthreadAttrSetschedpolicy and scePthreadAttrSetinheritsched but not the matching getters, scePthreadAttrGetschedpolicy (NID NMyIQ9WgWbU) and scePthreadAttrGetinheritsched (NID lpMP8HhkBbg), so a title that imports either one stopped at startup on the unresolved import. Dragon Ball Xenoverse 2 (PPSA08587) imports both. Implement them as FreeBSD 11.4 libthr implements pthread_attr_getschedpolicy and pthread_attr_getinheritsched (lib/libthr/thread/thr_attr.c): a null or uninitialized attribute returns EINVAL (0x80020016), as does a null output of scePthreadAttrGetschedpolicy; otherwise the attribute's policy or inheritance is stored and 0 is returned. libthr writes through a null output of the inheritance getter unchecked, so that case throws, as pthread_attr_getinheritsched and scePthreadAttrGetsolosched do. Neither getter was measured on a console. The scePthreadAttr entry in docs/dev/debt/libkernel.md, which describes the calls measured on a PS5, now says so and records the throw. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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.
|
|
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, The build is clean and AI-assisted |
|
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 |
|
Merged: checked diff against libthr 11.4 refs, setters' fields, test pins values; Windows run by @LeandroLP23 passes; merged. |
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 31cbb55), 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 fix(libkernel): report thread guard size from attribute queries #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, onmain889cee5.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: test: organize library tests and label CTest suites #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. test: organize library tests and label CTest suites #6044 movesGuestPthreadAttrErrors.cpptocore/libs/tests/threads/, and this branch's test changes are carried into the moved file. fix(libkernel): report thread guard size from attribute queries #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