Add eventswitch() in signal code

Route all crash and debugger related signal through eventswitch(), that
calls sigswitch() with preprocessed arguments.

This code avoids code duplication and allows to introduce changes that
will affect all callers of sigswitch() in debugger-related events.

No functional change intended.
This commit is contained in:
kamil 2019-05-01 17:21:55 +00:00
parent ff3a41b31a
commit d55073af77
4 changed files with 32 additions and 32 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_exec.c,v 1.462 2018/11/11 10:55:58 maxv Exp $ */
/* $NetBSD: kern_exec.c,v 1.463 2019/05/01 17:21:55 kamil Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -59,7 +59,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.462 2018/11/11 10:55:58 maxv Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.463 2019/05/01 17:21:55 kamil Exp $");
#include "opt_exec.h"
#include "opt_execfmt.h"
@ -1271,11 +1271,7 @@ execve_runproc(struct lwp *l, struct execve_data * restrict data,
if ((p->p_slflag & (PSL_TRACED|PSL_SYSCALL)) == PSL_TRACED) {
mutex_enter(p->p_lock);
p->p_xsig = SIGTRAP;
p->p_sigctx.ps_faked = true; // XXX
p->p_sigctx.ps_info._signo = p->p_xsig;
p->p_sigctx.ps_info._code = TRAP_EXEC;
sigswitch(0, SIGTRAP, false);
eventswitch(SIGTRAP, TRAP_EXEC);
// XXX ktrpoint(KTR_PSIG)
mutex_exit(p->p_lock);
mutex_enter(proc_lock);

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_fork.c,v 1.209 2019/04/07 14:50:41 kamil Exp $ */
/* $NetBSD: kern_fork.c,v 1.210 2019/05/01 17:21:55 kamil Exp $ */
/*-
* Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.209 2019/04/07 14:50:41 kamil Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.210 2019/05/01 17:21:55 kamil Exp $");
#include "opt_ktrace.h"
#include "opt_dtrace.h"
@ -575,11 +575,7 @@ fork1(struct lwp *l1, int flags, int exitsig, void *stack, size_t stacksize,
*/
if (tracefork || tracevfork) {
mutex_enter(p1->p_lock);
p1->p_xsig = SIGTRAP;
p1->p_sigctx.ps_faked = true; // XXX
p1->p_sigctx.ps_info._signo = p1->p_xsig;
p1->p_sigctx.ps_info._code = TRAP_CHLD;
sigswitch(0, SIGTRAP, false);
eventswitch(SIGTRAP, TRAP_CHLD);
// XXX ktrpoint(KTR_PSIG)
mutex_exit(p1->p_lock);
mutex_enter(proc_lock);
@ -597,12 +593,8 @@ fork1(struct lwp *l1, int flags, int exitsig, void *stack, size_t stacksize,
*/
if (tracevforkdone) {
mutex_enter(p1->p_lock);
p1->p_xsig = SIGTRAP;
p1->p_sigctx.ps_faked = true; // XXX
p1->p_sigctx.ps_info._signo = p1->p_xsig;
p1->p_sigctx.ps_info._code = TRAP_CHLD;
p1->p_vfpid_done = retval[0];
sigswitch(0, SIGTRAP, false);
eventswitch(SIGTRAP, TRAP_CHLD);
// XXX ktrpoint(KTR_PSIG)
mutex_exit(p1->p_lock);
// proc_lock unlocked
@ -627,11 +619,7 @@ child_return(void *arg)
}
mutex_enter(p->p_lock);
p->p_xsig = SIGTRAP;
p->p_sigctx.ps_faked = true; // XXX
p->p_sigctx.ps_info._signo = p->p_xsig;
p->p_sigctx.ps_info._code = TRAP_CHLD;
sigswitch(0, SIGTRAP, false);
eventswitch(SIGTRAP, TRAP_CHLD);
// XXX ktrpoint(KTR_PSIG)
mutex_exit(p->p_lock);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_sig.c,v 1.352 2019/04/03 08:34:33 kamil Exp $ */
/* $NetBSD: kern_sig.c,v 1.353 2019/05/01 17:21:55 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.352 2019/04/03 08:34:33 kamil Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.353 2019/05/01 17:21:55 kamil Exp $");
#include "opt_ptrace.h"
#include "opt_dtrace.h"
@ -914,11 +914,7 @@ trapsignal(struct lwp *l, ksiginfo_t *ksi)
if (ISSET(p->p_slflag, PSL_TRACED) &&
!(p->p_pptr == p->p_opptr && ISSET(p->p_lflag, PL_PPWAIT))) {
p->p_xsig = signo;
p->p_sigctx.ps_faked = true; // XXX
p->p_sigctx.ps_info._signo = signo;
p->p_sigctx.ps_info._code = ksi->ksi_code;
sigswitch(0, signo, false);
eventswitch(signo, ksi->ksi_code);
// XXX ktrpoint(KTR_PSIG)
mutex_exit(p->p_lock);
return;
@ -1537,6 +1533,25 @@ proc_stop_done(struct proc *p, int ppmask)
}
}
void
eventswitch(int signo, int code)
{
struct lwp *l = curlwp;
struct proc *p = l->l_proc;
KASSERT(mutex_owned(proc_lock));
KASSERT(mutex_owned(p->p_lock));
KASSERT(l->l_stat == LSONPROC);
KASSERT(p->p_nrlwps > 0);
p->p_xsig = signo;
p->p_sigctx.ps_faked = true;
p->p_sigctx.ps_info._signo = signo;
p->p_sigctx.ps_info._code = code;
sigswitch(0, signo, false);
}
/*
* Stop the current process and switch away when being stopped or traced.
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: signalvar.h,v 1.91 2018/05/20 04:00:35 kamil Exp $ */
/* $NetBSD: signalvar.h,v 1.92 2019/05/01 17:21:55 kamil Exp $ */
/*
* Copyright (c) 1991, 1993
@ -136,6 +136,7 @@ void killproc(struct proc *, const char *);
void setsigvec(struct proc *, int, struct sigaction *);
int killpg1(struct lwp *, struct ksiginfo *, int, int);
void proc_unstop(struct proc *p);
void eventswitch(int, int);
void sigswitch(int, int, bool);