summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorrobert <robert@FreeBSD.org>2003-10-09 10:17:16 +0000
committerrobert <robert@FreeBSD.org>2003-10-09 10:17:16 +0000
commit8519aa2ff041ebfe2fa21adb87df58dd07ab461a (patch)
treed286b80736e6c9743f984bcdfc12b33ff7eff197 /sys
parent20b1e12f1fef844ae5a2932fcacde82b2bd55ffa (diff)
downloadFreeBSD-src-8519aa2ff041ebfe2fa21adb87df58dd07ab461a.zip
FreeBSD-src-8519aa2ff041ebfe2fa21adb87df58dd07ab461a.tar.gz
Implement preliminary support for the PT_SYSCALL command to ptrace(2).
Diffstat (limited to 'sys')
-rw-r--r--sys/alpha/alpha/trap.c5
-rw-r--r--sys/amd64/amd64/trap.c5
-rw-r--r--sys/i386/i386/trap.c5
-rw-r--r--sys/ia64/ia64/trap.c6
-rw-r--r--sys/kern/sys_process.c17
-rw-r--r--sys/sparc64/sparc64/trap.c5
-rw-r--r--sys/sys/ptrace.h17
7 files changed, 59 insertions, 1 deletions
diff --git a/sys/alpha/alpha/trap.c b/sys/alpha/alpha/trap.c
index 0bb6cae..886a2f8 100644
--- a/sys/alpha/alpha/trap.c
+++ b/sys/alpha/alpha/trap.c
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
#include <sys/smp.h>
#include <sys/vmmeter.h>
#include <sys/sysent.h>
+#include <sys/signalvar.h>
#include <sys/syscall.h>
#include <sys/pioctl.h>
#include <vm/vm.h>
@@ -729,6 +730,8 @@ syscall(code, framep)
STOPEVENT(p, S_SCE, (callp->sy_narg & SYF_ARGMASK));
+ PTRACESTOP_SC(p, td, S_PT_SCE);
+
error = (*callp->sy_call)(td, args + hidden);
}
@@ -775,6 +778,8 @@ syscall(code, framep)
*/
STOPEVENT(p, S_SCX, code);
+ PTRACESTOP_SC(p, td, S_PT_SCX);
+
#ifdef DIAGNOSTIC
cred_free_thread(td);
#endif
diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c
index d0bf40c..024a9d5 100644
--- a/sys/amd64/amd64/trap.c
+++ b/sys/amd64/amd64/trap.c
@@ -55,6 +55,7 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/pioctl.h>
+#include <sys/ptrace.h>
#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/lock.h>
@@ -740,6 +741,8 @@ syscall(frame)
STOPEVENT(p, S_SCE, narg);
+ PTRACESTOP_SC(p, td, S_PT_SCE);
+
error = (*callp->sy_call)(td, argp);
}
@@ -808,6 +811,8 @@ syscall(frame)
*/
STOPEVENT(p, S_SCX, code);
+ PTRACESTOP_SC(p, td, S_PT_SCX);
+
#ifdef DIAGNOSTIC
cred_free_thread(td);
#endif
diff --git a/sys/i386/i386/trap.c b/sys/i386/i386/trap.c
index ee9e6b9..f5fe14f 100644
--- a/sys/i386/i386/trap.c
+++ b/sys/i386/i386/trap.c
@@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/pioctl.h>
+#include <sys/ptrace.h>
#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/lock.h>
@@ -1003,6 +1004,8 @@ syscall(frame)
STOPEVENT(p, S_SCE, narg);
+ PTRACESTOP_SC(p, td, S_PT_SCE);
+
error = (*callp->sy_call)(td, args);
}
@@ -1067,6 +1070,8 @@ syscall(frame)
*/
STOPEVENT(p, S_SCX, code);
+ PTRACESTOP_SC(p, td, S_PT_SCX);
+
#ifdef DIAGNOSTIC
cred_free_thread(td);
#endif
diff --git a/sys/ia64/ia64/trap.c b/sys/ia64/ia64/trap.c
index a524324..1513798 100644
--- a/sys/ia64/ia64/trap.c
+++ b/sys/ia64/ia64/trap.c
@@ -46,8 +46,10 @@ __FBSDID("$FreeBSD$");
#include <sys/smp.h>
#include <sys/vmmeter.h>
#include <sys/sysent.h>
+#include <sys/signalvar.h>
#include <sys/syscall.h>
#include <sys/pioctl.h>
+#include <sys/ptrace.h>
#include <sys/sysctl.h>
#include <vm/vm.h>
#include <vm/vm_kern.h>
@@ -968,6 +970,8 @@ syscall(struct trapframe *tf)
STOPEVENT(p, S_SCE, (callp->sy_narg & SYF_ARGMASK));
+ PTRACESTOP_SC(p, td, S_PT_SCE);
+
error = (*callp->sy_call)(td, args);
if (error != EJUSTRETURN) {
@@ -1010,6 +1014,8 @@ syscall(struct trapframe *tf)
*/
STOPEVENT(p, S_SCX, code);
+ PTRACESTOP_SC(p, td, S_PT_SCX);
+
#ifdef DIAGNOSTIC
cred_free_thread(td);
#endif
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index 51bbdcd..9e49d9d 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -382,6 +382,8 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
case PT_ATTACH:
case PT_STEP:
case PT_CONTINUE:
+ case PT_TO_SCE:
+ case PT_TO_SCX:
case PT_DETACH:
sx_xlock(&proctree_lock);
proctree_locked = 1;
@@ -507,6 +509,8 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
case PT_STEP:
case PT_CONTINUE:
+ case PT_TO_SCE:
+ case PT_TO_SCX:
case PT_DETACH:
/* Zero means do not send any signal */
if (data < 0 || data > _SIG_MAXSIG) {
@@ -516,12 +520,23 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
_PHOLD(p);
- if (req == PT_STEP) {
+ switch (req) {
+ case PT_STEP:
error = ptrace_single_step(td2);
if (error) {
_PRELE(p);
goto fail;
}
+ break;
+ case PT_TO_SCE:
+ p->p_stops |= S_PT_SCE;
+ break;
+ case PT_TO_SCX:
+ p->p_stops |= S_PT_SCX;
+ break;
+ case PT_SYSCALL:
+ p->p_stops |= S_PT_SCE | S_PT_SCX;
+ break;
}
if (addr != (void *)1) {
diff --git a/sys/sparc64/sparc64/trap.c b/sys/sparc64/sparc64/trap.c
index c60a53f..5fb5d5d 100644
--- a/sys/sparc64/sparc64/trap.c
+++ b/sys/sparc64/sparc64/trap.c
@@ -55,6 +55,7 @@
#include <sys/pioctl.h>
#include <sys/proc.h>
#include <sys/smp.h>
+#include <sys/signalvar.h>
#include <sys/syscall.h>
#include <sys/sysctl.h>
#include <sys/sysent.h>
@@ -578,6 +579,8 @@ syscall(struct trapframe *tf)
STOPEVENT(p, S_SCE, narg); /* MP aware */
+ PTRACESTOP_SC(p, td, S_PT_SCE);
+
error = (*callp->sy_call)(td, argp);
CTR5(KTR_SYSC, "syscall: p=%p error=%d %s return %#lx %#lx ", p,
@@ -642,6 +645,8 @@ syscall(struct trapframe *tf)
*/
STOPEVENT(p, S_SCX, code);
+ PTRACESTOP_SC(p, td, S_PT_SCX);
+
#ifdef DIAGNOSTIC
cred_free_thread(td);
#endif
diff --git a/sys/sys/ptrace.h b/sys/sys/ptrace.h
index ef7262a..4103df6 100644
--- a/sys/sys/ptrace.h
+++ b/sys/sys/ptrace.h
@@ -52,6 +52,10 @@
#define PT_DETACH 11 /* stop tracing a process */
#define PT_IO 12 /* do I/O to/from stopped process. */
+#define PT_TO_SCE 20
+#define PT_TO_SCX 21
+#define PT_SYSCALL 22
+
#define PT_GETREGS 33 /* get general-purpose registers */
#define PT_SETREGS 34 /* set general-purpose registers */
#define PT_GETFPREGS 35 /* get floating-point registers */
@@ -78,6 +82,19 @@ struct ptrace_io_desc {
#define PIOD_WRITE_I 4 /* Write to I space */
#ifdef _KERNEL
+
+#define PTRACESTOP_SC(p, td, flag) \
+ if ((p)->p_flag & P_TRACED && (p)->p_stops & (flag)) { \
+ PROC_LOCK(p); \
+ ptracestop((td), SIGTRAP); \
+ }
+/*
+ * The flags below are used for ptrace(2) tracing and have no relation
+ * to procfs. They are stored in struct proc's p_stops member.
+ */
+#define S_PT_SCE 0x000010000
+#define S_PT_SCX 0x000020000
+
int ptrace_set_pc(struct thread *_td, unsigned long _addr);
int ptrace_single_step(struct thread *_td);
OpenPOWER on IntegriCloud