From d4b01b72c032695021c2014bb4916a3a6bf8a031 Mon Sep 17 00:00:00 2001 From: Chad Date: Mon, 5 Oct 2026 20:11:20 -0500 Subject: [PATCH 1/2] feat(libkernel): accept PTHREAD_PROCESS_SHARED barrier attributes The PS5 kernel follows FreeBSD 11, whose libthr accepts process-shared barriers. Guest code runs in a single process, so a process-shared barrier synchronises the same threads a private one does; the attribute is stored and reported back by getpshared. Co-Authored-By: Claude Opus 5.5 --- core/libs/prx/libkernel/Pthread/Posix/Barrier.cpp | 3 +-- core/libs/tests/GuestPthreadBarrier.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/libs/prx/libkernel/Pthread/Posix/Barrier.cpp b/core/libs/prx/libkernel/Pthread/Posix/Barrier.cpp index 1c363ef32..140b6900e 100644 --- a/core/libs/prx/libkernel/Pthread/Posix/Barrier.cpp +++ b/core/libs/prx/libkernel/Pthread/Posix/Barrier.cpp @@ -54,8 +54,7 @@ int APS5_VABI pthread_barrierattr_getpshared_nid_postfix(PthreadBarrierattrPriva int APS5_VABI pthread_barrierattr_setpshared_nid_postfix(PthreadBarrierattrPrivate** attr, int pshared) { if (!attr || !*attr) return 22; - if (pshared == PROCESS_SHARED) NotImplemented_nid_no_patch("pthread_barrierattr_setpshared: PTHREAD_PROCESS_SHARED"); - if (pshared != PROCESS_PRIVATE) return 22; + if (pshared != PROCESS_PRIVATE && pshared != PROCESS_SHARED) return 22; (*attr)->pshared = pshared; return 0; } diff --git a/core/libs/tests/GuestPthreadBarrier.cpp b/core/libs/tests/GuestPthreadBarrier.cpp index d7286b7ee..64d67e201 100644 --- a/core/libs/tests/GuestPthreadBarrier.cpp +++ b/core/libs/tests/GuestPthreadBarrier.cpp @@ -66,14 +66,16 @@ int main() { Require(pthread_barrierattr_getpshared_nid_postfix(&attr, &pshared) == 0 && pshared == PROCESS_PRIVATE); Require(pthread_barrierattr_setpshared_nid_postfix(&attr, 2) == GUEST_EINVAL); Require(pthread_barrierattr_setpshared_nid_postfix(&attr, -1) == GUEST_EINVAL); - bool rejected = false; - try { pthread_barrierattr_setpshared_nid_postfix(&attr, PROCESS_SHARED); } - catch (const std::runtime_error&) { rejected = true; } - Require(rejected); + Require(pthread_barrierattr_setpshared_nid_postfix(&attr, PROCESS_SHARED) == 0); + Require(pthread_barrierattr_getpshared_nid_postfix(&attr, &pshared) == 0 && pshared == PROCESS_SHARED); + Context shared; + Require(pthread_barrier_init_nid_postfix(&shared.barrier, &attr, WAITERS) == 0); + RunWaiters(shared); + Require(pthread_barrier_destroy_nid_postfix(&shared.barrier) == 0); Require(pthread_barrierattr_setpshared_nid_postfix(&attr, PROCESS_PRIVATE) == 0); pshared = -1; Require(pthread_barrierattr_getpshared_nid_postfix(&attr, &pshared) == 0 && pshared == PROCESS_PRIVATE); - rejected = false; + bool rejected = false; try { pthread_barrierattr_getpshared_nid_postfix(&attr, nullptr); } catch (const std::invalid_argument&) { rejected = true; } Require(rejected); From cef560ecaf2a6cce5b954568b31e1c8aa60c2e55 Mon Sep 17 00:00:00 2001 From: Chad Date: Tue, 6 Oct 2026 13:41:05 -0500 Subject: [PATCH 2/2] docs: record the FreeBSD 11.0 assumption for process-shared barrier attributes Co-Authored-By: Claude Opus 5.5 --- docs/dev/TechnicalDebt.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/dev/TechnicalDebt.md b/docs/dev/TechnicalDebt.md index 645d976a4..4ae541006 100644 --- a/docs/dev/TechnicalDebt.md +++ b/docs/dev/TechnicalDebt.md @@ -77,7 +77,7 @@ Throughout the project, every function at every stage either **does exactly what - [_sceLibcInternalThreadAtexit, _sceLibcInternalThreadDtors](../../core/libs/prx/libSceLibcInternal/Export.cpp) (libSceLibcInternal) - FreeBSD `__cxa_thread_atexit` semantics assumed; a null or non-image destructor and an allocation failure throw - [_sceLibcInternalForceTlsDestructor](../../core/libs/prx/libSceLibcInternal/Export.cpp) (libSceLibcInternal) - unknown return type and behaviour; a title's `libc.prx` calls it from `__cxa_finalize` with the module handle of a non-null dso - [__progname](../../core/libs/prx/libkernel/System/src/Process.cpp) (libkernel) - unknown data export -- [pthread_barrierattr_setpshared](../../core/libs/prx/libkernel/Pthread/Posix/Barrier.cpp) (libkernel) - PTHREAD_PROCESS_SHARED throws: FreeBSD 9.0 libthr rejects it with EINVAL and 11.0 accepts it, and which one the console follows is unknown +- [pthread_barrierattr_setpshared](../../core/libs/prx/libkernel/Pthread/Posix/Barrier.cpp) (libkernel) - PTHREAD_PROCESS_SHARED is accepted on the assumption that the console follows FreeBSD 11.0 libthr, which accepts it (9.0 rejects it with EINVAL); unverified on hardware. Guest code runs in one process, so a shared barrier behaves as a private one - [sceSslClose](../../core/libs/prx/libSceSsl/Export.cpp) (libSceSsl) - unknown signature - [sceSslGetSerialNumber](../../core/libs/prx/libSceSsl/Export.cpp) (libSceSsl) - unknown signature - [X+4jdIS75P0](../../core/libs/prx/libSceAudioIn/Export.cpp) (libSceAudioIn) - unknown name, signature