Module Name: src Committed By: kamil Date: Sat Oct 12 19:57:09 UTC 2019
Modified Files: src/sys/kern: kern_sig.c src/sys/sys: signalvar.h Log Message: Refactor sigswitch() Make the function static as it is now local to kern_sig.c. Rename the 'relock' argument to 'proc_lock_held' as it is more verbose. This was suggested by mjg@freebsd. While there this flips the users between true<->false. Add additional KASSERT(9) calls here to validate whethe proc_lock is used accordingly. To generate a diff of this commit: cvs rdiff -u -r1.368 -r1.369 src/sys/kern/kern_sig.c cvs rdiff -u -r1.96 -r1.97 src/sys/sys/signalvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/kern_sig.c diff -u src/sys/kern/kern_sig.c:1.368 src/sys/kern/kern_sig.c:1.369 --- src/sys/kern/kern_sig.c:1.368 Sat Oct 12 10:55:23 2019 +++ src/sys/kern/kern_sig.c Sat Oct 12 19:57:09 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_sig.c,v 1.368 2019/10/12 10:55:23 kamil Exp $ */ +/* $NetBSD: kern_sig.c,v 1.369 2019/10/12 19:57:09 kamil Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.368 2019/10/12 10:55:23 kamil Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.369 2019/10/12 19:57:09 kamil Exp $"); #include "opt_ptrace.h" #include "opt_dtrace.h" @@ -125,6 +125,7 @@ static int sigchecktrace(void); static int sigpost(struct lwp *, sig_t, int, int); static int sigput(sigpend_t *, struct proc *, ksiginfo_t *); static int sigunwait(struct proc *, const ksiginfo_t *); +static void sigswitch(int, int, bool); static void sigacts_poolpage_free(struct pool *, void *); static void *sigacts_poolpage_alloc(struct pool *, int); @@ -931,7 +932,7 @@ repeat: * The process is already stopping. */ if ((p->p_sflag & PS_STOPPING) != 0) { - sigswitch(0, p->p_xsig, false); + sigswitch(0, p->p_xsig, true); mutex_enter(proc_lock); mutex_enter(p->p_lock); goto repeat; /* XXX */ @@ -949,7 +950,7 @@ repeat: p->p_sigctx.ps_faked = true; p->p_sigctx.ps_lwp = ksi->ksi_lid; p->p_sigctx.ps_info = ksi->ksi_info; - sigswitch(0, signo, false); + sigswitch(0, signo, true); if (ktrpoint(KTR_PSIG)) { if (p->p_emul->e_ktrpsig) @@ -1641,7 +1642,7 @@ repeat: * The process is already stopping. */ if ((p->p_sflag & PS_STOPPING) != 0) { - sigswitch(0, p->p_xsig, false); + sigswitch(0, p->p_xsig, true); mutex_enter(proc_lock); mutex_enter(p->p_lock); goto repeat; /* XXX */ @@ -1666,7 +1667,7 @@ repeat: p->p_sigctx.ps_lwp = ksi.ksi_lid; p->p_sigctx.ps_info = ksi.ksi_info; - sigswitch(0, signo, false); + sigswitch(0, signo, true); if (code == TRAP_CHLD) { mutex_enter(proc_lock); @@ -1686,8 +1687,8 @@ repeat: /* * Stop the current process and switch away when being stopped or traced. */ -void -sigswitch(int ppmask, int signo, bool relock) +static void +sigswitch(int ppmask, int signo, bool proc_lock_held) { struct lwp *l = curlwp; struct proc *p = l->l_proc; @@ -1697,6 +1698,12 @@ sigswitch(int ppmask, int signo, bool re KASSERT(l->l_stat == LSONPROC); KASSERT(p->p_nrlwps > 0); + if (proc_lock_held) { + KASSERT(mutex_owned(proc_lock)); + } else { + KASSERT(!mutex_owned(proc_lock)); + } + /* * If we are exiting, demise now. * @@ -1704,7 +1711,7 @@ sigswitch(int ppmask, int signo, bool re */ if (__predict_false(ISSET(p->p_sflag, PS_WEXIT))) { mutex_exit(p->p_lock); - if (!relock) { + if (proc_lock_held) { mutex_exit(proc_lock); } lwp_exit(l); @@ -1728,7 +1735,7 @@ sigswitch(int ppmask, int signo, bool re * a new signal, then signal the parent. */ if ((p->p_sflag & PS_STOPPING) != 0) { - if (relock && !mutex_tryenter(proc_lock)) { + if (!proc_lock_held && !mutex_tryenter(proc_lock)) { mutex_exit(p->p_lock); mutex_enter(proc_lock); mutex_enter(p->p_lock); @@ -1748,6 +1755,7 @@ sigswitch(int ppmask, int signo, bool re /* * Unlock and switch away. */ + KASSERT(!mutex_owned(proc_lock)); KERNEL_UNLOCK_ALL(l, &biglocks); if (p->p_stat == SSTOP || (p->p_sflag & PS_STOPPING) != 0) { p->p_nrlwps--; @@ -1837,7 +1845,7 @@ issignal(struct lwp *l) * we awaken, check for a signal from the debugger. */ if (p->p_stat == SSTOP || (p->p_sflag & PS_STOPPING) != 0) { - sigswitch(PS_NOCLDSTOP, 0, true); + sigswitch(PS_NOCLDSTOP, 0, false); mutex_enter(p->p_lock); signo = sigchecktrace(); } else if (p->p_stat == SACTIVE) @@ -1909,7 +1917,7 @@ issignal(struct lwp *l) p->p_xsig = signo; /* Handling of signal trace */ - sigswitch(0, signo, true); + sigswitch(0, signo, false); mutex_enter(p->p_lock); /* Check for a signal from the debugger. */ @@ -1966,7 +1974,7 @@ issignal(struct lwp *l) p->p_xsig = signo; p->p_sflag &= ~PS_CONTINUED; signo = 0; - sigswitch(PS_NOCLDSTOP, p->p_xsig, true); + sigswitch(PS_NOCLDSTOP, p->p_xsig, false); mutex_enter(p->p_lock); } else if (prop & SA_IGNORE) { /* @@ -2519,7 +2527,7 @@ repeat: * The process is already stopping. */ if ((p->p_sflag & PS_STOPPING) != 0) { - sigswitch(0, p->p_xsig, true); + sigswitch(0, p->p_xsig, false); mutex_enter(p->p_lock); goto repeat; /* XXX */ } @@ -2532,7 +2540,7 @@ repeat: p->p_xsig = signo; p->p_sigctx.ps_lwp = ksi.ksi_lid; p->p_sigctx.ps_info = ksi.ksi_info; - sigswitch(0, signo, true); + sigswitch(0, signo, false); if (ktrpoint(KTR_PSIG)) { if (p->p_emul->e_ktrpsig) Index: src/sys/sys/signalvar.h diff -u src/sys/sys/signalvar.h:1.96 src/sys/sys/signalvar.h:1.97 --- src/sys/sys/signalvar.h:1.96 Mon Sep 30 21:13:33 2019 +++ src/sys/sys/signalvar.h Sat Oct 12 19:57:09 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: signalvar.h,v 1.96 2019/09/30 21:13:33 kamil Exp $ */ +/* $NetBSD: signalvar.h,v 1.97 2019/10/12 19:57:09 kamil Exp $ */ /* * Copyright (c) 1991, 1993 @@ -153,7 +153,6 @@ void setsigvec(struct proc *, int, struc int killpg1(struct lwp *, struct ksiginfo *, int, int); void proc_unstop(struct proc *p); void eventswitch(int, int, int); -void sigswitch(int, int, bool); int sigaction1(struct lwp *, int, const struct sigaction *,