Instead of copying parts of sigswitch to process_stoptrace, use it directly.

Rename process_stoptrace -> proc_stoptrace and put it in kern_sig.c so we
don't need to expose any more functions from it.
This commit is contained in:
christos 2017-03-24 17:40:44 +00:00
parent 6460d27d61
commit 5915ff2ca3
5 changed files with 37 additions and 54 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_sig.c,v 1.333 2017/03/23 21:59:55 christos Exp $ */
/* $NetBSD: kern_sig.c,v 1.334 2017/03/24 17:40:44 christos 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.333 2017/03/23 21:59:55 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.334 2017/03/24 17:40:44 christos Exp $");
#include "opt_ptrace.h"
#include "opt_dtrace.h"
@ -83,6 +83,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.333 2017/03/23 21:59:55 christos Exp
#include <sys/param.h>
#include <sys/signalvar.h>
#include <sys/proc.h>
#include <sys/ptrace.h>
#include <sys/systm.h>
#include <sys/wait.h>
#include <sys/ktrace.h>
@ -116,6 +117,7 @@ static sigset_t stopsigmask __cacheline_aligned;
sigset_t sigcantmask __cacheline_aligned;
static void ksiginfo_exechook(struct proc *, void *);
static void proc_stop(struct proc *, int);
static void proc_stop_callout(void *);
static int sigchecktrace(void);
static int sigpost(struct lwp *, sig_t, int, int);
@ -1535,7 +1537,7 @@ sigswitch(bool ppsig, int ppmask, int signo)
*/
if (p->p_stat == SACTIVE && (p->p_sflag & PS_STOPPING) == 0) {
KASSERT(signo != 0);
proc_stop(p, 0, signo);
proc_stop(p, signo);
KASSERT(p->p_nrlwps > 0);
}
@ -2099,7 +2101,7 @@ sigexit(struct lwp *l, int signo)
* Put process 'p' into the stopped state and optionally, notify the parent.
*/
void
proc_stop(struct proc *p, int now, int signo)
proc_stop(struct proc *p, int signo)
{
struct lwp *l;
@ -2121,7 +2123,7 @@ proc_stop(struct proc *p, int now, int signo)
* LWP to stop will take care of it.
*/
if (p->p_nrlwps == 0 || (now && p->p_nrlwps == 1 && p == curproc)) {
if (p->p_nrlwps == 0) {
proc_stop_done(p, true, PS_NOCLDSTOP);
} else {
/*
@ -2254,6 +2256,27 @@ proc_unstop(struct proc *p)
}
}
void
proc_stoptrace(int trapno)
{
struct lwp *l = curlwp;
struct proc *p = l->l_proc, *pp;
mutex_enter(p->p_lock);
pp = p->p_pptr;
if (pp->p_pid == 1) {
CLR(p->p_slflag, PSL_SYSCALL); /* XXXSMP */
mutex_exit(p->p_lock);
return;
}
p->p_xsig = SIGTRAP;
p->p_sigctx.ps_info._signo = p->p_xsig;
p->p_sigctx.ps_info._code = trapno;
sigswitch(true, 0, p->p_xsig);
mutex_exit(p->p_lock);
}
static int
filt_sigattach(struct knote *kn)
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_syscall.c,v 1.15 2017/03/23 21:59:55 christos Exp $ */
/* $NetBSD: kern_syscall.c,v 1.16 2017/03/24 17:40:44 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_syscall.c,v 1.15 2017/03/23 21:59:55 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_syscall.c,v 1.16 2017/03/24 17:40:44 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_modular.h"
@ -248,7 +248,7 @@ trace_enter(register_t code, const struct sysent *sy, const void *args)
#ifdef PTRACE
if ((curlwp->l_proc->p_slflag & (PSL_SYSCALL|PSL_TRACED)) ==
(PSL_SYSCALL|PSL_TRACED)) {
process_stoptrace(TRAP_SCE);
proc_stoptrace(TRAP_SCE);
if (curlwp->l_proc->p_slflag & PSL_SYSCALLEMU) {
/* tracer will emulate syscall for us */
error = EJUSTRETURN;
@ -289,7 +289,7 @@ trace_exit(register_t code, const struct sysent *sy, const void *args,
#ifdef PTRACE
if ((p->p_slflag & (PSL_SYSCALL|PSL_TRACED|PSL_SYSCALLEMU)) ==
(PSL_SYSCALL|PSL_TRACED)) {
process_stoptrace(TRAP_SCX);
proc_stoptrace(TRAP_SCX);
}
CLR(p->p_slflag, PSL_SYSCALLEMU);
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: sys_process.c,v 1.177 2017/03/23 21:59:55 christos Exp $ */
/* $NetBSD: sys_process.c,v 1.178 2017/03/24 17:40:44 christos Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@ -118,7 +118,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.177 2017/03/23 21:59:55 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.178 2017/03/24 17:40:44 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_ptrace.h"
@ -185,44 +185,6 @@ process_domem(struct lwp *curl /*tracer*/,
#endif
return error;
}
void
process_stoptrace(int trapno)
{
struct lwp *l = curlwp;
struct proc *p = l->l_proc, *pp;
mutex_enter(p->p_lock);
mutex_enter(proc_lock);
pp = p->p_pptr;
if (pp->p_pid == 1) {
CLR(p->p_slflag, PSL_SYSCALL); /* XXXSMP */
mutex_exit(p->p_lock);
mutex_exit(proc_lock);
return;
}
p->p_sigctx.ps_info._signo = SIGTRAP;
p->p_sigctx.ps_info._code = trapno;
p->p_xsig = SIGTRAP;
proc_stop(p, 1, SIGSTOP);
mutex_exit(proc_lock);
if (sigispending(l, 0)) {
lwp_lock(l);
l->l_flag |= LW_PENDSIG;
lwp_unlock(l);
}
/* Switch and wait until we come to a stop */
do {
mutex_exit(p->p_lock);
lwp_lock(l);
mi_switch(l);
mutex_enter(p->p_lock);
} while (p->p_sflag & PS_STOPPING);
mutex_exit(p->p_lock);
}
#endif /* KTRACE || PTRACE_HOOKS */
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: proc.h,v 1.338 2017/02/23 03:34:23 kamil Exp $ */
/* $NetBSD: proc.h,v 1.339 2017/03/24 17:40:44 christos Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@ -538,7 +538,6 @@ void syscall_intern(struct proc *);
void child_return(void *);
int proc_isunder(struct proc *, struct lwp *);
void proc_stop(struct proc *, int, int);
int proc_uidmatch(kauth_cred_t, kauth_cred_t);
int proc_vmspace_getref(struct proc *, struct vmspace **);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ptrace.h,v 1.59 2017/03/23 21:59:54 christos Exp $ */
/* $NetBSD: ptrace.h,v 1.60 2017/03/24 17:40:44 christos Exp $ */
/*-
* Copyright (c) 1984, 1993
@ -208,8 +208,7 @@ int process_validdbregs(struct lwp *);
int process_domem(struct lwp *, struct lwp *, struct uio *);
void process_stoptrace(int);
void proc_stoptrace(int);
void proc_reparent(struct proc *, struct proc *);
void proc_changeparent(struct proc *, struct proc *);