xref: /openbsd/sys/sys/ktrace.h (revision df930be7)
1 /*	$NetBSD: ktrace.h,v 1.11 1995/07/19 15:27:05 christos 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.1 (Berkeley) 6/2/93
36  */
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 	int	ktr_len;		/* length of buf */
55 	short	ktr_type;		/* trace record type */
56 	pid_t	ktr_pid;		/* process id */
57 	char	ktr_comm[MAXCOMLEN+1];	/* command name */
58 	struct	timeval ktr_time;	/* timestamp */
59 	caddr_t	ktr_buf;
60 };
61 
62 /*
63  * Test for kernel trace point
64  */
65 #define KTRPOINT(p, type)	\
66 	(((p)->p_traceflag & ((1<<(type))|KTRFAC_ACTIVE)) == (1<<(type)))
67 
68 /*
69  * ktrace record types
70  */
71 
72 /*
73  * KTR_SYSCALL - system call record
74  */
75 #define KTR_SYSCALL	1
76 struct ktr_syscall {
77 	int	ktr_code;		/* syscall number */
78 	int	ktr_argsize;		/* size of arguments */
79 	/*
80 	 * followed by ktr_argsize/sizeof(register_t) "register_t"s
81 	 */
82 };
83 
84 /*
85  * KTR_SYSRET - return from system call record
86  */
87 #define KTR_SYSRET	2
88 struct ktr_sysret {
89 	short	ktr_code;
90 	short	ktr_eosys;
91 	int	ktr_error;
92 	int	ktr_retval;
93 };
94 
95 /*
96  * KTR_NAMEI - namei record
97  */
98 #define KTR_NAMEI	3
99 	/* record contains pathname */
100 
101 /*
102  * KTR_GENIO - trace generic process i/o
103  */
104 #define KTR_GENIO	4
105 struct ktr_genio {
106 	int	ktr_fd;
107 	enum	uio_rw ktr_rw;
108 	/*
109 	 * followed by data successfully read/written
110 	 */
111 };
112 
113 /*
114  * KTR_PSIG - trace processed signal
115  */
116 #define	KTR_PSIG	5
117 struct ktr_psig {
118 	int	signo;
119 	sig_t	action;
120 	int	mask;
121 	int	code;
122 };
123 
124 /*
125  * KTR_CSW - trace context switches
126  */
127 #define KTR_CSW		6
128 struct ktr_csw {
129 	int	out;	/* 1 if switch out, 0 if switch in */
130 	int	user;	/* 1 if usermode (ivcsw), 0 if kernel (vcsw) */
131 };
132 
133 /*
134  * KTR_EMUL - emulation change
135  */
136 #define KTR_EMUL	7
137 	/* record contains emulation name */
138 
139 /*
140  * kernel trace points (in p_traceflag)
141  */
142 #define KTRFAC_MASK	0x00ffffff
143 #define KTRFAC_SYSCALL	(1<<KTR_SYSCALL)
144 #define KTRFAC_SYSRET	(1<<KTR_SYSRET)
145 #define KTRFAC_NAMEI	(1<<KTR_NAMEI)
146 #define KTRFAC_GENIO	(1<<KTR_GENIO)
147 #define	KTRFAC_PSIG	(1<<KTR_PSIG)
148 #define KTRFAC_CSW	(1<<KTR_CSW)
149 #define KTRFAC_EMUL	(1<<KTR_EMUL)
150 /*
151  * trace flags (also in p_traceflags)
152  */
153 #define KTRFAC_ROOT	0x80000000	/* root set this trace */
154 #define KTRFAC_INHERIT	0x40000000	/* pass trace flags to children */
155 #define KTRFAC_ACTIVE	0x20000000	/* ktrace logging in progress, ignore */
156 
157 #ifndef	_KERNEL
158 
159 #include <sys/cdefs.h>
160 
161 __BEGIN_DECLS
162 int	ktrace __P((const char *, int, int, pid_t));
163 __END_DECLS
164 
165 #endif	/* !_KERNEL */
166