xref: /freebsd-13-stable/sys/cddl/dev/dtrace/dtrace_cddl.h (revision f8167e0404dab9ffeaca95853dd237ab7c587f82)
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  */
22 
23 #ifndef _DTRACE_CDDL_H_
24 #define	_DTRACE_CDDL_H_
25 
26 #include <sys/proc.h>
27 
28 #define LOCK_LEVEL	10
29 
30 /*
31  * Kernel DTrace extension to 'struct proc' for FreeBSD.
32  */
33 typedef struct kdtrace_proc {
34 	int		p_dtrace_probes;	/* Are there probes for this proc? */
35 	u_int64_t	p_dtrace_count;		/* Number of DTrace tracepoints */
36 	void		*p_dtrace_helpers;	/* DTrace helpers, if any */
37 	int		p_dtrace_model;
38 	uint64_t	p_fasttrap_tp_gen;	/* Tracepoint hash table gen */
39 } kdtrace_proc_t;
40 
41 /*
42  * Kernel DTrace extension to 'struct thread' for FreeBSD.
43  */
44 typedef struct kdtrace_thread {
45 	u_int8_t	td_dtrace_stop;	/* Indicates a DTrace-desired stop */
46 	u_int8_t	td_dtrace_sig;	/* Signal sent via DTrace's raise() */
47 	u_int8_t	td_dtrace_inprobe; /* Are we in a probe? */
48 	u_int		td_predcache;	/* DTrace predicate cache */
49 	u_int64_t	td_dtrace_vtime; /* DTrace virtual time */
50 	u_int64_t	td_dtrace_start; /* DTrace slice start time */
51 
52 	union __tdu {
53 		struct __tds {
54 			u_int8_t	_td_dtrace_on;
55 					/* Hit a fasttrap tracepoint. */
56 			u_int8_t	_td_dtrace_step;
57 					/* About to return to kernel. */
58 			u_int8_t	_td_dtrace_ret;
59 					/* Handling a return probe. */
60 			u_int8_t	_td_dtrace_ast;
61 					/* Saved ast flag. */
62 #ifdef __amd64__
63 			u_int8_t	_td_dtrace_reg;
64 #endif
65 		} _tds;
66 		u_long	_td_dtrace_ft;	/* Bitwise or of these flags. */
67 	} _tdu;
68 #define	td_dtrace_ft	_tdu._td_dtrace_ft
69 #define	td_dtrace_on	_tdu._tds._td_dtrace_on
70 #define	td_dtrace_step	_tdu._tds._td_dtrace_step
71 #define	td_dtrace_ret	_tdu._tds._td_dtrace_ret
72 #define	td_dtrace_ast	_tdu._tds._td_dtrace_ast
73 #define	td_dtrace_reg	_tdu._tds._td_dtrace_reg
74 
75 	uintptr_t	td_dtrace_pc;	/* DTrace saved pc from fasttrap. */
76 	uintptr_t	td_dtrace_npc;	/* DTrace next pc from fasttrap. */
77 	uintptr_t	td_dtrace_scrpc;
78 					/* DTrace per-thread scratch location. */
79 	uintptr_t	td_dtrace_astpc;
80 					/* DTrace return sequence location. */
81 #ifdef __amd64__
82 	uintptr_t	td_dtrace_regv;
83 #endif
84 	u_int64_t	td_hrtime;	/* Last time on cpu. */
85 	void		*td_dtrace_sscr; /* Saved scratch space location. */
86 	void		*td_systrace_args; /* syscall probe arguments. */
87 	uint64_t	td_fasttrap_tp_gen; /* Tracepoint hash table gen. */
88 	struct trapframe *td_dtrace_trapframe; /* Trap frame from invop. */
89 } kdtrace_thread_t;
90 
91 /*
92  * Definitions to reference fields in the FreeBSD DTrace structures defined
93  * above using the names of fields in similar structures in Solaris. Note
94  * that the separation on FreeBSD is a licensing constraint designed to
95  * keep the GENERIC kernel BSD licensed.
96  */
97 #define	t_dtrace_vtime	td_dtrace->td_dtrace_vtime
98 #define	t_dtrace_start	td_dtrace->td_dtrace_start
99 #define	t_dtrace_stop	td_dtrace->td_dtrace_stop
100 #define	t_dtrace_sig	td_dtrace->td_dtrace_sig
101 #define	t_dtrace_inprobe	td_dtrace->td_dtrace_inprobe
102 #define	t_predcache	td_dtrace->td_predcache
103 #define	t_dtrace_ft	td_dtrace->td_dtrace_ft
104 #define	t_dtrace_on	td_dtrace->td_dtrace_on
105 #define	t_dtrace_step	td_dtrace->td_dtrace_step
106 #define	t_dtrace_ret	td_dtrace->td_dtrace_ret
107 #define	t_dtrace_ast	td_dtrace->td_dtrace_ast
108 #define	t_dtrace_reg	td_dtrace->td_dtrace_reg
109 #define	t_dtrace_pc	td_dtrace->td_dtrace_pc
110 #define	t_dtrace_npc	td_dtrace->td_dtrace_npc
111 #define	t_dtrace_scrpc	td_dtrace->td_dtrace_scrpc
112 #define	t_dtrace_astpc	td_dtrace->td_dtrace_astpc
113 #define	t_dtrace_regv	td_dtrace->td_dtrace_regv
114 #define	t_dtrace_sscr	td_dtrace->td_dtrace_sscr
115 #define	t_dtrace_systrace_args	td_dtrace->td_systrace_args
116 #define	t_fasttrap_tp_gen	td_dtrace->td_fasttrap_tp_gen
117 #define	t_dtrace_trapframe	td_dtrace->td_dtrace_trapframe
118 #define	p_dtrace_helpers	p_dtrace->p_dtrace_helpers
119 #define	p_dtrace_count	p_dtrace->p_dtrace_count
120 #define	p_dtrace_probes	p_dtrace->p_dtrace_probes
121 #define	p_model		p_dtrace->p_dtrace_model
122 #define	p_fasttrap_tp_gen	p_dtrace->p_fasttrap_tp_gen
123 
124 #define	DATAMODEL_NATIVE	0
125 #ifdef __amd64__
126 #define	DATAMODEL_LP64		0
127 #define	DATAMODEL_ILP32		1
128 #else
129 #define	DATAMODEL_LP64		1
130 #define	DATAMODEL_ILP32		0
131 #endif
132 
133 /*
134  * Definitions for fields in struct proc which are named differently in FreeBSD.
135  */
136 #define	p_cred		p_ucred
137 #define	p_parent	p_pptr
138 
139 /*
140  * Definitions for fields in struct thread which are named differently in FreeBSD.
141  */
142 #define	t_procp		td_proc
143 #define	t_tid		td_tid
144 #define	t_did		td_tid
145 #define	t_cred		td_ucred
146 
147 
148 int priv_policy(const cred_t *, int, boolean_t, int, const char *);
149 boolean_t priv_policy_only(const cred_t *, int, boolean_t);
150 boolean_t priv_policy_choice(const cred_t *, int, boolean_t);
151 
152 /*
153  * Test privilege. Audit success or failure, allow privilege debugging.
154  * Returns 0 for success, err for failure.
155  */
156 #define	PRIV_POLICY(cred, priv, all, err, reason) \
157 		priv_policy((cred), (priv), (all), (err), (reason))
158 
159 /*
160  * Test privilege. Audit success only, no privilege debugging.
161  * Returns 1 for success, and 0 for failure.
162  */
163 #define	PRIV_POLICY_CHOICE(cred, priv, all) \
164 		priv_policy_choice((cred), (priv), (all))
165 
166 /*
167  * Test privilege. No priv_debugging, no auditing.
168  * Returns 1 for success, and 0 for failure.
169  */
170 
171 #define	PRIV_POLICY_ONLY(cred, priv, all) \
172 		priv_policy_only((cred), (priv), (all))
173 
174 #endif	/* !_DTRACE_CDDL_H_ */
175