aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2019-07-15 21:48:02 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2019-07-15 21:48:02 +0000
commit32451fb9fc71518dd5cf58a06d217eaa777e0206 (patch)
treea0db97356f121a565695a1690ee9c34645004bbb /sys
parent0cc1098a1a6b8353da73ee579091d399652aa57c (diff)
downloadsrc-32451fb9fc71518dd5cf58a06d217eaa777e0206.tar.gz
src-32451fb9fc71518dd5cf58a06d217eaa777e0206.zip
Add ptrace op PT_GET_SC_RET.
This ptrace operation returns a structure containing the error and return values from the current system call. It is only valid when a thread is stopped during a system call exit (PL_FLAG_SCX is set). The sr_error member holds the error value from the system call. Note that this error value is the native FreeBSD error value that has _not_ been translated to an ABI-specific error value similar to the values logged to ktrace. If sr_error is zero, then the return values of the system call will be set in sr_retval[0] and sr_retval[1]. Reviewed by: kib MFC after: 1 month Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D20901
Notes
Notes: svn path=/head/; revision=350017
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/sys_process.c63
-rw-r--r--sys/sys/ptrace.h7
2 files changed, 68 insertions, 2 deletions
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index b9649ee8053a..0444af49e82f 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -76,6 +76,11 @@ struct ptrace_io_desc32 {
uint32_t piod_len;
};
+struct ptrace_sc_ret32 {
+ uint32_t sr_retval[2];
+ int sr_error;
+};
+
struct ptrace_vm_entry32 {
int pve_entry;
int pve_timestamp;
@@ -518,6 +523,17 @@ ptrace_lwpinfo_to32(const struct ptrace_lwpinfo *pl,
pl32->pl_syscall_code = pl->pl_syscall_code;
pl32->pl_syscall_narg = pl->pl_syscall_narg;
}
+
+static void
+ptrace_sc_ret_to32(const struct ptrace_sc_ret *psr,
+ struct ptrace_sc_ret32 *psr32)
+{
+
+ bzero(psr32, sizeof(*psr32));
+ psr32->sr_retval[0] = psr->sr_retval[0];
+ psr32->sr_retval[1] = psr->sr_retval[1];
+ psr32->sr_error = psr->sr_error;
+}
#endif /* COMPAT_FREEBSD32 */
/*
@@ -580,6 +596,7 @@ sys_ptrace(struct thread *td, struct ptrace_args *uap)
struct ptrace_vm_entry32 pve32;
#endif
char args[sizeof(td->td_sa.args)];
+ struct ptrace_sc_ret psr;
int ptevents;
} r;
void *addr;
@@ -598,6 +615,7 @@ sys_ptrace(struct thread *td, struct ptrace_args *uap)
case PT_GET_EVENT_MASK:
case PT_LWPINFO:
case PT_GET_SC_ARGS:
+ case PT_GET_SC_RET:
break;
case PT_GETREGS:
BZERO(&r.reg, sizeof r.reg);
@@ -668,6 +686,10 @@ sys_ptrace(struct thread *td, struct ptrace_args *uap)
error = copyout(r.args, uap->addr, MIN(uap->data,
sizeof(r.args)));
break;
+ case PT_GET_SC_RET:
+ error = copyout(&r.psr, uap->addr, MIN(uap->data,
+ sizeof(r.psr)));
+ break;
}
return (error);
@@ -719,6 +741,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
struct thread *td2 = NULL, *td3;
struct ptrace_io_desc *piod = NULL;
struct ptrace_lwpinfo *pl;
+ struct ptrace_sc_ret *psr;
int error, num, tmp;
int proctree_locked = 0;
lwpid_t tid = 0, *buf;
@@ -726,7 +749,11 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
int wrap32 = 0, safe = 0;
struct ptrace_io_desc32 *piod32 = NULL;
struct ptrace_lwpinfo32 *pl32 = NULL;
- struct ptrace_lwpinfo plr;
+ struct ptrace_sc_ret32 *psr32 = NULL;
+ union {
+ struct ptrace_lwpinfo pl;
+ struct ptrace_sc_ret psr;
+ } r;
#endif
curp = td->td_proc;
@@ -1049,6 +1076,38 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
bcopy(td2->td_sa.args, addr, td2->td_sa.narg *
sizeof(register_t));
break;
+
+ case PT_GET_SC_RET:
+ if ((td2->td_dbgflags & (TDB_SCX)) == 0
+#ifdef COMPAT_FREEBSD32
+ || (wrap32 && !safe)
+#endif
+ ) {
+ error = EINVAL;
+ break;
+ }
+#ifdef COMPAT_FREEBSD32
+ if (wrap32) {
+ psr = &r.psr;
+ psr32 = addr;
+ } else
+#endif
+ psr = addr;
+ bzero(psr, sizeof(*psr));
+ psr->sr_error = td2->td_errno;
+ if (psr->sr_error == 0) {
+ psr->sr_retval[0] = td2->td_retval[0];
+ psr->sr_retval[1] = td2->td_retval[1];
+ }
+#ifdef COMPAT_FREEBSD32
+ if (wrap32)
+ ptrace_sc_ret_to32(psr, psr32);
+#endif
+ CTR4(KTR_PTRACE,
+ "PT_GET_SC_RET: pid %d error %d retval %#lx,%#lx",
+ p->p_pid, psr->sr_error, psr->sr_retval[0],
+ psr->sr_retval[1]);
+ break;
case PT_STEP:
case PT_CONTINUE:
@@ -1335,7 +1394,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
}
#ifdef COMPAT_FREEBSD32
if (wrap32) {
- pl = &plr;
+ pl = &r.pl;
pl32 = addr;
} else
#endif
diff --git a/sys/sys/ptrace.h b/sys/sys/ptrace.h
index e41f7a3ef024..1ee42318e57e 100644
--- a/sys/sys/ptrace.h
+++ b/sys/sys/ptrace.h
@@ -72,6 +72,7 @@
#define PT_SET_EVENT_MASK 26 /* set mask of optional events */
#define PT_GET_SC_ARGS 27 /* fetch syscall args */
+#define PT_GET_SC_RET 28 /* fetch syscall results */
#define PT_GETREGS 33 /* get general-purpose registers */
#define PT_SETREGS 34 /* set general-purpose registers */
@@ -155,6 +156,12 @@ struct ptrace_lwpinfo32 {
};
#endif
+/* Argument structure for PT_GET_SC_RET. */
+struct ptrace_sc_ret {
+ register_t sr_retval[2]; /* Only valid if sr_error == 0. */
+ int sr_error;
+};
+
/* Argument structure for PT_VM_ENTRY. */
struct ptrace_vm_entry {
int pve_entry; /* Entry number used for iteration. */