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 /sys/kern | |
parent | 7cdbb0a9da84b2132739098e79e1d64e2be81c79 (diff) |
Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@
Diffstat (limited to 'sys/kern')
-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 |
4 files changed, 73 insertions, 7 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); } |