Commit Graph
406 Commits
Author SHA1 Message Date
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
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
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
Emanueleandmugurc 86cdfb8647 feat(libkernel): thread-local storage for Mach-O guests
FreeBSD code reaches its thread pointer through %fs and macOS cannot set
the fs base. The macOS relinker turns each %fs access of a guest image
into a stub that reads the thread pointer from a pthread key and calls
Aps5GuestTlsAllocate on a thread's first access, registers the TLS
descriptor of an image with Aps5GuestTlsRegister, and routes
__tls_get_addr to Aps5GuestTlsGetAddr. No library provided them, so a
relinked executable could not start.

- Aps5GuestTlsRegister validates the descriptor the relinker wrote and
  creates the key; its destructor frees the block of a thread.
- Aps5GuestTlsAllocateThreadPointer allocates the block (the TLS template
  followed by zeros, then a 0x100-byte thread control block whose first
  word points at itself, as on FreeBSD) and stores the thread pointer
  under the key.
- Aps5GuestTlsAllocate is the entry the stubs call: rax holds the
  descriptor and returns the thread pointer, every other register is
  preserved, the upper halves of the ymm registers only where AVX exists.
- Aps5GuestTlsGetAddr returns the block of the thread plus the offset.

Co-authored-by: mugurc <[email protected]>
2026-10-27 08:42:04 +01:00
Adrià 5c356f41c3 Merge pull request #11048 from imellag/feat/libkernel-macos-main-thread
feat(libkernel): start the guest off the main thread on macOS
2026-10-27 08:27:20 +01:00
ionut27001 fc8fc19125 fix(libc): return the CPU count of the default thread mask from std::thread::hardware_concurrency 2026-10-27 09:26:20 +02:00
orezraeyandClaude Opus 5.5 cf1771ec7e Merge main into fix/libkernel-mutex-yieldloops-destroyed-measured-ps5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-26 23:10:34 -03:00
Dean af2a996527 Merge pull request #11263 from orezraey/fix/libkernel-cond-signalto-measured-ps5
fix(libkernel): fail scePthreadCondSignalto for a null or non-waiting thread as measured on a PS5
2026-10-27 15:01:44 +13:00
Dean 8056827ea8 Merge pull request #10133 from orezraey/fix/libkernel-posix-thread-attr-measured-ps5
fix(libkernel): follow the thread priority ranges and POSIX attribute errors measured on a PS5
2026-10-27 14:58:57 +13:00
Dean 6e98696398 Merge pull request #10061 from elieh999/fix/rwlockattr-destroyed-pshared
fix(libkernel): preserve destroyed rwlock attributes
2026-10-27 14:58:42 +13:00
Dean 86a38cdf6c Merge pull request #9187 from slider/feat/libkernel-sched-params
feat(libkernel): implement sched_getparam, sched_getscheduler and sched_setparam for the calling thread
2026-10-27 14:57:32 +13:00
Dean ad1caa840c Merge pull request #10385 from alvaroelpob/feat/libkernel-pthread-setname
feat(libkernel): implement pthread_mutex_setname_np, pthread_rwlock_setname_np and pthread_barrier_setname_np
2026-10-27 10:54:00 +13:00
Dean dd248b02ed Merge pull request #11201 from orezraey/fix/libkernel-pthread-create-long-name-handle-measured-ps5
fix(libkernel): clear the thread handle when scePthreadCreate rejects a long name as measured on a PS5
2026-10-27 10:39:25 +13:00
Alvaro a0eaec6611 fix(libkernel): fail pthread_condattr_getclock with EINVAL for a null attribute
pthread_condattr_getclock threw for a null attribute pointer or a null
handle. FreeBSD 11.4 libthr (lib/libthr/thread/thr_condattr.c) returns
EINVAL for both before reading the clock, as setclock, setpshared,
getpshared and destroy here already do. A null output pointer with a
valid attribute faults on FreeBSD, so it still throws.
2026-10-26 22:34:15 +01:00
Piyush Sagar 947e72e4d7 feat(libkernel): implement pthread_condattr_getclock 2026-10-26 21:44:53 +05:30
Adrià 7903201bb4 Merge pull request #10130 from orezraey/fix/libkernel-pthread-attr-measured-ps5
fix(libkernel): report thread attribute inheritance and null-output errors as measured on a PS5
2026-10-26 15:45:11 +01:00
Alvaro cf2aa7c362 fix(libkernel): return EAGAIN when renaming a named mutex, rwlock or barrier 2026-10-26 15:39:49 +01:00
Alvaro 20ead24d8b refactor(libkernel): declare the setname exports in the public header 2026-10-26 15:37:37 +01:00
Alvaro 5c30b97440 feat(libkernel): implement pthread_barrier_setname_np 2026-10-26 15:37:26 +01:00
Alvaro a27cecc950 feat(libkernel): implement pthread_rwlock_setname_np 2026-10-26 15:37:26 +01:00
Alvaro d100cdaf52 feat(libkernel): implement pthread_mutex_setname_np 2026-10-26 15:36:49 +01:00
orezraeyandClaude Opus 5.5 60b9e7f43f Merge main into fix/libkernel-posix-thread-attr-measured-ps5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-26 11:07:59 -03:00
Adrià 9656d366be Merge pull request #9962 from kallmek3nny/feat/libkernel-pthread-cond-setname-np
feat(libkernel): add pthread_cond_setname_np
2026-10-26 14:42:29 +01:00