Skip to content

feat(libkernel): implement four pthread_attr forms - #9156

Open
DavidSamir wants to merge 7 commits into
boykopovar:mainfrom
DavidSamir:feat/libkernel-sys-pthread-attr-np
Open

DavidSamir wants to merge 7 commits into
boykopovar:mainfrom
DavidSamir:feat/libkernel-sys-pthread-attr-np

Conversation

@DavidSamir

@DavidSamir DavidSamir commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What

Four pthread attribute exports in libkernel_sys were discovery stubs that threw NotImplemented. They are now implemented in libkernel, in libkernel/Pthread/Posix/AttrNp.cpp, and the libkernel_sys stubs are removed. They wrap libkernel's existing scePthreadAttr* calls, map the result to an errno the way PosixThread::ToErrno does (& 0xFFFF), and follow FreeBSD 11 lib/libthr/thread/thr_attr.c:

Export Over Errors
pthread_attr_getsolosched_np(attr, solosched) scePthreadAttrGetsolosched EINVAL for a NULL attr, *attr or out pointer, as the existing pthread_attr_getstackaddr does
pthread_attr_setstackaddr(attr, addr) scePthreadAttrSetstackaddr EINVAL for a NULL attr or *attr (_pthread_attr_setstackaddr)
pthread_attr_getaffinity_np(attr, size, set) scePthreadAttrGetaffinity EINVAL for a NULL attr or *attr; ERANGE for size below the 32-byte kernel set (_pthread_attr_getaffinity_np); the bytes past the 64-bit mask are zeroed; EFAULT for a NULL set, as the existing pthread_getaffinity_np does
pthread_attr_setaffinity_np(attr, size, set) scePthreadAttrSetaffinity EINVAL for a NULL attr or *attr, and for nonzero bytes past the 64-bit mask, which scePthreadAttrSetaffinity can't hold

Two inputs throw and are recorded in docs/dev/debt/libkernel.md:

  • pthread_attr_setstackaddr with a NULL address. FreeBSD stores it, but scePthreadAttrSetstackaddr refuses it.
  • pthread_attr_setaffinity_np with a zero size or a NULL set. FreeBSD takes that as clearing the attribute's set, and no scePthreadAttr* 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.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none (feat(libkernel_sys): create threads suspended and resume them #9573 goes second and rebases, agreed with its author on this PR)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Progress report (6cd36e6 → 550810d)

📈 System libraries: 48.34% (+0.01%, +2 implemented, +2 declared, -4 removed functions)

✅ 2 implemented
Library Name
libkernel pthread_attr_getaffinity_np_nid_postfix
libkernel pthread_attr_getsolosched_np_nid_postfix
🆕 2 declared as stubs
Library Name
libkernel pthread_attr_setaffinity_np_nid_postfix
libkernel pthread_attr_setstackaddr_nid_postfix
🗑️ 4 removed
Library Name
libkernel_sys pthread_attr_getaffinity_np_nid_postfix
libkernel_sys pthread_attr_getsolosched_np_nid_postfix
libkernel_sys pthread_attr_setaffinity_np_nid_postfix
libkernel_sys pthread_attr_setstackaddr_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libkernel 664/704 (94.32%) 666/708 (94.07%) -0.25 pp
libkernel_sys 48/531 (9.04%) 48/527 (9.11%) +0.07 pp

@github-actions

github-actions Bot commented Oct 21, 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 4563 core/libs/prx/libkernel/CMakeLists.txt
PR 4630 docs/dev/debt/libkernel.md
PR 5021 core/libs/CMakeLists.txt
core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6149 docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6830 core/libs/prx/libkernel/CMakeLists.txt
PR 6936 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7090 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7135 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7156 core/libs/prx/libkernel/CMakeLists.txt
PR 7192 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 7275 core/libs/CMakeLists.txt
PR 7447 docs/dev/debt/libkernel.md
PR 7464 docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md
PR 7532 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 7565 docs/dev/debt/libkernel.md
PR 7622 core/libs/CMakeLists.txt
PR 7780 core/libs/CMakeLists.txt
PR 7804 docs/dev/debt/libkernel.md
PR 8041 core/libs/prx/libkernel/CMakeLists.txt
PR 8285 core/libs/CMakeLists.txt
PR 8463 core/libs/prx/libkernel/CMakeLists.txt
PR 8477 core/libs/prx/libkernel/CMakeLists.txt
PR 8497 docs/dev/debt/libkernel.md
PR 8605 docs/dev/debt/libkernel.md
PR 8629 core/libs/CMakeLists.txt
PR 8650 core/libs/CMakeLists.txt
PR 8916 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9019 core/libs/CMakeLists.txt
core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 9161 core/libs/CMakeLists.txt
core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 9162 core/libs/CMakeLists.txt
core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 9199 docs/dev/debt/libkernel.md
PR 9326 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel.md
PR 9389 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel.md
PR 9442 core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel.md
PR 9491 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9515 docs/dev/debt/libkernel.md
PR 9535 core/libs/CMakeLists.txt
PR 9536 core/libs/CMakeLists.txt
PR 9571 core/libs/CMakeLists.txt
PR 9578 docs/dev/debt/libkernel.md
PR 9684 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9713 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 9772 core/libs/CMakeLists.txt
PR 9774 core/libs/CMakeLists.txt
PR 9792 core/libs/CMakeLists.txt
PR 9843 docs/dev/debt/libkernel.md
PR 9882 docs/dev/debt/libkernel.md
PR 9924 core/libs/CMakeLists.txt
PR 9933 core/libs/CMakeLists.txt
PR 9938 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9947 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 10025 docs/dev/debt/libkernel.md
PR 10042 core/libs/CMakeLists.txt
PR 10192 docs/dev/debt/libkernel.md
PR 10319 docs/dev/debt/libkernel.md
PR 10335 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 10421 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 10427 core/libs/CMakeLists.txt
PR 10442 docs/dev/debt/libkernel.md
PR 10552 docs/dev/debt/libkernel.md
PR 10558 docs/dev/debt/libkernel.md
PR 10645 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 10657 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 10695 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 10725 docs/dev/debt/libkernel.md
PR 10749 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 10755 core/libs/prx/libkernel/CMakeLists.txt
PR 10789 docs/dev/debt/libkernel.md
PR 10806 core/libs/prx/libkernel/CMakeLists.txt
PR 10809 docs/dev/debt/libkernel.md
PR 10810 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 10816 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 10817 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 10856 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 10898 docs/dev/debt/libkernel.md
PR 10953 core/libs/prx/libkernel/CMakeLists.txt
PR 10975 core/libs/prx/libkernel/CMakeLists.txt
PR 10979 core/libs/prx/libkernel/CMakeLists.txt
PR 11002 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 11005 docs/dev/debt/libkernel.md
PR 11031 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 11032 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 11034 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 11042 docs/dev/debt/libkernel.md
PR 11130 core/libs/CMakeLists.txt
core/libs/prx/libkernel/CMakeLists.txt
PR 11212 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 11215 docs/dev/debt/libkernel.md
PR 11216 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 11219 docs/dev/debt/libkernel.md
PR 11223 docs/dev/debt/libkernel.md
PR 11231 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 11247 docs/dev/debt/libkernel.md
PR 11264 docs/dev/debt/libkernel.md
PR 11267 core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel.md
PR 11341 docs/dev/debt/libkernel.md
PR 11403 docs/dev/debt/libkernel.md
PR 11412 core/libs/CMakeLists.txt
PR 11431 docs/dev/debt/libkernel.md
PR 11441 core/libs/CMakeLists.txt
core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 11446 core/libs/prx/libkernel/CMakeLists.txt
PR 11500 core/libs/prx/libkernel/CMakeLists.txt
PR 11592 docs/dev/debt/libkernel.md
PR 11594 core/libs/prx/libkernel/CMakeLists.txt
PR 11624 docs/dev/debt/libkernel.md
PR 11625 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 11628 docs/dev/debt/libkernel.md
PR 11661 docs/dev/debt/libkernel.md
PR 11689 docs/dev/debt/libkernel.md
PR 11698 docs/dev/debt/libkernel.md
PR 11725 core/libs/CMakeLists.txt
PR 11729 core/libs/CMakeLists.txt
PR 11732 docs/dev/debt/libkernel.md
PR 11754 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 11799 core/libs/prx/libkernel/CMakeLists.txt
PR 11827 docs/dev/debt/libkernel.md
PR 11838 core/libs/prx/libkernel/CMakeLists.txt
PR 11849 docs/dev/debt/libkernel.md
PR 11851 core/libs/prx/libkernel/CMakeLists.txt
PR 11858 docs/dev/debt/libkernel.md
PR 11861 docs/dev/debt/libkernel.md
PR 11862 docs/dev/debt/libkernel.md
PR 11863 docs/dev/debt/libkernel.md
PR 11864 docs/dev/debt/libkernel.md
PR 11865 docs/dev/debt/libkernel.md
PR 11872 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 11891 core/libs/prx/libkernel/CMakeLists.txt
PR 11894 core/libs/prx/libkernel/CMakeLists.txt
PR 11896 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 11897 docs/dev/debt/libkernel.md
PR 11937 docs/dev/debt/libkernel.md
PR 11939 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 11949 core/libs/CMakeLists.txt
PR 11969 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md

@DavidSamir DavidSamir mentioned this pull request Oct 21, 2026
12 tasks done
@DavidSamir

Copy link
Copy Markdown
Contributor Author

Overlap note: #9160 (opened 4 minutes after this PR) also implements pthread_attr_getsolosched_np, pthread_attr_setstackaddr, pthread_attr_getaffinity_np and pthread_attr_setaffinity_np, together with pthread_main_np. This PR covers only the four attribute forms, and it merges cleanly with current main.

The PS5 3.20 export lists have these pthread_attr forms in libkernel
as well as libkernel_sys, and on Windows a libkernel import never
reaches libkernel_sys. They move unchanged to
libkernel/Pthread/Posix/AttrNp.cpp.
@DavidSamir DavidSamir changed the title feat(libkernel_sys): implement the pthread attribute solosched, stackaddr and affinity forms feat(libkernel): implement four pthread_attr forms Oct 21, 2026
@DavidSamir

Copy link
Copy Markdown
Contributor Author

Linux: Ubuntu 24.04.1 LTS (WSL2), GCC 13.3.0, Release; head 44e997ec4 merged onto main 8c26eac3c.

  • guest_kernel_sys_pthread_attr passes 3/3.
  • Link control: with pthread_attr_getsolosched_np_nid_postfix renamed in AttrNp.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.

@zaryabzip

Copy link
Copy Markdown
Contributor

Hi @DavidSamir, this PR and #9573 (threads created suspended) meet in core/libs/prx/libkernel_sys/Export.Discovery.cpp. This PR deletes the pthread_attr_getaffinity_np, pthread_attr_getsolosched_np and pthread_attr_setaffinity_np stubs (L361-375 on main), and #9573 changes the pthread_attr_setcreatesuspend_np signature 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.

@DavidSamir

Copy link
Copy Markdown
Contributor Author

Thanks @zaryabzip, that order works for me: #9156 first, and #9573 rebases onto main after it. I've noted it in this PR's description.

AI-assisted: yes

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 24, 2026
danielradosa added a commit to danielradosa/AnyPS5 that referenced this pull request Oct 24, 2026
…ttr forms

Moved the four exports into the PR's libkernel/Pthread/Posix/AttrNp.cpp so libkernel exports them; kept our getaffinity/setaffinity (from boykopovar#9160: 32-byte set, tail bytes, clearing on a zero size as FreeBSD does) and getsolosched, took the PR's setstackaddr null checks (null attr EINVAL, null address throws). Dropped the PR's test (its 8-byte and byte-9 affinity cases contradict FreeBSD's 32-byte set) and its setaffinity debt line; guest_kernel_sys_threads now loads the four from libkernel.
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 24, 2026

@harisibrar1 harisibrar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked against main 99feaf0 and FreeBSD 11.4 lib/libthr/thread/thr_attr.c:

  • pthread_attr_setstackaddr with a NULL address: FreeBSD 11.4 returns EINVAL (_pthread_attr_setstackaddr checks stackaddr == NULL together with attr/*attr, L545); it doesn't store it. So the throw in AttrNp.cpp:52 and its debt bullet aren't needed. scePthreadAttrSetstackaddr on main already returns SCE_KERNEL_ERROR_EINVAL for a NULL address, which PthreadAttrErrno maps to 22.
  • pthread_attr_setaffinity_np has no lower bound on cpusetsize, so (attr, 1, "\x03") stores mask 0x3 and returns 0. FreeBSD returns ERANGE below the kernel set size (L609-611), and the getter here already uses 32 for ERANGE. Could the setter use the same bound? The test at GuestKernelSysPthreadAttr.cpp:85 (size 8 → 0) would change with it. Main's cpuset_getaffinity/cpuset_setaffinity use 8 as the minimum, so it's worth deciding which bound both should use.
  • Small note: on an attribute that never had a set, FreeBSD's getter returns an all-ones set, while this returns main's 0x1FFF default. That seems reasonable for the sce layer; only mentioning it in case it matters.
  • docs/dev/debt/libkernel.md now conflicts with main, because the neighbouring sceKernelAioSetParam bullet was rewritten, so it needs a rebase.
  • Optional: Posix/Attr.cpp uses PthreadAttr* and PosixThread::ToErrno/GUEST_EINVAL from Common.hpp. Using those here instead of redeclaring them with void** and a local PthreadAttrErrno would keep the two files consistent.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 24, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@DavidSamir I agree the null-stack-address refusal is unnecessary: please delegate to the existing setter and return mapped EINVAL (22), correct the debt claim, and add a null-argument return-code case. Please also make the non-clearing setaffinity cpuset minimum coherent with the paired getter: its current minimum is 32, while setter accepts 1 and tests 8. Use that guest minimum with ERANGE/boundary/unchanged-mask checks unless measured guest evidence supports another contract, and explain any deliberate difference from the 8-byte cpuset syscalls. Keep unsupported clearing behavior separate; do not add throw-pinning tests.

InfinitySpeed added a commit to InfinitySpeed/AnyPS5 that referenced this pull request Oct 24, 2026
Reuse the existing SCE getter and preserve POSIX errors and caller errno. Adapter contract follows DavidSamir PR boykopovar#9156; alias ABI remains inferred. Tested with real Linux libraries, raw and NID-patched loading, pthread regressions and rejected mutations.
@rooklz

rooklz commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Measured on a PS5 (a payload calling the console's libthr; return values):

call size 0 1 4 8 16 32 64 128
pthread_attr_getaffinity_np (fresh attr) 34 34 34 0 0 0 0 0
pthread_attr_setaffinity_np 0 34 34 0 0 0 0 0

A fresh attribute's mask reads back as eight 0xff bytes followed by zeros. After pthread_attr_setaffinity_np(&a, 8, {00 02 ..}), a 32-byte get returns 00 02 and then zeros. So the size floor is 8, the kernel's cpuset_t (cpuset_getaffinity there accepts exactly 8 and gives ERANGE for 4, 32 and 64), not the 32-byte userland type. Here, cpusetSize < GuestCpusetBytes with 32 makes the 8- and 16-byte gets fail (the test expects 16 to give ERANGE), and a set of size 0 throws where the console returns 0.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@DavidSamir The local declarations differ from main’s public headers: int pthread_attr_destroy_nid_postfix(void** attr) at core/libs/tests/GuestKernelSysPthreadAttr.cpp:12 versus int pthread_attr_destroy_nid_postfix(PthreadAttr* attr) at core/libs/prx/libkernel/include/Api.hpp:384; int pthread_attr_getaffinity_np_nid_postfix(void* const* attr, std::size_t cpusetSize, void* cpuset) at core/libs/tests/GuestKernelSysPthreadAttr.cpp:19 versus int pthread_attr_getaffinity_np_nid_postfix(void) at core/libs/prx/libkernel_sys/include/Api.hpp:124; int pthread_attr_getsolosched_np_nid_postfix(void* const* attr, int* solosched) at core/libs/tests/GuestKernelSysPthreadAttr.cpp:17 versus int pthread_attr_getsolosched_np_nid_postfix(void) at core/libs/prx/libkernel_sys/include/Api.hpp:125; int pthread_attr_getstackaddr_nid_postfix(void* const* attr, void** stackAddress) at core/libs/tests/GuestKernelSysPthreadAttr.cpp:14 versus int pthread_attr_getstackaddr_nid_postfix(const PthreadAttr* __restrict attr, void** __restrict stackAddr) at core/libs/prx/libkernel/include/Api.hpp:393; int pthread_attr_init_nid_postfix(void** attr) at core/libs/tests/GuestKernelSysPthreadAttr.cpp:11 versus int pthread_attr_init_nid_postfix(PthreadAttr* attr) at core/libs/prx/libkernel/include/Api.hpp:395; int pthread_attr_setaffinity_np_nid_postfix(void** attr, std::size_t cpusetSize, const void* cpuset) at core/libs/tests/GuestKernelSysPthreadAttr.cpp:20 versus int pthread_attr_setaffinity_np_nid_postfix(void) at core/libs/prx/libkernel_sys/include/Api.hpp:126; int pthread_attr_setsolosched_np_nid_postfix(void** attr, int solosched) at core/libs/tests/GuestKernelSysPthreadAttr.cpp:13 versus int pthread_attr_setsolosched_np_nid_postfix(PthreadAttr* attr, int solosched) at core/libs/prx/libkernel/include/Api.hpp:404; int pthread_attr_setstackaddr_nid_postfix(void** attr, void* stackAddress) at core/libs/tests/GuestKernelSysPthreadAttr.cpp:18 versus int pthread_attr_setstackaddr_nid_postfix(void) at core/libs/prx/libkernel_sys/include/Api.hpp:128; int scePthreadAttrGetaffinity(void* const* attr, KernelCpumask* mask) at core/libs/tests/GuestKernelSysPthreadAttr.cpp:16 versus int scePthreadAttrGetaffinity(const PthreadAttr* attr, KernelCpumask* mask) at core/libs/prx/libkernel/include/Api.hpp:522; int scePthreadAttrGetsolosched(void* const* attr, int* solosched) at core/libs/prx/libkernel/Pthread/Posix/AttrNp.cpp:9 versus int scePthreadAttrGetsolosched(const PthreadAttr* attr, int* solosched) at core/libs/prx/libkernel/include/Api.hpp:528; int scePthreadAttrSetaffinity(void** attr, KernelCpumask mask) at core/libs/tests/GuestKernelSysPthreadAttr.cpp:15 versus int scePthreadAttrSetaffinity(PthreadAttr* attr, KernelCpumask mask) at core/libs/prx/libkernel/include/Api.hpp:531; int scePthreadAttrSetstackaddr(void** attr, void* stackAddress) at core/libs/prx/libkernel/Pthread/Posix/AttrNp.cpp:11 versus int scePthreadAttrSetstackaddr(PthreadAttr* attr, void* addr) at core/libs/prx/libkernel/include/Api.hpp:537. Main now requires each exported function to be declared once, in the library's public header (checked by the public_headers tests). Could you use main’s public signatures and types throughout the implementation and tests, or explain why the public declarations need to change?

@rooklz

rooklz commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Correction to my measurement above: I hadn't tried sizes between 8 and 16. A fuller sweep (sizes 0, 1, 4, 7, 8, 9, 12, 16, 24, 32, 64, 128) shows cpuset_getaffinity, cpuset_setaffinity and pthread_getaffinity_np all accept any size from 8 to 16 bytes, zero-fill a get past byte 8, and return ERANGE below 8 and from 24 up. So the rule is 8 to 16 bytes, not exactly 8. 32 is still rejected. The EPERM I saw from cpuset_setaffinity came from asking for a CPU outside the payload's set; a subset of it at size 8 to 16 returns 0.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@DavidSamir rooklz's original and corrected reports distinguish attribute APIs from thread/kernel cpuset APIs. For this PR's pthread_attr_get/setaffinity_np, the first report supports an 8-byte floor (8, 16, 32, 64 and 128 bytes succeed); please replace the getter 16-byte ERANGE assertion with success and add checks at 8 bytes and below 8 bytes, with unchanged-mask checks. Our earlier provisional 32-byte setter minimum is withdrawn; keep 8-byte setter success. The correction's 8-16 byte range is for cpuset_getaffinity/cpuset_setaffinity/pthread_getaffinity_np, without attr, so please don't apply its 16-byte ceiling to attribute calls or describe the syscalls as exactly 8. The reported size 0 attribute setter returns 0; the report doesn't state resulting mask/reset behavior, so that still needs clarification before defining clearing semantics. The null-stack mapped EINVAL/debt/test ask and public-header/signature reconciliation remain. No test should require an unsupported clearing path to throw.

danielradosa added a commit to danielradosa/AnyPS5 that referenced this pull request Oct 25, 2026
…tribute and initial-thread queries

Kept the four attribute forms in libkernel (AttrNp.cpp, from the boykopovar#9156 port) instead of the PR's libkernel_sys copies, since libkernel_sys imports fall back to libkernel; took the PR's null-address EINVAL for setstackaddr (dropped our throw and its debt line), its Linux TID/PID pthread_main_np, the main_late_load test and the module path check; tests keep loading the four from libkernel.

(cherry picked from commit 4f0c7d0780aa229981994ed8f8368a0e1b4658b6)
@Gruzzberry

Copy link
Copy Markdown
Contributor

Hi @DavidSamir, the overlap check shows my open PR next to this one:

The changes are separate. Only the neighbouring lines overlap. Proposed merge order: this PR first, then #11026, which I'll rebase onto it after it merges. I've recorded that under Depends on in #11026. If you'd prefer to go second, say so and I'll switch it.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 25, 2026

This branch has not been deployed

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

Labels

build docs libkernel needs rebase Conflicts with main, rebase needed prx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants