]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/ktrace.h
xnu-792.21.3.tar.gz
[apple/xnu.git] / bsd / sys / ktrace.h
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
8f6c56a5
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
29/*
30 * Copyright (c) 1988, 1993
31 * The Regents of the University of California. All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 *
61 * @(#)ktrace.h 8.1 (Berkeley) 6/2/93
9bccf70c 62 * $FreeBSD: src/sys/sys/ktrace.h,v 1.19.2.3 2001/01/06 09:58:23 alfred Exp $
1c79356b
A
63 */
64
65#ifndef _SYS_KTRACE_H_
66#define _SYS_KTRACE_H_
67
9bccf70c
A
68#include <sys/appleapiopts.h>
69
91447636 70#ifdef MACH_KERNEL_PRIVATE
9bccf70c 71
21362eb3
A
72void ktrsyscall(void *, int, int, u_int64_t *, int);
73void ktrsysret(void *, int, int, int, int);
9bccf70c
A
74
75#else
9bccf70c 76#ifdef __APPLE_API_UNSTABLE
1c79356b
A
77/*
78 * operations to ktrace system call (KTROP(op))
79 */
80#define KTROP_SET 0 /* set trace points */
81#define KTROP_CLEAR 1 /* clear trace points */
82#define KTROP_CLEARFILE 2 /* stop all tracing to file */
83#define KTROP(o) ((o)&3) /* macro to extract operation */
84/*
85 * flags (ORed in with operation)
86 */
87#define KTRFLAG_DESCEND 4 /* perform op on all children too */
88
89/*
90 * ktrace record header
91447636
A
91 *
92 * LP64todo: not 64-bit safe
1c79356b
A
93 */
94struct ktr_header {
95 int ktr_len; /* length of buf */
96 short ktr_type; /* trace record type */
97 pid_t ktr_pid; /* process id */
98 char ktr_comm[MAXCOMLEN+1]; /* command name */
99 struct timeval ktr_time; /* timestamp */
100 caddr_t ktr_buf;
101};
102
103/*
104 * Test for kernel trace point
105 */
106#define KTRPOINT(p, type) \
107 (((p)->p_traceflag & ((1<<(type))|KTRFAC_ACTIVE)) == (1<<(type)))
108
109/*
110 * ktrace record types
111 */
112
113/*
114 * KTR_SYSCALL - system call record
115 */
116#define KTR_SYSCALL 1
117struct ktr_syscall {
9bccf70c
A
118 short ktr_code; /* syscall number */
119 short ktr_narg; /* number of arguments */
1c79356b 120 /*
9bccf70c 121 * followed by ktr_narg register_t
1c79356b 122 */
91447636 123 u_int64_t ktr_args[1];
1c79356b
A
124};
125
126/*
127 * KTR_SYSRET - return from system call record
128 */
129#define KTR_SYSRET 2
130struct ktr_sysret {
131 short ktr_code;
132 short ktr_eosys;
133 int ktr_error;
9bccf70c 134 register_t ktr_retval;
1c79356b
A
135};
136
137/*
138 * KTR_NAMEI - namei record
139 */
140#define KTR_NAMEI 3
141 /* record contains pathname */
142
143/*
144 * KTR_GENIO - trace generic process i/o
145 */
146#define KTR_GENIO 4
147struct ktr_genio {
148 int ktr_fd;
149 enum uio_rw ktr_rw;
150 /*
151 * followed by data successfully read/written
152 */
153};
154
155/*
156 * KTR_PSIG - trace processed signal
157 */
158#define KTR_PSIG 5
159struct ktr_psig {
160 int signo;
161 sig_t action;
1c79356b 162 int code;
9bccf70c 163 sigset_t mask;
1c79356b
A
164};
165
166/*
167 * KTR_CSW - trace context switches
168 */
169#define KTR_CSW 6
170struct ktr_csw {
171 int out; /* 1 if switch out, 0 if switch in */
172 int user; /* 1 if usermode (ivcsw), 0 if kernel (vcsw) */
173};
174
9bccf70c
A
175/*
176 * KTR_USER - data comming from userland
177 */
178#define KTR_USER_MAXLEN 2048 /* maximum length of passed data */
179#define KTR_USER 7
180
1c79356b
A
181/*
182 * kernel trace points (in p_traceflag)
183 */
184#define KTRFAC_MASK 0x00ffffff
185#define KTRFAC_SYSCALL (1<<KTR_SYSCALL)
186#define KTRFAC_SYSRET (1<<KTR_SYSRET)
187#define KTRFAC_NAMEI (1<<KTR_NAMEI)
188#define KTRFAC_GENIO (1<<KTR_GENIO)
189#define KTRFAC_PSIG (1<<KTR_PSIG)
190#define KTRFAC_CSW (1<<KTR_CSW)
9bccf70c 191#define KTRFAC_USER (1<<KTR_USER)
1c79356b
A
192/*
193 * trace flags (also in p_traceflags)
194 */
195#define KTRFAC_ROOT 0x80000000 /* root set this trace */
196#define KTRFAC_INHERIT 0x40000000 /* pass trace flags to children */
197#define KTRFAC_ACTIVE 0x20000000 /* ktrace logging in progress, ignore */
198
9bccf70c
A
199
200#ifdef KERNEL
201#ifdef __APPLE_API_PRIVATE
91447636
A
202void ktrnamei(struct vnode *,char *);
203void ktrcsw(struct vnode *, int, int);
204void ktrpsig(struct vnode *, int, sig_t, sigset_t *, int);
205void ktrgenio(struct vnode *, int, enum uio_rw, struct uio *, int);
21362eb3 206void ktrsyscall(struct proc *, int, int, u_int64_t args[]);
91447636 207void ktrsysret(struct proc *, int, int, register_t);
9bccf70c
A
208#endif /* __APPLE_API_PRIVATE */
209#else
1c79356b
A
210
211#include <sys/cdefs.h>
212
213__BEGIN_DECLS
91447636
A
214int ktrace(const char *, int, int, pid_t);
215int utrace(const void *, size_t);
1c79356b
A
216__END_DECLS
217
218#endif /* !KERNEL */
9bccf70c
A
219
220#endif /* __APPLE_API_UNSTABLE */
221#endif /* !MACH_KERNEL_PRIVATE */
1c79356b
A
222#endif /* !_SYS_KTRACE_H_ */
223