feat(libkernel_sys): implement the scePthread scope, atfork and setconcurrency forms #9141

Merged
MarrasFederico merged 9 commits from upstream-pr/9141 into main 2026-10-23 10:18:25 +00:00
MarrasFederico commented 2026-10-21 13:19:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-10-21T13:19:39Z.


What

scePthreadAttrGetscope, scePthreadAttrSetscope, scePthreadAtfork and scePthreadSetconcurrency were libkernel_sys discovery stubs that threw. libkernel already implements their POSIX forms (pthread_attr_getscope, pthread_attr_setscope, pthread_atfork, pthread_setconcurrency). The four sce forms now call them and turn a POSIX error into 0x80020000 | errno, as #8987 does for the barrier, cpuclockid and concurrency forms; this builds on its SceResult helper.

shadPS4 exports scePthreadAttrGetscope (+7B2AEKKns8) as ORBIS(posix_pthread_attr_getscope), the same wrapping. It has no export for the other three. Their names and NIDs (YdZfEZfRnPk, i1kREW2pchs, gdnv6wF6hwI) are in the symbol database, and their signatures follow the same POSIX forms.

What they do is libkernel's behaviour:

  • Scope: 0 (process) or 2 (system), with system as the default; any other scope and null pointers return EINVAL.
  • Concurrency: a negative level returns EINVAL; otherwise the level is stored and read back by scePthreadGetconcurrency.
  • Atfork: handlers are recorded in order, null handlers included, since no process forks.

The debt entry records that none of this is measured on a console.

Tested

Ubuntu 26.04.1, kernel 7.0.0-38, GCC 15.2.0, Release, full build with BUILD_TESTING=ON. Windows was not compiled. No title was run.

  • New guest_kernel_sys_pthread, registered next to guest_kernel_sys_barrier (#8987, now merged):
    • Scope: a new attribute reads scope 2 and switches to 0 and back. Scopes 1, 3 and -1 return 0x80020016 without changing it. Null attribute or output pointers return 0x80020016.
    • Concurrency: level 3 reads back as 3. -1 returns 0x80020016 and keeps 3. 0 reads back as 0.
    • Atfork: two registrations, one with null handlers, append exactly those handlers in order.
  • The test fails on this branch's base, where the four calls throw. Returning the raw errno instead of the sce code, or registering the atfork handlers in the wrong order, makes it fail.
  • guest_kernel_sys and guest_kernel_sys_barrier still pass.
  • tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py finds no shared export. It reports neighbouring lines in docs/dev/debt/libkernel_sys.md with #8457, #8531, #9040 and #9103 (fchown, chown and title-workaround calls), and could not compare #5021, which conflicts with main; none touches these four calls.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4952252003 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9141). Originally posted by [MarrasFederico](https://github.com/MarrasFederico) on 2026-10-21T13:19:39Z. --- ### What `scePthreadAttrGetscope`, `scePthreadAttrSetscope`, `scePthreadAtfork` and `scePthreadSetconcurrency` were `libkernel_sys` discovery stubs that threw. libkernel already implements their POSIX forms (`pthread_attr_getscope`, `pthread_attr_setscope`, `pthread_atfork`, `pthread_setconcurrency`). The four `sce` forms now call them and turn a POSIX error into `0x80020000 | errno`, as #8987 does for the barrier, cpuclockid and concurrency forms; this builds on its `SceResult` helper. [shadPS4](https://github.com/shadps4-emu/shadPS4/blob/15abf68c9b52c4b04d094f2837719fdb871021f3/src/core/libraries/kernel/threads/pthread_attr.cpp#L392) exports `scePthreadAttrGetscope` (`+7B2AEKKns8`) as `ORBIS(posix_pthread_attr_getscope)`, the same wrapping. It has no export for the other three. Their names and NIDs (`YdZfEZfRnPk`, `i1kREW2pchs`, `gdnv6wF6hwI`) are in the [symbol database](https://github.com/zecoxao/sce_symbols/blob/2883963a0a514ba6e77407a08ef4730a65e88254/aerolib.csv), and their signatures follow the same POSIX forms. What they do is libkernel's behaviour: - **Scope:** 0 (process) or 2 (system), with system as the default; any other scope and null pointers return `EINVAL`. - **Concurrency:** a negative level returns `EINVAL`; otherwise the level is stored and read back by `scePthreadGetconcurrency`. - **Atfork:** handlers are recorded in order, null handlers included, since no process forks. The debt entry records that none of this is measured on a console. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Ubuntu 26.04.1, kernel 7.0.0-38, GCC 15.2.0, Release, full build with `BUILD_TESTING=ON`. Windows was not compiled. No title was run. - New `guest_kernel_sys_pthread`, registered next to `guest_kernel_sys_barrier` (#8987, now merged): - **Scope:** a new attribute reads scope 2 and switches to 0 and back. Scopes 1, 3 and -1 return `0x80020016` without changing it. Null attribute or output pointers return `0x80020016`. - **Concurrency:** level 3 reads back as 3. -1 returns `0x80020016` and keeps 3. 0 reads back as 0. - **Atfork:** two registrations, one with null handlers, append exactly those handlers in order. - The test fails on this branch's base, where the four calls throw. Returning the raw errno instead of the `sce` code, or registering the atfork handlers in the wrong order, makes it fail. - `guest_kernel_sys` and `guest_kernel_sys_barrier` still pass. - `tools/check_conventions.py --base origin/main` passes. `tools/pr_overlap.py` finds no shared export. It reports neighbouring lines in `docs/dev/debt/libkernel_sys.md` with #8457, #8531, #9040 and #9103 (fchown, chown and title-workaround calls), and could not compare #5021, which conflicts with `main`; none touches these four calls. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
ycbuzi commented 2026-10-21 20:49:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T20:49:29Z.


Windows run of d6b384688a merged onto main 0c6a5bd593 (a3706ed2cf, clean), the platform the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON.

Built libkernel_sys, guest_kernel_sys_barrier_tests and guest_kernel_sys_pthread_tests with no errors or warnings. ctest --repeat until-fail:2 on guest_kernel_sys_barrier and guest_kernel_sys_pthread: both pass on both repeats. Not run: a title.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6326240495 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9141#issuecomment-6326240495). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-21T20:49:29Z. --- Windows run of d6b384688a merged onto `main` 0c6a5bd593 (a3706ed2cf, clean), the platform the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, `BUILD_TESTING=ON`. Built `libkernel_sys`, `guest_kernel_sys_barrier_tests` and `guest_kernel_sys_pthread_tests` with no errors or warnings. `ctest --repeat until-fail:2` on `guest_kernel_sys_barrier` and `guest_kernel_sys_pthread`: both pass on both repeats. Not run: a title.
MarcZX10 commented 2026-10-23 05:18:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T05:18:31Z.

Review: APPROVED


Reviewed exact head e8f8e59a35. The dependent #8987 changes are retained, and the checklist declares that dependency. The four new SCE forms delegate to the existing POSIX providers with SCE errno mapping; tests cover scope state/error preservation, concurrency, and atfork registration order. Local diff whitespace, conventions, registration, and current-main checks pass. The PR reports a Linux full build/focused tests, and an independent Windows build plus repeated barrier/pthread runs; I did not execute those binaries locally. Hosted product jobs are skipped by policy, and console behavior remains documented as unmeasured.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5624202157 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9141#pullrequestreview-5624202157). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T05:18:31Z. **Review:** APPROVED --- Reviewed exact head e8f8e59a3504684784acc1012cb727f9691108a0. The dependent #8987 changes are retained, and the checklist declares that dependency. The four new SCE forms delegate to the existing POSIX providers with SCE errno mapping; tests cover scope state/error preservation, concurrency, and atfork registration order. Local diff whitespace, conventions, registration, and current-main checks pass. The PR reports a Linux full build/focused tests, and an independent Windows build plus repeated barrier/pthread runs; I did not execute those binaries locally. Hosted product jobs are skipped by policy, and console behavior remains documented as unmeasured.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9141
No description provided.