xref: /freebsd/sys/cddl/dev/dtrace/dtrace_cddl.h (revision 830940567b49bb0c08dfaed40418999e76616909)
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 
40 } kdtrace_proc_t;
41 
42 /*
43  * Kernel DTrace extension to 'struct thread' for FreeBSD.
44  */
45 typedef struct kdtrace_thread {
46 	u_int8_t	td_dtrace_stop;	/* Indicates a DTrace-desired stop */
47 	u_int8_t	td_dtrace_sig;	/* Signal sent via DTrace's raise() */
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 		} _tds;
63 		u_long	_td_dtrace_ft;	/* Bitwise or of these flags. */
64 	} _tdu;
65 #define	td_dtrace_ft	_tdu._td_dtrace_ft
66 #define	td_dtrace_on	_tdu._tds._td_dtrace_on
67 #define	td_dtrace_step	_tdu._tds._td_dtrace_step
68 #define	td_dtrace_ret	_tdu._tds._td_dtrace_ret
69 #define	td_dtrace_ast	_tdu._tds._td_dtrace_ast
70 
71 	uintptr_t	td_dtrace_pc;	/* DTrace saved pc from fasttrap. */
72 	uintptr_t	td_dtrace_npc;	/* DTrace next pc from fasttrap. */
73 	uintptr_t	td_dtrace_scrpc;
74 					/* DTrace per-thread scratch location. */
75 	uintptr_t	td_dtrace_astpc;
76 					/* DTrace return sequence location. */
77 	u_int64_t	td_hrtime;	/* Last time on cpu. */
78 	int		td_errno;	/* Syscall return value. */
79 } kdtrace_thread_t;
80 
81 /*
82  * Definitions to reference fields in the FreeBSD DTrace structures defined
83  * above using the names of fields in similar structures in Solaris. Note
84  * that the separation on FreeBSD is a licensing constraint designed to
85  * keep the GENERIC kernel BSD licensed.
86  */
87 #define	t_dtrace_vtime	td_dtrace->td_dtrace_vtime
88 #define	t_dtrace_start	td_dtrace->td_dtrace_start
89 #define	t_dtrace_stop	td_dtrace->td_dtrace_stop
90 #define	t_dtrace_sig	td_dtrace->td_dtrace_sig
91 #define	t_predcache	td_dtrace->td_predcache
92 #define p_dtrace_helpers	p_dtrace->p_dtrace_helpers
93 
94 /*
95  * Definitions for fields in struct proc which are named differntly in FreeBSD.
96  */
97 #define	p_cred		p_ucred
98 #define	p_parent	p_pptr
99 
100 /*
101  * Definitions for fields in struct thread which are named differntly in FreeBSD.
102  */
103 #define	t_procp		td_proc
104 #define	t_tid		td_tid
105 #define	t_did		td_tid
106 
107 
108 int priv_policy(const cred_t *, int, boolean_t, int, const char *);
109 boolean_t priv_policy_only(const cred_t *, int, boolean_t);
110 boolean_t priv_policy_choice(const cred_t *, int, boolean_t);
111 
112 /*
113  * Test privilege. Audit success or failure, allow privilege debugging.
114  * Returns 0 for success, err for failure.
115  */
116 #define	PRIV_POLICY(cred, priv, all, err, reason) \
117 		priv_policy((cred), (priv), (all), (err), (reason))
118 
119 /*
120  * Test privilege. Audit success only, no privilege debugging.
121  * Returns 1 for success, and 0 for failure.
122  */
123 #define	PRIV_POLICY_CHOICE(cred, priv, all) \
124 		priv_policy_choice((cred), (priv), (all))
125 
126 /*
127  * Test privilege. No priv_debugging, no auditing.
128  * Returns 1 for success, and 0 for failure.
129  */
130 
131 #define	PRIV_POLICY_ONLY(cred, priv, all) \
132 		priv_policy_only((cred), (priv), (all))
133 
134 #endif	/* !_DTRACE_CDDL_H_ */
135