Commit Graph
113 Commits
Author SHA1 Message Date
Dean 5924ecf2df Merge pull request #7156 from Amoenus/codex/fix-wait-trace-empty-main47
fix(libkernel): omit inactive wait trace sites
2026-11-04 16:58:26 +13:00
Dean f806099805 Merge pull request #14618 from slopgobblercobbler/test/libkernel-clock-gettime-invalid-clock-bounds
test(libkernel): cover invalid clock ID in clock_gettime
2026-11-03 11:40:23 +13:00
Romans Pokrovskis 82fd54db36 chore: refresh PR7156 against current prerequisites 2026-11-02 19:04:58 +02:00
Dean e03931ca93 Merge pull request #12281 from fogydes/fix/ktimer-settime-invalid-flags
fix(libkernel): reject invalid flags in ktimer_settime
2026-11-03 02:36:43 +13:00
Dean b052a9307b Merge pull request #12005 from akkadbakkad89/exception-drain-mailbox
fix(libkernel): post guest raises to the delivery drain mailbox on Windows
2026-11-03 01:29:04 +13:00
Dean 9dc910f515 Merge pull request #11042 from EagleBearerYS/fix/count-throwing-done-net-kernel
fix: report five always-throwing network and kernel exports as not implemented
2026-11-02 23:26:36 +13:00
slopgobblercobbler 4e913b7444 test(libkernel): cover invalid clock ID in clock_gettime 2026-11-01 17:25:04 +01:00
akkadbakkad89 2189fb06ea fix(libkernel): retire delivery-drain posts against a finished target
QueueForDeliveryDrain ran after ResumeThread with no coordination with
the target's final ReapDeliveryDrain: a target could exit between resume
and enqueue, leaving the post in a box nothing would drain again and
retaining the QueuedDelivery reference.

Admission is now decided under drainBoxesLock against the target's
_finished flag, which is stored before the final reap in program order;
denied posts run their callback inline so the entry and the reference
are resolved exactly once on either path.

The GuestRaiseException regression arms a post hook, holds the producer
between resume and enqueue, lets the target finish and reap, then
completes the post and requires the drain to stay empty; the churn
rounds also assert the post hook observed mailbox posts alongside the
delivered raises.
2026-11-01 18:30:44 +05:30
Romans Pokrovskis 442b990f19 chore: refresh wait trace fix onto main26fa 2026-11-01 11:13:36 +02:00
akkadbakkad89andDevin 7ff3b7091b fix(libkernel): post guest raises to the delivery drain mailbox on Windows
Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-01 13:23:10 +05:30
DeveshB-1 132b7bad73 fix(libkernel): return EFAULT from time conversions for unwritable stores 2026-11-01 07:36:05 +01:00
Yunus Shaikh 49a05d8769 Merge main into fix/count-throwing-done-net-kernel
The conflict in core/libs/tests/GuestRudpContextLifecycle.cpp with #13799 keeps both changes: this branch's removal of the check that sceRudpActivate throws, and main's sceRudpBind(ctx, 5, 0, 2) call after it.
2026-10-31 18:38:17 -07:00
Romans Pokrovskis 70f7250c3b chore: refresh wait trace fix onto main5857 2026-10-31 01:27:06 +02:00
boykopovar 950b697477 fix(libkernel): preserve exception delivery ownership and alertable drains 2026-10-31 00:13:13 +03:00
Oscar45397andClaude Opus 5.5 03722a1570 fix(libkernel): deliver raises at the spin that ends a sleep on Windows
On Windows a sleep shorter than TimedWait's 0.5 ms lead, and the last 0.5 ms of a longer one, is a YieldProcessor spin in host code with no wait counted. A raise that found the target there could only be delivered through the return-address breakpoint or sampling, so sceKernelRaiseException at a thread looping on such sleeps was lost: a thread looping on sceKernelUsleep(200) lost the first raise in 5 of 5 runs.

The spins in SleepUntil and SleepNanosUnlessChanged now run under a DeliveryDeferral and drain APCs afterwards, as BeginPark and Unpark already do. A raise that finds the target spinning is queued as an APC and runs when the sleep ends.

GuestRaiseShortSleep raises 100 times each at a thread sleeping 100, 200 and 400 us in a loop, with sleep wakes on (SleepNanosUnlessChanged) and with APS5_NO_SLEEP_WAKE (SleepUntil). Both fail on main at the first or second raise.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-30 13:26:59 +01:00
Adrià 45d0ed5f35 Merge pull request #11725 from camezaro-intc/fix/libkernel-timedwait-busy-spin
fix(libkernel): prevent sub-millisecond timed wait busy-spinning on Windows
2026-10-30 12:44:23 +01:00
Romans Pokrovskis 1443f0a43f chore: merge current main into PR7156 2026-10-29 00:36:39 +02:00
XairRrR 5da36327d3 fix(libkernel): scale the reported TSC frequency under APS5_TIME_SCALE
Titles that execute rdtsc themselves ignored APS5_TIME_SCALE, because
only sceKernelReadTsc scaled its ticks. The reported TSC frequency is
now divided by the scale and sceKernelReadTsc returns raw ticks, so
ticks over the reported frequency follow the scale for both. The
JobManager worker spin keeps real time through the host frequency.

AI-assisted: yes
2026-10-28 18:47:46 +01:00
camezaro-intc 1cf6f482c0 fix(libkernel): prevent sub-millisecond timed wait busy-spinning on Windows 2026-10-28 11:39:08 -06:00
fogydes bdf916d924 fix(libkernel): reject invalid flags in ktimer_settime 2026-10-28 12:44:01 +05:30
Romans Pokrovskis 7fb4c1d471 chore: refresh wait trace regression on current main 2026-10-28 08:27:47 +02:00
tkcm01andClaude Opus 5.5 1127dacf68 fix(libkernel): keep errno across cancellable sleeps
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-28 01:49:47 -04:00
Yunus Shaikh 06e6e107a1 Merge main into fix/count-throwing-done-net-kernel
# Conflicts:
#	core/libs/prx/libkernel/Time/Time.cpp
#	core/libs/tests/GuestMlock.cpp
#	docs/dev/debt/libkernel.md
2026-10-27 20:23:15 -07:00
Dean b3b449cfe4 Merge pull request #8916 from Henryisdjfunkyho/fix/cancellable-timed-sleeps
fix(libkernel): wake timed sleeps for thread cancellation
2026-10-28 13:48:32 +13:00
Dean a6816811f3 Merge pull request #10975 from xXPBSXx/fix/gettimeofday-itimer-efault
fix(libkernel): fail gettimeofday, getitimer, setitimer and the sceKernel time getters with EFAULT on an unusable pointer
2026-10-28 13:02:14 +13:00
Dean 7f02cb1802 Merge pull request #11402 from 00xDisaster/fix/libkernel-settime-efault
fix(libkernel): check settimeofday and clock_settime pointers
2026-10-27 21:25:30 +13:00
Henryisdjfunkyho 42bbc98235 chore: merge main into cancellable timed sleeps 2026-10-26 17:13:30 -07:00
xXPBSXx 506d69b015 Merge main (e0b13f2990) into fix/gettimeofday-itimer-efault
The only conflict is sceKernelGettimezone in Time.cpp: main now reports the host zone, so the zone is built from that into a local and copied out with the checked write.
2026-10-26 20:49:00 +01:00
Romans Pokrovskis e079c87e82 Merge commit 'd3b397b750bf55fed924036a344917c1e6fa920f' into codex/refresh-pr7156-maind3b-20261026 2026-10-26 18:55:12 +02:00
Disaster 78571ca2fb fix(libkernel): check settimeofday and clock_settime pointers
Both read their caller's structures in place before validation, so an unreadable pointer crashed the host. Copy them in with a checked read first and return EFAULT, as FreeBSD 11.4 does.

Fixes #11370
2026-10-26 14:29:02 +03:00
frankea 4db6ed7635 Merge remote-tracking branch 'origin/main' into fix/kernel-gettimezone-host-zone
# Conflicts:
#	core/libs/tests/GuestFreebsdClocks.cpp
2026-10-25 20:22:45 -04:00
xXPBSXxandClaude Sonnet 5.5 080c77547c Merge main (49d1f9b07e) into fix/gettimeofday-itimer-efault
The only conflict is in Time.cpp with the guest timezone store of the
settimeofday change: gettimeofday reads the timezone under the mutex into
a local copy, releases it, then copies it out with the checked write.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-26 00:52:14 +01:00
Yunus Shaikh 077a4ae318 Merge main into fix/count-throwing-done-net-kernel 2026-10-25 15:32:54 -07:00
Adrià d19a809639 Merge pull request #9682 from Gruzzberry/feat/settimeofday
feat(libkernel_sys): implement settimeofday
2026-10-25 23:04:11 +01:00
Adrià e1ef22e888 Merge pull request #9461 from milescoviello/fix/tsc-calibration-one-cpu
fix(libkernel): measure the TSC frequency on one CPU
2026-10-25 19:48:55 +01:00
Itamar Medyoni 3db438f997 fix(libkernel): answer process CPU clocks like FreeBSD instead of throwing
A clock id with CPUCLOCK_PROCESS_BIT threw in clock_gettime and
clock_getres. FreeBSD 11 get_cputime reads the process's CPU time, or
fails with EINVAL when pget finds no such process, and kern_clock_getres
gives every CPU clock the CPU time resolution without a lookup. The
guest's own process clock now reads CLOCK_PROCESS_CPUTIME_ID, any other
fails with EINVAL, as kill already finds no other process.
2026-10-25 16:07:10 +01:00
GruzzberryandClaude Opus 5.5 e6b07323de feat(libkernel_sys): implement settimeofday
FreeBSD 11.4's kern_settimeofday rejects a timeval with a microsecond
field outside 0 to 999999 or a negative second field with EINVAL before
changing anything, sets the clock from a valid timeval, and then stores
the timezone, which gettimeofday reports. settimeofday now checks the
timeval the same way and throws for a valid one, as clock_settime does,
because the host clock is not changed. A timezone given without a
timeval is stored and gettimeofday reports it instead of 0 and 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 13:20:31 +00:00
Yunus Shaikh 79d7265aa9 fix(libkernel): report the internal pool query, mlockall and clock_settime as not implemented
sceKernelInternalMemoryGetAvailableSize with an output, mlockall with valid flags and clock_settime with a valid CLOCK_REALTIME request threw bare exceptions on every such call, so progress.py counted them as done. Internal pool statistics, locking every mapping and setting the clock are not implemented, so those calls now go through NotImplemented_nid_no_patch. The -1, EINVAL and EFAULT answers before them are unchanged.
2026-10-25 12:53:43 +00:00
xXPBSXxandClaude Sonnet 5.5 c8430e739c fix(libkernel): fail gettimeofday, getitimer, setitimer and the sceKernel time getters with EFAULT on an unusable pointer
These wrote their result through the caller's pointer in place, or read
the itimerval of setitimer without a check, so a pointer into unmapped
memory crashed the host. Build the result locally and copy it out with
the checked write (and read the setitimer value with a checked read),
failing with EFAULT as FreeBSD 11.4 does: copyout in sys_gettimeofday
(sys/kern/kern_time.c:646 and 651) and sys_getitimer (kern_time.c:745),
copyin (kern_time.c:803) and copyout (kern_time.c:808) in sys_setitimer.

getrlimit and getrusage are left to #8986 and #8988, which cover the same
family for those two calls.

Builds on fix/output-structs-efault, which adds GuestCopyOut_nid_no_patch.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-25 12:22:40 +01:00
milescovielloandClaude Opus 5.5 6508231c0e fix(libkernel): measure the TSC frequency on one CPU
sceKernelGetTscFrequency times 20 ms of TSC ticks against the monotonic
clock. A thread that moves to another CPU during the sleep reads its end
value from another TSC. Where the TSCs of the CPUs differ, as on a Windows
VM whose vCPU 0 counts about 3.8 billion ticks ahead of the others, the
frequency came out as 0 or as 180 GHz. Pin the calibrating thread to the
CPU it runs on and restore its affinity afterwards.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 02:24:56 +00:00
Henryisdjfunkyho 5d0ddabbde Merge remote-tracking branch 'origin/main' into fix/cancellable-timed-sleeps
# Conflicts:
#	core/libs/tests/GuestSleepCancel.cpp
2026-10-24 18:06:20 -07:00
Henryisdjfunkyho 4d8f05891b test(libkernel): restore synchronized SCE sleep cancellation coverage 2026-10-24 13:58:16 -07:00
Henryisdjfunkyho 7b7ff0bbae Merge remote-tracking branch 'origin/main' into fix/cancellable-timed-sleeps 2026-10-24 13:46:20 -07:00
boykopovar f38d29fd08 refactor(sdk): add canonical headers for remaining libraries 2026-10-24 23:17:42 +03:00
Romans Pokrovskis a540b59a36 fix(libkernel): omit inactive wait trace sites 2026-10-24 11:39:18 +03:00
Emanuele d93cdf402d fix(libkernel): defer raises while a thread holds the address-wait lock on Linux and macOS
On Linux and macOS, sceKernelRaiseException runs the guest handler in
the target's SIGUSR1 handler wherever the thread was interrupted. A
thread interrupted while it held the address-wait lock of
sceKernelSyncOnAddressWait, sceKernelSyncOnAddressWake or _umtx_op ran
the handler with the lock held, so a handler that waits, as a
stop-the-world collector's does, blocked every other thread that waits
on or wakes an address. #5756 fixed this on Windows.

The address-wait lock is now taken under DeliveryDeferral on every
host. On POSIX the deferral is a count per thread: while it is raised
the SIGUSR1 handler only records the signal, and DeliverDeferred sends
it to the thread again once the lock is released. An address waiter
waits on its own semaphore (sem_t, a dispatch semaphore on macOS) with
the lock released and the deferral lifted, so a raise reaches a thread
that waits for an address without a timeout.

The address-lock phases of guest_raise_exception now run on every
host, with a new phase that raises at a thread in an unbounded address
wait.
2026-10-24 08:40:37 +02:00
frankea fabe448517 fix(libkernel): report the host zone's standard offset and daylight saving amount from sceKernelGettimezone
sceKernelGettimezone wrote {0, 0} for every zone. A PS5 on firmware
13.40 set to US Eastern returned tz_minuteswest -300 and tz_dsttime 60:
the standard offset in minutes east of UTC, without the summer time in
effect on the run date, and the zone's daylight saving amount in
minutes. Both now come from the host zone, through the same HostZoneAt
and HostDaylightAmount the calendar conversions use.

guest_freebsd_clocks checks five TZ settings (UTC0, IST-5:30, BRT+3,
EST5EDT, CET-1CEST) and the null pointer.
2026-10-23 23:27:29 -04:00
Dean Galvin c7e2611b6d Merge main into fix/cancellable-timed-sleeps 2026-10-24 15:38:58 +13:00
Dean f075f91737 Merge pull request #9314 from DavidSamir/feat/libkernel-sys-ktimer
feat(libkernel): implement SIGEV_NONE POSIX timers
2026-10-23 20:34:29 +13:00
David 7820a5353a refactor(libkernel): move the ktimer calls into libkernel
The PS5 3.20 export lists have ktimer_* in libkernel as well as
libkernel_sys, and on Windows a libkernel import never reaches
libkernel_sys. The implementation moves unchanged to
libkernel/Time/Ktimer.cpp.
2026-10-21 22:22:16 +01:00