Implement preliminary support for the PT_SYSCALL command to ptrace(2).
This commit is contained in:
parent
a14c617681
commit
ea924c4cd3
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user