xref: /freebsd/sys/cddl/dev/dtrace/dtrace_cddl.h (revision 22508c8b6c284ad9ad1385c703e224e1ed3fbd7c)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  *
21  * $FreeBSD$
22  *
23  */
24 
25 #ifndef _DTRACE_CDDL_H_
26 #define	_DTRACE_CDDL_H_
27 
28 #include <sys/proc.h>
29 
30 #define LOCK_LEVEL	10
31 
32 /*
33  * Kernel DTrace extension to 'struct proc' for FreeBSD.
34  */
35 typedef struct kdtrace_proc {
36 	int		p_dtrace_probes;	/* Are there probes for this proc? */
37 	uint64_t	p_dtrace_count;		/* Number of DTrace tracepoints */
38 	void		*p_dtrace_helpers;	/* DTrace helpers, if any */
39 	int		p_dtrace_model;
40 	uint64_t	p_fasttrap_tp_gen;	/* Tracepoint hash table gen */
41 } kdtrace_proc_t;
42 
43 /*
44  * Kernel DTrace extension to 'struct thread' for FreeBSD.
45  */
46 typedef struct kdtrace_thread {
47 	uint8_t		td_dtrace_stop;	/* Indicates a DTrace-desired stop */
48 	uint8_t		td_dtrace_sig;	/* Signal sent via DTrace's raise() */
49 	uint8_t		td_dtrace_inprobe; /* Are we in a probe? */
50 	u_int		td_predcache;	/* DTrace predicate cache */
51 	uint64_t	td_dtrace_vtime; /* DTrace virtual time */
52 	uint64_t	td_dtrace_start; /* DTrace slice start time */
53 
54 	union __tdu {
55 		struct __tds {
56 			uint8_t		_td_dtrace_on;
57 					/* Hit a fasttrap tracepoint. */
58 			uint8_t		_td_dtrace_step;
59 					/* About to return to kernel. */
60 			uint8_t		_td_dtrace_ret;
61 					/* Handling a return probe. */
62 			uint8_t		_td_dtrace_ast;
63 					/* Saved ast flag. */
64 #ifdef __amd64__
65 			uint8_t		_td_dtrace_reg;
66 #endif
67 		} _tds;
68 		u_long	_td_dtrace_ft;	/* Bitwise or of these flags. */
69 	} _tdu;
70 #define	td_dtrace_ft	_tdu._td_dtrace_ft
71 #define	td_dtrace_on	_tdu._tds._td_dtrace_on
72 #define	td_dtrace_step	_tdu._tds._td_dtrace_step
73 #define	td_dtrace_ret	_tdu._tds._td_dtrace_ret
74 #define	td_dtrace_ast	_tdu._tds._td_dtrace_ast
75 #define	td_dtrace_reg	_tdu._tds._td_dtrace_reg
76 
77 	uintptr_t	td_dtrace_pc;	/* DTrace saved pc from fasttrap. */
78 	uintptr_t	td_dtrace_npc;	/* DTrace next pc from fasttrap. */
79 	uintptr_t	td_dtrace_scrpc;
80 					/* DTrace per-thread scratch location. */
81 	uintptr_t	td_dtrace_astpc;
82 					/* DTrace return sequence location. */
83 #ifdef __amd64__
84 	uintptr_t	td_dtrace_regv;
85 #endif
86 	uint64_t	td_hrtime;	/* Last time on cpu. */
87 	void		*td_dtrace_sscr; /* Saved scratch space location. */
88 	void		*td_systrace_args; /* syscall probe arguments. */
89 	uint64_t	td_fasttrap_tp_gen; /* Tracepoint hash table gen. */
90 	struct trapframe *td_dtrace_trapframe; /* Trap frame from invop. */
91 	void		*td_kinst_tramp;
92 	void		*td_kinst_curprobe;
93 } kdtrace_thread_t;
94 
95 /*
96  * Definitions to reference fields in the FreeBSD DTrace structures defined
97  * above using the names of fields in similar structures in Solaris. Note
98  * that the separation on FreeBSD is a licensing constraint designed to
99  * keep the GENERIC kernel BSD licensed.
100  */
101 #define	t_dtrace_vtime	td_dtrace->td_dtrace_vtime
102 #define	t_dtrace_start	td_dtrace->td_dtrace_start
103 #define	t_dtrace_stop	td_dtrace->td_dtrace_stop
104 #define	t_dtrace_sig	td_dtrace->td_dtrace_sig
105 #define	t_dtrace_inprobe	td_dtrace->td_dtrace_inprobe
106 #define	t_predcache	td_dtrace->td_predcache
107 #define	t_dtrace_ft	td_dtrace->td_dtrace_ft
108 #define	t_dtrace_on	td_dtrace->td_dtrace_on
109 #define	t_dtrace_step	td_dtrace->td_dtrace_step
110 #define	t_dtrace_ret	td_dtrace->td_dtrace_ret
111 #define	t_dtrace_ast	td_dtrace->td_dtrace_ast
112 #define	t_dtrace_reg	td_dtrace->td_dtrace_reg
113 #define	t_dtrace_pc	td_dtrace->td_dtrace_pc
114 #define	t_dtrace_npc	td_dtrace->td_dtrace_npc
115 #define	t_dtrace_scrpc	td_dtrace->td_dtrace_scrpc
116 #define	t_dtrace_astpc	td_dtrace->td_dtrace_astpc
117 #define	t_dtrace_regv	td_dtrace->td_dtrace_regv
118 #define	t_dtrace_sscr	td_dtrace->td_dtrace_sscr
119 #define	t_dtrace_systrace_args	td_dtrace->td_systrace_args
120 #define	t_fasttrap_tp_gen	td_dtrace->td_fasttrap_tp_gen
121 #define	t_dtrace_trapframe	td_dtrace->td_dtrace_trapframe
122 #define	t_kinst_tramp		td_dtrace->td_kinst_tramp
123 #define	t_kinst_curprobe	td_dtrace->td_kinst_curprobe
124 #define	p_dtrace_helpers	p_dtrace->p_dtrace_helpers
125 #define	p_dtrace_count	p_dtrace->p_dtrace_count
126 #define	p_dtrace_probes	p_dtrace->p_dtrace_probes
127 #define	p_model		p_dtrace->p_dtrace_model
128 #define	p_fasttrap_tp_gen	p_dtrace->p_fasttrap_tp_gen
129 
130 #define	DATAMODEL_NATIVE	0
131 #ifdef __amd64__
132 #define	DATAMODEL_LP64		0
133 #define	DATAMODEL_ILP32		1
134 #else
135 #define	DATAMODEL_LP64		1
136 #define	DATAMODEL_ILP32		0
137 #endif
138 
139 /*
140  * Definitions for fields in struct proc which are named differently in FreeBSD.
141  */
142 #define	p_cred		p_ucred
143 #define	p_parent	p_pptr
144 
145 /*
146  * Definitions for fields in struct thread which are named differently in FreeBSD.
147  */
148 #define	t_procp		td_proc
149 #define	t_tid		td_tid
150 #define	t_did		td_tid
151 #define	t_cred		td_ucred
152 
153 
154 int priv_policy(const cred_t *, int, boolean_t, int, const char *);
155 boolean_t priv_policy_only(const cred_t *, int, boolean_t);
156 boolean_t priv_policy_choice(const cred_t *, int, boolean_t);
157 
158 /*
159  * Test privilege. Audit success or failure, allow privilege debugging.
160  * Returns 0 for success, err for failure.
161  */
162 #define	PRIV_POLICY(cred, priv, all, err, reason) \
163 		priv_policy((cred), (priv), (all), (err), (reason))
164 
165 /*
166  * Test privilege. Audit success only, no privilege debugging.
167  * Returns 1 for success, and 0 for failure.
168  */
169 #define	PRIV_POLICY_CHOICE(cred, priv, all) \
170 		priv_policy_choice((cred), (priv), (all))
171 
172 /*
173  * Test privilege. No priv_debugging, no auditing.
174  * Returns 1 for success, and 0 for failure.
175  */
176 
177 #define	PRIV_POLICY_ONLY(cred, priv, all) \
178 		priv_policy_only((cred), (priv), (all))
179 
180 #endif	/* !_DTRACE_CDDL_H_ */
181