Commit Graph
104 Commits
Author SHA1 Message Date
Adrià 510d0bf986 Merge pull request #16677 from xXPBSXx/fix/kernel-gettimezone-null-output-v2
fix(kernel): sceKernelGettimezone returns 0 for a null output
2026-11-11 03:01:46 +01:00
JJenkx a95aa1b5e9 chore: integrate current main for PR 12592 2026-11-09 14:25:15 -05:00
Dean d792f1ad5f Merge pull request #16437 from XatiX/fix/libkernel-measured-clock-einval
fix(libkernel): answer the clock ids a PS5 measured invalid as it does
2026-11-10 02:47:56 +13:00
XatiXandClaude Opus 5.5 4c5544719f fix(libkernel): declare GUEST_EIO for every platform
The measured EIO clock ids use GUEST_EIO in the shared clock_gettime path, but
the constant was declared only inside the Windows block, so non-Windows builds
failed. It now sits with the other guest errno constants.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 13:08:59 +00:00
Dean a6255d676e Merge pull request #15797 from oberonlift/lifted-cpu-helpers
refactor: route the libraries' fenv, TSC, cpuid and pause instructions through helpers
2026-11-09 07:08:42 +13:00
XatiXandClaude Opus 5.5 90c86fb36a fix(libkernel): answer the clock ids a PS5 measured invalid as it does
clock_gettime and sceKernelClockGettime threw for every clock id they do
not map. PS5 measurements of both exports (firmware 11.60, a payload
process, #16437) settle ids 3, 6 and 16 to 31 but 20 and 21:

- ids 3, 6 and 22 to 31 fail with EINVAL before the result is written,
  as both exports did; the raw system call also failed them with EINVAL
  (CFI-1216A, firmware 12.00, #15725);
- ids 16 to 19 fail with EIO (errno 5, 0x80020005 from
  sceKernelClockGettime) before the result is written, as both exports
  did.

Ids 20 and 21 succeed on the console with a time from clocks the probes
do not identify, so they still throw; the debt entry records what was
read and closes when what they count is measured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:05:17 +00:00
Adrià 9594527a0c Merge pull request #7804 from mugurc/feat/libkernel-process-clock-macos
feat(libkernel): process, thread and clock queries on macOS hosts
2026-11-08 10:59:04 +01:00
Adrià ae2b0c0614 Merge pull request #13664 from jotitadev/fix/guest-copy-preserve-errno
fix(libc): keep errno when a checked guest copy faults on Linux
2026-11-08 03:06:38 +01:00
oberonliftandClaude Opus 5.5 f7f4b6c9d8 refactor(libkernel): read the timestamp counter through GuestCpu
sceKernelReadTsc and the TSC frequency measurement read the counter
through GuestCpu::ReadTsc, which is __rdtsc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 17:19:45 +00:00
xXPBSXxandClaude Sonnet 5.5 f474d21c86 fix(kernel): sceKernelGettimezone returns 0 for a null output
We returned EFAULT.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 11:21:48 +01:00
GruzzberryandClaude Sonnet 5.5 a7dee2017e fix(libkernel_sys): fail settimeofday and clock_settime with EPERM for a jailed caller
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-06 17:05:56 +00:00
Dean 946bde70ed Merge pull request #11579 from plexerPK/codex/nanosleep-guest-request
fix(libkernel): copy nanosleep requests before reading guest fields
2026-11-06 00:04:17 +13:00
Dean 430a9b5473 Merge pull request #14620 from Danigamer05/feat/libc-timespec-getres-20261101
feat(libc): forward time resolution queries to the kernel
2026-11-05 17:27:46 +13:00
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
Jota 17d9e63030 Merge main into fix/guest-copy-preserve-errno 2026-11-02 17:16:16 +00:00
Romans Pokrovskis 82fd54db36 chore: refresh PR7156 against current prerequisites 2026-11-02 19:04:58 +02: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
Danigamer05 e8caaeb57a feat(libc): forward time resolution queries to the kernel 2026-11-01 17:07:28 +01:00
Romans Pokrovskis 442b990f19 chore: refresh wait trace fix onto main26fa 2026-11-01 11:13:36 +02:00
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
Jota 829f40c523 fix(libkernel): keep errno when libkernel guest copies fault on Linux
libkernel has its own checked guest copy helpers that call
process_vm_readv/process_vm_writev directly: ReadGuest, WriteGuest and
StoreGuestId in Process.cpp, ReadGuest/WriteGuest in Udp.cpp (also
exported as GuestSocketReadGuest), CopyIovecs in Stdio.cpp and
ReadGuestTime in Time.cpp. On EFAULT they left errno at 14, which is the
guest errno, so a caller that reports the fault through a return code
(sceKernelReadv, or sceKernelGetAppInfo in #13798) still changed the
guest's errno. Windows and macOS do not touch errno there.

Apply the same rule as GuestCopyIn/GuestCopyOut: save errno before the
call and restore it when the call fails with EFAULT. Failures other than
EFAULT behave as before.
2026-10-31 06:43:55 -03:00
Romans Pokrovskis 70f7250c3b chore: refresh wait trace fix onto main5857 2026-10-31 01:27:06 +02:00
Romans Pokrovskis 1443f0a43f chore: merge current main into PR7156 2026-10-29 00:36:39 +02:00
JJenkx 0329c61962 fix(libc): ignore unavailable positive daylight hints 2026-10-28 17:41:59 -04:00
mugurc d05d5093a4 feat(libkernel): process, thread and clock queries on macOS hosts
The process, thread and clock functions that read /proc or call glibc
extensions:

- The program arguments come from _NSGetArgc and _NSGetArgv instead of
  /proc/self/cmdline.
- The current CPU comes from pthread_cpu_number_np.
- getrusage for a thread, the CPU clock of a thread and the CPU time of a
  guest thread (clock_gettime with the thread CPU clock) read the Mach
  thread_info of the thread. macOS has no pthread_getcpuclockid, and under
  Rosetta CLOCK_THREAD_CPUTIME_ID advances by about 1/41.7 of the thread's
  CPU time (24 MHz ticks read as nanoseconds), where natively it matches
  thread_info.
- The stack limits of a thread come from pthread_get_stackaddr_np and
  pthread_get_stacksize_np.
- sleeping with nanosleep restores errno, because macOS leaves ETIMEDOUT
  in it on success and the guest's errno is the host's.

The first local of a guest thread lies 4,464 bytes below the top of its
stack on macOS, more than the frame the pthread stack test allowed, so the
test allows two frames there.
2026-10-28 20:00:02 +01: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
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 <noreply@anthropic.com>
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
plexerPK 7af32724b9 fix(libkernel): copy nanosleep requests before reading guest fields 2026-10-27 10:46:48 +01: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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
2026-10-25 02:24:56 +00:00