feat(libkernel): implement pthread_getaffinity_np #1922
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1922"
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 rmz-24 on 2026-10-09T00:06:11Z.
What
Implements
pthread_getaffinity_np(libkernel, NIDJb2uGFMr688), claimed in #1578. EVO-PLAYER PPSA99039 v0.11.0 imports it, and it is the only one of the title's absent imports with no open pull request. The title calls it once, at0xE1DB90:pthread_getaffinity_np(pthread_self(), 0x20, &set), then counts the bits of the 32-byte set. On failure it logs and falls back.Semantics follow FreeBSD 11
lib/libthr/thread/thr_affinity.candkern_cpuset_getaffinityinsys/kern/kern_cpuset.c:errno.cpuset_tisCPU_MAXSIZE(256) bits, 32 bytes. The kernel accepts onlysizeof(cpuset_t) <= cpusetsize <= CPU_MAXSIZE / 8, so any size other than 32 returnsERANGE.ESRCH, and a null set returnsEFAULT.scePthreadGetaffinityreturns, in its low 64 bits. The other 24 bytes are zeroed, as the kernel copies out the whole zero-filled set.Tested
guest_available_cpumaskis extended:pthread_self()and of a created thread matchesscePthreadGetaffinity, including after eachscePthreadSetaffinity.ERANGE. A null thread returnsESRCH, and a null set returnsEFAULT.guest_*tests pass.--windows:tools/import_audit.pyno longer listsJb2uGFMr688as absent. The title can't reach the call yet, because 20 other imports are still absent, all with open pull requests (#1578).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-09T00:37:41Z.
Review: APPROVED
Correct, general implementation of
pthread_getaffinity_np. The error paths are handled properly (ERANGE for a mismatchedcpusetsize, ESRCH for a null thread, EFAULT for a null buffer) and the buffer is zeroed to the full guestcpu_set_tbefore theKernelCpumaskis copied in — so callers reading the whole structure don't see stale bytes. The test covers the happy path plus all three error codes and verifies the bytes past the mask are zeroed and the guard bytes after the buffer are untouched.One ABI assumption worth a sanity check before merge:
GUEST_CPUSET_BYTESis hard-fixed at 32 and any other size is rejected with ERANGE. That's correct only if the PS5'scpu_set_tis exactly 32 bytes. If a title ever passes a largercpusetsizeexpecting zero-fill (glibc permitscpusetsize >= needed), this would spuriously fail. Worth confirming the 32-byte figure against the guest ABI / a title, or accepting>= sizeof(KernelCpumask)and zero-filling the remainder.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:30:37Z.
Closing: EVO-PLAYER can't reach
pthread_getaffinity_npyet; as the description says, 20 other imports stop it first. Reopen when it's the title's next stop on main, with the log line.Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T06:37:18Z.
@rmz-24
pthread_getaffinity_npis now the next stop for three catalog titles onmain52ce9b8a(Linux, catalog builds withsce_module/libc.prxunwrapped as #2605 requires), each withapp.elf: symbol lookup error: app.elf: undefined symbol: Jb2uGFMr688:setcontextwith this PRlinkgetprogname(#1869)The head (79e3daf5) conflicts with
mainonly inGuestAvailableCpumask.cpp: a newer test there declares its owncpusetin the same function. Keeping both sides and renaming this PR's array toaffinitymakesguest_available_cpumaskpass 5/5 (--repeat until-fail:5).Intake needs 10 merged PRs to open a new one. If you'd like, I can open it as a carry that keeps your commit and authorship, with that rename on top. I'll wait for your yes.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T08:19:28Z.
Reopened: it's now the next stop for three titles (see above). Two things before it goes in:
EINVALon FreeBSD 11, notESRCH(_thr_find_threadinthr_list.c), and the thread is looked up before the size is checked, so a null thread with a wrong size isEINVALtoo;GuestAvailableCpumask.cppconflicts with a newer test'scpusetin the same function.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T08:19:47Z.
Progress report (
0c617ba→45eb492)➖ System libraries: 85.54% (+0.0%, +1 implemented functions)
✅ 1 implemented
pthread_getaffinity_np_nid_postfixImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T08:27:47Z.
Rebased onto current
mainand pushed the two changes @oneandonlydean asked for, so this can merge:EINVAL(_thr_find_threadin FreeBSD 11thr_list.c), and the thread is looked up before the size check, so a null thread with a wrong size isEINVALtoo.GuestAvailableCpumask.cpp(the new test'scpusetvs. ours), reusedPosixThread::GUEST_EINVAL/GUEST_EFAULTinstead of local copies, dropped a duplicatescePthreadGetaffinitydeclaration. The test now pinsEINVALfor a null thread with sizes 32 and 0.Checked: build + ctest on the rebased tree (
guest_available_cpumaskpasses and fails to link without the change), no other open PR touches these exports. Merging once CI is green.