FreeBSD/Linux Kernel Cross Reference
sys/sys/ktrace.h
1 /* $OpenBSD: ktrace.h,v 1.44 2023/01/16 05:32:05 deraadt Exp $ */
2 /* $NetBSD: ktrace.h,v 1.12 1996/02/04 02:12:29 christos Exp $ */
3
4 /*
5 * Copyright (c) 1988, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @(#)ktrace.h 8.1 (Berkeley) 6/2/93
33 */
34
35 #include <sys/uio.h>
36 #include <sys/syslimits.h>
37
38 /*
39 * operations to ktrace system call (KTROP(op))
40 */
41 #define KTROP_SET 0 /* set trace points */
42 #define KTROP_CLEAR 1 /* clear trace points */
43 #define KTROP_CLEARFILE 2 /* stop all tracing to file */
44 #define KTROP(o) ((o)&3) /* macro to extract operation */
45 /*
46 * flags (ORed in with operation)
47 */
48 #define KTRFLAG_DESCEND 4 /* perform op on all children too */
49
50 /*
51 * ktrace record header
52 */
53 struct ktr_header {
54 uint ktr_type; /* trace record type */
55 pid_t ktr_pid; /* process id */
56 pid_t ktr_tid; /* thread id */
57 struct timespec ktr_time; /* timestamp */
58 char ktr_comm[_MAXCOMLEN]; /* command name, incl NUL */
59 size_t ktr_len; /* length of buf */
60 };
61
62 /*
63 * ktrace record types
64 */
65
66 /*
67 * KTR_START - start of trace record, one per ktrace(KTROP_SET) syscall
68 */
69 #define KTR_START 0x4b545200 /* "KTR" */
70
71 /*
72 * KTR_SYSCALL - system call record
73 */
74 #define KTR_SYSCALL 1
75 struct ktr_syscall {
76 int ktr_code; /* syscall number */
77 #define KTRC_CODE_MASK 0x0000ffff
78 #define KTRC_CODE_SYSCALL 0x20000000
79 #define KTRC_CODE__SYSCALL 0x40000000
80 int ktr_argsize; /* size of arguments */
81 /*
82 * followed by ktr_argsize/sizeof(register_t) "register_t"s
83 */
84 };
85
86 /*
87 * KTR_SYSRET - return from system call record
88 */
89 #define KTR_SYSRET 2
90 struct ktr_sysret {
91 int ktr_code;
92 int ktr_error;
93 /*
94 * If ktr_error is zero, then followed by retval: register_t for
95 * all syscalls except lseek(), which uses long long
96 */
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 int mask;
125 int code;
126 siginfo_t si;
127 };
128
129 /*
130 * KTR_STRUCT - misc. structs
131 */
132 #define KTR_STRUCT 8
133 /*
134 * record contains null-terminated struct name followed by
135 * struct contents
136 */
137 struct sockaddr;
138 struct stat;
139
140 /*
141 * KTR_USER - user record
142 */
143 #define KTR_USER 9
144 #define KTR_USER_MAXIDLEN 20
145 #define KTR_USER_MAXLEN 2048 /* maximum length of passed data */
146 struct ktr_user {
147 char ktr_id[KTR_USER_MAXIDLEN]; /* string id of caller */
148 /*
149 * Followed by ktr_len - sizeof(struct ktr_user) of user data.
150 */
151 };
152
153 /*
154 * KTR_EXECARGS and KTR_EXECENV - args and environment records
155 */
156 #define KTR_EXECARGS 10
157 #define KTR_EXECENV 11
158
159
160 /*
161 * KTR_PLEDGE - details of pledge violation
162 */
163 #define KTR_PLEDGE 12
164 struct ktr_pledge {
165 int error;
166 int syscall;
167 uint64_t code;
168 };
169
170 /*
171 * kernel trace points (in ps_traceflag)
172 */
173 #define KTRFAC_MASK 0x00ffffff
174 #define KTRFAC_SYSCALL (1<<KTR_SYSCALL)
175 #define KTRFAC_SYSRET (1<<KTR_SYSRET)
176 #define KTRFAC_NAMEI (1<<KTR_NAMEI)
177 #define KTRFAC_GENIO (1<<KTR_GENIO)
178 #define KTRFAC_PSIG (1<<KTR_PSIG)
179 #define KTRFAC_STRUCT (1<<KTR_STRUCT)
180 #define KTRFAC_USER (1<<KTR_USER)
181 #define KTRFAC_EXECARGS (1<<KTR_EXECARGS)
182 #define KTRFAC_EXECENV (1<<KTR_EXECENV)
183 #define KTRFAC_PLEDGE (1<<KTR_PLEDGE)
184
185 /*
186 * trace flags (also in ps_traceflag)
187 */
188 #define KTRFAC_ROOT 0x80000000U /* root set this trace */
189 #define KTRFAC_INHERIT 0x40000000 /* pass trace flags to children */
190
191 #ifndef _KERNEL
192
193 #include <sys/cdefs.h>
194
195 __BEGIN_DECLS
196 int ktrace(const char *, int, int, pid_t);
197 int utrace(const char *, const void *, size_t);
198 __END_DECLS
199
200 #else
201
202 /*
203 * Test for kernel trace point
204 */
205 #define KTRPOINT(p, type) \
206 ((p)->p_p->ps_traceflag & (1<<(type)) && ((p)->p_flag & P_INKTR) == 0)
207
208 void ktrgenio(struct proc *, int, enum uio_rw, struct iovec *, ssize_t);
209 void ktrnamei(struct proc *, char *);
210 void ktrpsig(struct proc *, int, sig_t, int, int, siginfo_t *);
211 void ktrsyscall(struct proc *, register_t, size_t, register_t []);
212 void ktrsysret(struct proc *, register_t, int, const register_t [2]);
213 int ktruser(struct proc *, const char *, const void *, size_t);
214 void ktrexec(struct proc *, int, const char *, ssize_t);
215 void ktrpledge(struct proc *, int, uint64_t, int);
216
217 void ktrcleartrace(struct process *);
218 void ktrsettrace(struct process *, int, struct vnode *, struct ucred *);
219
220 void ktrstruct(struct proc *, const char *, const void *, size_t);
221 #define ktrsockaddr(p, s, l) \
222 ktrstruct((p), "sockaddr", (s), (l))
223 #define ktrstat(p, s) \
224 ktrstruct((p), "stat", (s), sizeof(struct stat))
225 #define ktrabstimespec(p, s) \
226 ktrstruct((p), "abstimespec", (s), sizeof(struct timespec))
227 #define ktrreltimespec(p, s) \
228 ktrstruct((p), "reltimespec", (s), sizeof(struct timespec))
229 #define ktrabstimeval(p, s) \
230 ktrstruct((p), "abstimeval", (s), sizeof(struct timeval))
231 #define ktrreltimeval(p, s) \
232 ktrstruct((p), "reltimeval", (s), sizeof(struct timeval))
233 #define ktrsigaction(p, s) \
234 ktrstruct((p), "sigaction", (s), sizeof(struct sigaction))
235 #define ktrrlimit(p, s) \
236 ktrstruct((p), "rlimit", (s), sizeof(struct rlimit))
237 #define ktrrusage(p, s) \
238 ktrstruct((p), "rusage", (s), sizeof(struct rusage))
239 #define ktrfdset(p, s, l) \
240 ktrstruct((p), "fdset", (s), l)
241 #define ktrquota(p, s) \
242 ktrstruct((p), "quota", (s), sizeof(struct dqblk))
243 #define ktrmsghdr(p, s) \
244 ktrstruct(p, "msghdr", s, sizeof(struct msghdr))
245 #define ktrmmsghdr(p, s) \
246 ktrstruct(p, "mmsghdr", s, sizeof(struct mmsghdr))
247 #define ktriovec(p, s, count) \
248 ktrstruct(p, "iovec", s, (count) * sizeof(struct iovec))
249 #define ktrcmsghdr(p, c, len) \
250 ktrstruct(p, "cmsghdr", c, len)
251 #define ktrevent(p, kev, count) \
252 ktrstruct(p, "kevent", kev, (count) * sizeof(struct kevent))
253 #define ktrpollfd(p, pfd, count) \
254 ktrstruct(p, "pollfd", pfd, (count) * sizeof(struct pollfd))
255 #define ktrfds(p, fds, count) \
256 ktrstruct(p, "fds", fds, (count) * sizeof(int))
257 #define ktrflock(p, fl) \
258 ktrstruct(p, "flock", (fl), sizeof(struct flock))
259 #define ktrsiginfo(p, si) \
260 ktrstruct(p, "siginfo", (si), sizeof(siginfo_t))
261
262 #endif /* !_KERNEL */
Cache object: 5a360d3d516deb35d0650b7983d126df
|