Commit Graph
273 Commits
Author SHA1 Message Date
Dean 87f3526562 Merge pull request #8617 from Lindamea1/fix/libkernel-mutex-unlock-static-eperm
fix(libkernel): fail scePthreadMutexUnlock on a statically initialized mutex with EPERM
2026-10-23 21:08:24 +13:00
Dean c31f139db4 Merge pull request #8890 from UnhealthyKraken/feat/libkernel-pthread-timedjoin
feat(libkernel): implement pthread_timedjoin_np
2026-10-23 20:05:52 +13:00
Dean ee8a7349b5 Merge pull request #9265 from HQasper/claude/project-thread-6o4na3
feat(libkernel): implement pthread_rwlock_reltimedrdlock_np and pthread_rwlock_reltimedwrlock_np
2026-10-23 16:05:37 +13:00
3fcafeb420 fix(libkernel): keep the thread stack lock alive through static destruction
#9272 keeps liveStacks and protectedStackPages alive through static
destruction so that a late mprotect from an atexit handler can still
look up guest thread stacks. The mutex guarding them is still a static
std::mutex. libstdc++'s std::mutex has a trivial destructor, so it keeps
working on Linux, but libc++ destroys the pthread mutex, and a later lock
throws "mutex lock failed: Invalid argument": on macOS the exit probe of
guest_memory_lifetime fails at its mapping protection stage. The lock is
now allocated and never destroyed, like the maps.

The same change is part of #7201 and #8658.

Co-Authored-By: marion909 <[email protected]>
Co-Authored-By: iamthehimansh <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-22 20:19:51 -04:00
Dean 9d3becbe51 Merge pull request #9272 from milescoviello/fix/thread-stack-maps-outlive-exit
fix(libkernel): keep the thread stack maps alive through static destruction
2026-10-23 13:05:31 +13:00
Kraken bf787dc895 chore(libkernel): merge current main for timed join integration 2026-10-22 15:25:35 +01:00
Dean d6eafa54d0 Merge pull request #9279 from YossiYad/feat/kernel-sys-thread-defaults
feat(libkernel_sys): implement pthread_set_defaultstacksize_np, scePthreadSetDefaultstacksize and scePthreadSetName
2026-10-22 19:16:30 +13:00
Kang, Harry Zixuan 726edc503b feat(windows): support MSYS2 GCC runtime builds 2026-10-21 20:29:55 -07:00
Kraken 40c7168f9c Merge remote-tracking branch 'origin/main' into feat/libkernel-pthread-timedjoin 2026-10-22 03:48:39 +01:00
Adrià fe93440dfd Merge pull request #8502 from xXPBSXx/fix/pthread-barrier-count-limit
fix(libkernel): reject a pthread barrier count above INT_MAX like libthr
2026-10-21 21:02:25 +02:00
Adrià ea241c01b3 Merge pull request #8504 from xXPBSXx/fix/pthread-cond-timedwait-negative-seconds
fix(libkernel): reject a negative cond timedwait deadline like libthr
2026-10-21 20:29:21 +02:00
Yossi Yadgar bc09ce3128 feat(libkernel): keep the default thread stack size in one settable place 2026-10-21 20:24:13 +03:00
milescovielloandClaude Opus 5.5 5360173da5 fix(libkernel): keep the thread stack maps alive through static destruction
liveStacks, protectedStackPages and guestStackMappings were plain
globals, so libkernel's static destructors freed them at exit while
detached threads could still unregister their stacks or look one up.
ThreadSanitizer reports the race in guest_pthread_join_detach: the main
thread's static destruction of liveStacks against a detached thread's
UnregisterStack under stackLock. The maps are now created once and
never destroyed, as Apr.cpp does for its globals.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-21 17:05:38 +00:00
Claude 8f13fe70b9 feat(libkernel): implement pthread_rwlock_reltimedrdlock_np and pthread_rwlock_reltimedwrlock_np
Both were missing from libkernel.prx, so a title importing either
(dYv-+If2GPk, RRnSj8h8VR4) failed to load. They take a relative timeout
in microseconds and are scePthreadRwlockTimedrdlock and
scePthreadRwlockTimedwrlock with POSIX error numbers; a zero lock is
initialized as by pthread_rwlock_rdlock. The signature comes from
shadPS4, which registers one function for each NID and its
scePthreadRwlockTimed* twin; FreeBSD 11.4 has no such calls. The throwing
libkernel_sys copies are removed, as an export may live in one library
only. Recorded in the libkernel debt file.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2026-10-21 15:27:52 +00:00
Adrià 5faed506a5 Merge pull request #8428 from hypermoist/feat/libkernel-pthread-cleanup-push
feat(libkernel): implement pthread_cleanup_push and pthread_cleanup_pop
2026-10-21 15:32:45 +02:00
Adrià 1ae3f38d9e Merge pull request #8400 from slider/feat/libkernel-mutex-np
feat(libkernel): add mutex ownership, relative lock and spin/yield accessors
2026-10-21 15:32:34 +02:00
Dean 1d2f8cfe0e Merge pull request #8859 from hypermoist/feat/libc-c11-thread-forwards
feat(libc): forward the C11 thread and TSS calls to libkernel
2026-10-22 01:54:23 +13:00
SebastianandClaude Opus 5.5 74bd5d9fa5 feat(libkernel): add mutex ownership, relative lock and spin/yield accessors
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QnkpF2oEMofseVz9Z7WEAC
2026-10-21 08:00:19 +00:00
Dean ef1f41c4c9 Merge pull request #8061 from Dragost/fix/libkernel-pthread-yield-busy-spin
fix(libkernel): prevent 100% CPU busy-spinning on pthread yield on Windows
2026-10-21 20:57:20 +13:00
Dragost 2716dee730 fix(libkernel): prevent 100% CPU busy-spinning on pthread yield on Windows 2026-10-21 09:30:27 +02:00
Kraken c44f3b59f7 feat(libkernel): implement pthread_timedjoin_np 2026-10-21 05:50:29 +01:00
hypermistandClaude Opus 5.5 8bddc39245 feat(libc): forward the C11 thread and TSS calls to libkernel
_Call_once, _Tss_create, _Tss_delete, _Tss_get, _Tss_set, _Thrd_equal,
_Thrd_current and _Thrd_exit call scePthreadOnce, scePthreadKeyCreate,
scePthreadKeyDelete, scePthreadGetspecific, scePthreadSetspecific,
scePthreadEqual, scePthreadSelf and scePthreadExit and return their
results unchanged, as the console's libSceLibcInternal does.
_Mtx_current_owns returns 1 there. libkernel registers the calls with
libc at load, next to the pthread_create registration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
2026-10-21 16:31:00 +13:00
Dean a806c69bfe Merge pull request #8758 from p3n1cillin/codex/pthread-getprio-20261021
feat(libkernel): implement pthread_getprio
2026-10-21 14:27:54 +13:00
p3nicillin 5a79dda21d feat(libkernel): implement pthread_getprio 2026-10-21 00:08:30 +01:00
cadenasynysterandClaude Sonnet 5.5 a8b6d1c411 feat(libc): implement _Thrd_detach
Animal Well (PPSA22520) imports _Thrd_detach (L7f7zYwBvZA) from libc.prx and nothing exports it, so the Windows loader stops at startup. Register libkernel's pthread_detach with libc like pthread_create and pthread_join, and return _Thrd_error (4) when it fails.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01GtXavMkgCTCdmRpweviHcQ
2026-10-20 21:31:16 +02:00
Lindamea1andClaude Opus 5.5 c68ffcfd21 fix(libkernel): fail scePthreadMutexUnlock on a statically initialized mutex with EPERM
scePthreadMutexUnlock resolved the slot with resolveMutex(mutex, false),
which throws "Mutex is not initialized" while the slot still holds the
static initializer (0) or the adaptive static initializer (1), so
unlocking a statically initialized mutex that was never locked ended
the process. FreeBSD 11.4's mutex_unlock_common returns EPERM for both
without initializing the slot, and EINVAL for the destroyed marker.

Load the slot once: the destroyed marker still returns 0x80020016, and
the two initializers now return 0x80020001 and stay in the slot, so a
later lock still creates the mutex.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-20 19:31:14 +01:00
Dean 352dbe751a Merge pull request #8583 from Ondra97/codex/fix-pthread-attr-policy
fix(libkernel): report current thread scheduling policy in attributes
2026-10-21 07:14:27 +13:00
Dean 0b1d678fe5 Merge pull request #8148 from hamb3r/feat/libc-dinkumware-threads
feat(libc): export Dinkumware thread primitives from libc.prx
2026-10-21 06:21:49 +13:00
Ondra97 07486d7cfa fix(libkernel): report current thread scheduling policy in attributes 2026-10-20 19:05:08 +02:00
xXPBSXxandClaude Sonnet 5.5 894e9993a2 fix(libkernel): reject a negative cond timedwait deadline like libthr
_pthread_cond_timedwait fails an abstime with a negative tv_sec with EINVAL
before it looks at the condition variable or the mutex. pthread_cond_timedwait
took it as a deadline in the past and answered ETIMEDOUT.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-20 15:56:07 +02:00
xXPBSXxandClaude Sonnet 5.5 669455d1f2 fix(libkernel): reject a pthread barrier count above INT_MAX like libthr
_pthread_barrier_init fails a count above INT_MAX with EINVAL.
pthread_barrier_init accepted any count above zero.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-20 15:56:03 +02:00
hypermistandClaude Opus 5.5 fa0e7b8c13 feat(libkernel): implement pthread_cleanup_push and pthread_cleanup_pop
The exported forms allocate the handler record themselves and free it
when it is popped, as libkernel does; __pthread_cleanup_pop_imp now frees
such records too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
2026-10-21 01:33:25 +13:00
Dean 1ae9833228 Merge pull request #8035 from pushkarreddyy/feat/libkernel-pthread-mutexattr-getprotocol
feat(libkernel): implement pthread_mutexattr_getprotocol
2026-10-20 17:55:35 +13:00
Dean 56a0be39dd Merge pull request #7957 from Lindamea1/fix/libkernel-attrget-esrch-ended-thread
fix(libkernel): return ESRCH from scePthreadAttrGet for a thread that has ended
2026-10-20 17:40:20 +13:00
hamb3r 6ce8bc0373 feat(libc, libkernel): register pthread_create and pthread_join callbacks with libc 2026-10-20 03:21:53 +03:00
Adrià 88fb5592c6 Merge pull request #7611 from Lindamea1/fix/kernel-pthread-attr-sched-getters
feat(libkernel): implement scePthreadAttrGetschedpolicy and scePthreadAttrGetinheritsched
2026-10-20 01:23:13 +02:00
pushkarreddyy 4ea1c112bb feat(libkernel): implement pthread_mutexattr_getprotocol 2026-10-19 23:48:09 +05:30
Lindamea1andClaude Opus 5.5 3237083172 fix(libkernel): return ESRCH from scePthreadAttrGet for a thread that has ended
scePthreadAttrGet copied the attributes of any non-null handle, so a
thread that was joined or had finished still answered 0, and a thread
that ended detached was read after its object had been freed. FreeBSD
11.4's _pthread_attr_get_np returns ESRCH for a dead or reclaimed thread,
and Monster Hunter Wilds (PPSA24191) reuses a slot of its thread table
only when scePthreadAttrGet returns 0x80020003.

After the EINVAL checks it now returns ESRCH unless the handle is a live
guest thread, and copies the fields while holding the thread registry
lock (LockLiveGuestThread), so a detached thread exiting during the call
is not freed under the copy. GuestThreadIsLive uses the same lookup.
pthread_attr_get_np, which the title does not import, is left as it is;
the debt entry records the difference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-19 16:25:14 +01:00
Zinebyte 9895030146 fix(libkernel): wake POSIX sleep for thread cancellation 2026-10-19 12:57:09 +02:00
Adrià 2eb4de8e13 Merge pull request #6711 from Ondra97/codex/fix-rwlock-unlock-lifetime
fix(libkernel): notify rwlock waiters before unlocking state
2026-10-19 11:03:06 +02:00
Doğukan Atlıhan 1ad6c746b8 fix(libkernel): replace anonymous Windows stack mappings 2026-10-19 06:42:30 +02:00
klosixgaming-arch 30cbb2fd66 fix(libkernel): refuse to detach or rejoin a thread that is being joined
PPSA34015 (EA SPORTS FC 27) stopped with "Joining guest thread: Access is
denied": scePthreadJoin waited on a thread that another call released
under it, and then waited on its closed handle. As FreeBSD 11.4's
thr_join.c and thr_detach.c do with the joiner field, scePthreadDetach
now returns EINVAL while a thread waits to join the target, a second
concurrent scePthreadJoin returns EOPNOTSUPP, a cancelled join backs out,
and a completed join leaves the thread detached.
2026-10-19 03:30:58 +02:00
Adrià bebc294607 Merge pull request #6443 from EagleBearerYS/fix/libkernel-host-stack-guard-page
fix(libkernel): keep a protected host stack's guard page, and protect the Linux main stack
2026-10-19 02:41:09 +02:00
Adrià 5768b25925 Merge pull request #6244 from xXPBSXx/fix/pthread-destroyed-einval
fix(libkernel): return EINVAL for pthread mutex and cond operations on a destroyed object
2026-10-18 23:27:09 +02:00
Adrià 3a14fdb321 Merge pull request #6241 from Ondra97/codex/fix-semaphore-canceled-wakeup
fix(libkernel): preserve semaphore wakeups across cancellation
2026-10-18 22:59:45 +02:00
Adrià 1288433e8e Merge pull request #6184 from MarcZX10/codex/cache-inaccessible-guest-pages-6183
fix(agc): cache inaccessible guest pages
2026-10-18 22:37:09 +02:00
xXPBSXxandClaude Sonnet 5.5 c664ffbec4 fix(libkernel): return EINVAL for pthread mutex and cond operations on a destroyed object
Locking, trylocking, unlocking a destroyed mutex and signalling, broadcasting,
waiting on or destroying a destroyed condition variable threw a C++ exception
into the guest. FreeBSD 11.4 libthr returns EINVAL for all of them (thr_mutex.c
check_and_init_mutex and mutex_unlock_common compare against THR_MUTEX_DESTROYED,
thr_cond.c CHECK_AND_INIT_COND and _pthread_cond_destroy against
THR_COND_DESTROYED). The condition wait path already reported EINVAL for a
destroyed mutex.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-18 21:23:54 +02:00
Lindamea1andClaude Opus 5.5 2514eadcbd feat(libkernel): implement scePthreadAttrGetschedpolicy and scePthreadAttrGetinheritsched
libkernel exported scePthreadAttrSetschedpolicy and
scePthreadAttrSetinheritsched but not the matching getters,
scePthreadAttrGetschedpolicy (NID NMyIQ9WgWbU) and
scePthreadAttrGetinheritsched (NID lpMP8HhkBbg), so a title that
imports either one stopped at startup on the unresolved import. Dragon
Ball Xenoverse 2 (PPSA08587) imports both.

Implement them as FreeBSD 11.4 libthr implements
pthread_attr_getschedpolicy and pthread_attr_getinheritsched
(lib/libthr/thread/thr_attr.c): a null or uninitialized attribute
returns EINVAL (0x80020016), as does a null output of
scePthreadAttrGetschedpolicy; otherwise the attribute's policy or
inheritance is stored and 0 is returned. libthr writes through a null
output of the inheritance getter unchecked, so that case throws, as
pthread_attr_getinheritsched and scePthreadAttrGetsolosched do.

Neither getter was measured on a console. The scePthreadAttr entry in
docs/dev/debt/libkernel.md, which describes the calls measured on a
PS5, now says so and records the throw.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-18 17:45:49 +01:00
Adrià a0f3dc4014 Merge pull request #6091 from Ondra97/codex/fix-cond-canceled-signal
fix(libkernel): preserve condition signals across cancellation
2026-10-18 17:33:22 +02:00
Karim Ibrahim 267cb56a0d fix(libkernel): report the precommitted stack of an adopted thread on Windows
An adopted thread (the main thread, or a host thread that calls
scePthreadSelf) reported its whole Windows stack reservation, and so
did sceKernelIsStack on a host thread before adoption. A relinked
executable reserves 0x210000 bytes for its main thread and commits the
top 0x200000, so the lowest 64 KiB of the reported stack hold only
reserved pages and Windows' guard pages. mprotect fails there, so
HotSpot in Java 25 LAN / DNS (PPSA99869) could not create the main
thread's stack guard pages ("Attempt to allocate stack guard pages
failed").

When everything above the bottom allocation granule is committed
read-write, the host stack is now reported from there, as created
guest threads report only their committed stack. Other host stacks
keep the whole range. The committed-pages walk is shared with
StartNativeThread and throws when VirtualQuery fails.
2026-10-18 16:24:10 +02:00