Skip to content

feat(libkernel): implement scePthreadAttrGetschedpolicy and scePthreadAttrGetinheritsched - #7611

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Lindamea1:fix/kernel-pthread-attr-sched-getters
Oct 19, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Lindamea1:fix/kernel-pthread-attr-sched-getters

Conversation

@Lindamea1

@Lindamea1 Lindamea1 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

What

No library exported scePthreadAttrGetschedpolicy (NID NMyIQ9WgWbU) or scePthreadAttrGetinheritsched (lpMP8HhkBbg). libkernel exports their setters, scePthreadAttrSetschedpolicy (4+h9EzwKF4I) and scePthreadAttrSetinheritsched (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-binding is given. So a title that imports either getter stops before it starts: on Linux the loader fails with symbol lookup error: ... undefined symbol: NMyIQ9WgWbU, and on Windows the entry stub prints FAIL: unresolved ELF import for it and stops with 0xc0000139 (WindowsEntryStubBuilder.cpp).

Dragon Ball Xenoverse 2 (PPSA08587) imports both. In #6591 (Windows, AnyPS5 31cbb55), LuisAguilarDev lists them under "Local changes, not yet submitted": "libkernel: scePthreadAttrGetschedpolicy and scePthreadAttrGetinheritsched. These are imported but missing. The title has not called them yet." This PR adds them. On main the 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, sceNpSessionSignalingGetGroupInfo is on main since #7125, and sceNetCtlGetInfoV6, still missing on main, 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_getinheritsched returns EINVAL when attr or *attr is null and otherwise stores the attribute's sched_inherit; it does not check the output pointer. _pthread_attr_getschedpolicy returns EINVAL when attr, *attr or policy is null and otherwise stores sched_policy. libkernel's sce calls return 0x80020000 | errno, so EINVAL is 0x80020016. #4153 measured the neighbouring getters on a PS5 (firmware 13.60): a null or uninitialized attribute returns EINVAL, and so does a null output of scePthreadAttrGetstacksize, scePthreadAttrGetdetachstate and scePthreadAttrGetschedparam, whose libthr twins check it (L332, L182, L240). The two calls #4153 found to crash the console, a null attribute pointer to scePthreadAttrInit and a null output of scePthreadAttrGetaffinity, 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 return 0x80020016 for a null or uninitialized attribute, and scePthreadAttrGetschedpolicy also 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 values scePthreadAttrInit stores. The values the setters accept (policies 1 and 3, inheritances 0 and 4) read back as set.

Where this still differs from FreeBSD:

Tested

Gentoo Linux, kernel 7.2.8, GCC 16.2.1, glibc 2.43, Release, BUILD_TESTING=ON, on main 889cee5.

  • guest_pthread_attr_errors, extended:
    • A new attribute reports policy 1 and inheritance 4.
    • After each rejected scePthreadAttrSetschedpolicy (-1, 0, 2, 4) and scePthreadAttrSetinheritsched (-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.
    • scePthreadAttrGetschedpolicy with a null output returns 0x80020016, and scePthreadAttrGetinheritsched with a null output throws std::runtime_error. Both return 0x80020016 for a null and for an uninitialized attribute.
    • With only Attr.cpp reverted to main, the test does not link (undefined reference to 'scePthreadAttrGetschedpolicy' and 'scePthreadAttrGetinheritsched'). With the change it passes.
  • nm -D on the NID-patched libraries: with the change, libkernel.prx exports NMyIQ9WgWbU and lpMP8HhkBbg, at the addresses of scePthreadAttrGetschedpolicy and scePthreadAttrGetinheritsched in the unpatched build. None of the other 126 NID-patched .prx files in build/core/libs/libs exports either NID. On main, libkernel.prx exports neither.
  • A load probe shaped like the relinker's Linux output (a global FUNC import of the NID, DT_NEEDED libkernel.prx, BIND_NOW), run against the built libkernel.prx. On main, importing NMyIQ9WgWbU stops in the loader with symbol lookup error: ./load_NMyIQ9WgWbU: undefined symbol: NMyIQ9WgWbU (exit 127), and importing lpMP8HhkBbg fails the same way; importing the setter's eXbUSpEaTsA reaches main. With the change, all three reach main.
  • A probe with the change:
    • The sce and POSIX getters report the same values, after the sce setters and after the POSIX setters. A policy of 2 set with pthread_attr_setschedpolicy reads back as 2.
    • On a thread created with explicit inheritance and policy 3, scePthreadGetschedparam reports 3, while scePthreadAttrGet followed by the new getters reports 1 and 4 (the difference described above).
  • Tests the change reaches, selected by tools/select_tests.py as CI selects them: 1202 tests, 0 failed, 13 skipped. Full ctest -j6 --timeout 300: 1452 tests, 0 failed, 13 skipped (12 VideoOut tests and agc_driver_stencil_ref_export, which skip on main on this machine too).
  • Windows: Attr.cpp and GuestPthreadAttrErrors.cpp compile with x86_64-w64-mingw32-g++ 16.2 (-fsyntax-only -Wall -Wextra). This is a syntax check, not a Windows build or run.
  • tools/check_conventions.py passes against main. tools/pr_overlap.py --branch reports no overlapping lines with other pull requests. It could not compare 20 pull requests that conflict with main and share a file with this branch: test: organize library tests and label CTest suites #6044 (GuestPthreadAttrErrors.cpp) and 19 that change docs/dev/debt/libkernel.md. Merged with this branch, each has exactly the conflicts it has with main. Of the files in those conflicts, this branch changes only docs/dev/debt/libkernel.md, and its line there merges cleanly. test: organize library tests and label CTest suites #6044 moves GuestPthreadAttrErrors.cpp to core/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 to scePthreadAttrGet in Attr.cpp and merges with this branch without a conflict.

Not run on Windows, macOS or a console.

Checklist

🤖 Generated with Claude Code

…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>
@github-actions

Copy link
Copy Markdown

Progress report (e1338ff → 2514ead)

📈 System libraries: 90.25% (+0.01%, +2 implemented functions)

✅ 2 implemented
Library Name
libkernel scePthreadAttrGetinheritsched
libkernel scePthreadAttrGetschedpolicy

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

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 5021 docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestPthreadAttrErrors.cpp
PR 6149 docs/dev/debt/libkernel.md
PR 6446 docs/dev/debt/libkernel.md
PR 6469 docs/dev/debt/libkernel.md
PR 6519 docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6977 docs/dev/debt/libkernel.md
PR 7049 docs/dev/debt/libkernel.md
PR 7088 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 7332 docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md
PR 7554 docs/dev/debt/libkernel.md
PR 7556 docs/dev/debt/libkernel.md
PR 7605 docs/dev/debt/libkernel.md

@LeandroLP23

Copy link
Copy Markdown
Contributor

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: main c3591adf9 with #7623, #7612, #7611, #7603, #7579, #7563 and #7541 merged together (each merge clean, built once).

The build is clean and guest_pthread_attr_errors passes 3 runs of 3.

AI-assisted

@LuisAguilarDev

LuisAguilarDev commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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.

@adriadam10 adriadam10 self-assigned this Oct 19, 2026
@adriadam10
adriadam10 merged commit 88fb559 into boykopovar:main Oct 19, 2026
11 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Merged: checked diff against libthr 11.4 refs, setters' fields, test pins values; Windows run by @LeandroLP23 passes; merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs libkernel unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants