Add the utrace(caddr_t addr,size_t len) syscall, that will store the
data pointed at in a ktrace file, if this process is being ktrace'ed. I'm using this to profile malloc usage. The advantage is that there is no context around this call, ie, no open file or socket, so it will work in any process, and you can decide if you want it to collect data or not.
This commit is contained in:
parent
030e2e9ebb
commit
e6c4b9ba32
@ -239,7 +239,7 @@ struct sysent sysent[] = {
|
||||
{ 6, (sy_call_t *)__sysctl }, /* 202 = __sysctl */
|
||||
{ 2, (sy_call_t *)mlock }, /* 203 = mlock */
|
||||
{ 2, (sy_call_t *)munlock }, /* 204 = munlock */
|
||||
{ 0, (sy_call_t *)nosys }, /* 205 = nosys */
|
||||
{ 2, (sy_call_t *)utrace }, /* 205 = utrace */
|
||||
{ 0, (sy_call_t *)nosys }, /* 206 = nosys */
|
||||
{ 0, (sy_call_t *)nosys }, /* 207 = nosys */
|
||||
{ 0, (sy_call_t *)nosys }, /* 208 = nosys */
|
||||
|
@ -31,7 +31,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)kern_ktrace.c 8.2 (Berkeley) 9/23/93
|
||||
* $Id: kern_ktrace.c,v 1.11 1996/03/11 06:03:23 hsu Exp $
|
||||
* $Id: kern_ktrace.c,v 1.12 1996/08/04 20:13:07 phk Exp $
|
||||
*/
|
||||
|
||||
#include "opt_ktrace.h"
|
||||
@ -346,6 +346,45 @@ ktrace(curp, uap, retval)
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* utrace system call
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
int
|
||||
utrace(curp, uap, retval)
|
||||
struct proc *curp;
|
||||
register struct utrace_args *uap;
|
||||
int *retval;
|
||||
{
|
||||
#ifdef KTRACE
|
||||
register struct ktr_user *ktp;
|
||||
struct ktr_header *kth;
|
||||
struct proc *p = curproc; /* XXX */
|
||||
register caddr_t cp;
|
||||
|
||||
if (!KTRPOINT(p, KTR_USER))
|
||||
return (0);
|
||||
p->p_traceflag |= KTRFAC_ACTIVE;
|
||||
kth = ktrgetheader(KTR_USER);
|
||||
MALLOC(ktp, struct ktr_user *, sizeof(struct ktr_user) + uap->len,
|
||||
M_KTRACE, M_WAITOK);
|
||||
ktp->len = uap->len;
|
||||
cp = (caddr_t)((char *)ktp + sizeof (struct ktr_user));
|
||||
if (!copyin(uap->addr, cp, uap->len)) {
|
||||
kth->ktr_buf = (caddr_t)ktp;
|
||||
kth->ktr_len = sizeof (struct ktr_user) + uap->len;
|
||||
ktrwrite(p->p_tracep, kth);
|
||||
}
|
||||
FREE(kth, M_KTRACE);
|
||||
FREE(ktp, M_KTRACE);
|
||||
p->p_traceflag &= ~KTRFAC_ACTIVE;
|
||||
|
||||
return (0);
|
||||
#else
|
||||
return (ENOSYS);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef KTRACE
|
||||
static int
|
||||
ktrops(curp, p, ops, facs, vp)
|
||||
|
@ -226,7 +226,7 @@ char *syscallnames[] = {
|
||||
"__sysctl", /* 202 = __sysctl */
|
||||
"mlock", /* 203 = mlock */
|
||||
"munlock", /* 204 = munlock */
|
||||
"#205", /* 205 = nosys */
|
||||
"utrace", /* 205 = utrace */
|
||||
"#206", /* 206 = nosys */
|
||||
"#207", /* 207 = nosys */
|
||||
"#208", /* 208 = nosys */
|
||||
|
@ -1,4 +1,4 @@
|
||||
$Id: syscalls.master,v 1.27 1996/03/02 16:51:25 peter Exp $
|
||||
$Id: syscalls.master,v 1.28 1996/08/20 07:17:49 smpatel Exp $
|
||||
; from: @(#)syscalls.master 8.2 (Berkeley) 1/13/94
|
||||
;
|
||||
; System call name/number master file.
|
||||
@ -322,7 +322,7 @@
|
||||
; here allows to avoid one in libc/sys/Makefile.inc.
|
||||
203 STD BSD { int mlock(caddr_t addr, size_t len); }
|
||||
204 STD BSD { int munlock(caddr_t addr, size_t len); }
|
||||
205 UNIMPL NOHIDE nosys
|
||||
205 STD BSD { int utrace(caddr_t addr, size_t len); }
|
||||
206 UNIMPL NOHIDE nosys
|
||||
207 UNIMPL NOHIDE nosys
|
||||
208 UNIMPL NOHIDE nosys
|
||||
|
@ -31,7 +31,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)ktrace.h 8.1 (Berkeley) 6/2/93
|
||||
* $Id: ktrace.h,v 1.7 1995/03/16 18:16:19 bde Exp $
|
||||
* $Id: ktrace.h,v 1.8 1995/12/14 08:32:31 phk Exp $
|
||||
*/
|
||||
|
||||
#ifndef _SYS_KTRACE_H_
|
||||
@ -132,6 +132,17 @@ struct ktr_csw {
|
||||
int user; /* 1 if usermode (ivcsw), 0 if kernel (vcsw) */
|
||||
};
|
||||
|
||||
/*
|
||||
* KTR_USER - data comming from userland
|
||||
*/
|
||||
#define KTR_USER 7
|
||||
struct ktr_user {
|
||||
int len; /* number of bytes */
|
||||
/*
|
||||
* followed by data provided by user
|
||||
*/
|
||||
};
|
||||
|
||||
/*
|
||||
* kernel trace points (in p_traceflag)
|
||||
*/
|
||||
@ -142,6 +153,7 @@ struct ktr_csw {
|
||||
#define KTRFAC_GENIO (1<<KTR_GENIO)
|
||||
#define KTRFAC_PSIG (1<<KTR_PSIG)
|
||||
#define KTRFAC_CSW (1<<KTR_CSW)
|
||||
#define KTRFAC_USER (1<<KTR_USER)
|
||||
/*
|
||||
* trace flags (also in p_traceflags)
|
||||
*/
|
||||
@ -163,6 +175,7 @@ void ktrsysret __P((struct vnode *, int, int, int));
|
||||
|
||||
__BEGIN_DECLS
|
||||
int ktrace __P((const char *, int, int, pid_t));
|
||||
int utrace __P((const caddr_t , size_t));
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !KERNEL */
|
||||
|
@ -196,6 +196,7 @@ HIDE_BSD(ftruncate)
|
||||
HIDE_BSD(__sysctl)
|
||||
HIDE_BSD(mlock)
|
||||
HIDE_BSD(munlock)
|
||||
HIDE_BSD(utrace)
|
||||
HIDE_BSD(__semctl)
|
||||
HIDE_BSD(semget)
|
||||
HIDE_BSD(semop)
|
||||
|
@ -190,6 +190,7 @@
|
||||
#define SYS___sysctl 202
|
||||
#define SYS_mlock 203
|
||||
#define SYS_munlock 204
|
||||
#define SYS_utrace 205
|
||||
#define SYS___semctl 220
|
||||
#define SYS_semget 221
|
||||
#define SYS_semop 222
|
||||
|
@ -653,6 +653,10 @@ struct munlock_args {
|
||||
caddr_t addr;
|
||||
size_t len;
|
||||
};
|
||||
struct utrace_args {
|
||||
caddr_t addr;
|
||||
size_t len;
|
||||
};
|
||||
struct __semctl_args {
|
||||
int semid;
|
||||
int semnum;
|
||||
@ -873,6 +877,7 @@ int ftruncate __P((struct proc *, struct ftruncate_args *, int []));
|
||||
int __sysctl __P((struct proc *, struct sysctl_args *, int []));
|
||||
int mlock __P((struct proc *, struct mlock_args *, int []));
|
||||
int munlock __P((struct proc *, struct munlock_args *, int []));
|
||||
int utrace __P((struct proc *, struct utrace_args *, int []));
|
||||
int lkmnosys __P((struct proc *, struct nosys_args *, int []));
|
||||
int __semctl __P((struct proc *, struct __semctl_args *, int []));
|
||||
int semget __P((struct proc *, struct semget_args *, int []));
|
||||
|
Loading…
Reference in New Issue
Block a user