2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)ktrace.h 8.1 (Berkeley) 6/2/93
33 #ifndef _SYS_KTRACE_H_
34 #define _SYS_KTRACE_H_
37 * operations to ktrace system call (KTROP(op))
39 #define KTROP_SET 0 /* set trace points */
40 #define KTROP_CLEAR 1 /* clear trace points */
41 #define KTROP_CLEARFILE 2 /* stop all tracing to file */
42 #define KTROP(o) ((o)&3) /* macro to extract operation */
44 * flags (ORed in with operation)
46 #define KTRFLAG_DESCEND 4 /* perform op on all children too */
49 * ktrace record header
52 int ktr_len; /* length of buf */
53 short ktr_type; /* trace record type */
54 pid_t ktr_pid; /* process id */
55 char ktr_comm[MAXCOMLEN+1]; /* command name */
56 struct timeval ktr_time; /* timestamp */
57 intptr_t ktr_tid; /* was ktr_buffer */
61 * Test for kernel trace point (MP SAFE).
63 * KTRCHECK() just checks that the type is enabled and is only for
64 * internal use in the ktrace subsystem. KTRPOINT() checks against
65 * ktrace recursion as well as checking that the type is enabled and
66 * is the public interface.
68 #define KTRCHECK(td, type) ((td)->td_proc->p_traceflag & (1 << type))
69 #define KTRPOINT(td, type) \
70 (KTRCHECK((td), (type)) && !((td)->td_pflags & TDP_INKTRACE))
71 #define KTRCHECKDRAIN(td) (!(STAILQ_EMPTY(&(td)->td_proc->p_ktr)))
72 #define KTRUSERRET(td) do { \
73 if (KTRCHECKDRAIN(td)) \
76 #define KTRPROCEXIT(td) do { \
77 if (KTRCHECKDRAIN(td)) \
86 * KTR_SYSCALL - system call record
90 short ktr_code; /* syscall number */
91 short ktr_narg; /* number of arguments */
93 * followed by ktr_narg register_t
95 register_t ktr_args[1];
99 * KTR_SYSRET - return from system call record
106 register_t ktr_retval;
110 * KTR_NAMEI - namei record
113 /* record contains pathname */
116 * KTR_GENIO - trace generic process i/o
123 * followed by data successfully read/written
128 * KTR_PSIG - trace processed signal
139 * KTR_CSW - trace context switches
143 int out; /* 1 if switch out, 0 if switch in */
144 int user; /* 1 if usermode (ivcsw), 0 if kernel (vcsw) */
148 * KTR_USER - data coming from userland
150 #define KTR_USER_MAXLEN 2048 /* maximum length of passed data */
154 * KTR_STRUCT - misc. structs
161 * KTR_DROP - If this bit is set in ktr_type, then at least one event
162 * between the previous record and this record was dropped.
164 #define KTR_DROP 0x8000
167 * kernel trace points (in p_traceflag)
169 #define KTRFAC_MASK 0x00ffffff
170 #define KTRFAC_SYSCALL (1<<KTR_SYSCALL)
171 #define KTRFAC_SYSRET (1<<KTR_SYSRET)
172 #define KTRFAC_NAMEI (1<<KTR_NAMEI)
173 #define KTRFAC_GENIO (1<<KTR_GENIO)
174 #define KTRFAC_PSIG (1<<KTR_PSIG)
175 #define KTRFAC_CSW (1<<KTR_CSW)
176 #define KTRFAC_USER (1<<KTR_USER)
177 #define KTRFAC_STRUCT (1<<KTR_STRUCT)
179 * trace flags (also in p_traceflags)
181 #define KTRFAC_ROOT 0x80000000 /* root set this trace */
182 #define KTRFAC_INHERIT 0x40000000 /* pass trace flags to children */
183 #define KTRFAC_DROP 0x20000000 /* last event was dropped */
186 extern struct mtx ktrace_mtx;
188 void ktrnamei(char *);
189 void ktrcsw(int, int);
190 void ktrpsig(int, sig_t, sigset_t *, int);
191 void ktrgenio(int, enum uio_rw, struct uio *, int);
192 void ktrsyscall(int, int narg, register_t args[]);
193 void ktrsysret(int, int, register_t);
194 void ktrprocexit(struct thread *);
195 void ktruserret(struct thread *);
196 void ktrstruct(const char *, size_t, void *, size_t);
197 #define ktrsockaddr(s) \
198 ktrstruct("sockaddr", 8, (s), ((struct sockaddr *)(s))->sa_len)
200 ktrstruct("stat", 4, (s), sizeof(struct stat))
204 #include <sys/cdefs.h>
207 int ktrace(const char *, int, int, pid_t);
208 int utrace(const void *, size_t);