feat(libkernel): implement sigsuspend on the pending-signal set #5666
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5666"
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 Kurenaiiiii on 2026-10-14T05:25:33Z.
What
Adds
sigsuspend(KZ-4qlqlpmo) to libkernel's signal model: swaps the process-wide blocked mask for its argument, waits aspausedoes for a pending signal that is not blocked and deliverable, restores the mask, delivers what the restore unblocked as_sigprocmaskdoes, and returns -1 withEINTR; a null set returns -1 withEFAULT. Extends thepause, sigwait, sigwaitinfodebt entry andguest_signal_tests(null set, plus a suspender/sender pair covering delivery on the suspender, mask restore andEINTR, mirroring the sender pattern ofguest_sigtimedwait_tests).Tested
No full build in this container (no submodules/toolchain for it). Verified: the new wait path compiled and ran natively against the real
Signals.cppTU 10/10 (swap, pending take under the new mask, handler delivery on the suspender, mask restore,EINTR); both touched TUs parse clean;python3 tools/check_conventions.pypasses. Full build andguest_signal_testsleft to CI / reviewer run.Checklist
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)FAIL: unresolved ELF import KZ-4qlqlpmo from libkernel.prx, 4th loader blocker after sysctlnametomib/fegetenv/mincore)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T05:36:40Z.
Review: COMMENTED
One mask-width gap:
GuestSignalSethas four 32-bit words andMaxSignalis 128, butsigsuspendcopies onlyset->bits[0]into the 32-bitblockedMask;SignalBlockedalso returns false for every signal above 32. A caught/pending signal represented in bits 1–3 therefore remains deliverable duringsigsuspendeven when the supplied mask includes it. The existing_sigprocmaskshares this state-width limitation, so fixing the new entry point fully may require widening the shared mask representation and exercising a high-word signal in the regression test. The debt entry describes pending/wait support for all 128 signals.Imported from boykopovar/AnyPS5. Originally posted by Kurenaiiiii on 2026-10-14T05:44:54Z.
Thanks for the review — you're right about the width gap. I kept the 32-signal mask on purpose:
blockedMask,SignalBlocked,_sigprocmaskandsigpendingall share that representation (recorded debt), so widening it means changing the shared state plus the tests that assert words 1–3 stay zero — a separate-PR-sized change touching heavily-tested code. I recorded the limit in the debt entry instead ("words 1 to 3 of the argument are not applied ... widening the shared mask is a follow-up"). If you'd rather have the widening in this PR, say so and I'll do it.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T05:45:27Z.
Follow-up note from #5669: that PR keeps the scalar low-word
blockedMaskfor source compatibility, while adding words 1–3 tosigprocmaskandsigpending. This makes high-numbered blocked signals active in the shared model.sigsuspend_nid_postfixcurrently swaps onlyset->bits[0], so it will need to save, replace, and restore all four words to preserve the full mask semantics once #5669 lands. I kept that separate from the mask-width PR; linking here for integration.Imported from boykopovar/AnyPS5. Originally posted by Kurenaiiiii on 2026-10-14T05:46:09Z.
Noted, thanks — and thanks for keeping #5669 source-compatible. Plan on my side: once #5669 lands I'll rebase this branch, extend the swap/restore to all four mask words, and add a high-word signal case to the test (the regression coverage you asked for in the first review). Until then this PR stays as-is against current
main— no action needed here.Imported from boykopovar/AnyPS5. Originally posted by pipe1os on 2026-10-14T06:02:57Z.
Did that on Windows:
95634182fmerged ontomain0b6d033b8(no conflicts), Windows 11, WinLibs GCC 15.2.0, Ninja Release. The new headba13bf210only changes the debt entry, so the code is the same.guest_signalspasses 10/10, and so doguest_sigtimedwait,guest_signal_setsandguest_sigaltstack. WithSignals.cppput back tomainand the test kept, it doesn't link (undefined reference to sigsuspend_nid_postfix).main: the loader stops atFAIL: unresolved ELF import KZ-4qlqlpmo from libkernel.prx. With this PR added it gets past it, reaches the title's own[notification] Java 25 VM startup attempt readyand keeps running for 120 s with no stop. The import's only call site in the eboot (0xB8A9F8) is HotSpot'sSR_handler(signals_posix.cpp), which only runs when the VM suspends a thread, so I didn't see it called in those 120 s.The wait itself looks right to me: the first check runs under the pending lock and
MarkPendingtakes the same lock, so nothing gets lost between the swap and the wait. Two things, separate from the mask width @MarcZX100 raised (#5669):sigsuspendgoes through libthr's__thr_sigsuspend(thr_syscalls.c L640, thr_sig.c L621-L644), which copies*setin userland before the syscall (thr_sig.c L128), so a null set faults there instead of returningEFAULT. A local probe on the merge getssigsuspend(NULL) = -1, errno 14. A throw would fit the "exact or throw" rule better; theEFAULTcheck inguest_signalswould change with it.pause's loop and the restore a copy of the delivery loop in_sigprocmask. Movingpause's loop into a helper that can swap the mask, and restoring through_sigprocmaskitself, would keep them from drifting apart. Just a suggestion.In case it's useful, I put a test on a branch on top of your head: pipe1os:test/sigsuspend-freebsd-checks (
git cherry-pick 79673e4f2). It adds toguest_sigtimedwaitthe null-set throw, a signal that is already pending when the wait starts, the old mask coming back afterwards, a 50 ms sender, and 500 rounds of a sender with no delay. On your head it aborts at the null check. With the null check throwing, it passes 10/10 here, the 500 rounds included.AI-assisted.
Imported from boykopovar/AnyPS5. Originally posted by Kurenaiiiii on 2026-10-14T06:08:25Z.
Did both. Null now throws std::invalid_argument, same as _sigprocmask for a bad argument. The wait loop is shared with pause, and the restore goes through _sigprocmask itself. The test covers the throw, a main-thread wake, and a sender wakeup, all on signal 30 so no host signal is involved. I looked at your branch but wrote the cases here to match this file. Left the mask width for #5669.
Imported from boykopovar/AnyPS5. Originally posted by pipe1os on 2026-10-14T06:33:21Z.
Checked
1ce5c2c4eon Windows (merged ontomaina94675fb1):guest_signalsandguest_sigtimedwaitpass 10/10, and the cases from my branch (null throw, a signal pending before the wait, the old mask coming back, a 50 ms sender, 500 rounds with no delay) pass on it as well. Java 25 LAN / DNS (PPSA99869) with #5502 + #5563 + #5643 + this head onmain107190d11still gets pastKZ-4qlqlpmoto its menu; starting the VM from there stops atgetrlimit: unsupported resource 8, which is #5187. Looks good to me, thanks for taking it.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T12:44:21Z.
Progress report (
6546a33→1ce5c2c)➖ System libraries: 88.22% (+0.0%, +1 implemented functions)
✅ 1 implemented
sigsuspend_nid_postfixImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T12:49:13Z.
Checked on Linux (merged onto main): libkernel builds and
guest_sig*pass; without theSignals.cppchange the test doesn't link. Windows run by @pipe1os confirmed too. The 32-signal mask limit is recorded in the debt entry and is covered by the #5669 follow-up. Merging.