Repository navigation
fix(libkernel): keep the signal mask per thread - #3986
Conversation
|
Tested on native Linux (CachyOS x86_64, GCC) with an NVIDIA GeForce RTX 5060 Ti:
Validates the fix on native Linux and title execution as requested in the description. LGTM! |
|
One thing before merging: please drop the comment at |
Dextroid17
left a comment
There was a problem hiding this comment.
The control is what the record above does not have, and the overlap the bot lists is a text conflict rather than a same-file warning. Head 066b18da0, parent 0a8b1d32b, in a worktree:
head guest_signal + guest_signal_sets → 100% tests passed out of 2, exit 0
control parent's Pthread/src/Thread.cpp + System/src/Signals.cpp, the PR's tests kept
→ the test process exits 134 (SIGABRT, "Aborted (core dumped)"),
ctest: 691 - guest_signals (Subprocess aborted), 50% passed, 1 failed out of 2 (ctest exit 8)
The abort is deterministic and comes from the parent's own bookkeeping: it wrote previousSet->bits[1..3] = 0, while the new test asserts the previous mask above bit 31 comes back set (previous.bits[1] == 0x1, with bit 32 reaching bits[2] and bits[3]). That is the half a green head cannot show.
Two checks on the change itself:
- The mechanism fits this port.
GuestSignalSethas heldstd::uint32_t bits[4](Signals.cpp:24) since before this change; what was wrong is the mask bookkeeping — a singlestd::atomic<std::uint32_t> blockedMask, the operation applied toset->bits[0]only, andbits[1..3]returned as zero, so a mask above 32 was dropped and never read back. The change keeps the blocked and pending sets per thread and applies the operation to all four words. Per-thread storage is meaningful here because each guest thread runs on its own host thread:pthread_create(&p->hostThread, …, StartNativeThread, …)on the POSIX path (Thread.cpp:586),_beginthreadexon the Windows path (Thread.cpp:549), the entered thread adopted throughpthread_self()(Thread.cpp:692). - On the overlap, the bot's table is a same-file, same-line-range warning computed against
mainand says nothing about whether the two branches can merge; the measured state is that they cannot be merged without a decision.git merge-tree --write-tree pr-3986 pr-4138exits 1 withCONFLICT (content)incore/libs/prx/libkernel/System/src/Signals.cpp, in three regions — the blocked check inDispatch,raise_nid_postfix, and_sigprocmask_nid_postfix— where both branches add the same threehowvalues under differently capitalised names (GuestSigBlock/GuestSigUnblock/GuestSigSetmaskagainstGuestSigblock/GuestSigunblock/GuestSigsetmask, the second side also addingGuestEintr,GuestEagainandGuestSiuser) and both add pending-set handling.pr-3986withpr-4383andpr-4138withpr-4383produce trees with no textual conflict (exit 0; neither result was built or run, so that is all it shows). #4138's body already says it will keep this PR's per-thread masks and drop its own duplicate pending handling, so the conflict makes that rebase required rather than optional, and #4383 can go either side of the pair without cost. A line recording that would spare the next reader the experiment.
The comment oneandonlydean asked to be dropped sits at Signals.cpp:46-47 on this head (his range says 47-48); nothing above depends on it — and if the overlap is worth recording in the repository, docs/dev/TechnicalDebt.md in the same pull request is the place for it.
Written with AI assistance.
Hermes Agent 🤖 at your service
|
A small observation on the AI-assisted (Claude Code). |
adriadam10
left a comment
There was a problem hiding this comment.
Thanks for this, the per-thread mask is the right model. It no longer applies to main, and the conflict is not only textual:
mainnow keeps a process-wide pending set inSignals.cpp(MarkPending/TakePending/PendingInSet, added withsigtimedwaitin #3430, used bysigwait,sigwaitinfo,pauseandkillpg). The per-threadpendingSignalshere is a second store for the same thing: a signal thatraiseleaves in it is never seen bysigwait/sigtimedwait. Please rebase and decide how the two relate (for example blocked mask per thread, pending set kept onmain's structure), then cover the interaction with a test.ExpireAlarm(setitimer/alarm, #3800) readsblockedMaskforSIGALRMandSignalBlockedonly looks at the first 32 signals. Both need to use the new per-thread mask, and the alarm thread is not a guest thread, so say which mask it checks.docs/dev/TechnicalDebt.mdwas split per library: the entry now lives indocs/dev/debt/libkernel.md, where the oldpthread_sigmaskline (line 123) and thesigtimedwaitline (149, which describes the process-wide pending set) both need updating.- @oneandonlydean's request is still open: drop the comment at
Signals.cpp:47-48. - @xXPBSXx's point about an unknown
how(write the old mask, returnEINVALinstead ofthrow, per FreeBSD 11.4kern_sigprocmask) touches the same lines you rewrite, so it fits in this PR.
After the rebase, guest_signals, guest_signal_sets, the sigtimedwait tests and guest_itimer should pass together, with the new guest_signals still failing on main's Signals.cpp/Thread.cpp.
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Draft #11273 (signal calls EFAULT) touches neighbouring lines. Proposal: yours first, mine rebases. |
|
@Silverash-i8 are you still working on this? Main has moved under it: If you are not, I would like to carry it as a separate PR with your commit kept and your authorship intact, rebased onto current main and reduced to what main still lacks: a blocked mask per guest thread, started from the creating thread's mask in @xXPBSXx you offered a carry here on 24 October; I see no branch or PR since. Are you still on it? If so I will stay out of the way, otherwise I will start in 48 hours. |
|
Yes, I'm still on this, sorry for the silence. I was away for a few weeks and only caught up on the thread today. I'm redoing it on current main as asked: a blocked mask per thread inherited from the creating thread in I expect to push the rebased head within a day or so. xXPBSXx and sherySJ, thank you for offering to carry it. If you'd rather not wait, say so here and I'll check my branch against yours, but I'd like to finish it myself if that's fine with everyone. AI-assisted (Claude Code); I'll run the tests on my machine before pushing. |
|
Thanks, that covers it. Please go ahead; I will not open a carry. Happy to run the |
The blocked mask of sigprocmask, _sigprocmask, pthread_sigmask and sigsuspend was one process-wide set, so a thread changing its mask changed every thread's, and scePthreadCreate did not hand the creating thread's mask to the new thread. Each guest thread now has its own blocked mask and handler holds, and a new thread starts with its creator's mask. The pending set stays the process-wide one, so a signal that raise leaves pending is still taken by sigwait and sigtimedwait on any thread and delivered by the first thread that unblocks it. A SIGALRM expiry checks the mask of the thread that armed the timer. Fixes boykopovar#2879. Claude-Session: https://claude.ai/code/session_012SLQbhAiexxW6TtjYToW8a
066b18d to
694b2b4
Compare
|
The rebased head is up ( The two questions from the reviews: the sherySJ, thanks, a Linux run of AI-assisted (Claude Code); I ran the above on my machine. |
|
@Silverash-i8 Linux run of head 694b2b4 (one commit on current main), Omarchy (Arch) x86_64, g++ 16.2.1, Release, ccache,
Negative control: with Windows not tested. AI-assisted: yes. |
|
Hi @adriadam10, the author has rewritten this on current main (
Could you take another look when you have time, and update or dismiss your review if you agree? Thanks. |
The author rewrote this on current main (694b2b4). Our re-check of all six points from the 13 Oct review found each met at that head (point-by-point list in #3986 (comment)). No reply in 24 h, so we are dismissing it as stale. Happy to reopen if anything still looks wrong.
What
Fixes #2879.
sigprocmask,_sigprocmask,pthread_sigmaskandsigsuspendshare one process-wide blocked mask: a thread changing its mask changes every thread's, andscePthreadCreatedoes not hand the creating thread's mask to the new thread. Rebased onto currentmainand reduced to that, as asked in the reviews of 13 and 22 October. The 128-bit mask, SIGKILL and SIGSTOP never blocked,EINVALfor an unknownhowand the process-wide pending set are already onmainand are not touched.ThreadSignalsinSignals.cpp);sigprocmask,_sigprocmask,pthread_sigmask,sigsuspend,sigpendingand the delivery checks (raise,Dispatch,pause, the unblock path) read the calling thread's.scePthreadCreatestarts the new thread with its creator's mask.main's structure (MarkPending,TakePending,PendingInSet). A signal thatraiseleaves pending is still seen bysigwait,sigtimedwaitandsigwaitinfoon any thread, and is delivered by the first thread that unblocks it, as a process-directed signal is in FreeBSD.SIGALRMexpiry runs on the timer thread, which is not a guest thread, so it checks the mask of the thread that armed the timer (alarm,setitimer); a host signal from outside the guest (Ctrl+C,SIGTERMfrom another process) is checked against the host thread that receives it. FreeBSD would deliver either to any thread that does not block it. Both are recorded indocs/dev/debt/libkernel.mdwith thepthread_sigmask,sigpending,sigsuspendandsetitimerentries.SIGALRMblocked stays pending.Tests:
guest_signalsnow checks a child inheriting its creator's mask and changing its own without touching the creator's, a signal raised while blocked being taken bysigtimedwaiton a child thread, and a child that unblocks a signal the creator still blocks running the handler. The threeCheckOtherThread*Keptchecks inguest_signal_handler_maskasserted the process-wide behaviour (another thread's change showing up in this thread's mask); they now assert that the other thread's change leaves this thread's mask alone.Tested
On
main03cfa4c067:guest_signals,guest_signal_sets,guest_signal_handler_mask,guest_signal_interrupt,guest_signal_list,guest_sigtimedwait,guest_itimer(with_pending_defaultand_short_expiry),guest_getitimer,guest_legacy_signal_mask(and_forwarding),guest_user_context(and_exit),guest_sigaltstack,guest_kernel_sys_pselectandguest_sigvecpass 18 of 18 five times in a row (--repeat until-fail:5).agc_driver*: everything passes excepttest_registrationandselect_tests_MissingCommandTests(both need the Windows symlink privilege,WinError 1314) andguest_video_out_high_frame_rate, which skips when run alone and failed once under-j8load; none touches signals.guest_signals,guest_signal_sets,guest_signal_handler_mask,guest_signal_interrupt,guest_sigtimedwait,guest_itimer(with_pending_defaultand_short_expiry),guest_getitimer,guest_legacy_signal_mask(and_forwarding),guest_user_context(and_exit) andguest_kernel_sys_pselectpass 14 of 14. Not run on native Linux, and the control run againstmain's sources was done on Windows only.main'sSignals.cppandThread.cpp, with this PR's tests kept,guest_signalsandguest_signal_handler_maskfail on this machine (exit0xc0000409).tools/check_conventions.py --base upstream/main: 0 errors (twodebt-lengthwarnings on existing entries).Overlaps: #4138 touches the same
sigprocmasklines, and draft #11273 (signal callsEFAULT) the neighbouring ones; whichever lands first decides the order.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)https://claude.ai/code/session_012SLQbhAiexxW6TtjYToW8a