libkernel: pthread spinlocks and pthread_cond_reltimedwait_np are absent (Porpoise, RetroArch); fix branch ready #3554

Closed
opened 2026-10-11 13:06:43 +00:00 by screamm · 1 comment
screamm commented 2026-10-11 13:06:43 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-11T13:06:43Z.


libkernel does not export the pthread_spin_* family (init ZMn3clnAGBA, destroy IJIggoPZExk, lock pw+70ClLYlY, trylock rCTGkBIHfPY, unlock LEfMMCT+SlM) or pthread_cond_reltimedwait_np (K953PF5u6Pc). From the relink registry order they are the predicted next stops of Porpoise (PPSA99764: K953PF5u6Pc at index 384, then pw+70ClLYlY at 387) and RetroArch (PPSA99169, indices 490 and 493); not yet observed in a run.

Fix branch ready: screamm:feat/libkernel-spin-reltimedwait (two commits on main a11c8f7f: 13ebf7f9 feat(libkernel): implement the pthread spinlock calls, c86ec841 feat(libkernel): implement pthread_cond_reltimedwait_np). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commits as they are. The only prior art is the bulk intake-closed #3293.

  • Spinlocks (new Pthread/Posix/Spinlock.cpp, no SCE twin exists in aerolib): FreeBSD 11.4 libthr thr_pspinlock.c/thr_umtx.h (8c639945): EINVAL for null/uninitialised/destroyed locks and a pshared outside 0 or 1, ENOMEM on allocation failure, EBUSY from trylock whenever held (including by the caller), EPERM from unlock by a non-holder, a spin that yields every 100000 checks like libthr's SPIN_COUNT; a holder locking again throws where libthr would spin forever; PTHREAD_PROCESS_SHARED gets an ordinary allocation (one process). The guest pthread_spinlock_t holds a pointer to the allocated lock like the other pthread types here.
  • pthread_cond_reltimedwait_np(cond, mutex, timeout) calls scePthreadCondTimedwait and returns POSIX errors; the third argument is microseconds, following shadPS4 condvar.cpp (3a9f5726), which registers one function for this NID and scePthreadCondTimedwait; width 32-bit as the SCE twin and sem_reltimedwait_np here. Both choices are in TechnicalDebt.
  • New guest_pthread_spin (argument errors, both pshared values, EPERM/EBUSY rules, the double-lock throw, cross-thread trylock/unlock, two threads × 200000 increments); guest_cond_timedwait gains EPERM without the mutex, a 50 ms and a zero timeout returning ETIMEDOUT with the mutex held, and a signal waking a 10 s wait.

Tested on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including libs: the four pthread tests 3/3; ctest -j8 -E "^agc_driver_|^video_out_flip" 533/537, the failures being the known windows_exceptions (#3411), guest_kernel_sys (#3510), guest_filesystem (#3518) and the agc_driver heap flake (#3171); with main's Cond.cpp the extended cond test fails; tools/check_conventions.py --base main and git diff --check pass. Not run on Linux.

Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5801325336 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3554). Originally posted by [screamm](https://github.com/screamm) on 2026-10-11T13:06:43Z. --- libkernel does not export the `pthread_spin_*` family (`init` `ZMn3clnAGBA`, `destroy` `IJIggoPZExk`, `lock` `pw+70ClLYlY`, `trylock` `rCTGkBIHfPY`, `unlock` `LEfMMCT+SlM`) or `pthread_cond_reltimedwait_np` (`K953PF5u6Pc`). From the relink registry order they are the predicted next stops of Porpoise (PPSA99764: `K953PF5u6Pc` at index 384, then `pw+70ClLYlY` at 387) and RetroArch (PPSA99169, indices 490 and 493); not yet observed in a run. **Fix branch ready:** [`screamm:feat/libkernel-spin-reltimedwait`](https://github.com/screamm/AnyPS5/tree/feat/libkernel-spin-reltimedwait) (two commits on `main` `a11c8f7f`: `13ebf7f9` `feat(libkernel): implement the pthread spinlock calls`, `c86ec841` `feat(libkernel): implement pthread_cond_reltimedwait_np`). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commits as they are. The only prior art is the bulk intake-closed #3293. - Spinlocks (new `Pthread/Posix/Spinlock.cpp`, no SCE twin exists in aerolib): FreeBSD 11.4 libthr `thr_pspinlock.c`/`thr_umtx.h` (`8c639945`): `EINVAL` for null/uninitialised/destroyed locks and a `pshared` outside 0 or 1, `ENOMEM` on allocation failure, `EBUSY` from trylock whenever held (including by the caller), `EPERM` from unlock by a non-holder, a spin that yields every 100000 checks like libthr's `SPIN_COUNT`; a holder locking again throws where libthr would spin forever; `PTHREAD_PROCESS_SHARED` gets an ordinary allocation (one process). The guest `pthread_spinlock_t` holds a pointer to the allocated lock like the other pthread types here. - `pthread_cond_reltimedwait_np(cond, mutex, timeout)` calls `scePthreadCondTimedwait` and returns POSIX errors; the third argument is microseconds, following shadPS4 `condvar.cpp` (`3a9f5726`), which registers one function for this NID and `scePthreadCondTimedwait`; width 32-bit as the SCE twin and `sem_reltimedwait_np` here. Both choices are in TechnicalDebt. - New `guest_pthread_spin` (argument errors, both `pshared` values, `EPERM`/`EBUSY` rules, the double-lock throw, cross-thread trylock/unlock, two threads × 200000 increments); `guest_cond_timedwait` gains `EPERM` without the mutex, a 50 ms and a zero timeout returning `ETIMEDOUT` with the mutex held, and a signal waking a 10 s wait. **Tested** on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including `libs`: the four pthread tests 3/3; `ctest -j8 -E "^agc_driver_|^video_out_flip"` 533/537, the failures being the known `windows_exceptions` (#3411), `guest_kernel_sys` (#3510), `guest_filesystem` (#3518) and the `agc_driver` heap flake (#3171); with `main`'s `Cond.cpp` the extended cond test fails; `tools/check_conventions.py --base main` and `git diff --check` pass. Not run on Linux. Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).
blawesom commented 2026-10-11 14:01:57 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-11T14:01:57Z.


Independent verification on Linux (the gap noted in the report): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON.

  • The branch is already based on current main — no rebase needed, the commit (c86ec8417) is unchanged.
  • tools/check_conventions.py --base origin/main and git diff --check pass.
  • The pthread spinlock and condition tests pass, including the new reltimedwait cases.
  • Full suite: 833/833 passed (all tests including the Vulkan suites on AMD RX 9070 XT / RADV).

The branch is also mirrored at blawesom:verify/3554 for anyone carrying.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109818837 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3554#issuecomment-6109818837). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-11T14:01:57Z. --- Independent verification on **Linux** (the gap noted in the report): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`. - The branch is already based on current `main` — no rebase needed, the commit (`c86ec8417`) is unchanged. - `tools/check_conventions.py --base origin/main` and `git diff --check` pass. - The pthread spinlock and condition tests pass, including the new reltimedwait cases. - Full suite: **833/833 passed** (all tests including the Vulkan suites on AMD RX 9070 XT / RADV). The branch is also mirrored at [`blawesom:verify/3554`](https://github.com/blawesom/AnyPS5/tree/verify/3554) for anyone carrying.
Sign in to join this conversation.
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#3554
No description provided.