Add ktrace of env and args during exec.

This commit is contained in:
dsl 2003-07-16 22:42:47 +00:00
parent 5dbcc1e019
commit 0e2308c0c0
3 changed files with 40 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_exec.c,v 1.169 2003/06/29 22:31:19 fvdl Exp $ */
/* $NetBSD: kern_exec.c,v 1.170 2003/07/16 22:42:48 dsl Exp $ */
/*-
* Copyright (C) 1993, 1994, 1996 Christopher G. Demetriou
@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.169 2003/06/29 22:31:19 fvdl Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.170 2003/07/16 22:42:48 dsl Exp $");
#include "opt_ktrace.h"
#include "opt_syscall_debug.h"
@ -465,6 +465,10 @@ sys_execve(struct lwp *l, void *v, register_t *retval)
error = E2BIG;
goto bad;
}
#ifdef KTRACE
if (KTRPOINT(p, KTR_EXEC_ARG))
ktrkmem(p, KTR_EXEC_ARG, dp, len - 1);
#endif
dp += len;
cpp++;
argc++;
@ -484,6 +488,10 @@ sys_execve(struct lwp *l, void *v, register_t *retval)
error = E2BIG;
goto bad;
}
#ifdef KTRACE
if (KTRPOINT(p, KTR_EXEC_ENV))
ktrkmem(p, KTR_EXEC_ENV, dp, len - 1);
#endif
dp += len;
cpp++;
envc++;

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_ktrace.c,v 1.74 2003/06/29 22:31:21 fvdl Exp $ */
/* $NetBSD: kern_ktrace.c,v 1.75 2003/07/16 22:42:47 dsl Exp $ */
/*
* Copyright (c) 1989, 1993
@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.74 2003/06/29 22:31:21 fvdl Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.75 2003/07/16 22:42:47 dsl Exp $");
#include "opt_ktrace.h"
#include "opt_compat_mach.h"
@ -221,6 +221,20 @@ ktremul(p)
p->p_traceflag &= ~KTRFAC_ACTIVE;
}
void
ktrkmem(struct proc *p, int ktr, const void *buf, size_t len)
{
struct ktr_header kth;
p->p_traceflag |= KTRFAC_ACTIVE;
ktrinitheader(&kth, p, ktr);
kth.ktr_len = len;
kth.ktr_buf = buf;
(void)ktrwrite(p, &kth);
p->p_traceflag &= ~KTRFAC_ACTIVE;
}
void
ktrgenio(p, fd, rw, iov, len, error)
struct proc *p;
@ -696,7 +710,7 @@ ktrwrite(p, kth)
auio.uio_procp = (struct proc *)0;
if (kth->ktr_len > 0) {
auio.uio_iovcnt++;
aiov[1].iov_base = kth->ktr_buf;
aiov[1].iov_base = (void *)kth->ktr_buf;
aiov[1].iov_len = kth->ktr_len;
auio.uio_resid += kth->ktr_len;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ktrace.h,v 1.30 2003/06/29 22:32:25 fvdl Exp $ */
/* $NetBSD: ktrace.h,v 1.31 2003/07/16 22:42:47 dsl Exp $ */
/*
* Copyright (c) 1988, 1993
@ -55,12 +55,12 @@
* ktrace record header
*/
struct ktr_header {
int ktr_len; /* length of buf */
int ktr_len; /* length of ktr_buf */
short ktr_type; /* trace record type */
pid_t ktr_pid; /* process id */
char ktr_comm[MAXCOMLEN+1]; /* command name */
struct timeval ktr_time; /* timestamp */
caddr_t ktr_buf;
const void *ktr_buf;
};
/*
@ -173,6 +173,13 @@ struct ktr_mmsg {
*/
};
/*
* KTR_EXEC_ARG, KTR_EXEC_ENV - Arguments and environment from exec
*/
#define KTR_EXEC_ARG 10
#define KTR_EXEC_ENV 11
/* record contains arg/env string */
/*
* kernel trace points (in p_traceflag)
*/
@ -186,6 +193,8 @@ struct ktr_mmsg {
#define KTRFAC_EMUL (1<<KTR_EMUL)
#define KTRFAC_USER (1<<KTR_USER)
#define KTRFAC_MMSG (1<<KTR_MMSG)
#define KTRFAC_EXEC_ARG (1<<KTR_EXEC_ARG)
#define KTRFAC_EXEC_ENV (1<<KTR_EXEC_ENV)
/*
* trace flags (also in p_traceflags)
*/
@ -215,6 +224,7 @@ void ktrsyscall(struct proc *, register_t, register_t,
void ktrsysret(struct proc *, register_t, int, register_t *);
void ktruser(struct proc *, const char *, void *, size_t, int);
void ktrmmsg(struct proc *, const void *, size_t);
void ktrkmem(struct proc *, int, const void *, size_t);
void ktrderef(struct proc *);
void ktradref(struct proc *);