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