feat(libkernel_sys): create threads suspended and resume them #9573

Merged
zaryabzip merged 1 commit from upstream-pr/9573 into main 2026-10-25 19:21:08 +00:00
zaryabzip commented 2026-10-22 02:47:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-22T02:47:44Z.


What

Implements pthread_attr_setcreatesuspend_np, pthread_resume_np, pthread_resume_all_np, pthread_multi_np, scePthreadAttrSetcreatesuspend, scePthreadResume, scePthreadResumeAll and scePthreadMulti (libkernel_sys), following FreeBSD 11.4 libthr at 8c639945.

  • Suspended start. A thread created with the create-suspended attribute waits in RunThread before its start routine. That is after it is registered and before the POSIX signal mask is restored.

    • The wait is not a cancellation point. A cancel requested while the thread is suspended takes effect at the first cancellation point after resume.
    • libthr sets the flag from attr.suspend (thr_create.c#L127-L132).
    • The new thread waits in _thr_ast, which runs check_suspend before check_cancel (thr_sig.c#L265-L274, thr_sig.c#L351-L399). It gets there from thread_start, before the mask restore and the start routine (thr_create.c#L252-L294).
  • pthread_attr_setcreatesuspend_np returns EINVAL for a null attr or *attr, otherwise 0 (thr_attr.c#L369-L381).

  • scePthreadAttrSetcreatesuspend returns 0x80020000 | errno.

  • pthread_resume_np returns EINVAL for a null thread, ESRCH for a thread that is gone or has finished, and 0 otherwise (thr_resume_np.c#L47-L60, thr_list.c#L339-L363).

  • pthread_resume_all_np returns void. It resumes every thread except the caller, then reaches a cancellation point (thr_resume_np.c#L62-L97).

  • pthread_multi_np resumes all threads and returns 0 (thr_multi_np.c#L40-L51).

  • Locking. Resume clears the flag and wakes the thread while it holds the guest-thread registry lock. A detached thread that exits at the same moment therefore cannot be freed during the wake.

  • Attribute getters. scePthreadAttrGet and pthread_attr_get_np now report the create-suspended attribute the thread was created with. libthr keeps attr.suspend in the thread and copies it with the other attributes (thr_create.c#L84-L88, thr_attr.c#L139-L172, thr_private.h#L263-L277).

  • Raise on Windows. sceKernelRaiseException throws for a thread still suspended at creation.

    • libthr starts such a thread with every signal except SIGTRAP blocked (thr_create.c#L177-L198) and restores its mask only after resume, so the signal waits.
    • Windows would instead redirect the thread to the handler before its start routine.
    • On Linux nothing changes: host signals stay blocked until resume, so the raise is delivered after it.
  • Test. New test guest_pthread_create_suspended (TIMEOUT 20) covers:

    • both creation forms;
    • the error codes;
    • resume of the calling thread and of a running thread;
    • pthread_multi_np and pthread_resume_all_np;
    • a cancel requested while suspended, and pthread_resume_all_np as a cancellation point;
    • both attribute getters;
    • detached suspended threads resumed while they exit;
    • the raise case (it throws on Windows and is deferred until resume elsewhere).
  • scePthreadResume, scePthreadMulti and scePthreadResumeAll follow the code of firmware 13.42's libkernel_sys.sprx, which BunnyFl read and ran in an emulator (comment):

    • scePthreadResume(thread) calls pthread_resume_np and returns 0x80020000 plus a non-zero errno (0x80020016 for a null thread, 0x80020003 for one that is gone or finished).
    • scePthreadMulti() calls pthread_multi_np the same way, so it always returns 0.
    • scePthreadResumeAll is a jump to pthread_resume_all_np and returns nothing.
    • The same check confirms the scePthreadAttrSetcreatesuspend error form and the return values of the four POSIX calls above.

Inferred or unverified:

  • When a thread created suspended stops relative to its signal mask has not been measured on a console; it follows FreeBSD 11.4 libthr. This is recorded in docs/dev/debt/libkernel_sys.md and, for the Windows raise, in docs/dev/debt/libkernel.md.
  • pthread_suspend_np, pthread_suspend_all_np and pthread_single_np still throw.

Overlap: no open PR implements any of these functions (searched the diffs of all 1175 other open PRs).

Merge order: #9156 goes first, and this PR depends on it.

  • Both change core/libs/prx/libkernel_sys/Export.Discovery.cpp at neighbouring lines. #9156 deletes the pthread_attr_getaffinity_np, pthread_attr_getsolosched_np and pthread_attr_setaffinity_np stubs (L361-375 on main). This PR changes the line right after them (L376), the pthread_attr_setcreatesuspend_np signature, which has to take attr. Git treats edits on adjacent lines as one conflict, so moving this PR's edit cannot avoid it.
  • Once #9156 is merged, this PR is rebased onto main and keeps both edits. #9156 has no prerequisites.
  • The two includes this PR adds to that file now go above the existing ones, so they no longer meet the blocks #8987, #9141 and #9369 add below them. No other open PR that merges cleanly with main conflicts with this one.

Tested

At 0b60e97834, on main e7e3e9c198, after rebasing over main's per-library Api.hpp headers and adding the three sce forms. libkernel_sys/include/Api.hpp now declares these eight functions with their signatures, and the test includes the Api.hpp headers instead of declaring the exports itself. The thread logic is unchanged.

  • Windows 11 Home 25H2, WinLibs MinGW-w64 GCC 15.2.0 (x86_64-ucrt-posix-seh r7), CMake 4.3.1, Ninja 1.13.2, Release, BUILD_TESTING=ON: libkernel_sys and the 8 test targets build with no warnings in the changed files. ctest 100% tests passed, 0 tests failed out of 8 (guest_kernel_sys, guest_pthread_create_suspended, guest_pthread_attr, guest_pthread_start, guest_pthread_join_detach, guest_pthread_cancel, guest_raise_exception, guest_raise_in_host_code). guest_pthread_create_suspended with --repeat until-fail:3: 3 of 3 (0.61 to 0.64 s).
  • Ubuntu 24.04.5 on WSL2, GCC 13.3.0, merged into main 5949d8bf92 as the Linux CI job does: libkernel_sys fully rebuilt with no warnings in the changed files. ctest 100% tests passed, 0 tests failed out of 7. The repeat passes 3 of 3 (0.49 to 0.50 s). All 14 executables built from files that include libkernel_sys/include/Api.hpp also build and link.

Earlier runs:

At 6cad46b612, on main 524398151f:

  • Windows 11 Home 25H2 (10.0.26200) on x86-64 (Intel i7-11800H), WinLibs MinGW-w64 GCC 15.2.0 (x86_64-ucrt-posix-seh, 15.2.0posix-14.0.0-ucrt-r7), CMake 4.3.1, Ninja 1.13.2, Release, BUILD_TESTING=ON:
    • The test targets build with no warnings. The full tree was not built: on main it stops at the unrelated libSceAgcDriver/tests/execution/ImageArrayWindowPastLayerLimit.cpp:33 (alignas(65536) exceeds the 8192 limit of Windows object files).
    • ctest, all passed (100% tests passed, 0 tests failed out of 8): guest_kernel_sys 0.14 s, guest_pthread_create_suspended 0.48 s, guest_pthread_attr 0.55 s, guest_pthread_start 1.57 s, guest_pthread_join_detach 0.13 s, guest_pthread_cancel 0.33 s, guest_raise_exception 12.10 s (about 11.4 s on main) and guest_raise_in_host_code 0.06 s.
    • guest_pthread_create_suspended with --repeat until-fail:3: passed 3 of 3 (0.44 to 0.45 s).
  • Ubuntu 24.04.5 LTS on WSL2 on the same machine, GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1, Release, BUILD_TESTING=ON, with this PR merged into main 524398151f as the Linux CI job does:
    • The build has no warnings.
    • ctest, all passed (100% tests passed, 0 tests failed out of 7): guest_kernel_sys 0.01 s, guest_pthread_create_suspended 0.39 s, guest_pthread_attr 0.04 s, guest_pthread_start 1.80 s, guest_pthread_join_detach 0.06 s, guest_pthread_cancel 0.17 s and guest_raise_exception 2.66 s. guest_raise_in_host_code is registered only on Windows.
    • guest_pthread_create_suspended with --repeat until-fail:3: passed 3 of 3 (0.39 s each).
  • The branch was then rebased onto main ef0d8ae3b5, with the code unchanged; only the docs/dev/debt/libkernel_sys.md entry was re-merged next to new entries from main. The runs above were not repeated on that head.
  • The earlier head e4ecf3025, which differs only in the position of the two includes, passed the same tests on both hosts. On main 6ef5a1c4c with only the new test file and its CMake block, the test aborts with pthread_attr_setcreatesuspend_np_nid_postfix not implemented on both hosts.
  • tools/pr_overlap.py --branch feat/pthread-create-suspended --base main (main 524398151f): no shared exports or new files. Its only conflict is the one with #9156 above.

Run earlier on an arm64 Mac without Rosetta, which can only compile:

  • Compile checks against main a6dcea9279, repeated against main 110a18ba01 after the rebase onto it and the include move (the later rebase onto 524398151f changes none of these files):
    • MinGW-w64 GCC 16.2 (Homebrew), -fsyntax-only -Wall -Wextra and -c -O0, on Pthread/src/Thread.cpp, System/src/Exception.cpp, libkernel_sys/Export.Discovery.cpp, Pthread/src/Attr.cpp, Pthread/Posix/Attr.cpp, Pthread/Posix/Thread.cpp and the new test: no new diagnostics.
    • clang -target x86_64-apple-macos13 -fsyntax-only on the same files: the same diagnostics as main.
    • Thread.cpp and Exception.cpp already fail on macOS (missing pthread_getattr_np, pthread_getcpuclockid and the Linux gregs), so the Linux path was not compiled.
  • tools/check_conventions.py --base origin/main: passed.
  • tools/progress.py: on main e7e3e9c198, library functions go from 6054 to 6062 of 12288, and libkernel_sys from 49 to 57. These are the 8 functions above.
  • git merge-tree: clean against main 110a18ba01 and 524398151f. Against the heads of all 1175 other open PRs, the only new conflict is the one with #9156 above.
  • Native arm64 model: a model of the resume and registry-lock logic, shaped like the new detached-thread case. It is a model, not the real export.
    • It is clean under ASan.
    • Variants that release the registry lock before the wake hit heap-use-after-free in 5 of 5 runs.

No title or console was used.

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: #9156
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4961328656 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9573). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-10-22T02:47:44Z. --- ### What Implements `pthread_attr_setcreatesuspend_np`, `pthread_resume_np`, `pthread_resume_all_np`, `pthread_multi_np`, `scePthreadAttrSetcreatesuspend`, `scePthreadResume`, `scePthreadResumeAll` and `scePthreadMulti` (libkernel_sys), following FreeBSD 11.4 libthr at [8c639945](https://github.com/freebsd/freebsd-src/tree/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libthr/thread). - **Suspended start.** A thread created with the create-suspended attribute waits in `RunThread` before its start routine. That is after it is registered and before the POSIX signal mask is restored. - The wait is not a cancellation point. A cancel requested while the thread is suspended takes effect at the first cancellation point after resume. - libthr sets the flag from `attr.suspend` ([thr_create.c#L127-L132](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libthr/thread/thr_create.c#L127-L132)). - The new thread waits in `_thr_ast`, which runs `check_suspend` before `check_cancel` ([thr_sig.c#L265-L274](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libthr/thread/thr_sig.c#L265-L274), [thr_sig.c#L351-L399](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libthr/thread/thr_sig.c#L351-L399)). It gets there from `thread_start`, before the mask restore and the start routine ([thr_create.c#L252-L294](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libthr/thread/thr_create.c#L252-L294)). - **`pthread_attr_setcreatesuspend_np`** returns `EINVAL` for a null `attr` or `*attr`, otherwise 0 ([thr_attr.c#L369-L381](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libthr/thread/thr_attr.c#L369-L381)). - **`scePthreadAttrSetcreatesuspend`** returns `0x80020000 | errno`. - shadPS4 615bcba5 registers NID `GZSR0Ooae9Q` as `ORBIS(posix_pthread_attr_setcreatesuspend_np)` ([pthread_attr.cpp#L399-L400](https://github.com/shadps4-emu/shadPS4/blob/615bcba5e21b82dc59588575f7ecbce8da09ca2c/src/core/libraries/kernel/threads/pthread_attr.cpp#L399-L400)). - `ORBIS` adds `ORBIS_KERNEL_ERROR_UNKNOWN` (0x80020000) to a non-zero result ([kernel.h#L26-L39](https://github.com/shadps4-emu/shadPS4/blob/615bcba5e21b82dc59588575f7ecbce8da09ca2c/src/core/libraries/kernel/kernel.h#L26-L39), [orbis_error.h#L9](https://github.com/shadps4-emu/shadPS4/blob/615bcba5e21b82dc59588575f7ecbce8da09ca2c/src/core/libraries/kernel/orbis_error.h#L9)). - **`pthread_resume_np`** returns `EINVAL` for a null thread, `ESRCH` for a thread that is gone or has finished, and 0 otherwise ([thr_resume_np.c#L47-L60](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libthr/thread/thr_resume_np.c#L47-L60), [thr_list.c#L339-L363](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libthr/thread/thr_list.c#L339-L363)). - **`pthread_resume_all_np`** returns `void`. It resumes every thread except the caller, then reaches a cancellation point ([thr_resume_np.c#L62-L97](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libthr/thread/thr_resume_np.c#L62-L97)). - **`pthread_multi_np`** resumes all threads and returns 0 ([thr_multi_np.c#L40-L51](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libthr/thread/thr_multi_np.c#L40-L51)). - **Locking.** Resume clears the flag and wakes the thread while it holds the guest-thread registry lock. A detached thread that exits at the same moment therefore cannot be freed during the wake. - **Attribute getters.** `scePthreadAttrGet` and `pthread_attr_get_np` now report the create-suspended attribute the thread was created with. libthr keeps `attr.suspend` in the thread and copies it with the other attributes ([thr_create.c#L84-L88](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libthr/thread/thr_create.c#L84-L88), [thr_attr.c#L139-L172](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libthr/thread/thr_attr.c#L139-L172), [thr_private.h#L263-L277](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libthr/thread/thr_private.h#L263-L277)). - **Raise on Windows.** `sceKernelRaiseException` throws for a thread still suspended at creation. - libthr starts such a thread with every signal except `SIGTRAP` blocked ([thr_create.c#L177-L198](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libthr/thread/thr_create.c#L177-L198)) and restores its mask only after resume, so the signal waits. - Windows would instead redirect the thread to the handler before its start routine. - On Linux nothing changes: host signals stay blocked until resume, so the raise is delivered after it. - **Test.** New test `guest_pthread_create_suspended` (TIMEOUT 20) covers: - both creation forms; - the error codes; - resume of the calling thread and of a running thread; - `pthread_multi_np` and `pthread_resume_all_np`; - a cancel requested while suspended, and `pthread_resume_all_np` as a cancellation point; - both attribute getters; - detached suspended threads resumed while they exit; - the raise case (it throws on Windows and is deferred until resume elsewhere). - **`scePthreadResume`, `scePthreadMulti` and `scePthreadResumeAll`** follow the code of firmware 13.42's `libkernel_sys.sprx`, which BunnyFl read and ran in an emulator ([comment](https://github.com/boykopovar/AnyPS5/pull/9573#issuecomment-6393877843)): - `scePthreadResume(thread)` calls `pthread_resume_np` and returns `0x80020000` plus a non-zero errno (`0x80020016` for a null thread, `0x80020003` for one that is gone or finished). - `scePthreadMulti()` calls `pthread_multi_np` the same way, so it always returns 0. - `scePthreadResumeAll` is a jump to `pthread_resume_all_np` and returns nothing. - The same check confirms the `scePthreadAttrSetcreatesuspend` error form and the return values of the four POSIX calls above. Inferred or unverified: - When a thread created suspended stops relative to its signal mask has not been measured on a console; it follows FreeBSD 11.4 libthr. This is recorded in `docs/dev/debt/libkernel_sys.md` and, for the Windows raise, in `docs/dev/debt/libkernel.md`. - `pthread_suspend_np`, `pthread_suspend_all_np` and `pthread_single_np` still throw. Overlap: no open PR implements any of these functions (searched the diffs of all 1175 other open PRs). Merge order: #9156 goes first, and this PR depends on it. - Both change `core/libs/prx/libkernel_sys/Export.Discovery.cpp` at neighbouring lines. #9156 deletes the `pthread_attr_getaffinity_np`, `pthread_attr_getsolosched_np` and `pthread_attr_setaffinity_np` stubs (L361-375 on main). This PR changes the line right after them (L376), the `pthread_attr_setcreatesuspend_np` signature, which has to take `attr`. Git treats edits on adjacent lines as one conflict, so moving this PR's edit cannot avoid it. - Once #9156 is merged, this PR is rebased onto main and keeps both edits. #9156 has no prerequisites. - The two includes this PR adds to that file now go above the existing ones, so they no longer meet the blocks #8987, #9141 and #9369 add below them. No other open PR that merges cleanly with `main` conflicts with this one. ### Tested At 0b60e97834, on main e7e3e9c198, after rebasing over main's per-library `Api.hpp` headers and adding the three sce forms. `libkernel_sys/include/Api.hpp` now declares these eight functions with their signatures, and the test includes the `Api.hpp` headers instead of declaring the exports itself. The thread logic is unchanged. - **Windows 11 Home 25H2**, WinLibs MinGW-w64 GCC 15.2.0 (`x86_64-ucrt-posix-seh` r7), CMake 4.3.1, Ninja 1.13.2, Release, `BUILD_TESTING=ON`: `libkernel_sys` and the 8 test targets build with no warnings in the changed files. ctest `100% tests passed, 0 tests failed out of 8` (`guest_kernel_sys`, `guest_pthread_create_suspended`, `guest_pthread_attr`, `guest_pthread_start`, `guest_pthread_join_detach`, `guest_pthread_cancel`, `guest_raise_exception`, `guest_raise_in_host_code`). `guest_pthread_create_suspended` with `--repeat until-fail:3`: 3 of 3 (0.61 to 0.64 s). - **Ubuntu 24.04.5 on WSL2**, GCC 13.3.0, merged into main 5949d8bf92 as the Linux CI job does: `libkernel_sys` fully rebuilt with no warnings in the changed files. ctest `100% tests passed, 0 tests failed out of 7`. The repeat passes 3 of 3 (0.49 to 0.50 s). All 14 executables built from files that include `libkernel_sys/include/Api.hpp` also build and link. Earlier runs: At 6cad46b612, on main 524398151f: - **Windows 11 Home 25H2 (10.0.26200)** on x86-64 (Intel i7-11800H), WinLibs MinGW-w64 GCC 15.2.0 (`x86_64-ucrt-posix-seh`, `15.2.0posix-14.0.0-ucrt-r7`), CMake 4.3.1, Ninja 1.13.2, Release, `BUILD_TESTING=ON`: - The test targets build with no warnings. The full tree was not built: on `main` it stops at the unrelated `libSceAgcDriver/tests/execution/ImageArrayWindowPastLayerLimit.cpp:33` (`alignas(65536)` exceeds the 8192 limit of Windows object files). - ctest, all passed (`100% tests passed, 0 tests failed out of 8`): `guest_kernel_sys` 0.14 s, `guest_pthread_create_suspended` 0.48 s, `guest_pthread_attr` 0.55 s, `guest_pthread_start` 1.57 s, `guest_pthread_join_detach` 0.13 s, `guest_pthread_cancel` 0.33 s, `guest_raise_exception` 12.10 s (about 11.4 s on main) and `guest_raise_in_host_code` 0.06 s. - `guest_pthread_create_suspended` with `--repeat until-fail:3`: passed 3 of 3 (0.44 to 0.45 s). - **Ubuntu 24.04.5 LTS on WSL2** on the same machine, GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1, Release, `BUILD_TESTING=ON`, with this PR merged into main 524398151f as the Linux CI job does: - The build has no warnings. - ctest, all passed (`100% tests passed, 0 tests failed out of 7`): `guest_kernel_sys` 0.01 s, `guest_pthread_create_suspended` 0.39 s, `guest_pthread_attr` 0.04 s, `guest_pthread_start` 1.80 s, `guest_pthread_join_detach` 0.06 s, `guest_pthread_cancel` 0.17 s and `guest_raise_exception` 2.66 s. `guest_raise_in_host_code` is registered only on Windows. - `guest_pthread_create_suspended` with `--repeat until-fail:3`: passed 3 of 3 (0.39 s each). - The branch was then rebased onto main ef0d8ae3b5, with the code unchanged; only the `docs/dev/debt/libkernel_sys.md` entry was re-merged next to new entries from `main`. The runs above were not repeated on that head. - The earlier head e4ecf3025, which differs only in the position of the two includes, passed the same tests on both hosts. On main 6ef5a1c4c with only the new test file and its CMake block, the test aborts with `pthread_attr_setcreatesuspend_np_nid_postfix not implemented` on both hosts. - `tools/pr_overlap.py --branch feat/pthread-create-suspended --base main` (main 524398151f): no shared exports or new files. Its only conflict is the one with #9156 above. Run earlier on an arm64 Mac without Rosetta, which can only compile: - **Compile checks against main a6dcea9279**, repeated against main 110a18ba01 after the rebase onto it and the include move (the later rebase onto 524398151f changes none of these files): - MinGW-w64 GCC 16.2 (Homebrew), `-fsyntax-only -Wall -Wextra` and `-c -O0`, on `Pthread/src/Thread.cpp`, `System/src/Exception.cpp`, `libkernel_sys/Export.Discovery.cpp`, `Pthread/src/Attr.cpp`, `Pthread/Posix/Attr.cpp`, `Pthread/Posix/Thread.cpp` and the new test: no new diagnostics. - `clang -target x86_64-apple-macos13 -fsyntax-only` on the same files: the same diagnostics as main. - `Thread.cpp` and `Exception.cpp` already fail on macOS (missing `pthread_getattr_np`, `pthread_getcpuclockid` and the Linux `gregs`), so the Linux path was not compiled. - **`tools/check_conventions.py --base origin/main`:** passed. - **`tools/progress.py`:** on `main` e7e3e9c198, library functions go from 6054 to 6062 of 12288, and libkernel_sys from 49 to 57. These are the 8 functions above. - **`git merge-tree`:** clean against main 110a18ba01 and 524398151f. Against the heads of all 1175 other open PRs, the only new conflict is the one with #9156 above. - **Native arm64 model:** a model of the resume and registry-lock logic, shaped like the new detached-thread case. It is a model, not the real export. - It is clean under ASan. - Variants that release the registry lock before the wake hit heap-use-after-free in 5 of 5 runs. No title or console was used. ### 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: <!-- #PR, or none --> #9156 - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
zaryabzip commented 2026-10-22 03:27:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-22T03:27:31Z.


Test results for e4ecf3025, on x86-64 (i7-11800H). The Tested section is updated with the same results.

Windows 11 25H2, WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, Release, BUILD_TESTING=ON:

  • These 8 tests pass: guest_pthread_create_suspended, guest_pthread_start, guest_pthread_join_detach, guest_pthread_attr, guest_pthread_cancel, guest_kernel_sys, guest_raise_exception and guest_raise_in_host_code.
  • guest_pthread_create_suspended with --repeat until-fail:3 passes 3 of 3, in about 0.44 s each.
  • No warnings in the changed files.
  • The full build stops at libSceAgcDriver/tests/execution/ImageArrayWindowPastLayerLimit.cpp:33 (alignas(65536) exceeds the 8192 limit). Main fails there too, and this PR doesn't touch that file; #8310 and #9150 address it.

Ubuntu 24.04.5 on WSL2, GCC 13.3.0, Release, BUILD_TESTING=ON, with the PR merged into main 6ef5a1c4c the way the Linux CI job does:

  • The full build passes, with no warnings in the changed files.
  • 7 of the tests pass. guest_raise_in_host_code is registered only on Windows.
  • --repeat until-fail:3 passes 3 of 3, in 0.42 s each.

Baseline: on main with only the new test and its CMake block, the test aborts with pthread_attr_setcreatesuspend_np_nid_postfix not implemented, on both hosts.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6331942795 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9573#issuecomment-6331942795). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-10-22T03:27:31Z. --- Test results for e4ecf3025, on x86-64 (i7-11800H). The Tested section is updated with the same results. **Windows 11 25H2**, WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, Release, `BUILD_TESTING=ON`: - These 8 tests pass: `guest_pthread_create_suspended`, `guest_pthread_start`, `guest_pthread_join_detach`, `guest_pthread_attr`, `guest_pthread_cancel`, `guest_kernel_sys`, `guest_raise_exception` and `guest_raise_in_host_code`. - `guest_pthread_create_suspended` with `--repeat until-fail:3` passes 3 of 3, in about 0.44 s each. - No warnings in the changed files. - The full build stops at `libSceAgcDriver/tests/execution/ImageArrayWindowPastLayerLimit.cpp:33` (`alignas(65536)` exceeds the 8192 limit). Main fails there too, and this PR doesn't touch that file; #8310 and #9150 address it. **Ubuntu 24.04.5 on WSL2**, GCC 13.3.0, Release, `BUILD_TESTING=ON`, with the PR merged into main 6ef5a1c4c the way the Linux CI job does: - The full build passes, with no warnings in the changed files. - 7 of the tests pass. `guest_raise_in_host_code` is registered only on Windows. - `--repeat until-fail:3` passes 3 of 3, in 0.42 s each. **Baseline:** on main with only the new test and its CMake block, the test aborts with `pthread_attr_setcreatesuspend_np_nid_postfix not implemented`, on both hosts.
MarcZX10 commented 2026-10-22 03:52:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T03:52:47Z.

Review: CHANGES_REQUESTED


The implementation and test report are unusually thorough, including Linux/Windows runs, cancellation and detached-thread cases, and the explicit limits on console/ABI evidence. I did not find a substantiated runtime defect in the code reviewed.

I am requesting changes for the repository's overlap rule. The automated overlap report names open PRs #8987, #9141, #9369 and #9156 in core/libs/prx/libkernel_sys/Export.Discovery.cpp. The PR body calls these expected textual conflicts, but it does not record coordination with those authors or an agreed merge order. In particular, #9156 touches the pthread attribute stubs around the pthread_attr_setcreatesuspend_np insertion; #8987, #9141 and #9369 share the file's include insertion. Please coordinate with the affected authors and update Depends on to list any agreed prerequisites (including transitive prerequisites that are still open). A clean merge-tree against current main does not establish the ordering between these concurrently open changes.

Hosted eligibility, intake, labels, report and conventions checks pass. Hosted Linux, Windows, relinker and sanitizer jobs are skipped; I relied on the author-reported Windows/WSL test results and did not treat those hosted jobs as executed. The unverified console behavior and PS4-derived error encoding are clearly disclosed in the description and debt entry.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609055716 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9573#pullrequestreview-5609055716). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T03:52:47Z. **Review:** CHANGES_REQUESTED --- The implementation and test report are unusually thorough, including Linux/Windows runs, cancellation and detached-thread cases, and the explicit limits on console/ABI evidence. I did not find a substantiated runtime defect in the code reviewed. I am requesting changes for the repository's overlap rule. The automated overlap report names open PRs #8987, #9141, #9369 and #9156 in `core/libs/prx/libkernel_sys/Export.Discovery.cpp`. The PR body calls these expected textual conflicts, but it does not record coordination with those authors or an agreed merge order. In particular, #9156 touches the pthread attribute stubs around the `pthread_attr_setcreatesuspend_np` insertion; #8987, #9141 and #9369 share the file's include insertion. Please coordinate with the affected authors and update `Depends on` to list any agreed prerequisites (including transitive prerequisites that are still open). A clean merge-tree against current `main` does not establish the ordering between these concurrently open changes. Hosted eligibility, intake, labels, report and conventions checks pass. Hosted Linux, Windows, relinker and sanitizer jobs are skipped; I relied on the author-reported Windows/WSL test results and did not treat those hosted jobs as executed. The unverified console behavior and PS4-derived error encoding are clearly disclosed in the description and debt entry.
zaryabzip commented 2026-10-22 08:04:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-22T08:04:33Z.


@MarcZX10 Thanks for the review. I rebased onto main 524398151f and updated the PR:

  • The two includes this PR adds to Export.Discovery.cpp now sit above the existing ones, so they no longer meet the blocks #8987, #9141 and #9369 add below them. That is the only code change. tools/pr_overlap.py now shows no conflict with any open PR except #9156.
  • Moving code can't avoid the #9156 conflict. #9156 deletes the stubs at L361-375, and this PR has to change the pthread_attr_setcreatesuspend_np signature on the very next line, L376. I proposed on #9156 that it goes first, and Depends on now reads #9156. #9156 has no prerequisites of its own.
  • The new head 6cad46b612 was re-run on Windows (WinLibs GCC 15.2.0) and on WSL2 Ubuntu (GCC 13.3.0, merged into main as CI does). All 8 tests pass on Windows and all 7 on Linux, and guest_pthread_create_suspended passes 3 of 3 repeats on both. The Tested section has the details.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6335877022 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9573#issuecomment-6335877022). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-10-22T08:04:33Z. --- @MarcZX10 Thanks for the review. I rebased onto main 524398151f and updated the PR: - The two includes this PR adds to `Export.Discovery.cpp` now sit above the existing ones, so they no longer meet the blocks #8987, #9141 and #9369 add below them. That is the only code change. `tools/pr_overlap.py` now shows no conflict with any open PR except #9156. - Moving code can't avoid the #9156 conflict. #9156 deletes the stubs at L361-375, and this PR has to change the `pthread_attr_setcreatesuspend_np` signature on the very next line, L376. I proposed on #9156 that it goes first, and `Depends on` now reads `#9156`. #9156 has no prerequisites of its own. - The new head 6cad46b612 was re-run on Windows (WinLibs GCC 15.2.0) and on WSL2 Ubuntu (GCC 13.3.0, merged into main as CI does). All 8 tests pass on Windows and all 7 on Linux, and `guest_pthread_create_suspended` passes 3 of 3 repeats on both. The Tested section has the details.
MarcZX10 commented 2026-10-22 10:58:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T10:58:23Z.

Review: CHANGES_REQUESTED


Re-reviewed head 6cad46b6128b7d65f2c905b1f0a55fa90aeaef8c. The earlier code concerns appear resolved: #9156 is explicitly declared as a prerequisite, and DavidSamir agreed that it lands first. The include reorder also removes the previously flagged overlaps with #8987, #9141 and #9369. I found no new implementation defect in the reviewed delta. I built guest_pthread_create_suspended_tests locally. CTest aborts in HostCpu before assertions because this Xeon E5-1620 v2 lacks LZCNT, BMI1/2, MOVBE, AVX2 and FMA. The Windows and WSL focused runs and repeats are author-reported; current hosted eligibility, conventions, labels and report checks pass, with product/relinker jobs skipped. Current-base diff --check and conventions pass. Please refresh from current main: check_main_sync.py reports 1 ahead / 66 behind (merge base 524398151f), despite a clean merge. I also reran pr_overlap.py against current main. #9156 is the only comparable conflict and its authors have agreed to the stated order. The scan cannot compare several shared files because those PRs conflict with main. I manually confirmed relevant interactions to preserve during the rebase: #3986 adds inherited guest-signal-mask setup in RunThread near the new suspended wait; #4563 adds Windows detached-thread reaping around the RunThread exit/ReleaseThread path, which intersects this PR's detached-suspended-thread case; #8592 adds thread signal-deferral binding and exception handling relevant to this PR's raised-exception case; #6044 reorganizes core/libs/CMakeLists.txt and the test tree. Please coordinate with the affected authors as needed, retain the new tests/registration in the relocated tree if #6044 lands first, and add a dependency only where the agreed sequence requires one.

I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5613095904 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9573#pullrequestreview-5613095904). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T10:58:23Z. **Review:** CHANGES_REQUESTED --- Re-reviewed head `6cad46b6128b7d65f2c905b1f0a55fa90aeaef8c`. The earlier code concerns appear resolved: #9156 is explicitly declared as a prerequisite, and DavidSamir agreed that it lands first. The include reorder also removes the previously flagged overlaps with #8987, #9141 and #9369. I found no new implementation defect in the reviewed delta. I built `guest_pthread_create_suspended_tests` locally. CTest aborts in `HostCpu` before assertions because this Xeon E5-1620 v2 lacks LZCNT, BMI1/2, MOVBE, AVX2 and FMA. The Windows and WSL focused runs and repeats are author-reported; current hosted eligibility, conventions, labels and report checks pass, with product/relinker jobs skipped. Current-base `diff --check` and conventions pass. Please refresh from current `main`: `check_main_sync.py` reports 1 ahead / 66 behind (merge base `524398151f`), despite a clean merge. I also reran `pr_overlap.py` against current main. #9156 is the only comparable conflict and its authors have agreed to the stated order. The scan cannot compare several shared files because those PRs conflict with main. I manually confirmed relevant interactions to preserve during the rebase: #3986 adds inherited guest-signal-mask setup in `RunThread` near the new suspended wait; #4563 adds Windows detached-thread reaping around the `RunThread` exit/`ReleaseThread` path, which intersects this PR's detached-suspended-thread case; #8592 adds thread signal-deferral binding and exception handling relevant to this PR's raised-exception case; #6044 reorganizes `core/libs/CMakeLists.txt` and the test tree. Please coordinate with the affected authors as needed, retain the new tests/registration in the relocated tree if #6044 lands first, and add a dependency only where the agreed sequence requires one. I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
zaryabzip commented 2026-10-22 12:31:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-22T12:31:19Z.


@MarcZX10 Thanks for the re-review.

  • Rebased onto main 8b3a6ba88d (head 0bab52b5e6). The patch is unchanged (same git patch-id), and check_main_sync.py and check_conventions.py pass. The Windows and WSL2 runs in Tested are from 6cad46b612, one rebase earlier, and the description says so.
  • Intake: no title is known to stop on these functions, so this waits for the hold to lift. I'll add an Unblocks: line if a title turns up.
  • #3986, #4563, #8592 and #6044 all conflict with main today, so none of them is a merge-order prerequisite. Whichever lands second carries the other's change. If #6044 lands first, guest_pthread_create_suspended moves into its layout. If #3986 lands first, its guest signal-mask sigprocmask call in RunThread moves after the suspended wait, because libthr restores a suspended thread's signal mask only after it is resumed (thread_start, thr_create.c L252-294). #8592's BindThreadSignalDeferralState stays with the other per-thread bindings ahead of the wait. If #4563 lands first, the rebase keeps resume clearing and waking a thread under the registry lock, ahead of its Windows reaping, so a detached suspended thread cannot be freed during the wake. ResumesDetachedThreadsWhileTheyExit checks this.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6340799171 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9573#issuecomment-6340799171). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-10-22T12:31:19Z. --- @MarcZX10 Thanks for the re-review. - Rebased onto main 8b3a6ba88d (head 0bab52b5e6). The patch is unchanged (same `git patch-id`), and `check_main_sync.py` and `check_conventions.py` pass. The Windows and WSL2 runs in Tested are from 6cad46b612, one rebase earlier, and the description says so. - Intake: no title is known to stop on these functions, so this waits for the hold to lift. I'll add an `Unblocks:` line if a title turns up. - #3986, #4563, #8592 and #6044 all conflict with `main` today, so none of them is a merge-order prerequisite. Whichever lands second carries the other's change. If #6044 lands first, `guest_pthread_create_suspended` moves into its layout. If #3986 lands first, its guest signal-mask `sigprocmask` call in `RunThread` moves after the suspended wait, because libthr restores a suspended thread's signal mask only after it is resumed (`thread_start`, thr_create.c L252-294). #8592's `BindThreadSignalDeferralState` stays with the other per-thread bindings ahead of the wait. If #4563 lands first, the rebase keeps resume clearing and waking a thread under the registry lock, ahead of its Windows reaping, so a detached suspended thread cannot be freed during the wake. `ResumesDetachedThreadsWhileTheyExit` checks this.
MarcZX10 commented 2026-10-22 14:14:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T14:14:38Z.

Review: DISMISSED


Re-reviewed exact current head 0bab52b5e6a907850db4e0e204d77ac28cfb9b38. I found no new behavior defect. The test covers suspended start, resume of self/other threads, cancellation timing, attribute getters, detached exit races and the platform-specific raise path. The CTest timeout is 20 seconds, within the repository limit. The #9156 prerequisite order is explicitly agreed, and the integration notes for #3986/#4563/#8592/#6044 identify the state/tests to preserve without creating unnecessary dependency edges.

Correction to my earlier review and your latest comment: please disregard the intake hold and title-unblock request. Your contribution-count eligibility means this PR does not need to wait for the old #5239 queue direction.

The remaining request is current-base validation. This head is based on 8b3a6ba88d8fc74e768f1a7e8e9e36fb69842768, 39 commits behind current upstream 8b3e39832af85f404c6195418d11b3e1ebd1924d; git diff --check, current-main conventions and merge-tree pass. The Windows/WSL focused runs and 3/3 repeats are attributed by the author to 6cad46b, before the latest rebase. I ran GCC 12.2 C++20 -Wall -Wextra -Werror -fsyntax-only on GuestPthreadCreateSuspended.cpp and the test registration audit (171 scripts); both pass. I did not rerun local runtime tests here; the earlier exact target build was blocked at execution by this host's unsupported CPU features before assertions. Please update to current main and rerun the focused Windows/Linux matrix, including the repeat test, after #9156 lands.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5615631389 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9573#pullrequestreview-5615631389). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T14:14:38Z. **Review:** DISMISSED --- Re-reviewed exact current head `0bab52b5e6a907850db4e0e204d77ac28cfb9b38`. I found no new behavior defect. The test covers suspended start, resume of self/other threads, cancellation timing, attribute getters, detached exit races and the platform-specific raise path. The CTest timeout is 20 seconds, within the repository limit. The #9156 prerequisite order is explicitly agreed, and the integration notes for #3986/#4563/#8592/#6044 identify the state/tests to preserve without creating unnecessary dependency edges. Correction to my earlier review and your latest comment: please disregard the intake hold and title-unblock request. Your contribution-count eligibility means this PR does not need to wait for the old #5239 queue direction. The remaining request is current-base validation. This head is based on `8b3a6ba88d8fc74e768f1a7e8e9e36fb69842768`, 39 commits behind current upstream `8b3e39832af85f404c6195418d11b3e1ebd1924d`; `git diff --check`, current-main conventions and merge-tree pass. The Windows/WSL focused runs and 3/3 repeats are attributed by the author to `6cad46b`, before the latest rebase. I ran GCC 12.2 C++20 `-Wall -Wextra -Werror -fsyntax-only` on `GuestPthreadCreateSuspended.cpp` and the test registration audit (171 scripts); both pass. I did not rerun local runtime tests here; the earlier exact target build was blocked at execution by this host's unsupported CPU features before assertions. Please update to current main and rerun the focused Windows/Linux matrix, including the repeat test, after #9156 lands.
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!9573
No description provided.