feat(libkernel): deliver SIGEV_SIGNAL and SIGEV_THREAD_ID ktimer expiries #19463
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19463"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by SHOnnay on 2026-11-13T11:07:47Z.
What
ktimer_createwithSIGEV_SIGNAL, withSIGEV_THREAD_IDor with a nullsigeventno longer throws, and its expiries are delivered through libkernel's existing guest signal queue. This follows FreeBSD stable/11 at5ed7eb0d97ba:kern_time.c:kern_ktimer_createL1182-1282,kern_ktimer_deleteL1323-1352,itimer_acceptL1577-1592,realtimer_expireL1606-1652,itimer_fireL1654-1682kern_sig.c:sigev_findtd,tdsendsignal,sigqueue_take, and theitimer_acceptcalls inkern_sigtimedwaitandpostsigKtimer.cppsigeventis copied in, and a bad pointer givesEFAULT. A null event meansSIGEV_SIGNALwithSIGALRMandsivalequal to the timer id, as FreeBSD defaults it.realtimer_expire: it fires due timers and counts missed intervals as overruns.SIGEV_NONEkeeps its lazy expiry. A signal timer'sktimer_gettimereports{0, 1}until the thread fires, asrealtimer_gettimedoes.ktimer_getoverrunreturnsit_overrun_last.SIGEV_THREAD_IDtimer whose thread does not exist is disarmed at expiry, asitimer_firedoes whensigev_findtdreturnsESRCH. FreeBSD does not check the id at create, so neither does this.Signals.cpp: the existing pending queue is reused rather than duplicated.SendTimerSignalfollowsitimer_fireandtdsendsignal:SI_TIMERitimer_accept, sosigtimedwait,sigwaitinfo,sigwaitand delivery on unblock all setit_overrun_last.ktimer_deleteremoves a pending entry, assigqueue_takedoes.siginfogetssi_errno,si_value,si_timeridandsi_overrunat offsets 4, 32, 40 and 44.pthread_sigmaskandsigsuspend, so an expiry can check the target thread's mask.System/include/TimerSignals.hpp.Still throwing, as
setitimeralready does:SIGALRMwith the default disposition exits with status 142.SA_SIGINFOhandlers are still not delivered, so the timer fields can be read throughsigtimedwait/sigwaitinfo, or a plain handler runs on unblock.The debt entry is rewritten to state this first, and is shorter: 899 to 835 characters. The
pthread_sigmaskentry gets one clause.Tested
macOS 27 on Apple M1. libkernel does not build on macOS, so the registered
guest_kernel_sys_ktimertest was not run; a Linux or Windows run is needed.Harness. A temporary harness, not committed, built the unchanged
Signals.cppandKtimer.cppwith the extendedGuestKernelSysKtimer.cpp. Its stand-ins fake errno, guest copies, the clock, thread ids, pthread create and join, and the guest-throw and terminate hooks.guest_kernel_sys_ktimer passed, 41 of 41 runsNotImplemented: ktimer_create delivering a signal, exit 3GuestSigtimedwait,GuestSignals,GuestItimerand the old ktimer test pass on both base and branch in the same harness.GuestSignals' pointer-fault subtest was skipped, because the stand-ins cannot fake read-only pages.New test cases
EINVALfor signal 0, -1 and 129, and notify -1, 3 and 5.EFAULTfor a badsigeventpointer.SIGUSR1expiries withSI_TIMER, thesivaland the timer id, and a handler run on unblock.sigeventgivesSIGALRMwithsivalequal to the id.ktimer_getoverrunagreeing.ktimer_deleteremoves the pending entry, and nothing arrives afterwards.SIGEV_THREAD_IDdeliversSIGUSR2to a second thread. An unknown thread id disarms the timer.Mutation check: 7 of 8 hand mutations failed the harness:
it_overrun_lastSIGEV_THREAD_IDusing the arming thread's masksiginfovalue not writtenThe survivor applies the lazy expiry to signal timers, which matters only in a timing race.
Overlap. No open PR delivers ktimer signals.
ktimer_createlines, because it rewraps theNotImplementedline this PR removes.mainin many files and now also inSignals.cpp.Not verified:
INT_MAXoverrun saturation pathChecklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-16T01:07:32Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
17547dc88c:tools/check_conventions.pypassed;git diff --checkclean.guest_kernel_sys_ktimer_exit_tests,guest_kernel_sys_ktimer_testsbuilt cleanly.guest_kernel_sys_ktimer,guest_kernel_sys_ktimer_exit_armed,guest_kernel_sys_ktimer_exit_deleted):core/libs/prx/libkernel/System/src/Signals.cpp,core/libs/prx/libkernel/Time/Ktimer.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T04:21:01Z.
Review: COMMENTED
Reviewed — comments
Material uncertainty remains around per-thread signal routing: the recipient mask map is populated only when a thread changes its mask, and registrations are never removed or refreshed after thread ID reuse.
What I ran
Reviewed head
17547dc88cdd3e402271117a2c108a2b34843a86. No commands or tests were run in this review; the author reports convention checks and harness runs in the PR description.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libkernel/System/src/Signals.cpp:142—RegisterSignalThreadcaches each thread’sThreadSignals*by guest ID once, but there is no unregister path. If a guest thread exits and its ID is reused, the map can retain the old mask pointer; if a live thread changes its guest ID, the cache is not refreshed.SendTimerSignalthen may check the wrong mask or treat the target as unregistered and take the unsupported unblocked-delivery path. Please tie registration to the guest thread lifecycle or validate/update the entry before using it.Not verified
The registered Linux or Windows build and test, console behavior, actual asynchronous handler delivery,
INT_MAXoverrun saturation, and thread-ID reuse/lifecycle behavior were not verified. The PR description reports macOS harness runs with stand-ins; those are author-reported, not runs performed here. All changed files listed in the manifest were read:core/libs/CMakeLists.txt,core/libs/prx/libkernel/System/include/TimerSignals.hpp,core/libs/prx/libkernel/System/src/Signals.cpp,core/libs/prx/libkernel/Time/Ktimer.cpp,core/libs/tests/GuestKernelSysKtimer.cpp,core/libs/tests/GuestKernelSysKtimerExit.cpp, anddocs/dev/debt/changes/feat-libkernel-ktimer-signal.md. No changed files were excluded.To get this to a good state
Nothing is required. Optional: address thread registration lifecycle and cover thread-ID reuse in a test.