Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Allow emulations to override the creation of ktrace reco...
details: https://anonhg.NetBSD.org/src/rev/c1566b264839
branches: trunk
changeset: 347728:c1566b264839
user: martin <martin%NetBSD.org@localhost>
date: Tue Sep 13 07:39:45 2016 +0000
description:
Allow emulations to override the creation of ktrace records for posting
signals. In compat_netbsd32 use this to write the 32bit version of
the records, so a 32bit userland kdump is happy.
diffstat:
sys/compat/netbsd32/netbsd32_netbsd.c | 9 ++-
sys/compat/netbsd32/netbsd32_signal.c | 90 ++++++++++++++++++++++++++++++++++-
sys/kern/kern_ktrace.c | 17 +++---
sys/kern/kern_sig.c | 20 +++++-
sys/sys/ktrace.h | 11 +++-
sys/sys/proc.h | 6 +-
6 files changed, 132 insertions(+), 21 deletions(-)
diffs (truncated from 311 to 300 lines):
diff -r be7d64bed75b -r c1566b264839 sys/compat/netbsd32/netbsd32_netbsd.c
--- a/sys/compat/netbsd32/netbsd32_netbsd.c Tue Sep 13 07:30:32 2016 +0000
+++ b/sys/compat/netbsd32/netbsd32_netbsd.c Tue Sep 13 07:39:45 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_netbsd.c,v 1.202 2016/09/10 08:21:26 skrll Exp $ */
+/* $NetBSD: netbsd32_netbsd.c,v 1.203 2016/09/13 07:39:45 martin Exp $ */
/*
* Copyright (c) 1998, 2001, 2008 Matthew R. Green
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.202 2016/09/10 08:21:26 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.203 2016/09/13 07:39:45 martin Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ddb.h"
@@ -103,6 +103,8 @@
void syscall(void);
#endif
+void netbsd32_ktrpsig(int, sig_t, const sigset_t *, const ksiginfo_t *);
+
#define LIMITCHECK(a, b) ((a) != RLIM_INFINITY && (a) > (b))
#ifdef COMPAT_16
@@ -162,7 +164,8 @@
.e_vm_default_addr = netbsd32_vm_default_addr,
.e_usertrap = NULL,
.e_ucsize = sizeof(ucontext32_t),
- .e_startlwp = startlwp32
+ .e_startlwp = startlwp32,
+ .e_ktrpsig = netbsd32_ktrpsig
};
/*
diff -r be7d64bed75b -r c1566b264839 sys/compat/netbsd32/netbsd32_signal.c
--- a/sys/compat/netbsd32/netbsd32_signal.c Tue Sep 13 07:30:32 2016 +0000
+++ b/sys/compat/netbsd32/netbsd32_signal.c Tue Sep 13 07:39:45 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_signal.c,v 1.39 2015/06/20 19:58:40 martin Exp $ */
+/* $NetBSD: netbsd32_signal.c,v 1.40 2016/09/13 07:39:45 martin 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.39 2015/06/20 19:58:40 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.40 2016/09/13 07:39:45 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -35,6 +35,7 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/signalvar.h>
+#include <sys/ktrace.h>
#include <sys/proc.h>
#include <sys/wait.h>
#include <sys/dirent.h>
@@ -51,6 +52,7 @@
#include <compat/sys/ucontext.h>
#include <compat/common/compat_sigaltstack.h>
+void netbsd32_ktrpsig(int, sig_t, const sigset_t *, const ksiginfo_t *);
int
netbsd32_sigaction(struct lwp *l, const struct netbsd32_sigaction_args *uap, register_t *retval)
@@ -220,6 +222,46 @@
}
}
+static void
+netbsd32_ksi_to_ksi32(struct __ksiginfo32 *si32, const struct _ksiginfo *si)
+{
+ memset(si32, 0, sizeof (*si32));
+ si32->_signo = si->_signo;
+ si32->_code = si->_code;
+ si32->_errno = si->_errno;
+
+ switch (si->_signo) {
+ case SIGILL:
+ case SIGBUS:
+ case SIGSEGV:
+ case SIGFPE:
+ case SIGTRAP:
+ si32->_reason._fault._addr =
+ NETBSD32PTR32I(si->_reason._fault._addr);
+ si32->_reason._fault._trap = si->_reason._fault._trap;
+ break;
+ case SIGALRM:
+ case SIGVTALRM:
+ case SIGPROF:
+ default: /* see sigqueue() and kill1() */
+ si32->_reason._rt._pid = si->_reason._rt._pid;
+ si32->_reason._rt._uid = si->_reason._rt._uid;
+ si32->_reason._rt._value.sival_int = si->_reason._rt._value.sival_int;
+ break;
+ case SIGCHLD:
+ si32->_reason._child._pid = si->_reason._child._pid;
+ si32->_reason._child._uid = si->_reason._child._uid;
+ si32->_reason._child._utime = si->_reason._child._utime;
+ si32->_reason._child._stime = si->_reason._child._stime;
+ break;
+ case SIGURG:
+ case SIGIO:
+ si32->_reason._poll._band = si->_reason._poll._band;
+ si32->_reason._poll._fd = si->_reason._poll._fd;
+ break;
+ }
+}
+
void
netbsd32_si_to_si32(siginfo32_t *si32, const siginfo_t *si)
{
@@ -455,3 +497,47 @@
return kill1(l, SCARG(uap, pid), &ksi, retval);
}
+
+struct netbsd32_ktr_psig {
+ int signo;
+ netbsd32_pointer_t action;
+ sigset_t mask;
+ int code;
+ /* and optional siginfo_t */
+};
+
+void
+netbsd32_ktrpsig(int sig, sig_t action, const sigset_t *mask,
+ const ksiginfo_t *ksi)
+{
+ struct ktrace_entry *kte;
+ lwp_t *l = curlwp;
+ struct {
+ struct netbsd32_ktr_psig kp;
+ siginfo32_t si;
+ } *kbuf;
+
+ if (!KTRPOINT(l->l_proc, KTR_PSIG))
+ return;
+
+ if (ktealloc(&kte, (void *)&kbuf, l, KTR_PSIG, sizeof(*kbuf)))
+ return;
+
+ kbuf->kp.signo = (char)sig;
+ NETBSD32PTR32(kbuf->kp.action, action);
+ kbuf->kp.mask = *mask;
+
+ if (ksi) {
+ kbuf->kp.code = KSI_TRAPCODE(ksi);
+ (void)memset(&kbuf->si, 0, sizeof(kbuf->si));
+ netbsd32_ksi_to_ksi32(&kbuf->si._info, &ksi->ksi_info);
+ ktesethdrlen(kte, sizeof(*kbuf));
+ } else {
+ kbuf->kp.code = 0;
+ ktesethdrlen(kte, sizeof(struct netbsd32_ktr_psig));
+ }
+
+ ktraddentry(l, kte, KTA_WAITOK);
+}
+
+
diff -r be7d64bed75b -r c1566b264839 sys/kern/kern_ktrace.c
--- a/sys/kern/kern_ktrace.c Tue Sep 13 07:30:32 2016 +0000
+++ b/sys/kern/kern_ktrace.c Tue Sep 13 07:39:45 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_ktrace.c,v 1.168 2016/09/13 07:01:08 martin Exp $ */
+/* $NetBSD: kern_ktrace.c,v 1.169 2016/09/13 07:39:45 martin Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.168 2016/09/13 07:01:08 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.169 2016/09/13 07:39:45 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -126,8 +126,6 @@
kcondvar_t ktd_cv;
};
-static int ktealloc(struct ktrace_entry **, void **, lwp_t *, int,
- size_t);
static void ktrwrite(struct ktr_desc *, struct ktrace_entry *);
static int ktrops(lwp_t *, struct proc *, int, int,
struct ktr_desc *);
@@ -142,11 +140,6 @@
ktd_lookup(file_t *);
static void ktdrel(struct ktr_desc *);
static void ktdref(struct ktr_desc *);
-static void ktraddentry(lwp_t *, struct ktrace_entry *, int);
-/* Flags for ktraddentry (3rd arg) */
-#define KTA_NOWAIT 0x0000
-#define KTA_WAITOK 0x0001
-#define KTA_LARGE 0x0002
static void ktefree(struct ktrace_entry *);
static void ktd_logerrl(struct ktr_desc *, int);
static void ktrace_thread(void *);
@@ -538,6 +531,12 @@
}
void
+ktesethdrlen(struct ktrace_entry *kte, size_t l)
+{
+ kte->kte_kth.ktr_len = l;
+}
+
+void
ktr_syscall(register_t code, const register_t args[], int narg)
{
lwp_t *l = curlwp;
diff -r be7d64bed75b -r c1566b264839 sys/kern/kern_sig.c
--- a/sys/kern/kern_sig.c Tue Sep 13 07:30:32 2016 +0000
+++ b/sys/kern/kern_sig.c Tue Sep 13 07:39:45 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_sig.c,v 1.329 2016/08/21 15:24:17 hannken Exp $ */
+/* $NetBSD: kern_sig.c,v 1.330 2016/09/13 07:39:45 martin Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.329 2016/08/21 15:24:17 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.330 2016/09/13 07:39:45 martin Exp $");
#include "opt_ptrace.h"
#include "opt_dtrace.h"
@@ -913,8 +913,14 @@
kpsendsig(l, ksi, mask);
mutex_exit(p->p_lock);
if (ktrpoint(KTR_PSIG)) {
- ktrpsig(signo, SIGACTION_PS(ps, signo).sa_handler,
- mask, ksi);
+ if (p->p_emul->e_ktrpsig)
+ p->p_emul->e_ktrpsig(signo,
+ SIGACTION_PS(ps, signo).sa_handler,
+ mask, ksi);
+ else
+ ktrpsig(signo,
+ SIGACTION_PS(ps, signo).sa_handler,
+ mask, ksi);
}
} else {
/* XXX for core dump/debugger */
@@ -1860,7 +1866,11 @@
if (ktrpoint(KTR_PSIG)) {
mutex_exit(p->p_lock);
- ktrpsig(signo, action, returnmask, &ksi);
+ if (p->p_emul->e_ktrpsig)
+ p->p_emul->e_ktrpsig(signo, action,
+ returnmask, &ksi);
+ else
+ ktrpsig(signo, action, returnmask, &ksi);
mutex_enter(p->p_lock);
}
diff -r be7d64bed75b -r c1566b264839 sys/sys/ktrace.h
--- a/sys/sys/ktrace.h Tue Sep 13 07:30:32 2016 +0000
+++ b/sys/sys/ktrace.h Tue Sep 13 07:39:45 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ktrace.h,v 1.64 2016/09/13 07:01:08 martin Exp $ */
+/* $NetBSD: ktrace.h,v 1.65 2016/09/13 07:39:45 martin Exp $ */
/*
* Copyright (c) 1988, 1993
@@ -432,6 +432,15 @@
ktr_execfd(fd, dtype);
}
+struct ktrace_entry;
+int ktealloc(struct ktrace_entry **, void **, lwp_t *, int, size_t);
+void ktesethdrlen(struct ktrace_entry *, size_t);
+void ktraddentry(lwp_t *, struct ktrace_entry *, int);
+/* Flags for ktraddentry (3rd arg) */
+#define KTA_NOWAIT 0x0000
+#define KTA_WAITOK 0x0001
+#define KTA_LARGE 0x0002
+
#endif /* !_KERNEL */
#endif /* _SYS_KTRACE_H_ */
diff -r be7d64bed75b -r c1566b264839 sys/sys/proc.h
--- a/sys/sys/proc.h Tue Sep 13 07:30:32 2016 +0000
+++ b/sys/sys/proc.h Tue Sep 13 07:39:45 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: proc.h,v 1.331 2016/06/10 23:24:33 christos Exp $ */
+/* $NetBSD: proc.h,v 1.332 2016/09/13 07:39:45 martin Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
Home |
Main Index |
Thread Index |
Old Index