Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys handle siginfo requests for ptrace32
details: https://anonhg.NetBSD.org/src/rev/72f685565ddf
branches: trunk
changeset: 358213:72f685565ddf
user: christos <christos%NetBSD.org@localhost>
date: Sun Dec 17 20:59:27 2017 +0000
description:
handle siginfo requests for ptrace32
diffstat:
sys/compat/netbsd32/netbsd32.h | 11 +++++-
sys/compat/netbsd32/netbsd32_ptrace.c | 59 ++++++++++++++++++++++++++--------
sys/compat/netbsd32/netbsd32_signal.c | 47 ++++++++++++++++++++++++++-
sys/kern/sys_ptrace.c | 47 ++++++++++++++++++++-------
sys/kern/sys_ptrace_common.c | 31 +++++++-----------
sys/sys/ptrace.h | 8 ++-
6 files changed, 151 insertions(+), 52 deletions(-)
diffs (truncated from 389 to 300 lines):
diff -r d583e447655d -r 72f685565ddf sys/compat/netbsd32/netbsd32.h
--- a/sys/compat/netbsd32/netbsd32.h Sun Dec 17 20:58:16 2017 +0000
+++ b/sys/compat/netbsd32/netbsd32.h Sun Dec 17 20:59:27 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32.h,v 1.114 2016/11/13 13:52:41 rin Exp $ */
+/* $NetBSD: netbsd32.h,v 1.115 2017/12/17 20:59:27 christos Exp $ */
/*
* Copyright (c) 1998, 2001, 2008, 2015 Matthew R. Green
@@ -292,6 +292,13 @@
actual count (out) */
};
+struct netbsd32_ptrace_siginfo {
+ siginfo32_t psi_siginfo; /* signal information structure */
+ lwpid_t psi_lwpid; /* destination LWP of the signal
+ * value 0 means the whole process
+ * (route signal to all LWPs) */
+};
+
/* from <sys/quotactl.h> */
typedef netbsd32_pointer_t netbsd32_quotactlargsp_t;
struct netbsd32_quotactlargs {
@@ -1121,6 +1128,8 @@
void netbsd32_adjust_limits(struct proc *);
void netbsd32_si_to_si32(siginfo32_t *, const siginfo_t *);
+void netbsd32_si32_to_si(siginfo_t *, const siginfo32_t *);
+
void netbsd32_ksi32_to_ksi(struct _ksiginfo *si, const struct __ksiginfo32 *si32);
#ifdef KTRACE
diff -r d583e447655d -r 72f685565ddf sys/compat/netbsd32/netbsd32_ptrace.c
--- a/sys/compat/netbsd32/netbsd32_ptrace.c Sun Dec 17 20:58:16 2017 +0000
+++ b/sys/compat/netbsd32/netbsd32_ptrace.c Sun Dec 17 20:59:27 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_ptrace.c,v 1.4 2017/02/23 03:34:22 kamil Exp $ */
+/* $NetBSD: netbsd32_ptrace.c,v 1.5 2017/12/17 20:59:27 christos Exp $ */
/*
* Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_ptrace.c,v 1.4 2017/02/23 03:34:22 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_ptrace.c,v 1.5 2017/12/17 20:59:27 christos Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ptrace.h"
@@ -54,18 +54,14 @@
* PTRACE methods
*/
-static int netbsd32_copyinpiod(struct ptrace_io_desc *, const void *);
-static void netbsd32_copyoutpiod(const struct ptrace_io_desc *, void *);
-static int netbsd32_doregs(struct lwp *, struct lwp *, struct uio *);
-static int netbsd32_dofpregs(struct lwp *, struct lwp *, struct uio *);
-static int netbsd32_dodbregs(struct lwp *, struct lwp *, struct uio *);
-
-
static int
-netbsd32_copyinpiod(struct ptrace_io_desc *piod, const void *addr)
+netbsd32_copyin_piod(struct ptrace_io_desc *piod, const void *addr, size_t len)
{
struct netbsd32_ptrace_io_desc piod32;
+ if (len != 0 && sizeof(piod32) != len)
+ return EINVAL;
+
int error = copyin(addr, &piod32, sizeof(piod32));
if (error)
return error;
@@ -77,18 +73,49 @@
return 0;
}
-static void
-netbsd32_copyoutpiod(const struct ptrace_io_desc *piod, void *addr)
+static int
+netbsd32_copyout_piod(const struct ptrace_io_desc *piod, void *addr, size_t len)
{
struct netbsd32_ptrace_io_desc piod32;
+ if (len != 0 && sizeof(piod32) != len)
+ return EINVAL;
+
piod32.piod_op = piod->piod_op;
NETBSD32PTR32(piod32.piod_offs, piod->piod_offs);
NETBSD32PTR32(piod32.piod_addr, piod->piod_addr);
piod32.piod_len = (netbsd32_size_t)piod->piod_len;
- (void) copyout(&piod32, addr, sizeof(piod32));
+ return copyout(&piod32, addr, sizeof(piod32));
}
+static int
+netbsd32_copyin_siginfo(struct ptrace_siginfo *psi, const void *addr, size_t len)
+{
+ struct netbsd32_ptrace_siginfo psi32;
+
+ if (sizeof(psi32) != len)
+ return EINVAL;
+
+ int error = copyin(addr, &psi32, sizeof(psi32));
+ if (error)
+ return error;
+ psi->psi_lwpid = psi32.psi_lwpid;
+ netbsd32_si32_to_si(&psi->psi_siginfo, &psi32.psi_siginfo);
+ return 0;
+}
+
+static int
+netbsd32_copyout_siginfo(const struct ptrace_siginfo *psi, void *addr, size_t len)
+{
+ struct netbsd32_ptrace_siginfo psi32;
+
+ if (sizeof(psi32) != len)
+ return EINVAL;
+
+ psi32.psi_lwpid = psi->psi_lwpid;
+ netbsd32_si_to_si32(&psi32.psi_siginfo, &psi->psi_siginfo);
+ return copyout(&psi32, addr, sizeof(psi32));
+}
static int
netbsd32_doregs(struct lwp *curl /*tracer*/,
@@ -205,8 +232,10 @@
}
static struct ptrace_methods netbsd32_ptm = {
- .ptm_copyinpiod = netbsd32_copyinpiod,
- .ptm_copyoutpiod = netbsd32_copyoutpiod,
+ .ptm_copyin_piod = netbsd32_copyin_piod,
+ .ptm_copyout_piod = netbsd32_copyout_piod,
+ .ptm_copyin_siginfo = netbsd32_copyin_siginfo,
+ .ptm_copyout_siginfo = netbsd32_copyout_siginfo,
.ptm_doregs = netbsd32_doregs,
.ptm_dofpregs = netbsd32_dofpregs,
.ptm_dodbregs = netbsd32_dodbregs
diff -r d583e447655d -r 72f685565ddf sys/compat/netbsd32/netbsd32_signal.c
--- a/sys/compat/netbsd32/netbsd32_signal.c Sun Dec 17 20:58:16 2017 +0000
+++ b/sys/compat/netbsd32/netbsd32_signal.c Sun Dec 17 20:59:27 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_signal.c,v 1.44 2017/12/06 19:15:27 christos Exp $ */
+/* $NetBSD: netbsd32_signal.c,v 1.45 2017/12/17 20:59:27 christos Exp $ */
/*
* Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.44 2017/12/06 19:15:27 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.45 2017/12/17 20:59:27 christos Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ktrace.h"
@@ -315,6 +315,49 @@
}
void
+netbsd32_si32_to_si(siginfo_t *si, const siginfo32_t *si32)
+{
+ memset(si, 0, sizeof (*si));
+ si->si_signo = si32->si_signo;
+ si->si_code = si32->si_code;
+ si->si_errno = si32->si_errno;
+
+ switch (si->si_signo) {
+ case 0: /* SA */
+ si->si_value.sival_int = si32->si_value.sival_int;
+ break;
+ case SIGILL:
+ case SIGBUS:
+ case SIGSEGV:
+ case SIGFPE:
+ case SIGTRAP:
+ si->si_addr = (void *)(uintptr_t)si32->si_addr;
+ si->si_trap = si32->si_trap;
+ break;
+ case SIGALRM:
+ case SIGVTALRM:
+ case SIGPROF:
+ default:
+ si->si_pid = si32->si_pid;
+ si->si_uid = si32->si_uid;
+ si->si_value.sival_int = si32->si_value.sival_int;
+ break;
+ case SIGCHLD:
+ si->si_pid = si32->si_pid;
+ si->si_uid = si32->si_uid;
+ si->si_status = si32->si_status;
+ si->si_utime = si32->si_utime;
+ si->si_stime = si32->si_stime;
+ break;
+ case SIGURG:
+ case SIGIO:
+ si->si_band = si32->si_band;
+ si->si_fd = si32->si_fd;
+ break;
+ }
+}
+
+void
getucontext32(struct lwp *l, ucontext32_t *ucp)
{
struct proc *p = l->l_proc;
diff -r d583e447655d -r 72f685565ddf sys/kern/sys_ptrace.c
--- a/sys/kern/sys_ptrace.c Sun Dec 17 20:58:16 2017 +0000
+++ b/sys/kern/sys_ptrace.c Sun Dec 17 20:59:27 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_ptrace.c,v 1.4 2017/02/23 03:34:22 kamil Exp $ */
+/* $NetBSD: sys_ptrace.c,v 1.5 2017/12/17 20:59: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.c,v 1.4 2017/02/23 03:34:22 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace.c,v 1.5 2017/12/17 20:59:27 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_ptrace.h"
@@ -149,24 +149,47 @@
* PTRACE methods
*/
-static int ptrace_copyinpiod(struct ptrace_io_desc *, const void *);
-static void ptrace_copyoutpiod(const struct ptrace_io_desc *, void *);
+static int
+ptrace_copyin_piod(struct ptrace_io_desc *piod, const void *addr, size_t len)
+{
+ if (len != 0 && sizeof(*piod) != len)
+ return EINVAL;
-static int
-ptrace_copyinpiod(struct ptrace_io_desc *piod, const void *addr)
-{
return copyin(addr, piod, sizeof(*piod));
}
-static void
-ptrace_copyoutpiod(const struct ptrace_io_desc *piod, void *addr)
+static int
+ptrace_copyout_piod(const struct ptrace_io_desc *piod, void *addr, size_t len)
+{
+ if (len != 0 && sizeof(*piod) != len)
+ return EINVAL;
+
+ return copyout(piod, addr, sizeof(*piod));
+}
+
+static int
+ptrace_copyin_siginfo(struct ptrace_siginfo *psi, const void *addr, size_t len)
{
- (void) copyout(piod, addr, sizeof(*piod));
+ if (sizeof(*psi) != len)
+ return EINVAL;
+
+ return copyin(addr, psi, sizeof(*psi));
+}
+
+static int
+ptrace_copyout_siginfo(const struct ptrace_siginfo *psi, void *addr, size_t len)
+{
+ if (sizeof(*psi) != len)
+ return EINVAL;
+
+ return copyout(psi, addr, sizeof(*psi));
}
static struct ptrace_methods native_ptm = {
- .ptm_copyinpiod = ptrace_copyinpiod,
- .ptm_copyoutpiod = ptrace_copyoutpiod,
+ .ptm_copyin_piod = ptrace_copyin_piod,
+ .ptm_copyout_piod = ptrace_copyout_piod,
+ .ptm_copyin_siginfo = ptrace_copyin_siginfo,
+ .ptm_copyout_siginfo = ptrace_copyout_siginfo,
.ptm_doregs = process_doregs,
.ptm_dofpregs = process_dofpregs,
.ptm_dodbregs = process_dodbregs,
diff -r d583e447655d -r 72f685565ddf sys/kern/sys_ptrace_common.c
--- a/sys/kern/sys_ptrace_common.c Sun Dec 17 20:58:16 2017 +0000
+++ b/sys/kern/sys_ptrace_common.c Sun Dec 17 20:59:27 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_ptrace_common.c,v 1.28 2017/12/17 15:43:27 christos Exp $ */
+/* $NetBSD: sys_ptrace_common.c,v 1.29 2017/12/17 20:59: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.28 2017/12/17 15:43:27 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.29 2017/12/17 20:59:27 christos Exp $");
#ifdef _KERNEL_OPT
Home |
Main Index |
Thread Index |
Old Index