diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2011-07-08 19:28:39 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2011-07-08 19:28:39 +0000 |
commit | dfa0ffc7c86951f332886c661e930a834f5c9a36 (patch) | |
tree | 0a28f66f3a8e7dca583b98c9de12dbfcaac78e3a | |
parent | 7cdbb0a9da84b2132739098e79e1d64e2be81c79 (diff) |
Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@
-rw-r--r-- | sys/kern/kern_descrip.c | 7 | ||||
-rw-r--r-- | sys/kern/kern_ktrace.c | 26 | ||||
-rw-r--r-- | sys/kern/uipc_syscalls.c | 40 | ||||
-rw-r--r-- | sys/kern/vfs_syscalls.c | 7 | ||||
-rw-r--r-- | sys/sys/ktrace.h | 21 |
5 files changed, 93 insertions, 8 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 0d3a6d1a627..7ead57404e6 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_descrip.c,v 1.86 2011/04/02 17:04:35 guenther Exp $ */ +/* $OpenBSD: kern_descrip.c,v 1.87 2011/07/08 19:28:36 otto Exp $ */ /* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */ /* @@ -59,6 +59,7 @@ #include <sys/syscallargs.h> #include <sys/event.h> #include <sys/pool.h> +#include <sys/ktrace.h> #include <uvm/uvm_extern.h> @@ -632,6 +633,10 @@ sys_fstat(struct proc *p, void *v, register_t *retval) error = copyout((caddr_t)&ub, (caddr_t)SCARG(uap, sb), sizeof (ub)); } +#ifdef KTRACE + if (error == 0 && KTRPOINT(p, KTR_STRUCT)) + ktrstat(p, &ub); +#endif return (error); } diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index 4ca73fced3c..09eb8d1d842 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_ktrace.c,v 1.52 2011/07/07 18:11:24 art Exp $ */ +/* $OpenBSD: kern_ktrace.c,v 1.53 2011/07/08 19:28:36 otto Exp $ */ /* $NetBSD: kern_ktrace.c,v 1.23 1996/02/09 18:59:36 christos Exp $ */ /* @@ -278,6 +278,30 @@ ktrcsw(struct proc *p, int out, int user) p->p_traceflag &= ~KTRFAC_ACTIVE; } +void +ktrstruct(struct proc *p, const char *name, const void *data, size_t datalen) +{ + struct ktr_header kth; + void *buf; + size_t buflen; + + p->p_traceflag |= KTRFAC_ACTIVE; + ktrinitheader(&kth, p, KTR_STRUCT); + + if (data == NULL) + datalen = 0; + buflen = strlen(name) + 1 + datalen; + buf = malloc(buflen, M_TEMP, M_WAITOK); + strlcpy(buf, name, buflen); + bcopy(data, buf + strlen(name) + 1, datalen); + kth.ktr_buf = buf; + kth.ktr_len = buflen; + + ktrwrite(p, &kth); + free(buf, M_TEMP); + p->p_traceflag &= ~KTRFAC_ACTIVE; +} + /* Interface and common routines */ /* diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 2189694e6b6..d9f707e82f0 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_syscalls.c,v 1.80 2011/07/08 05:01:27 matthew Exp $ */ +/* $OpenBSD: uipc_syscalls.c,v 1.81 2011/07/08 19:28:38 otto Exp $ */ /* $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $ */ /* @@ -114,6 +114,10 @@ sys_bind(struct proc *p, void *v, register_t *retval) error = sockargs(&nam, SCARG(uap, name), SCARG(uap, namelen), MT_SONAME); if (error == 0) { +#ifdef KTRACE + if (KTRPOINT(p, KTR_STRUCT)) + ktrsockaddr(p, mtod(nam, caddr_t), SCARG(uap, namelen)); +#endif error = sobind(fp->f_data, nam, p); m_freem(nam); } @@ -231,9 +235,14 @@ sys_accept(struct proc *p, void *v, register_t *retval) namelen = nam->m_len; /* SHOULD COPY OUT A CHAIN HERE */ if ((error = copyout(mtod(nam, caddr_t), - SCARG(uap, name), namelen)) == 0) + SCARG(uap, name), namelen)) == 0) { +#ifdef KTRACE + if (KTRPOINT(p, KTR_STRUCT)) + ktrsockaddr(p, mtod(nam, caddr_t), namelen); +#endif error = copyout(&namelen, SCARG(uap, anamelen), sizeof (*SCARG(uap, anamelen))); + } } /* if an error occurred, free the file descriptor */ if (error) { @@ -276,6 +285,10 @@ sys_connect(struct proc *p, void *v, register_t *retval) MT_SONAME); if (error) goto bad; +#ifdef KTRACE + if (KTRPOINT(p, KTR_STRUCT)) + ktrsockaddr(p, mtod(nam, caddr_t), SCARG(uap, namelen)); +#endif error = soconnect(so, nam); if (error) goto bad; @@ -481,6 +494,10 @@ sendit(struct proc *p, int s, struct msghdr *mp, int flags, register_t *retsize) MT_SONAME); if (error) goto bad; +#ifdef KTRACE + if (KTRPOINT(p, KTR_STRUCT)) + ktrsockaddr(p, mtod(to, caddr_t), mp->msg_namelen); +#endif } if (mp->msg_control) { if (mp->msg_controllen < CMSG_ALIGN(sizeof(struct cmsghdr)) @@ -703,6 +720,11 @@ recvit(struct proc *p, int s, struct msghdr *mp, caddr_t namelenp, error = copyout(mtod(from, caddr_t), mp->msg_name, alen); if (error) goto out; +#ifdef KTRACE + if (KTRPOINT(p, KTR_STRUCT)) + ktrsockaddr(p, mtod(from, caddr_t), alen); +#endif + } mp->msg_namelen = alen; if (namelenp && @@ -917,8 +939,13 @@ sys_getsockname(struct proc *p, void *v, register_t *retval) if (len > m->m_len) len = m->m_len; error = copyout(mtod(m, caddr_t), SCARG(uap, asa), len); - if (error == 0) + if (error == 0) { +#ifdef KTRACE + if (KTRPOINT(p, KTR_STRUCT)) + ktrsockaddr(p, mtod(m, caddr_t), len); +#endif error = copyout(&len, SCARG(uap, alen), sizeof (len)); + } bad: FRELE(fp); if (m) @@ -961,8 +988,13 @@ sys_getpeername(struct proc *p, void *v, register_t *retval) if (len > m->m_len) len = m->m_len; error = copyout(mtod(m, caddr_t), SCARG(uap, asa), len); - if (error == 0) + if (error == 0) { +#ifdef KTRACE + if (KTRPOINT(p, KTR_STRUCT)) + ktrsockaddr(p, mtod(m, caddr_t), len); +#endif error = copyout(&len, SCARG(uap, alen), sizeof (len)); + } bad: FRELE(fp); m_freem(m); diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 10b8d420d5f..4f94147b51a 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_syscalls.c,v 1.170 2011/07/08 04:23:24 matthew Exp $ */ +/* $OpenBSD: vfs_syscalls.c,v 1.171 2011/07/08 19:28:38 otto Exp $ */ /* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */ /* @@ -53,6 +53,7 @@ #include <sys/dirent.h> #include <sys/dkio.h> #include <sys/disklabel.h> +#include <sys/ktrace.h> #include <sys/syscallargs.h> @@ -1710,6 +1711,10 @@ dofstatat(struct proc *p, int fd, const char *path, struct stat *buf, if (suser(p, 0)) sb.st_gen = 0; error = copyout(&sb, buf, sizeof(sb)); +#ifdef KTRACE + if (error == 0 && KTRPOINT(p, KTR_STRUCT)) + ktrstat(p, &sb); +#endif return (error); } diff --git a/sys/sys/ktrace.h b/sys/sys/ktrace.h index c3273354dc1..fb6442eca38 100644 --- a/sys/sys/ktrace.h +++ b/sys/sys/ktrace.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ktrace.h,v 1.10 2011/06/02 16:19:12 deraadt Exp $ */ +/* $OpenBSD: ktrace.h,v 1.11 2011/07/08 19:28:38 otto Exp $ */ /* $NetBSD: ktrace.h,v 1.12 1996/02/04 02:12:29 christos Exp $ */ /* @@ -134,6 +134,16 @@ struct ktr_csw { #define KTR_EMUL 7 /* record contains emulation name */ +/* + * KTR_STRUCT - misc. structs + */ +#define KTR_STRUCT 8 + /* + * record contains null-terminated struct name followed by + * struct contents + */ +struct sockaddr; +struct stat; /* * kernel trace points (in p_traceflag) @@ -146,6 +156,8 @@ struct ktr_csw { #define KTRFAC_PSIG (1<<KTR_PSIG) #define KTRFAC_CSW (1<<KTR_CSW) #define KTRFAC_EMUL (1<<KTR_EMUL) +#define KTRFAC_STRUCT (1<<KTR_STRUCT) + /* * trace flags (also in p_traceflags) */ @@ -173,4 +185,11 @@ void ktrsysret(struct proc *, register_t, int, register_t); void ktrsettracevnode(struct proc *, struct vnode *); +void ktrstruct(struct proc *, const char *, const void *, size_t); +#define ktrsockaddr(p, s, l) \ + ktrstruct((p), "sockaddr", (s), (l)) +#define ktrstat(p, s) \ + ktrstruct((p), "stat", (s), sizeof(struct stat)) + + #endif /* !_KERNEL */ |