Module Name:    src
Committed By:   martin
Date:           Tue Oct 15 19:25:12 UTC 2019

Modified Files:
        src/sys/kern [netbsd-9]: kern_sig.c

Log Message:
Pull up following revision(s) (requested by kamil in ticket #327):

        sys/kern/kern_sig.c: revision 1.370

Add sigswitch_unlock_and_switch_away(), extracted from sigswitch()

Use sigswitch_unlock_and_switch_away() whenever there is no need for
sigswitch().


To generate a diff of this commit:
cvs rdiff -u -r1.364.2.4 -r1.364.2.5 src/sys/kern/kern_sig.c

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.364.2.4 src/sys/kern/kern_sig.c:1.364.2.5
--- src/sys/kern/kern_sig.c:1.364.2.4	Tue Oct 15 19:23:09 2019
+++ src/sys/kern/kern_sig.c	Tue Oct 15 19:25:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sig.c,v 1.364.2.4 2019/10/15 19:23:09 martin Exp $	*/
+/*	$NetBSD: kern_sig.c,v 1.364.2.5 2019/10/15 19:25:11 martin 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.364.2.4 2019/10/15 19:23:09 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.364.2.5 2019/10/15 19:25:11 martin Exp $");
 
 #include "opt_ptrace.h"
 #include "opt_dtrace.h"
@@ -126,6 +126,7 @@ static int	sigpost(struct lwp *, sig_t, 
 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	sigswitch_unlock_and_switch_away(struct lwp *);
 
 static void	sigacts_poolpage_free(struct pool *, void *);
 static void	*sigacts_poolpage_alloc(struct pool *, int);
@@ -932,10 +933,11 @@ repeat:
 	 * The process is already stopping.
 	 */
 	if ((p->p_sflag & PS_STOPPING) != 0) {
-		sigswitch(0, p->p_xsig, true);
+		mutex_exit(proc_lock);
+		sigswitch_unlock_and_switch_away(l);
 		mutex_enter(proc_lock);
 		mutex_enter(p->p_lock);
-		goto repeat; /* XXX */
+		goto repeat;
 	}
 
 	mask = &l->l_sigmask;
@@ -1640,10 +1642,11 @@ repeat:
 	 * The process is already stopping.
 	 */
 	if ((p->p_sflag & PS_STOPPING) != 0) {
-		sigswitch(0, p->p_xsig, true);
+		mutex_exit(proc_lock);
+		sigswitch_unlock_and_switch_away(l);
 		mutex_enter(proc_lock);
 		mutex_enter(p->p_lock);
-		goto repeat; /* XXX */
+		goto repeat;
 	}
 
 	KSI_INIT_TRAP(&ksi);
@@ -1690,7 +1693,6 @@ sigswitch(int ppmask, int signo, bool pr
 {
 	struct lwp *l = curlwp;
 	struct proc *p = l->l_proc;
-	int biglocks;
 
 	KASSERT(mutex_owned(p->p_lock));
 	KASSERT(l->l_stat == LSONPROC);
@@ -1750,10 +1752,26 @@ sigswitch(int ppmask, int signo, bool pr
 		mutex_exit(proc_lock);
 	}
 
-	/*
-	 * Unlock and switch away.
-	 */
+	sigswitch_unlock_and_switch_away(l);
+}
+
+/*
+ * Unlock and switch away.
+ */
+static void
+sigswitch_unlock_and_switch_away(struct lwp *l)
+{
+	struct proc *p;
+	int biglocks;
+
+	p = l->l_proc;
+
+	KASSERT(mutex_owned(p->p_lock));
 	KASSERT(!mutex_owned(proc_lock));
+
+	KASSERT(l->l_stat == LSONPROC);
+	KASSERT(p->p_nrlwps > 0);
+
 	KERNEL_UNLOCK_ALL(l, &biglocks);
 	if (p->p_stat == SSTOP || (p->p_sflag & PS_STOPPING) != 0) {
 		p->p_nrlwps--;
@@ -1843,7 +1861,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, false);
+			sigswitch_unlock_and_switch_away(l);
 			mutex_enter(p->p_lock);
 			signo = sigchecktrace();
 		} else if (p->p_stat == SACTIVE)
@@ -2525,9 +2543,9 @@ repeat:
 	 * The process is already stopping.
 	 */
 	if ((p->p_sflag & PS_STOPPING) != 0) {
-		sigswitch(0, p->p_xsig, false);
+		sigswitch_unlock_and_switch_away(l);
 		mutex_enter(p->p_lock);
-		goto repeat; /* XXX */
+		goto repeat;
 	}
 
 	/* Needed for ktrace */

Reply via email to