xref: /original-bsd/sys/sys/ktrace.h (revision fac0c393)
1 /*
2  * Copyright (c) 1988, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)ktrace.h	8.2 (Berkeley) 02/19/95
8  */
9 
10 /*
11  * operations to ktrace system call  (KTROP(op))
12  */
13 #define KTROP_SET		0	/* set trace points */
14 #define KTROP_CLEAR		1	/* clear trace points */
15 #define KTROP_CLEARFILE		2	/* stop all tracing to file */
16 #define	KTROP(o)		((o)&3)	/* macro to extract operation */
17 /*
18  * flags (ORed in with operation)
19  */
20 #define KTRFLAG_DESCEND		4	/* perform op on all children too */
21 
22 /*
23  * ktrace record header
24  */
25 struct ktr_header {
26 	int	ktr_len;		/* length of buf */
27 	short	ktr_type;		/* trace record type */
28 	pid_t	ktr_pid;		/* process id */
29 	char	ktr_comm[MAXCOMLEN+1];	/* command name */
30 	struct	timeval ktr_time;	/* timestamp */
31 	caddr_t	ktr_buf;
32 };
33 
34 /*
35  * Test for kernel trace point
36  */
37 #define KTRPOINT(p, type)	\
38 	(((p)->p_traceflag & ((1<<(type))|KTRFAC_ACTIVE)) == (1<<(type)))
39 
40 /*
41  * ktrace record types
42  */
43 
44 /*
45  * KTR_SYSCALL - system call record
46  */
47 #define KTR_SYSCALL	1
48 struct ktr_syscall {
49 	int	ktr_code;		/* syscall number */
50 	int	ktr_argsize;		/* size of arguments */
51 	/*
52 	 * followed by ktr_argsize/sizeof(register_t) 'register_t's
53 	 */
54 };
55 
56 /*
57  * KTR_SYSRET - return from system call record
58  */
59 #define KTR_SYSRET	2
60 struct ktr_sysret {
61 	short	ktr_code;
62 	short	ktr_eosys;
63 	int	ktr_error;
64 	int	ktr_retval;
65 };
66 
67 /*
68  * KTR_NAMEI - namei record
69  */
70 #define KTR_NAMEI	3
71 	/* record contains pathname */
72 
73 /*
74  * KTR_GENIO - trace generic process i/o
75  */
76 #define KTR_GENIO	4
77 struct ktr_genio {
78 	int	ktr_fd;
79 	enum	uio_rw ktr_rw;
80 	/*
81 	 * followed by data successfully read/written
82 	 */
83 };
84 
85 /*
86  * KTR_PSIG - trace processed signal
87  */
88 #define	KTR_PSIG	5
89 struct ktr_psig {
90 	int	signo;
91 	sig_t	action;
92 	int	mask;
93 	int	code;
94 };
95 
96 /*
97  * KTR_CSW - trace context switches
98  */
99 #define KTR_CSW		6
100 struct ktr_csw {
101 	int	out;	/* 1 if switch out, 0 if switch in */
102 	int	user;	/* 1 if usermode (ivcsw), 0 if kernel (vcsw) */
103 };
104 
105 /*
106  * kernel trace points (in p_traceflag)
107  */
108 #define KTRFAC_MASK	0x00ffffff
109 #define KTRFAC_SYSCALL	(1<<KTR_SYSCALL)
110 #define KTRFAC_SYSRET	(1<<KTR_SYSRET)
111 #define KTRFAC_NAMEI	(1<<KTR_NAMEI)
112 #define KTRFAC_GENIO	(1<<KTR_GENIO)
113 #define	KTRFAC_PSIG	(1<<KTR_PSIG)
114 #define KTRFAC_CSW	(1<<KTR_CSW)
115 /*
116  * trace flags (also in p_traceflags)
117  */
118 #define KTRFAC_ROOT	0x80000000	/* root set this trace */
119 #define KTRFAC_INHERIT	0x40000000	/* pass trace flags to children */
120 #define KTRFAC_ACTIVE	0x20000000	/* ktrace logging in progress, ignore */
121 
122 #ifndef	KERNEL
123 
124 #include <sys/cdefs.h>
125 
126 __BEGIN_DECLS
127 int	ktrace __P((const char *, int, int, pid_t));
128 __END_DECLS
129 
130 #endif	/* !KERNEL */
131