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