FreeBSD/Linux Kernel Cross Reference
sys/sys/ktrace.h
1 /* $NetBSD: ktrace.h,v 1.55 2008/10/20 11:36:39 ad 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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)ktrace.h 8.2 (Berkeley) 2/19/95
32 */
33
34 #ifndef _SYS_KTRACE_H_
35 #define _SYS_KTRACE_H_
36
37 #include <sys/mutex.h>
38
39 /*
40 * operations to ktrace system call (KTROP(op))
41 */
42 #define KTROP_SET 0 /* set trace points */
43 #define KTROP_CLEAR 1 /* clear trace points */
44 #define KTROP_CLEARFILE 2 /* stop all tracing to file */
45 #define KTROP_MASK 0x3
46 #define KTROP(o) ((o)&KTROP_MASK) /* macro to extract operation */
47 /*
48 * flags (ORed in with operation)
49 */
50 #define KTRFLAG_DESCEND 4 /* perform op on all children too */
51
52 /*
53 * ktrace record header
54 */
55 struct ktr_header {
56 int ktr_len; /* length of record minus length of old header */
57 #if BYTE_ORDER == LITTLE_ENDIAN
58 short ktr_type; /* trace record type */
59 short ktr_version; /* trace record version */
60 #else
61 short ktr_version; /* trace record version */
62 short ktr_type; /* trace record type */
63 #endif
64 pid_t ktr_pid; /* process id */
65 char ktr_comm[MAXCOMLEN+1]; /* command name */
66 union {
67 struct timeval _tv; /* v0 timestamp */
68 struct timespec _ts; /* v1 timespec */
69 } _ktr_time;
70 union {
71 const void *_buf; /* v0 unused */
72 lwpid_t _lid; /* v1 lwp id */
73 } _ktr_id;
74 };
75
76 #define ktr_lid _ktr_id._lid
77 #define ktr_time _ktr_time._ts
78 #define ktr_tv _ktr_time._tv
79 #define ktr_ts _ktr_time._ts
80 #define ktr_unused _ktr_id._buf
81
82 #define KTR_SHIMLEN offsetof(struct ktr_header, ktr_pid)
83
84 /*
85 * Test for kernel trace point
86 */
87 #define KTRPOINT(p, type) \
88 (((p)->p_traceflag & (1<<(type))) != 0)
89
90 /*
91 * ktrace record types
92 */
93
94 /*
95 * KTR_SYSCALL - system call record
96 */
97 #define KTR_SYSCALL 1
98 struct ktr_syscall {
99 int ktr_code; /* syscall number */
100 int ktr_argsize; /* size of arguments */
101 /*
102 * followed by ktr_argsize/sizeof(register_t) "register_t"s
103 */
104 };
105
106 /*
107 * KTR_SYSRET - return from system call record
108 */
109 #define KTR_SYSRET 2
110 struct ktr_sysret {
111 short ktr_code;
112 short ktr_eosys; /* XXX unused */
113 int ktr_error;
114 register_t ktr_retval;
115 register_t ktr_retval_1;
116 };
117
118 /*
119 * KTR_NAMEI - namei record
120 */
121 #define KTR_NAMEI 3
122 /* record contains pathname */
123
124 /*
125 * KTR_GENIO - trace generic process i/o
126 */
127 #define KTR_GENIO 4
128 struct ktr_genio {
129 int ktr_fd;
130 enum uio_rw ktr_rw;
131 /*
132 * followed by data successfully read/written
133 */
134 };
135
136 /*
137 * KTR_PSIG - trace processed signal
138 */
139 #define KTR_PSIG 5
140 struct ktr_psig {
141 int signo;
142 sig_t action;
143 sigset_t mask;
144 int code;
145 /*
146 * followed by optional siginfo_t
147 */
148 };
149
150 /*
151 * KTR_CSW - trace context switches
152 */
153 #define KTR_CSW 6
154 struct ktr_csw {
155 int out; /* 1 if switch out, 0 if switch in */
156 int user; /* 1 if usermode (ivcsw), 0 if kernel (vcsw) */
157 };
158
159 /*
160 * KTR_EMUL - emulation change
161 */
162 #define KTR_EMUL 7
163 /* record contains emulation name */
164
165 /*
166 * KTR_USER - user record
167 */
168 #define KTR_USER 8
169 #define KTR_USER_MAXIDLEN 20
170 #define KTR_USER_MAXLEN 2048 /* maximum length of passed data */
171 struct ktr_user {
172 char ktr_id[KTR_USER_MAXIDLEN]; /* string id of caller */
173 /*
174 * Followed by ktr_len - sizeof(struct ktr_user) of user data.
175 */
176 };
177
178 /*
179 * KTR_MMSG - Mach message
180 */
181 #define KTR_MMSG 9
182 struct ktr_mmsg {
183 /*
184 * This is a Mach message header
185 */
186 int ktr_bits;
187 int ktr_size;
188 int ktr_remote_port;
189 int ktr_local_port;
190 int ktr_reserved;
191 int ktr_id;
192 /*
193 * Followed by ktr_size - sizeof(mach_msg_header_t) of message payload
194 */
195 };
196
197 /*
198 * KTR_EXEC_ARG, KTR_EXEC_ENV - Arguments and environment from exec
199 */
200 #define KTR_EXEC_ARG 10
201 #define KTR_EXEC_ENV 11
202 /* record contains arg/env string */
203
204 /*
205 * KTR_MOOL - Mach Out Of Line data
206 */
207 #define KTR_MOOL 12
208 struct ktr_mool {
209 const void *uaddr; /* User address */
210 size_t size; /* Data len */
211 /* Followed by size bytes of data */
212 };
213
214 /*
215 * KTR_SAUPCALL - scheduler activated upcall.
216 */
217 #define KTR_SAUPCALL 13
218 struct ktr_saupcall {
219 int ktr_type;
220 int ktr_nevent;
221 int ktr_nint;
222 void *ktr_sas;
223 void *ktr_ap;
224 /*
225 * followed by nevent sa_t's from sas[]
226 */
227 };
228
229 /*
230 * KTR_MIB - MIB name and data
231 */
232 #define KTR_MIB 14
233 /* Record contains MIB name */
234
235
236 /*
237 * kernel trace points (in p_traceflag)
238 */
239 #define KTRFAC_MASK 0x00ffffff
240 #define KTRFAC_SYSCALL (1<<KTR_SYSCALL)
241 #define KTRFAC_SYSRET (1<<KTR_SYSRET)
242 #define KTRFAC_NAMEI (1<<KTR_NAMEI)
243 #define KTRFAC_GENIO (1<<KTR_GENIO)
244 #define KTRFAC_PSIG (1<<KTR_PSIG)
245 #define KTRFAC_CSW (1<<KTR_CSW)
246 #define KTRFAC_EMUL (1<<KTR_EMUL)
247 #define KTRFAC_USER (1<<KTR_USER)
248 #define KTRFAC_MMSG (1<<KTR_MMSG)
249 #define KTRFAC_EXEC_ARG (1<<KTR_EXEC_ARG)
250 #define KTRFAC_EXEC_ENV (1<<KTR_EXEC_ENV)
251 #define KTRFAC_MOOL (1<<KTR_MOOL)
252 #define KTRFAC_SAUPCALL (1<<KTR_SAUPCALL)
253 #define KTRFAC_MIB (1<<KTR_MIB)
254 /*
255 * trace flags (also in p_traceflags)
256 */
257 #define KTRFAC_PERSISTENT 0x80000000 /* persistent trace across sugid
258 exec (exclusive) */
259 #define KTRFAC_INHERIT 0x40000000 /* pass trace flags to children */
260 #define KTRFAC_TRC_EMUL 0x10000000 /* ktrace KTR_EMUL before next trace */
261 #define KTRFAC_VER_MASK 0x0f000000 /* record version mask */
262 #define KTRFAC_VER_SHIFT 24 /* record version shift */
263
264 #define KTRFAC_VERSION(tf) (((tf) & KTRFAC_VER_MASK) >> KTRFAC_VER_SHIFT)
265
266 #define KTRFACv0 (0 << KTRFAC_VER_SHIFT)
267 #define KTRFACv1 (1 << KTRFAC_VER_SHIFT)
268
269 #ifndef _KERNEL
270
271 #include <sys/cdefs.h>
272
273 __BEGIN_DECLS
274 int ktrace(const char *, int, int, pid_t);
275 int fktrace(int, int, int, pid_t);
276 int utrace(const char *, void *, size_t);
277 __END_DECLS
278
279 #else
280
281 void ktrinit(void);
282 void ktrderef(struct proc *);
283 void ktradref(struct proc *);
284
285 extern kmutex_t ktrace_lock;
286 extern int ktrace_on;
287
288 int ktruser(const char *, void *, size_t, int);
289 bool ktr_point(int);
290
291 void ktr_csw(int, int);
292 void ktr_emul(void);
293 void ktr_geniov(int, enum uio_rw, struct iovec *, size_t, int);
294 void ktr_genio(int, enum uio_rw, const void *, size_t, int);
295 void ktr_mibio(int, enum uio_rw, const void *, size_t, int);
296 void ktr_namei(const char *, size_t);
297 void ktr_namei2(const char *, size_t, const char *, size_t);
298 void ktr_psig(int, sig_t, const sigset_t *, const ksiginfo_t *);
299 void ktr_syscall(register_t, const register_t [], int);
300 void ktr_sysret(register_t, int, register_t *);
301 void ktr_kuser(const char *, void *, size_t);
302 void ktr_mmsg(const void *, size_t);
303 void ktr_mib(const int *a , u_int b);
304 void ktr_mool(const void *, size_t, const void *);
305 void ktr_execarg(const void *, size_t);
306 void ktr_execenv(const void *, size_t);
307 void ktr_saupcall(struct lwp *, int, int, int, void *, void *, void *);
308
309 static inline bool
310 ktrpoint(int fac)
311 {
312 return __predict_false(ktrace_on) && __predict_false(ktr_point(1 << fac));
313 }
314
315 static inline void
316 ktrcsw(int a, int b)
317 {
318 if (__predict_false(ktrace_on))
319 ktr_csw(a, b);
320 }
321
322 static inline void
323 ktremul(void)
324 {
325 if (__predict_false(ktrace_on))
326 ktr_emul();
327 }
328
329 static inline void
330 ktrgenio(int a, enum uio_rw b, const void *c, size_t d, int e)
331 {
332 if (__predict_false(ktrace_on))
333 ktr_genio(a, b, c, d, e);
334 }
335
336 static inline void
337 ktrgeniov(int a, enum uio_rw b, struct iovec *c, int d, int e)
338 {
339 if (__predict_false(ktrace_on))
340 ktr_geniov(a, b, c, d, e);
341 }
342
343 static inline void
344 ktrmibio(int a, enum uio_rw b, const void *c, size_t d, int e)
345 {
346 if (__predict_false(ktrace_on))
347 ktr_mibio(a, b, c, d, e);
348 }
349
350 static inline void
351 ktrnamei(const char *a, size_t b)
352 {
353 if (__predict_false(ktrace_on))
354 ktr_namei(a, b);
355 }
356
357 static inline void
358 ktrnamei2(const char *a, size_t b, const char *c, size_t d)
359 {
360 if (__predict_false(ktrace_on))
361 ktr_namei2(a, b, c, d);
362 }
363
364 static inline void
365 ktrpsig(int a, sig_t b, const sigset_t *c, const ksiginfo_t * d)
366 {
367 if (__predict_false(ktrace_on))
368 ktr_psig(a, b, c, d);
369 }
370
371 static inline void
372 ktrsyscall(register_t code, const register_t args[], int narg)
373 {
374 if (__predict_false(ktrace_on))
375 ktr_syscall(code, args, narg);
376 }
377
378 static inline void
379 ktrsysret(register_t a, int b, register_t *c)
380 {
381 if (__predict_false(ktrace_on))
382 ktr_sysret(a, b, c);
383 }
384
385 static inline void
386 ktrkuser(const char *a, void *b, size_t c)
387 {
388 if (__predict_false(ktrace_on))
389 ktr_kuser(a, b, c);
390 }
391
392 static inline void
393 ktrmmsg(const void *a, size_t b)
394 {
395 if (__predict_false(ktrace_on))
396 ktr_mmsg(a, b);
397 }
398
399 static inline void
400 ktrmib(const int *a , u_int b)
401 {
402 if (__predict_false(ktrace_on))
403 ktr_mib(a, b);
404 }
405
406 static inline void
407 ktrmool(const void *a, size_t b, const void *c)
408 {
409 if (__predict_false(ktrace_on))
410 ktr_mool(a, b, c);
411 }
412
413 static inline void
414 ktrexecarg(const void *a, size_t b)
415 {
416 if (__predict_false(ktrace_on))
417 ktr_execarg(a, b);
418 }
419
420 static inline void
421 ktrexecenv(const void *a, size_t b)
422 {
423 if (__predict_false(ktrace_on))
424 ktr_execenv(a, b);
425 }
426
427 static inline void
428 ktrsaupcall(struct lwp *a, int b, int c, int d, void *e, void *f, void *g)
429 {
430 if (__predict_false(ktrace_on))
431 ktr_saupcall(a, b, c, d, e, f, g);
432 }
433
434 #endif /* !_KERNEL */
435
436 #endif /* _SYS_KTRACE_H_ */
Cache object: 4e07be33bd07bca56fc9df2f19c2c5f1
|