feat(libkernel): wait for pending guest signals in the signal waits #4138
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4138"
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 VitzS7 on 2026-10-11T23:52:37Z.
What
pause,sigwait,sigwaitinfoandsigtimedwaitno longer callNotImplemented_nid_no_patch, andpthread_killto another thread no longer throws. They wait on a process-wide set of pending guest signals that covers every number from 1 to 128:_sigprocmaskunblocks it, taken bysigwait,sigwaitinfoorsigtimedwait, or delivered bypause, which runs its handler on the calling thread and returns -1 withEINTR;pthread_killto another thread leaves the signal pending for whichever thread waits for or unblocks it, and answersESRCHfor a handle that is not a live guest thread; it threw for every thread other than the caller before;raiseandkillaccept every number from 1 to 128: an unblocked one whose handler is registered runs its handler on the calling thread, which is what the signals with no host equivalent (SIGIO,SIGALRM,SIGBUS,SIGPIPE) need to be usable at all. An unblocked signal with no host equivalent and no handler still fails withEINVALas before, so no path that used to continue now runs a default action.sigtimedwaitfollows FreeBSD's sigtimedwait(2): it returns the selected signal number,EAGAINwhen the timeout expires with nothing pending in the set,EINVALfor atv_nsecoutside 0 to 1000000000 while nothing is pending, and a null timeout blocks indefinitely.sigwaitreturns 0 with the number through its pointer, as POSIX specifies. The guestsiginfo_tthatsigwaitinfoandsigtimedwaitwrite follows FreeBSD 11'ssys/sys/siginfo.h(80 bytes,si_signoat 0,si_codeat 8,si_pidat 12,si_uidat 16,si_addrat 24,si_valueat 32,si_bandat 40, asserted in the source); onlysi_signo,si_code(SI_USER) andsi_pidare written, andsi_uidstays 0 because no uid is modelled.The limits that remain are recorded in technical debt: the set is process-wide like the mask, the waits are not cancellation points, an unblocked caught signal does not interrupt them with
EINTR, and a pending signal whose disposition is the default action and that has no host equivalent stays pending instead of running that action, which on FreeBSD terminates the process for most signals.guest_sigtimedwaitreplaces itsNotImplementedchecks with the behaviour above, including a signal sent from another thread andpausewoken by one. One line ofguest_signalschanged:pthread_killwith a handle that is not a live guest thread threw and now returnsESRCH, as FreeBSD's does.Overlap: #3986 changes the same file with a per-thread mask and pending set. No open pull request implements these four waits; if #3986 lands first this rebases onto it, keeps its per-thread masks and drops the duplicate part of the pending handling here.
Tested
Linux (Fedora 44 container, GCC 16.2.1, Release,
BUILD_TESTING=ON, bundled dependencies), on this branch rebased ontomainbca7a29d2:guest_signals,guest_sigtimedwait,guest_signal_sets,guest_kill,guest_ioctl_getsid,guest_getitimer,guest_thread_cpu_clock,guest_memoryand everyguest_pthread_*test pass;guest_sigtimedwaitwas run five times in a row.ctest -E "agc_|video_out|lds_|msaa" --timeout 90 -j6: 482 of 482 passed in 7.7 s. The excluded tests need a GPU, and this machine only has lavapipe.python3 tools/check_conventions.py --base origin/main,git diff --checkandpython3 tools/tests/test_progress.pypass.std::mutex,std::condition_variable,std::atomicandstd::chrono, but the Windows build is unchecked by me.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T08:25:29Z.
Which title stops at
pause,sigwait,sigwaitinfo,sigtimedwaitorpthread_killto another thread on main? With the title ID and the log line this can go in, rebased on #3986 once that lands (it replaces the process-wide mask and pending set this builds on); otherwise I'll close it until one does.Imported from boykopovar/AnyPS5. Originally posted by VitzS7 on 2026-10-12T16:41:16Z.
The title IDs, with the NIDs they stop on:
pauseEDyhWelj7UYsigwaitmrbHXqK8wkgsigwaitinfoUq5BGthgbl4sigtimedwaitD2-dIoJ0ZtEWhere each of those comes from, all in the catalog sweep on #1578:
pauseis the next stop of Ruffle once #1702 lands and of RetroArch once #3598 lands (the orchestration of that round records both), PS5MC and XPSemu appear as stops onmain0694c579in the third-run table, andsigtimedwaitis reported in thefeat/libc-rand48run ("VLC then stops atsigtimedwait(D2-dIoJ0ZtE)"). #3552 has the same set with call sites: Rufflepauseat0x8F7266; PS5MCpause0x3BD80F6/0x3C9E220,sigwait0x3C9E4C7,sigwaitinfo0x3C9E588; XPSemu'ssigwait_compatthread at0x1101294/0x1101368.To be exact about what is not verified: no run has shown the process dying inside the wait itself. What the sweep records is the NID at the import/next-stop level, which is why #3552 says "not yet observed in a run", and #4561 now tracks the same four calls throwing on
main. Thepthread_killto another thread in this PR is a fix to that same pending model rather than a title-observed stop.I will rebase on #3986 as soon as it lands and keep the pending set consistent with the per-thread mask that replaces the process-wide one.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T20:32:49Z.
Progress report (
955f4fb→01874b4)📈 System libraries: 87.54% (+0.15%, +5 implemented functions)
✅ 5 implemented
pause_nid_postfixpthread_kill_nid_postfixsigtimedwait_nid_postfixsigwait_nid_postfixsigwaitinfo_nid_postfixImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T20:33:21Z.
Review: CHANGES_REQUESTED
Thanks for the title list. Three things before this can land:
Signals.cpp:93-97:MarkPendingdoesfetch_orandnotify_allwithout holdingpending.lock, whileWaitForPendingInSet(:209-223) andpause(:476-484) check the set under that lock and then wait. A signal raised between the check and thewaitis lost and an infinite wait (sigwait,sigwaitinfo, null-timeoutsigtimedwait,pause) hangs forever. Take the lock (or at least lock/unlock it) between thefetch_orand thenotify_all. The 50 ms sleep inGuestSigtimedwait.cpphides this; a test that raises with no delay, repeated many times, would show it.pthread_killto another thread (:396) marks the target's set, not a process-wide one.mainindocs/dev/TechnicalDebt.md.Imported from boykopovar/AnyPS5. Originally posted by VitzS7 on 2026-10-12T20:57:42Z.
Thanks — all three:
1. The lost wakeup. You were right.
MarkPendingset the bit and notified withoutpending.lock, so a raise landing between the check and the wait was lost and the wait never returned. The bit is now set while holding that lock and the notification is sent after releasing it, so a wait either sees the bit or is notified after it has blocked.GuestSigtimedwaitnow raises the signal from another thread with no delay, 500 times, instead of relying on the 50 ms sleep the other senders use. On the previous code the test hung: 2 of 10 runs ended at the 60 s timeout (exit 124); on this one 5 of 5 runs pass, and the full suite is 526/526 with the GPU targets excluded.2. The conflict. Rebased onto
mainc952c2b0e.TechnicalDebt.mdis the hub now, so the entries went todocs/dev/debt/libkernel.md:sigtimedwait,pause, sigwait, sigwaitinfo,sigactionandpthread_killare updated there. The pull request touches no other documentation file.3. Per-thread pending. Agreed, and I would rather not guess it here: this still keeps one process-wide pending set, as you said it builds on the mask #3986 replaces. As soon as #3986 lands I will rebase on it and keep the set per thread, so
pthread_killto another thread marks the target's set and every wait reads the calling thread's set.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T21:04:13Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libkernel.mdL146-149docs/dev/debt/libkernel.mdL145-147docs/dev/debt/libkernel.mdL149-150Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T21:06:22Z.
Review: APPROVED
Checked the lost-wakeup fix (bit set under
pending.lock, notify after release):guest_sigtimedwaitwith 500 undelayed raises passes 30 runs in a row, and bothguest_signalsandguest_sigtimedwaitfail without the change. Scoped build and ctest (141 tests) pass on the PR merged onto main. The process-wide pending set stays until #3986 lands, as recorded indocs/dev/debt/libkernel.md; whichever of the two merges second rebases. Merging.