feat(libkernel): implement four pthread_attr forms #9156
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9156"
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 DavidSamir on 2026-10-21T14:00:41Z.
What
Four pthread attribute exports in
libkernel_syswere discovery stubs that threwNotImplemented. They are now implemented in libkernel, inlibkernel/Pthread/Posix/AttrNp.cpp, and the libkernel_sys stubs are removed. They wrap libkernel's existingscePthreadAttr*calls, map the result to anerrnothe wayPosixThread::ToErrnodoes (& 0xFFFF), and follow FreeBSD 11lib/libthr/thread/thr_attr.c:pthread_attr_getsolosched_np(attr, solosched)scePthreadAttrGetsoloschedEINVALfor a NULLattr,*attror out pointer, as the existingpthread_attr_getstackaddrdoespthread_attr_setstackaddr(attr, addr)scePthreadAttrSetstackaddrEINVALfor a NULLattror*attr(_pthread_attr_setstackaddr)pthread_attr_getaffinity_np(attr, size, set)scePthreadAttrGetaffinityEINVALfor a NULLattror*attr;ERANGEforsizebelow the 32-byte kernel set (_pthread_attr_getaffinity_np); the bytes past the 64-bit mask are zeroed;EFAULTfor a NULL set, as the existingpthread_getaffinity_npdoespthread_attr_setaffinity_np(attr, size, set)scePthreadAttrSetaffinityEINVALfor a NULLattror*attr, and for nonzero bytes past the 64-bit mask, whichscePthreadAttrSetaffinitycan't holdTwo inputs throw and are recorded in
docs/dev/debt/libkernel.md:pthread_attr_setstackaddrwith a NULL address. FreeBSD stores it, butscePthreadAttrSetstackaddrrefuses it.pthread_attr_setaffinity_npwith a zerosizeor a NULL set. FreeBSD takes that as clearing the attribute's set, and noscePthreadAttr*call clears it.Moved to libkernel so libkernel imports reach it on Windows. The PS5 3.20 export lists have these four in libkernel as well as libkernel_sys, and on Windows a libkernel import never searches libkernel_sys (
WindowsEntryStubBuilder.cpp:175). With the libkernel exports and no libkernel_sys stubs, both imports reach them, and the duplicate-export rule holds. The code is unchanged by the move.Tested
Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. These are CPU-side exports, so no GPU is involved.
guest_kernel_sys_pthread_attr(core/libs/tests/GuestKernelSysPthreadAttr.cpp):pthread_attr_getstackaddr;0x5, a 40-byte set zero-filled past the mask,ERANGEat 16 bytes,EFAULTfor a NULL set) and set (32- and 8-byte sets,EINVALfor a nonzero byte 9, the stored mask unchanged after it, read back throughscePthreadAttrGetaffinity), each with a NULL attribute as well.mainthe test aborts withpthread_attr_getsolosched_np_nid_postfix not implemented. On this branch it passes.guest_kernel_sysstill passes.tools/check_conventions.pypasses, including the duplicate-export rule.AttrNp.cppremoved from libkernel's sources, the test fails to link (undefined reference to pthread_attr_getsolosched_np_nid_postfix), so it reaches libkernel's exports, the only ones.tools/pr_overlap.pycrashes on this machine's partial clone, so it was replaced by a check against an index of every open PR's diff, plusgit merge-treeagainst the 8 open PRs that touch these files (#9141, #8373, #8987, #9103, #9019, #9008, #9040, #9097). All 8 merge cleanly.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 DavidSamir on 2026-10-21T15:01:13Z.
Overlap note: #9160 (opened 4 minutes after this PR) also implements
pthread_attr_getsolosched_np,pthread_attr_setstackaddr,pthread_attr_getaffinity_npandpthread_attr_setaffinity_np, together withpthread_main_np. This PR covers only the four attribute forms, and it merges cleanly with current main.Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T02:06:14Z.
Linux: Ubuntu 24.04.1 LTS (WSL2), GCC 13.3.0, Release; head
44e997ec4merged ontomain8c26eac3c.guest_kernel_sys_pthread_attrpasses 3/3.pthread_attr_getsolosched_np_nid_postfixrenamed inAttrNp.cpp(instead of removing the file from the sources), the test fails to link:undefined reference to pthread_attr_getsolosched_np_nid_postfix, as listed.Run from the PC (Windows host, Linux in WSL2), not from the PR author's machine.
Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-22T08:04:26Z.
Hi @DavidSamir, this PR and #9573 (threads created suspended) meet in
core/libs/prx/libkernel_sys/Export.Discovery.cpp. This PR deletes thepthread_attr_getaffinity_np,pthread_attr_getsolosched_npandpthread_attr_setaffinity_npstubs (L361-375 on main), and #9573 changes thepthread_attr_setcreatesuspend_npsignature on the very next line (L376). Git counts edits on adjacent lines as one conflict, and that signature can't move, so one of the two has to go first.I'd suggest this PR goes first, which needs nothing from you: #9573 now says
Depends on: #9156, and I'll rebase it onto main and resolve the conflict once this one is merged. If you'd rather have the other order, let me know and I'll switch it.Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T09:20:33Z.
Thanks @zaryabzip, that order works for me: #9156 first, and #9573 rebases onto
mainafter it. I've noted it in this PR's description.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T12:55:45Z.
Review: COMMENTED
Checked against main
99feaf0eb8and FreeBSD 11.4 lib/libthr/thread/thr_attr.c:pthread_attr_setstackaddrwith a NULL address: FreeBSD 11.4 returnsEINVAL(_pthread_attr_setstackaddrchecksstackaddr == NULLtogether withattr/*attr, L545); it doesn't store it. So the throw inAttrNp.cpp:52and its debt bullet aren't needed.scePthreadAttrSetstackaddron main already returnsSCE_KERNEL_ERROR_EINVALfor a NULL address, whichPthreadAttrErrnomaps to 22.pthread_attr_setaffinity_nphas no lower bound oncpusetsize, so(attr, 1, "\x03")stores mask 0x3 and returns 0. FreeBSD returnsERANGEbelow the kernel set size (L609-611), and the getter here already uses 32 forERANGE. Could the setter use the same bound? The test atGuestKernelSysPthreadAttr.cpp:85(size 8 → 0) would change with it. Main'scpuset_getaffinity/cpuset_setaffinityuse 8 as the minimum, so it's worth deciding which bound both should use.docs/dev/debt/libkernel.mdnow conflicts with main, because the neighbouringsceKernelAioSetParambullet was rewritten, so it needs a rebase.Posix/Attr.cppusesPthreadAttr*andPosixThread::ToErrno/GUEST_EINVALfromCommon.hpp. Using those here instead of redeclaring them withvoid**and a localPthreadAttrErrnowould keep the two files consistent.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:32:05Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the targeted code review found the four wrappers consistent with the documented behavior and existing attribute APIs.
What I ran
Reviewed head
550810d74a304089683fd7f6994315974df0aaa1using the prepared diff and repository reader. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No automated checks were run. Reviewed all six changed files listed in the manifest; no files were excluded. The described Windows test runs and overlap checks are author-reported, not independently verified.
To get this to a good state
Nothing is required.
Pull request closed