Commit Graph

7 Commits

Author SHA1 Message Date
Adrià b8cf0eb24f
Merge pull request #1520 from popcoder565/fix/kernel-nested-sleep-timer
fix(libkernel): give a sleep nested in an APC its own timer on Windows
2026-10-10 03:07:46 +02:00
popcoder565 d80d5ff8c6 fix(libkernel): give a sleep nested in an APC its own timer on Windows
SleepUntil, PollSleepUntil and SleepNanosCoarse each wait on one
thread_local high-resolution timer. A sceKernelRaiseException handler
that runs as an APC inside a sleeping thread's wait and sleeps itself
re-armed that timer and consumed its signal, so the interrupted sleep
never returned. A nested TimerWait now waits on its own timer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 07:01:09 -04:00
clem-gb 39c3d0451d fix(libkernel): give each nested TimedWait its own waiter on Windows
A thread had one TimedWait waiter for every wait. When
sceKernelRaiseException reached a thread blocked in a TimedWait
condition, its handler ran as an APC inside that wait, and a wait in
the handler queued the same waiter on a second condition while it was
still linked into the first. The links of the first queue were
overwritten, so waiters behind it were never woken, and a wake of the
outer wait set the shared event and was consumed by the inner wait.

A wait now takes the thread's first waiter that is not in use, and
creates a deeper one for a wait nested inside another.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HeC9bA3n74TzJRYv9AgBE8
2026-10-08 10:47:32 +02:00
Merijn 2654e3a4ca fix(kernel): drain raised exceptions when leaving an alertable wait
A raise that suspends the thread after its wait returned but before the
wait count drops queued an APC that only ran at the next alertable wait.
Pending APCs are now run right after the count drops. The 0 ms poll in
Condition::waitSignalUntil runs under queueLock and is no longer
alertable, and a target that exits during the raise returns ESRCH.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 22:11:29 +02:00
Merijn 51b6079b5b fix(libkernel): no allocation while the target is suspended; own the wait count
The APC delivery was allocated after SuspendThread, so a target holding
the allocator lock deadlocked the raising thread; it is now allocated
before the suspend. The wait count a raise checks lived in the target's
thread_local storage and dangled once the thread exited; it is now a
member of PthreadPrivate, which TimedWait counts into through a
thread-local pointer bound when the thread starts, and a raise on a
thread that already finished returns ESRCH. TechnicalDebt gets one line
per unverified choice: Windows only, the FreeBSD ucontext layout, the
signal mask, the YMM upper halves, and delivery to threads outside
TimedWait.

AI-assisted: yes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 21:10:25 +02:00
Merijn dd2890c1c5 feat(libkernel): deliver sceKernelRaiseException on Windows
Run the SIGUSR1 handler recorded by sceKernelInstallExceptionHandler on the
target thread with a PS5 ucontext (uc_mcontext at 0x40, FreeBSD amd64
layout) of its interrupted state:

- on the calling thread, directly;
- on a thread in a libkernel wait, from an APC: the TimedWait waits are
  alertable and count themselves in a per-thread wait state, so the
  handler runs inside the wait, which then continues;
- on a running thread, by suspending it and redirecting it to an entry
  that calls the handler and restores the possibly modified context.

Other signals return EINVAL, as in shadPS4; raising without a handler
throws. Linux still throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 23:19:38 +02:00
devilismyfriend af3c2024ed feat(runtime): timed waits, sync primitive fixes, heap and RTC fixes, unattended-run switches
libkernel: a TimedWait service for condition variables, semaphores, event flags, rwlocks and
equeues with the scheduler tick; mutex/cond/sem corner cases the title hits; job worker
affinity is opt-in (APS5_JOB_AFFINITY). libc: calloc/realloc heap slot swap, a default
terminate handler with a backtrace, CPU topology helper. libSceRtc export fixes with tests.
libSceVideoOut: APS5_NO_PAD_INPUT ignores host input for unattended measurements,
APS5_FLIP_QUEUE_WAIT keeps a stalled process alive for a debugger. ApplicationHeap and
GuestRtc tests wired into the test build.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0177gthrWEBBfBu5xJDXgBfo
2026-09-26 19:00:39 -07:00