Move the lock, condition, timer table and thread-started flag into one
KtimerState behind a never-destroyed function-local pointer, as Alarms()
does, so exit never destroys a condition the timer thread waits on.
Restore the SIGEV_NONE sentence in the debt entry and state that a timer's
thread id is taken to equal the guest thread id.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The timer thread can still be waiting on the condition when static
destructors run at process exit. Destroying it under the waiter hung
guest_kernel_sys_ktimer on Linux after the test returned.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ktimer_create no longer throws for SIGEV_SIGNAL, SIGEV_THREAD_ID or a null
sigevent (SIGALRM with the timer id as sival, as kern_ktimer_create does).
A host timer thread runs realtimer_expire and itimer_fire from FreeBSD
stable/11 sys/kern/kern_time.c at 5ed7eb0d97ba4436218e810f61bd059acba984c2:
the expiry is queued on the existing guest pending set with SI_TIMER,
si_value, si_timerid and si_overrun; while that entry is still queued a
further expiry, or an interval missed by a late wake-up, counts an overrun
instead; taking the entry (sigtimedwait, sigwaitinfo, sigwait or handler
delivery on unblock) applies itimer_accept, and ktimer_getoverrun returns
it_overrun_last. ktimer_delete removes a queued entry as sigqueue_take does.
A SIGEV_THREAD_ID target that is not a live thread disarms the timer at
expiry, as sigev_findtd does. The sigevent is now copied in (EFAULT).
As with setitimer, an expiry for a thread that does not block the signal
throws, since guest handlers are not run from a host thread.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ktimer_settime returned EINVAL for any flag bit other than TIMER_ABSTIME. The
check cited FreeBSD's `if ((flags & ~TIMER_ABSTIME) != 0) return (EINVAL);`,
but in kern_time.c at 8c639945 that line (504) is in kern_clock_nanosleep.
sys_ktimer_settime, kern_ktimer_settime and realtimer_settime never reject
flags; they only test flags & TIMER_ABSTIME (line 1548). The test now pins that
flags 2, 4 and 0x7ffffffe arm a relative timer and that -1 arms an absolute one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.