[CFR][PATCH] Call proper signal handler from libthr for non-SA_SIGINFO case

Konstantin Belousov kostikbel at gmail.com
Thu Nov 27 10:14:12 UTC 2014

On Thu, Nov 27, 2014 at 07:21:14AM +0300, Eygene Ryabinkin wrote:
> "td->td_ru.ru_nsignals++;" perhaps doesn't belong to the new function,
> but it is a matter of taste.  By the way, shouldn't
Well, there is no common theme in the operations done in the
postsig_done(), except some fiddling with the signal state after the
frame is pushed to usermode stack. I have trouble formulating the
purpose of the function in the introductory comment, due to this.
ru_nsignals++ is not better or worse than any other operation performed.

> "PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);" be also present single
> kern_sigprocmask() is called with SIGPROCMASK_PROC_LOCKED?
This is what I suggested in my earlier mail. When I started looking into
details, I decided not to do it. The reasoning is that the function
itself touches no process state protected by the proc lock. It is
kern_sigprocmask which works with process lock-protected data. On the
other hand, the function works with p_sigacts, which is covered by
ps_mtx, and I asserted it.

I believe that the following patch is due.  It is better way to ensure
the invariants, instead of adding assert to postsig_done().

diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 15638e0..502f334 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -998,8 +998,12 @@ kern_sigprocmask(struct thread *td, int how, sigset_t *set, sigset_t *oset,
 	int error;
 	p = td->td_proc;
+	if ((flags & SIGPROCMASK_PROC_LOCKED) != 0)
+	else
+	mtx_assert(&p->p_sigacts->ps_mtx, (flags & SIGPROCMASK_PS_LOCKED) != 0
 	if (oset != NULL)
 		*oset = td->td_sigmask;
@@ -2510,9 +2514,11 @@ reschedule_signals(struct proc *p, sigset_t block, int flags)
 	int sig;
+	ps = p->p_sigacts;
+	mtx_assert(&ps->ps_mtx, (flags & SIGPROCMASK_PS_LOCKED) != 0 ?
 	if (SIGISEMPTY(p->p_siglist))
-	ps = p->p_sigacts;
 	SIGSETAND(block, p->p_siglist);
 	while ((sig = sig_ffs(&block)) != 0) {
 		SIGDELSET(block, sig);

More information about the freebsd-threads mailing list