Commit Graph
214 Commits
Author SHA1 Message Date
milescovielloandClaude Opus 5.5 4ebc7d7d43 fix(libkernel): answer a join of the calling thread before its detach state
scePthreadJoin checked whether the thread was detached before whether it
was the calling thread. So a detached thread joining itself got EINVAL
instead of EDEADLK, and so did the main thread, which scePthreadSelf
adopts as detached. FreeBSD's join checks the calling thread right after
the null check and before it looks at the detach state. The self check
now comes first; the null, detached and already-joined answers are
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 02:41:38 +00:00
Dean 51cee90311 Merge pull request #7295 from ionut27001/fix/libkernel-pshared-private-only
fix(libkernel): reject PTHREAD_PROCESS_SHARED as the PS5 does and add the missing pshared accessors
2026-10-18 12:02:32 +13:00
ionut27001andClaude Opus 5.5 c00c58ae34 fix(libkernel): reject PTHREAD_PROCESS_SHARED in pthread_condattr_setpshared and add pthread_condattr_getpshared
On a PS5 (firmware 12.70), of the values 0, 1, 2 and -1,
pthread_condattr_setpshared accepts only 0 and leaves the attribute
unchanged otherwise. pthread_condattr_getpshared reports 0 and returns
EINVAL for a null, uninitialized or destroyed attribute, also with a
null output. With an initialized attribute a null output crashes the
console; here it throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 00:50:09 +03:00
ionut27001andClaude Opus 5.5 bdf3adb379 feat(libkernel): add pthread_rwlockattr_getpshared and pthread_rwlockattr_setpshared
Measured on a PS5 (firmware 12.70): the getter reports 0, and of the
values 0, 1, 2 and -1 the setter accepts only 0 and checks the value
before the attribute. A null or uninitialized attribute, or a null
output, crashes the console; here it throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 00:50:09 +03:00
ionut27001andClaude Opus 5.5 db504f6b9c fix(libkernel): reject PTHREAD_PROCESS_SHARED in pshared setters as the PS5 does
On a PS5 (firmware 12.70), of the values 0, 1, 2 and -1,
pthread_spin_init, pthread_barrierattr_setpshared and
pthread_mutexattr_setpshared accept only PTHREAD_PROCESS_PRIVATE (0);
1, 2 and -1 return EINVAL and leave the attribute unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 00:49:58 +03:00
Dean c0a7468f6f Merge pull request #7270 from Lindamea1/fix/cond-init-unset-attr
fix(libkernel): accept an uninitialized attribute in scePthreadCondInit
2026-10-18 10:39:14 +13:00
Dean 770e207ce5 Merge pull request #7115 from milescoviello/fix/asan-stack-reserve
fix(libkernel): measure the host stack reserve from the frame address
2026-10-18 10:25:49 +13:00
Dean a3d2f6ef50 Merge pull request #7225 from nicolasfalesy/feat/libkernel-condattr-setpshared
feat(libkernel): implement pthread_condattr_setpshared
2026-10-18 10:09:16 +13:00
Lindamea1andClaude Opus 5.5 111d81786b fix(libkernel): accept an uninitialized attribute in scePthreadCondInit
scePthreadCondInit, and pthread_cond_init through it, threw when attr
pointed to a null attribute: a zeroed one that was never initialized or
one that scePthreadCondattrDestroy has set to null. FreeBSD 11.4 libthr
(thr_cond.c, cond_init) takes a null attribute as the default one and
creates a CLOCK_REALTIME condition variable. A PS5 (firmware 13.60)
takes a zeroed attribute as the default one in scePthreadMutexInit
(#4158). Take it as the default here too, as scePthreadMutexInit and
scePthreadCreate already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 21:54:15 +01:00
Dean b95768d1b0 Merge pull request #6540 from JJenkx/fix/kernel-cpuset-thread-id
feat(libkernel): support cpuset affinity by guest thread ID
2026-10-18 09:43:55 +13:00
Dean e0045fb6ef Merge pull request #6518 from qpavyros/codex/mutexattr-invalid-attributes
fix(libkernel): return EINVAL for invalid mutex priority attributes
2026-10-18 09:41:01 +13:00
Nicolas FalesyandClaude Opus 5.5 05b457d49a feat(libkernel): implement pthread_condattr_setpshared
PSFlyCast (PPSA99247) imports pthread_condattr_setpshared (3BpP850hBT4)
from libkernel and fails to load without it:
"./app.elf: symbol lookup error: ./app.elf: undefined symbol: 3BpP850hBT4".

The attribute stores PTHREAD_PROCESS_PRIVATE (0) or
PTHREAD_PROCESS_SHARED (1); a null or uninitialized attribute and any
other value return EINVAL without changing it, following FreeBSD 11
libthr thr_condattr.c and pthread_mutexattr_setpshared here. Sharing
across processes is not modeled, as for mutexes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sovthwyu4H63RMbRVha2Sy
2026-10-17 14:06:11 -04:00
Dean 13d07428a1 Merge pull request #7035 from milescoviello/fix/timed-locks-null-deadline
fix(libkernel): treat a null deadline as an untimed lock in the timed pthread locks
2026-10-18 04:48:21 +13:00
Dean 4827f36cb5 Merge pull request #7029 from milescoviello/fix/condattr-setclock-einval
fix(libkernel): return EINVAL from scePthreadCondattrSetclock and Destroy for a null attribute
2026-10-18 02:22:59 +13:00
Dean c0b37ca726 Merge pull request #7028 from milescoviello/fix/pthread-attr-sched-enotsup
fix(libkernel): return ENOTSUP from pthread_attr_setschedparam and setschedpolicy like libthr
2026-10-18 02:00:22 +13:00
milescovielloandClaude Opus 5.5 e88b7de3c1 fix(libkernel): measure the host stack reserve from the frame address
MeasureStackReserve took the distance from the stack top to a local
variable. In an ANYPS5_ENABLE_ASAN build that local lives on
AddressSanitizer's fake stack (detect_stack_use_after_return is on by
default on Linux), away from the thread's stack, so the reserve could
come out negative. scePthreadCreate then asked the guest arena for a
stack of nearly 2^64 bytes and threw 'guest address space arena
exhausted'. The frame address is on the real stack in every build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 12:06:42 +00:00
Dean aa819ac74a Merge pull request #6956 from jradic/fix/libkernel-thread-local-slot-first-use
fix(libkernel): allocate the Windows thread-local slot on first use
2026-10-18 00:31:01 +13:00
Dean a08bdcb309 Merge pull request #7026 from milescoviello/fix/pthread-attr-stack-einval
fix(libkernel): return EINVAL from the scePthreadAttr stack and guard size calls
2026-10-18 00:23:13 +13:00
Adrià 673f7406c5 Merge pull request #6103 from Zinebyte/fix/sem-timedwait-cancellation
fix(libkernel): cancel before acquiring a ready timed semaphore
2026-10-17 12:15:32 +02:00
milescovielloandClaude Opus 5.5 676ee71c34 fix(libkernel): treat a null deadline as an untimed lock in the timed pthread locks
pthread_rwlock_timedrdlock, pthread_rwlock_timedwrlock and
pthread_mutex_timedlock threw for a null abstime. FreeBSD's libthr
passes a null abstime on to the untimed kernel lock, so these calls
then wait like pthread_rwlock_rdlock, pthread_rwlock_wrlock and
pthread_mutex_lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 06:46:25 +00:00
milescovielloandClaude Opus 5.5 62ac8d655f fix(libkernel): return EINVAL from scePthreadCondattrSetclock and Destroy for a null attribute
Both threw std::invalid_argument for a null or uninitialized attribute.
FreeBSD's libthr returns EINVAL for one, as the other scePthread
attribute calls here already do. The clock id is still stored as
given.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 06:42:41 +00:00
milescovielloandClaude Opus 5.5 19b236a4c5 fix(libkernel): return EINVAL from the scePthreadAttr stack and guard size calls
scePthreadAttrGetstack, Getstackaddr, Getguardsize, Setguardsize,
Setstack and Setstackaddr threw for a null attribute, a null pointer
argument or a stack below the 16 KiB minimum. FreeBSD's libthr returns
EINVAL for those, as the pthread_attr_* wrappers here and the other
scePthreadAttr calls already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 06:21:18 +00:00
milescovielloandClaude Opus 5.5 b693ef2340 fix(libkernel): return ENOTSUP from pthread_attr_setschedparam and setschedpolicy like libthr
FreeBSD's libthr rejects a null sched_param and, under SCHED_FIFO or
SCHED_RR, a priority outside sched_get_priority_min..max with ENOTSUP,
and a policy outside SCHED_FIFO..SCHED_RR with ENOTSUP. The wrappers
returned EINVAL for the null parameter and stored any priority or
policy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 06:05:43 +00:00
Dean 72a848ca52 Merge pull request #4533 from Roojool/contrib/g07-pthread-getname
fix(libkernel): answer pthread_getname_np for a joined thread with ESRCH
2026-10-17 13:05:38 +13:00
jradicandClaude Opus 5.5 75d29f5b3f fix(libkernel): allocate the Windows thread-local slot on first use
WindowsThreadLocal<T>::slot was a template static, so its dynamic
initialization was unordered against the timer self-test in Time.cpp.
With APS5_TRACE_TIMERS set, the self-test ran first, used slot 0 and
aborted every title with "Cannot bind native thread state". The slot is
now a function-local static. guest_nanosleep_timer_self_test runs
guest_nanosleep_tests with APS5_TRACE_TIMERS=1 on Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KwsvKtVsZDLefysUM9m2QS
2026-10-16 16:03:14 -05:00
JJenkx 7777219ee1 feat(libkernel): support cpuset affinity by guest thread ID 2026-10-15 15:25:34 -04:00
Codex ced0305455 fix(libkernel): return EINVAL for invalid mutex priority attributes 2026-10-15 21:34:35 +03:00
Adrià 63b377b51b Merge pull request #5612 from JJenkx/feat/private-mutex-sharing
fix(libkernel): store mutex process-sharing attributes
2026-10-15 17:03:30 +02:00
Adrià 264a528877 Merge pull request #5556 from Nixitov/feat/rtprio-thread
feat(libkernel): implement rtprio_thread and the pthread concurrency controls
2026-10-15 14:10:58 +02:00
Zinebyte 58a1e712cb fix(libkernel): cancel before acquiring a ready timed semaphore 2026-10-14 18:09:37 -04:00
Adrià b0a4753de1 Merge pull request #5230 from hugodearaujo/fix/inherit-creator-priority
fix(libkernel): give an inheriting thread its creator's priority
2026-10-14 21:07:30 +02:00
Nixitov 4091519b04 feat(libkernel): implement rtprio_thread and the pthread concurrency controls
Morrowind imports rtprio_thread, pthread_setconcurrency and pthread_getconcurrency and stops at start-up. Report every guest thread as normal priority and accept a set without applying it; store the concurrency level as a hint. Recorded in the libkernel debt.
2026-10-14 16:23:12 +02:00
Rujul Talekar 7ef0931ffd fix(libkernel): answer pthread_getname_np for a joined thread with ESRCH 2026-10-14 10:59:48 +05:30
Rujul Talekar e41f7f292e fix(libkernel): answer a second scePthreadJoin with ESRCH 2026-10-14 10:57:05 +05:30
JJenkx bfa0de72cb fix(libkernel): retain shared mutex attributes 2026-10-13 23:13:51 -04:00
JJenkx d1527840ea fix(libkernel): retire stack metadata before releasing mappings 2026-10-13 20:30:24 -04:00
JJenkx 73840e4f43 Merge remote-tracking branch 'origin/main' into feat/private-mutex-sharing 2026-10-13 19:49:21 -04:00
Dean d1670009fb Merge pull request #5429 from Dripl1x/perf/windows-mutex-wake
perf(libkernel): wake guest mutex waiters on release on Windows
2026-10-14 12:31:24 +13:00
Evgeniy KazarinandClaude Opus 5.5 99eaf73102 perf(libkernel): wake guest mutex waiters on release on Windows
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 02:18:33 +03:00
JJenkx 9bd29e4767 Merge commit '30f961266ade83b41d5c9de7dec1393e7fcecfb7' into feat/private-mutex-sharing 2026-10-13 18:59:59 -04:00
Dean ea2b2d364f Merge pull request #4514 from kallmek3nny/feat/libkernel-pthread-setaffinity
feat(libkernel): implement pthread_setaffinity_np
2026-10-14 10:20:33 +13:00
Dean 40047f46bd Merge pull request #4377 from MarcZX100/codex/carry-pthread-atfork-3628
feat(libkernel): implement pthread_atfork registration
2026-10-14 05:54:54 +13:00
screammandClaude Opus 5.5 74c3fb6576 feat(libkernel): implement pthread_setaffinity_np
PS5CEMU-HAR (PPSA99360, ps5-payload-dev build, relinks with
--trap-sdk-syscall-stubs) imports pthread_setaffinity_np (5KWrg7-ZqvE)
from libkernel.prx. babyhuey's run with #3787 merged onto main e7c70a2d
(PR #3787, 2026-10-12T10:54:44Z) stops at it:

  Windows: FAIL: unresolved ELF import 5KWrg7-ZqvE (pthread_setaffinity_np) from libkernel.prx
  Linux: undefined symbol: 5KWrg7-ZqvE (pthread_setaffinity_np)

It follows FreeBSD 11.4 libthr thr_affinity.c (8c639945) over
kern_cpuset_setaffinity: another thread is looked up first (EINVAL for
null, ESRCH when unknown or finished, as _thr_find_thread without dead
threads), a size other than the 32-byte cpuset_t returns ERANGE, the
mask is clipped to sceKernelGetAvailableCpumask and an empty result
returns EDEADLK, as cpuset_setaffinity does. The affinity is stored on
the guest thread through scePthreadSetaffinity, for the caller and for
any live guest thread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 16:39:07 +00:00
JJenkx 9258d2eba8 Merge current main into feat/private-mutex-sharing 2026-10-13 11:57:54 -04:00
Adrià 9c05bf25f5 Merge pull request #4585 from jagrat04/feat/libkernel-cpuset-affinity-errors-pr
feat(libkernel): return ESRCH and EINVAL for unsupported cpuset affinity targets
2026-10-13 17:23:01 +02:00
hugodearaujoandClaude Opus 5.5 143eb6aaed fix(libkernel): give an inheriting thread its creator's priority
Measured on a PS5 (firmware 13.60): a thread created with
PTHREAD_INHERIT_SCHED, a null attribute or a default attribute runs at
its creator's priority, whatever priority the attribute holds; with
explicit scheduling it takes the attribute's priority.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 12:02:33 -03:00
MarcZX100 9b6e7f66c4 fix(libkernel): protect host-only guest stack pages 2026-10-13 16:03:36 +02:00
Cesar RodriguezandClaude Opus 5.5 7637cac13e fix(libkernel): place guest thread stacks inside the application area
On Linux, glibc maps the stack of every guest thread near the top of the
host address space (around 0x7fff00000000). On the console, application
stacks lie inside the application area below 0xFC00000000, and guest code
relies on that: ChakraCore's garbage collector indexes a 4 MiB table with
address >> 18, so it only covers addresses below 1 TiB and reports
Js::OutOfMemoryException for a stack above it.

Map each guest thread's stack with DoMapAnon, which allocates from the
guest arena, behind a PROT_NONE guard page, and pass it to pthread_attr_setstack.
The stack is freed after a join; the stack of a detached thread is freed once its
host thread is gone from /proc/self/task.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 16:03:36 +02:00
hugodearaujoandClaude Opus 5.5 5c6a9d22c4 fix(libkernel): check and keep the scheduling policy of a thread
On a PS5 (firmware 13.60) pthread_setschedparam and
scePthreadSetschedparam accept only SCHED_FIFO and SCHED_RR with a
priority of 256 to 767 or 896 to 959, return EINVAL otherwise, and
keep the policy for pthread_getschedparam. A created thread takes the
policy of explicit scheduling attributes, or its creator's when it
inherits. Here any policy and priority were accepted and SCHED_FIFO
was always reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 12:53:19 +02:00
jagrat Singh 9efabff1cb feat(libkernel): return ESRCH and EINVAL for unsupported cpuset affinity targets
Allow calling threads to query and set affinity using their own thread ID in addition to -1. Return ESRCH for non-matching thread or process IDs and EINVAL for invalid level/which arguments instead of throwing NotImplemented, matching FreeBSD cpuset semantics.
2026-10-13 15:58:11 +05:30