1 /*	$NetBSD: dtrace_cddl.h,v 1.2 2010/02/21 01:46:33 darran Exp $	*/
2 
3 /*
4  * CDDL HEADER START
5  *
6  * The contents of this file are subject to the terms of the
7  * Common Development and Distribution License (the "License").
8  * You may not use this file except in compliance with the License.
9  *
10  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11  * or http://www.opensolaris.org/os/licensing.
12  * See the License for the specific language governing permissions
13  * and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL HEADER in each
16  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17  * If applicable, add the following below this CDDL HEADER, with the
18  * fields enclosed by brackets "[]" replaced with your own identifying
19  * information: Portions Copyright [yyyy] [name of copyright owner]
20  *
21  * CDDL HEADER END
22  *
23  * $FreeBSD: src/sys/cddl/dev/dtrace/dtrace_cddl.h,v 1.1.4.1 2009/08/03 08:13:06 kensmith Exp $
24  *
25  */
26 
27 #ifndef _DTRACE_CDDL_H_
28 #define	_DTRACE_CDDL_H_
29 
30 #include <sys/proc.h>
31 
32 #define LOCK_LEVEL	10
33 
34 /*
35  * Kernel DTrace extension to 'struct proc' for FreeBSD.
36  */
37 typedef struct kdtrace_proc {
38 	int		p_dtrace_probes;	/* Are there probes for this proc? */
39 	u_int64_t	p_dtrace_count;		/* Number of DTrace tracepoints */
40 	void		*p_dtrace_helpers;	/* DTrace helpers, if any */
41 
42 } kdtrace_proc_t;
43 
44 /*
45  * Kernel DTrace extension to 'struct thread' for FreeBSD.
46  */
47 typedef struct kdtrace_thread {
48 	u_int8_t	td_dtrace_stop;	/* Indicates a DTrace-desired stop */
49 	u_int8_t	td_dtrace_sig;	/* Signal sent via DTrace's raise() */
50 	u_int		td_predcache;	/* DTrace predicate cache */
51 	u_int64_t	td_dtrace_vtime; /* DTrace virtual time */
52 	u_int64_t	td_dtrace_start; /* DTrace slice start time */
53 
54 	union __tdu {
55 		struct __tds {
56 			u_int8_t	_td_dtrace_on;
57 					/* Hit a fasttrap tracepoint. */
58 			u_int8_t	_td_dtrace_step;
59 					/* About to return to kernel. */
60 			u_int8_t	_td_dtrace_ret;
61 					/* Handling a return probe. */
62 			u_int8_t	_td_dtrace_ast;
63 					/* Saved ast flag. */
64 		} _tds;
65 		u_long	_td_dtrace_ft;	/* Bitwise or of these flags. */
66 	} _tdu;
67 #define	td_dtrace_ft	_tdu._td_dtrace_ft
68 #define	td_dtrace_on	_tdu._tds._td_dtrace_on
69 #define	td_dtrace_step	_tdu._tds._td_dtrace_step
70 #define	td_dtrace_ret	_tdu._tds._td_dtrace_ret
71 #define	td_dtrace_ast	_tdu._tds._td_dtrace_ast
72 
73 	uintptr_t	td_dtrace_pc;	/* DTrace saved pc from fasttrap. */
74 	uintptr_t	td_dtrace_npc;	/* DTrace next pc from fasttrap. */
75 	uintptr_t	td_dtrace_scrpc;
76 					/* DTrace per-thread scratch location. */
77 	uintptr_t	td_dtrace_astpc;
78 					/* DTrace return sequence location. */
79 	u_int64_t	td_hrtime;	/* Last time on cpu. */
80 	int		td_errno;	/* Syscall return value. */
81 } kdtrace_thread_t;
82 
83 /*
84  * Definitions to reference fields in the FreeBSD DTrace structures defined
85  * above using the names of fields in similar structures in Solaris. Note
86  * that the separation on FreeBSD is a licensing constraint designed to
87  * keep the GENERIC kernel BSD licensed.
88  */
89 #define	t_dtrace_vtime	l_dtrace->td_dtrace_vtime
90 #define	t_dtrace_start	l_dtrace->td_dtrace_start
91 #define	t_dtrace_stop	l_dtrace->td_dtrace_stop
92 #define	t_dtrace_sig	l_dtrace->td_dtrace_sig
93 #define	t_predcache	l_dtrace->td_predcache
94 #define p_dtrace_helpers	p_dtrace->p_dtrace_helpers
95 
96 /*
97  * Definitions for fields in struct proc which are named differntly in FreeBSD.
98  */
99 //#define	p_cred		p_ucred
100 #define	p_parent	p_pptr
101 
102 /*
103  * Definitions for fields in struct thread which are named differntly in NetBSD.
104  */
105 #define	t_procp		l_proc
106 #define	t_tid		l_lid
107 #define	t_did		l_lid
108 
109 
110 int priv_policy(const cred_t *, int, boolean_t, int, const char *);
111 boolean_t priv_policy_only(const cred_t *, int, boolean_t);
112 boolean_t priv_policy_choice(const cred_t *, int, boolean_t);
113 
114 /*
115  * Test privilege. Audit success or failure, allow privilege debugging.
116  * Returns 0 for success, err for failure.
117  */
118 #define	PRIV_POLICY(cred, priv, all, err, reason) \
119 		priv_policy((cred), (priv), (all), (err), (reason))
120 
121 /*
122  * Test privilege. Audit success only, no privilege debugging.
123  * Returns 1 for success, and 0 for failure.
124  */
125 #define	PRIV_POLICY_CHOICE(cred, priv, all) \
126 		priv_policy_choice((cred), (priv), (all))
127 
128 /*
129  * Test privilege. No priv_debugging, no auditing.
130  * Returns 1 for success, and 0 for failure.
131  */
132 
133 #define	PRIV_POLICY_ONLY(cred, priv, all) \
134 		priv_policy_only((cred), (priv), (all))
135 
136 #endif	/* !_DTRACE_CDDL_H_ */
137