Commit Graph
433 Commits
Author SHA1 Message Date
Dean 947ebf3d2c Merge pull request #10817 from MarcZX10/marc/fix-thread-join-detach-released
fix(libkernel): return ESRCH from join, detach and cancel of a released thread handle
2026-11-02 23:24:36 +13:00
Dean 0ba2a2a124 Merge pull request #10810 from MarcZX10/marc/fix-thread-detached-race
fix(libkernel): read and write the detached state of a guest thread atomically
2026-11-02 23:24:31 +13:00
Dean 4b1076c483 Merge pull request #8477 from ycarogabriel-lgtm/codex/macos-host-fault-signals
fix(libkernel): keep host fault signals available on macOS
2026-11-02 20:56:46 +13:00
Dean 042c5fa5ce Merge pull request #12925 from KernelPanicNT/feat/libkernel-condattr-getclock-null-output
feat(libkernel): throw for a null pthread_condattr_getclock output
2026-11-02 20:55:04 +13:00
Ycaro Gabriel adefe80eea chore(merge): sync host fault signals with upstream main
Update the host-fault signal change to current main while preserving the Windows pending-exception delivery path and macOS unblocked fault signals.
2026-11-01 14:10:11 -03:00
Adrià 6c0bdd2014 Merge pull request #13908 from DeveshB-1/fix/cpuset-affinity-efault
fix(libkernel): return EFAULT from cpuset and pthread affinity for invalid memory
2026-11-01 09:55:39 +01:00
Dean Galvin c4629cbbe0 Merge main into feat/libkernel-condattr-getclock-null-output
# Conflicts:
#	docs/dev/debt/libkernel.md
#	docs/dev/debt/libkernel_sys.md
2026-11-01 21:13:14 +13:00
DeveshB-1 51bd568169 fix(libkernel): return EFAULT from cpuset and pthread affinity for invalid memory 2026-11-01 08:18:41 +01:00
GruzzberryandClaude Sonnet 5.5 5ba892d391 fix(libkernel): fail rtprio_thread, sched_setscheduler and setpriority with the jail privilege errors
A title is jailed (agreed on #11216). FreeBSD 11.4 prison_priv_check denies
PRIV_SCHED_RTPRIO, PRIV_SCHED_SET and PRIV_SCHED_SETPRIORITY to a jailed caller.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-01 07:56:25 +01:00
Adrià 97ca8c8751 Merge pull request #13832 from zaryabzip/fix/pthread-cond-signalto-esrch
fix(libkernel): return ESRCH from signalto for a handle that is not a thread
2026-11-01 04:28:11 +01:00
Adrià cac9da41e4 Merge pull request #13725 from cocoa55/fix/cond-relock-spin
fix(libkernel): spin and yield when a condition variable wait relocks its mutex
2026-10-31 22:20:43 +01:00
Adrià e23eea90e2 Merge pull request #13660 from w4rc0n/fix/sched-own-pid-main-thread
fix(libkernel): select the registered main thread for own-pid scheduling
2026-10-31 12:45:48 +01:00
zaryabzip 0a5c3be283 fix(libkernel): return ESRCH from signalto for a handle that is not a thread
scePthreadCondSignalto and pthread_cond_signalto_np answered EPERM for a
handle that is not a live thread, where a PS5 on firmware 13.60 returns
ESRCH. The check sits between the null-thread and not-waiting checks, as
that console orders them.
2026-10-31 13:37:23 +05:00
cocoa55andClaude Opus 5.5 8c4cdf84a2 test(libkernel): count the yields a woken condition variable wait makes
The mutex yield step counts each yield in a counter that
MutexYieldsForTest_nid_no_patch reads. With no spins and a yield count
of 5, a waiter woken while another thread holds its mutex must yield
exactly 5 times before it blocks, for each mutex type and for the outer
level of a recursive mutex held twice. With WakingLock::lock calling
the native lock directly the count stays 0 and the test aborts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-30 23:37:35 -04:00
cocoa55andClaude Opus 5.5 16375634e3 fix(libkernel): spin and yield when a condition variable wait relocks its mutex
FreeBSD 11.4's _mutex_cv_lock takes the mutex back through
mutex_lock_common, so a woken waiter tries once, spins and yields by
the mutex's counts before it blocks. The wait here called the native
lock directly; it now goes through the same spin and yield path as
scePthreadMutexLock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-30 22:47:35 -04:00
infra-rig 5090bcd175 fix(libkernel): select the registered main thread for own-pid scheduling
sched_getparam, sched_getscheduler and sched_setparam with the own pid
from a thread other than the main thread act on the main thread once it
has registered through scePthreadSelf, as FreeBSD's p1003_1b.c selects
the first thread. Before registration, after the main thread exits and
on macOS they still throw.
2026-10-30 16:35:04 -06:00
cocoa55andClaude Opus 5.5 32abcb15a0 fix(libkernel): try a mutex once before its spin and yield budget
FreeBSD's mutex_lock_common tries the lock before mutex_lock_sleep
spins or yields, so a free mutex with yield loops and no spins was
yielding before its first try here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-30 15:30:54 -04:00
cocoa55andClaude Opus 5.5 9a7acb3677 fix(libkernel): spin and yield by the mutex spin and yield loop counts
Lock and timed lock now try the mutex up to the spin count with a pause
between tries, then up to the yield count with a yield before each try,
before they block, as FreeBSD 11.4's mutex_lock_sleep does. Trylock and
a lock the thread already holds do not spin. A uniprocessor host skips
the spins and keeps the yields.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-30 13:56:31 -04:00
Adrià 96ff704249 Merge pull request #12667 from xdCloudy/feat/libkernel-sys-pthread-attr-helpers
feat(libkernel_sys): implement mutex attribute generation helpers
2026-10-30 14:02:33 +01:00
DeveshB-1 9e5683dd8b fix(libkernel): return EFAULT from sched_getparam and sched_setparam for invalid memory 2026-10-30 15:05:54 +05:30
Cloudy d833429467 feat(libkernel_sys): implement pthread attribute helpers 2026-10-30 08:12:52 +01:00
Adrià 5ba6b2b917 Merge pull request #12963 from JJenkx/windows/libkernel-raise-pending-until-resume
fix(libkernel): keep sceKernelRaiseException pending on a suspended thread on Windows
2026-10-30 06:32:05 +01:00
Adrià 8f21dd5a6a Merge pull request #12897 from AdnanKhan-ak47/fix/libkernel-thread-exit-signal-mask
fix(libkernel): leave other threads' signal masks alone when a thread exits through scePthreadExit
2026-10-30 06:30:49 +01:00
Adrià 87d938c650 Merge pull request #12556 from babyhuey/fix/sched-efault
fix(libkernel): return EFAULT from rtprio_thread and sched_rr_get_interval for a bad pointer
2026-10-30 02:32:23 +01:00
Adrià 4725feb152 Merge pull request #11431 from p3n1cillin/claude/pthread-getaffinity-set-size
fix(libkernel): answer pthread_getaffinity_np for the console's 8- and 16-byte sets
2026-10-30 01:20:44 +01:00
Adrià 43332e5f3b Merge pull request #11865 from ionut27001/fix/libkernel-sched-own-pid
fix(libkernel): sched_getparam reads out-of-range priorities, sched_setparam EPERM outside 256-767, own pid on the main thread
2026-10-29 20:34:52 +01:00
JJenkxandClaude Opus 5.5 db14f7a49d fix(libkernel): keep sceKernelRaiseException pending on a suspended thread on Windows
On Windows, sceKernelRaiseException threw for a thread created suspended
and not resumed yet. FreeBSD libthr starts such a thread with signals
blocked and restores its mask on resume, so the signal stays pending and
is delivered on that thread once it runs.

The raise is now recorded in the thread's pendingException with a
compare-exchange, and the thread exchanges it for -1 when it leaves the
creation wait and delivers it to itself before its start routine. Both
sides use one atomic, so a raise racing a resume is either taken by the
thread or, after it started, delivered as for a running thread. Raises
while pending are merged, as for a standard signal.

guest_pthread_create_suspended now runs the deferred-delivery case on
every host, with a second raise while the thread is suspended.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 13:39:50 -04:00
KernelPanicNT 602fc9c55a feat(libkernel): throw for a null pthread_condattr_getclock output
pthread_condattr_getclock reached NotImplemented_nid_no_patch for a null
output pointer with a valid attribute. Measured as a payload process on
a device, that call faults, as does scePthreadCondattrGetclock in the
same case, so both now throw std::invalid_argument. Every other measured
result of the condition attribute clock getters and setters already
matched. The test covers every invalid clock ID from -1 to 16.
2026-10-29 14:33:36 +00:00
Adrià 9036e3c9e4 Merge pull request #12126 from morten-holm/fix/macos-host-stack-above-arena
fix(libkernel): move the macOS main stack out of the guest arena
2026-10-29 14:51:57 +01:00
p3nicillinandClaude Opus 5.5 7c97d68937 fix(libkernel): throw for every set size the console was not measured with
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 12:18:00 +00:00
p3nicillinandClaude Opus 5.5 b4861eb197 fix(libkernel): answer pthread_getaffinity_np for the console's set sizes
PS5_PayloadSDK measured in a title (firmware 12.09) that
pthread_getaffinity_np answers sets of 8 and 16 bytes and returns ERANGE
for 32 bytes or more, so FreeBSD's 32-byte cpuset_t is refused. The call
accepted exactly 32 bytes and refused every other size. Sizes under 8
keep ERANGE; 17 to 31 bytes, between the measured sizes, throw.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 12:18:00 +00:00
Adrià 578b8311ac Merge pull request #11267 from kallmek3nny/feat/libkernel-sem-setname
feat(libkernel): implement sem_setname
2026-10-29 11:31:34 +01:00
Adnan Khan 33afa6a464 fix(libkernel): leave other threads' signal masks alone when a thread exits through scePthreadExit 2026-10-29 12:55:41 +05:30
Dean 711c4eca09 Merge pull request #11785 from ionut27001/fix/libc-hardware-concurrency
fix(libc): return the CPU count of the default thread mask from std::thread::hardware_concurrency
2026-10-29 12:16:46 +13:00
babyhuey 24135ac3a5 fix(libkernel): copy the rtprio_thread RTP_SET struct in after the thread lookup
FreeBSD's sys_rtprio_thread returns ESRCH for an unknown lwpid before a
failed copyin of the struct, so the copy-in now follows the thread
lookup, and RTP_SET with an unknown lwpid and an unreadable struct
reports ESRCH. Tests pin that order and sched_rr_get_interval's pid check
before its copy-out.
2026-10-28 18:59:00 -04:00
babyhuey c565100965 fix(libkernel): return EFAULT from rtprio_thread and sched_rr_get_interval for a bad pointer
rtprio_thread read and wrote the guest rtprio struct in place, and
sched_rr_get_interval wrote the interval in place, so a non-null pointer
into unmapped or read-only memory crashed the host. rtprio_thread now
copies the struct in with GuestCopyIn_nid_no_patch before the thread
lookup for RTP_SET, as FreeBSD's sys_rtprio_thread does, and builds the
RTP_LOOKUP result locally and copies it out with
GuestCopyOut_nid_no_patch. sched_rr_get_interval copies its interval out
the same way. A failed copy returns EFAULT.
2026-10-28 14:15:57 -04:00
kenny soloandClaude Opus 5.5 20c9a93999 feat(libkernel): implement sem_setname
Keep a copy of the name with the semaphore and move the export from the libkernel_sys stub into libkernel next to the other sem_* exports.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2026-10-28 14:51:17 +01:00
Morten HolmandClaude Sonnet 5.5 11ca3cb744 fix(libkernel): release only the main thread stack when moving it off the arena
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-28 12:43:40 +01:00
Dean bc7cc27e55 Merge pull request #10856 from Felipebmaitan/feat/guest-signal-cancellation
fix(libkernel): avoid cancellation wakeups during thread exit
2026-10-28 22:52:08 +13:00
Dean 4a6693acf8 Merge pull request #12083 from KernelPanicNT/fix/libkernel-mutexattr-setkind-any-kind
fix(libkernel): store any scePthreadMutexattrSetkind kind as firmware 13.42 does
2026-10-28 22:46:46 +13:00
Felipebmaitan 4ba0a6f9c4 chore: integrate current main for guest-signal-cancellation 2026-10-28 00:48:38 -03:00
Dean e778405b5b Merge pull request #11592 from alvaroelpob/fix/libkernel-condattr-getclock-einval
fix(libkernel): fail pthread_condattr_getclock with EINVAL for a null attribute
2026-10-28 13:04:04 +13:00
Ycaro Gabriel 1fcf61e455 Merge remote-tracking branch 'origin/main' into codex/macos-host-fault-signals 2026-10-27 19:36:36 -03:00
Morten HolmandClaude Sonnet 5.5 3b1697cf1c fix(libkernel): move the macOS main stack out of the guest arena
Under Rosetta the main thread stack lies at about 12 GiB, inside the guest
arena, where a title can map fixed addresses; a fixed mapping over it
aborts with a host region overlap.

- Aps5StartGuest moves the main thread onto a 16 MiB stack at
  0x600000000000 when the old stack overlaps a host region of the arena.
  It copies argv, environ, the program name and the initial block off the
  old stack, then frees the old stack and releases its range to the arena.
- The guest thread keeps the stack size of the original main thread.
- The arena gets GuestArenaOverlapsHostRegion and
  GuestArenaReleaseHostRegion for POSIX hosts.
- guest_main_stack_move starts the guest, then requires the main thread
  outside the arena, a fixed mapping where the old stack was, and argv and
  the environment intact.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-27 22:55:41 +01:00
KernelPanicNT 625a3fbb62 fix(libkernel): store any scePthreadMutexattrSetkind kind as firmware 13.42 does
scePthreadMutexattrSetkind called NotImplemented_nid_no_patch for a kind
outside 1 to 4. Firmware 13.42's libkernel, run in an emulator, makes it
call pthread_mutexattr_setkind_np, which stores any kind as a signed
16-bit value and returns 0, and turns a null attribute's -1 with errno 22
into 0x8001FFFF. It now forwards to pthread_mutexattr_setkind_np and
converts the result with sceKernelError, so a null attribute or object
still returns 0x8001FFFF and now also sets errno 22.

An out-of-range kind is refused by scePthreadMutexInit with 0x80020016,
leaving the mutex untouched, as measured for the same module.
scePthreadMutexattrGetkind is unchanged; kind 0 now reaches it and
returns 0.
2026-10-27 19:24:23 +00:00
KernelPanicNT 9ed4377be4 Merge main into fix/libkernel-mutexattr-setkind-any-kind 2026-10-27 19:22:42 +00:00
Adrià e2a5118839 Merge pull request #11047 from imellag/feat/libkernel-macho-tls
feat(libkernel): thread-local storage for Mach-O guests
2026-10-27 15:18:46 +01:00
Adrià 1089f2bbfd Merge pull request #11039 from orezraey/fix/libkernel-mutex-yieldloops-destroyed-measured-ps5
fix(libkernel): fail the yield loop setter on a destroyed mutex as measured on a PS5
2026-10-27 14:08:31 +01:00
ionut27001 e679177c1b fix(libkernel): sched_getparam reads out-of-range priorities, sched_setparam EPERM outside 256-767, own pid on the main thread 2026-10-27 14:11:42 +02:00
Adrià FranchandClaude Sonnet 5.5 c8cac8e090 fix(libkernel): initialise the CPU model before reading AVX support for guest TLS
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-27 08:42:09 +01:00