1 /* $NetBSD: ktrace.h,v 1.22 2001/01/05 22:25:27 jdolecek Exp $ */ 2 3 /* 4 * Copyright (c) 1988, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)ktrace.h 8.2 (Berkeley) 2/19/95 36 */ 37 38 #ifndef _SYS_KTRACE_H_ 39 #define _SYS_KTRACE_H_ 40 41 /* 42 * operations to ktrace system call (KTROP(op)) 43 */ 44 #define KTROP_SET 0 /* set trace points */ 45 #define KTROP_CLEAR 1 /* clear trace points */ 46 #define KTROP_CLEARFILE 2 /* stop all tracing to file */ 47 #define KTROP_MASK 0x3 48 #define KTROP(o) ((o)&KTROP_MASK) /* macro to extract operation */ 49 /* 50 * flags (ORed in with operation) 51 */ 52 #define KTRFLAG_DESCEND 4 /* perform op on all children too */ 53 54 /* 55 * ktrace record header 56 */ 57 struct ktr_header { 58 int ktr_len; /* length of buf */ 59 short ktr_type; /* trace record type */ 60 pid_t ktr_pid; /* process id */ 61 char ktr_comm[MAXCOMLEN+1]; /* command name */ 62 struct timeval ktr_time; /* timestamp */ 63 caddr_t ktr_buf; 64 }; 65 66 /* 67 * Test for kernel trace point 68 */ 69 #define KTRPOINT(p, type) \ 70 (((p)->p_traceflag & ((1<<(type))|KTRFAC_ACTIVE)) == (1<<(type))) 71 72 /* 73 * ktrace record types 74 */ 75 76 /* 77 * KTR_SYSCALL - system call record 78 */ 79 #define KTR_SYSCALL 1 80 struct ktr_syscall { 81 int ktr_code; /* syscall number */ 82 int ktr_argsize; /* size of arguments */ 83 /* 84 * followed by ktr_argsize/sizeof(register_t) "register_t"s 85 */ 86 }; 87 88 /* 89 * KTR_SYSRET - return from system call record 90 */ 91 #define KTR_SYSRET 2 92 struct ktr_sysret { 93 short ktr_code; 94 short ktr_eosys; /* XXX unused */ 95 int ktr_error; 96 register_t ktr_retval; 97 }; 98 99 /* 100 * KTR_NAMEI - namei record 101 */ 102 #define KTR_NAMEI 3 103 /* record contains pathname */ 104 105 /* 106 * KTR_GENIO - trace generic process i/o 107 */ 108 #define KTR_GENIO 4 109 struct ktr_genio { 110 int ktr_fd; 111 enum uio_rw ktr_rw; 112 /* 113 * followed by data successfully read/written 114 */ 115 }; 116 117 /* 118 * KTR_PSIG - trace processed signal 119 */ 120 #define KTR_PSIG 5 121 struct ktr_psig { 122 int signo; 123 sig_t action; 124 sigset_t mask; 125 int code; 126 }; 127 128 /* 129 * KTR_CSW - trace context switches 130 */ 131 #define KTR_CSW 6 132 struct ktr_csw { 133 int out; /* 1 if switch out, 0 if switch in */ 134 int user; /* 1 if usermode (ivcsw), 0 if kernel (vcsw) */ 135 }; 136 137 /* 138 * KTR_EMUL - emulation change 139 */ 140 #define KTR_EMUL 7 141 /* record contains emulation name */ 142 143 /* 144 * KTR_USER - user record 145 */ 146 #define KTR_USER 8 147 #define KTR_USER_MAXIDLEN 20 148 #define KTR_USER_MAXLEN 2048 /* maximum length of passed data */ 149 struct ktr_user { 150 char ktr_id[KTR_USER_MAXIDLEN]; /* string id of caller */ 151 /* 152 * Followed by ktr_len - sizeof(struct ktr_user) of user data. 153 */ 154 }; 155 156 /* 157 * kernel trace points (in p_traceflag) 158 */ 159 #define KTRFAC_MASK 0x00ffffff 160 #define KTRFAC_SYSCALL (1<<KTR_SYSCALL) 161 #define KTRFAC_SYSRET (1<<KTR_SYSRET) 162 #define KTRFAC_NAMEI (1<<KTR_NAMEI) 163 #define KTRFAC_GENIO (1<<KTR_GENIO) 164 #define KTRFAC_PSIG (1<<KTR_PSIG) 165 #define KTRFAC_CSW (1<<KTR_CSW) 166 #define KTRFAC_EMUL (1<<KTR_EMUL) 167 #define KTRFAC_USER (1<<KTR_USER) 168 /* 169 * trace flags (also in p_traceflags) 170 */ 171 #define KTRFAC_ROOT 0x80000000 /* root set this trace */ 172 #define KTRFAC_INHERIT 0x40000000 /* pass trace flags to children */ 173 #define KTRFAC_ACTIVE 0x20000000 /* ktrace logging in progress, ignore */ 174 175 #ifndef _KERNEL 176 177 #include <sys/cdefs.h> 178 179 __BEGIN_DECLS 180 int ktrace __P((const char *, int, int, pid_t)); 181 int fktrace __P((int, int, int, pid_t)); 182 int utrace __P((const char *, void *, size_t)); 183 __END_DECLS 184 185 #else 186 187 void ktrcsw __P((struct proc *, int, int)); 188 void ktremul __P((struct proc *)); 189 void ktrgenio __P((struct proc *, int, enum uio_rw, struct iovec *, int, int)); 190 void ktrnamei __P((struct proc *, char *)); 191 void ktrpsig __P((struct proc *, int, sig_t, sigset_t *, int)); 192 void ktrsyscall __P((struct proc *, register_t, size_t, register_t [])); 193 void ktrsysret __P((struct proc *, register_t, int, register_t)); 194 void ktruser __P((struct proc *, const char *, void *, size_t, int)); 195 void ktrderef __P((struct proc *)); 196 void ktradref __P((struct proc *)); 197 198 #endif /* !_KERNEL */ 199 200 #endif /* _SYS_KTRACE_H_ */ 201