Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern - reduce ifdef ugliness by moving it up top.
details: https://anonhg.NetBSD.org/src/rev/e8acd9a4b44a
branches: trunk
changeset: 358208:e8acd9a4b44a
user: christos <christos%NetBSD.org@localhost>
date: Sun Dec 17 15:43:27 2017 +0000
description:
- reduce ifdef ugliness by moving it up top.
- factor out PT_IO and make PT_{READ,WRITE}_{I,D} use it
- factor out PT_DUMPCORE
- factor out sendsig code
... more to come ...
diffstat:
sys/kern/sys_ptrace_common.c | 551 +++++++++++++++++++++---------------------
1 files changed, 272 insertions(+), 279 deletions(-)
diffs (truncated from 756 to 300 lines):
diff -r c27f4962ad34 -r e8acd9a4b44a sys/kern/sys_ptrace_common.c
--- a/sys/kern/sys_ptrace_common.c Sun Dec 17 09:39:00 2017 +0000
+++ b/sys/kern/sys_ptrace_common.c Sun Dec 17 15:43:27 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_ptrace_common.c,v 1.27 2017/12/17 04:35:21 christos Exp $ */
+/* $NetBSD: sys_ptrace_common.c,v 1.28 2017/12/17 15:43:27 christos Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.27 2017/12/17 04:35:21 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.28 2017/12/17 15:43:27 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_ptrace.h"
@@ -170,6 +170,48 @@
static kcondvar_t ptrace_cv;
#endif
+#ifdef PT_GETREGS
+# define case_PT_GETREGS case PT_GETREGS:
+#else
+# define case_PT_GETREGS
+#endif
+
+#ifdef PT_SETREGS
+# define case_PT_SETREGS case PT_SETREGS:
+#else
+# define case_PT_SETREGS
+#endif
+
+#ifdef PT_GETFPREGS
+# define case_PT_GETFPREGS case PT_GETFPREGS:
+#else
+# define case_PT_GETFPREGS
+#endif
+
+#ifdef PT_SETFPREGS
+# define case_PT_SETFPREGS case PT_SETFPREGS:
+#else
+# define case_PT_SETFPREGS
+#endif
+
+#ifdef PT_GETDBREGS
+# define case_PT_GETDBREGS case PT_GETDBREGS:
+#else
+# define case_PT_GETDBREGS
+#endif
+
+#ifdef PT_SETDBREGS
+# define case_PT_SETDBREGS case PT_SETDBREGS:
+#else
+# define case_PT_SETDBREGS
+#endif
+
+#if defined(PT_SETREGS) || defined(PT_GETREGS) || \
+ defined(PT_SETFPREGS) || defined(PT_GETFOREGS) || \
+ defined(PT_SETDBREGS) || defined(PT_GETDBREGS)
+# define PT_REGISTERS
+#endif
+
static int
ptrace_listener_cb(kauth_cred_t cred, kauth_action_t action, void *cookie,
void *arg0, void *arg1, void *arg2, void *arg3)
@@ -196,24 +238,12 @@
case PT_READ_I:
case PT_READ_D:
case PT_IO:
-#ifdef PT_GETREGS
- case PT_GETREGS:
-#endif
-#ifdef PT_SETREGS
- case PT_SETREGS:
-#endif
-#ifdef PT_GETFPREGS
- case PT_GETFPREGS:
-#endif
-#ifdef PT_SETFPREGS
- case PT_SETFPREGS:
-#endif
-#ifdef PT_GETDBREGS
- case PT_GETDBREGS:
-#endif
-#ifdef PT_SETDBREGS
- case PT_SETDBREGS:
-#endif
+ case_PT_GETREGS
+ case_PT_SETREGS
+ case_PT_GETFPREGS
+ case_PT_SETFPREGS
+ case_PT_GETDBREGS
+ case_PT_SETDBREGS
case PT_SET_EVENT_MASK:
case PT_GET_EVENT_MASK:
case PT_GET_PROCESS_STATE:
@@ -339,11 +369,11 @@
/* Make sure we can operate on it. */
switch (req) {
- case PT_TRACE_ME:
+ case PT_TRACE_ME:
/* Saying that you're being traced is always legal. */
return 0;
- case PT_ATTACH:
+ case PT_ATTACH:
/*
* You can't attach to a process if:
* (1) it's the process that's doing the attaching,
@@ -374,33 +404,21 @@
return EPERM;
return 0;
- case PT_READ_I:
- case PT_READ_D:
- case PT_WRITE_I:
- case PT_WRITE_D:
- case PT_IO:
- case PT_SET_SIGINFO:
- case PT_GET_SIGINFO:
- case PT_SET_SIGMASK:
- case PT_GET_SIGMASK:
-#ifdef PT_GETREGS
- case PT_GETREGS:
-#endif
-#ifdef PT_SETREGS
- case PT_SETREGS:
-#endif
-#ifdef PT_GETFPREGS
- case PT_GETFPREGS:
-#endif
-#ifdef PT_SETFPREGS
- case PT_SETFPREGS:
-#endif
-#ifdef PT_GETDBREGS
- case PT_GETDBREGS:
-#endif
-#ifdef PT_SETDBREGS
- case PT_SETDBREGS:
-#endif
+ case PT_READ_I:
+ case PT_READ_D:
+ case PT_WRITE_I:
+ case PT_WRITE_D:
+ case PT_IO:
+ case PT_SET_SIGINFO:
+ case PT_GET_SIGINFO:
+ case PT_SET_SIGMASK:
+ case PT_GET_SIGMASK:
+ case_PT_GETREGS
+ case_PT_SETREGS
+ case_PT_GETFPREGS
+ case_PT_SETFPREGS
+ case_PT_GETDBREGS
+ case_PT_SETDBREGS
#ifdef __HAVE_PTRACE_MACHDEP
PTRACE_MACHDEP_REQUEST_CASES
#endif
@@ -416,23 +434,23 @@
return EPERM;
/*FALLTHROUGH*/
- case PT_CONTINUE:
- case PT_KILL:
- case PT_DETACH:
- case PT_LWPINFO:
- case PT_SYSCALL:
- case PT_SYSCALLEMU:
- case PT_DUMPCORE:
+ case PT_CONTINUE:
+ case PT_KILL:
+ case PT_DETACH:
+ case PT_LWPINFO:
+ case PT_SYSCALL:
+ case PT_SYSCALLEMU:
+ case PT_DUMPCORE:
#ifdef PT_STEP
- case PT_STEP:
- case PT_SETSTEP:
- case PT_CLEARSTEP:
+ case PT_STEP:
+ case PT_SETSTEP:
+ case PT_CLEARSTEP:
#endif
- case PT_SET_EVENT_MASK:
- case PT_GET_EVENT_MASK:
- case PT_GET_PROCESS_STATE:
- case PT_RESUME:
- case PT_SUSPEND:
+ case PT_SET_EVENT_MASK:
+ case PT_GET_EVENT_MASK:
+ case PT_GET_PROCESS_STATE:
+ case PT_RESUME:
+ case PT_SUSPEND:
/*
* You can't do what you want to the process if:
* (1) It's not being traced at all,
@@ -738,29 +756,18 @@
return 0;
}
+#ifdef PT_REGISTERS
static int
ptrace_uio_dir(int req)
{
switch (req) {
-#if defined(PT_GETREGS)
- case PT_GETREGS:
-#endif
-#if defined(PT_GETFPREGS)
- case PT_GETFPREGS:
-#endif
-#if defined(PT_GETDBREGS)
- case PT_GETDBREGS:
-#endif
+ case_PT_GETREGS
+ case_PT_GETFPREGS
+ case_PT_GETDBREGS
return UIO_READ;
-#if defined(PT_SETREGS)
- case PT_SETREGS:
-#endif
-#if defined(PT_SETFPREGS)
- case PT_SETFPREGS:
-#endif
-#if defined(PT_SETDBREGS)
- case PT_SETDBREGS:
-#endif
+ case_PT_SETREGS
+ case_PT_SETFPREGS
+ case_PT_SETDBREGS
return UIO_WRITE;
default:
return -1;
@@ -784,12 +791,8 @@
switch (rq) {
#if defined(PT_SETREGS) || defined(PT_GETREGS)
-#if defined(PT_GETREGS)
- case PT_GETREGS:
-#endif
-#if defined(PT_GETREGS)
- case PT_SETREGS:
-#endif
+ case_PT_GETREGS
+ case_PT_SETREGS
if (!process_validregs(*lt))
return EINVAL;
size = PROC_REGSZ(t);
@@ -797,12 +800,8 @@
break;
#endif
#if defined(PT_SETFPREGS) || defined(PT_GETFPREGS)
-#if defined(PT_GETFPREGS)
- case PT_GETFPREGS:
-#endif
-#if defined(PT_GETFPREGS)
- case PT_SETFPREGS:
-#endif
+ case_PT_GETFPREGS
+ case_PT_SETFPREGS
if (!process_validfpregs(*lt))
return EINVAL;
size = PROC_FPREGSZ(t);
@@ -810,12 +809,8 @@
break;
#endif
#if defined(PT_SETDBREGS) || defined(PT_GETDBREGS)
-#if defined(PT_GETDBREGS)
- case PT_GETDBREGS:
-#endif
-#if defined(PT_GETDBREGS)
- case PT_SETDBREGS:
-#endif
+ case_PT_GETDBREGS
+ case_PT_SETDBREGS
if (!process_validdbregs(*lt))
return EINVAL;
size = PROC_DBREGSZ(t);
@@ -846,6 +841,135 @@
uvmspace_free(vm);
return error;
}
+#endif
+
+static int
+ptrace_sendsig(struct proc *t, struct lwp *lt, int signo, int resume_all)
+{
+ ksiginfo_t ksi;
+
+ t->p_fpid = 0;
+ t->p_vfpid = 0;
+ t->p_vfpid_done = 0;
+ t->p_lwp_created = 0;
+ t->p_lwp_exited = 0;
+
+ /* Finally, deliver the requested signal (or none). */
Home |
Main Index |
Thread Index |
Old Index