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.
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.
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]
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2011, Joyent, Inc. All rights reserved.
27 #include <sys/types.h>
28 #include <sys/modctl.h>
29 #include <sys/systeminfo.h>
30 #include <sys/resource.h>
43 #define _POSIX_PTHREAD_SEMANTICS
45 #undef _POSIX_PTHREAD_SEMANTICS
48 #include <dt_program.h>
49 #include <dt_module.h>
50 #include <dt_printf.h>
51 #include <dt_string.h>
52 #include <dt_provider.h>
55 * Stability and versioning definitions. These #defines are used in the tables
56 * of identifiers below to fill in the attribute and version fields associated
57 * with each identifier. The DT_ATTR_* macros are a convenience to permit more
58 * concise declarations of common attributes such as Stable/Stable/Common. The
59 * DT_VERS_* macros declare the encoded integer values of all versions used so
60 * far. DT_VERS_LATEST must correspond to the latest version value among all
61 * versions exported by the D compiler. DT_VERS_STRING must be an ASCII string
62 * that contains DT_VERS_LATEST within it along with any suffixes (e.g. Beta).
63 * You must update DT_VERS_LATEST and DT_VERS_STRING when adding a new version,
64 * and then add the new version to the _dtrace_versions[] array declared below.
65 * Refer to the Solaris Dynamic Tracing Guide Stability and Versioning chapters
66 * respectively for an explanation of these DTrace features and their values.
68 * NOTE: Although the DTrace versioning scheme supports the labeling and
69 * introduction of incompatible changes (e.g. dropping an interface in a
70 * major release), the libdtrace code does not currently support this.
71 * All versions are assumed to strictly inherit from one another. If
72 * we ever need to provide divergent interfaces, this will need work.
74 #define DT_ATTR_STABCMN { DTRACE_STABILITY_STABLE, \
75 DTRACE_STABILITY_STABLE, DTRACE_CLASS_COMMON }
77 #define DT_ATTR_EVOLCMN { DTRACE_STABILITY_EVOLVING, \
78 DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON \
82 * The version number should be increased for every customer visible release
83 * of Solaris. The major number should be incremented when a fundamental
84 * change has been made that would affect all consumers, and would reflect
85 * sweeping changes to DTrace or the D language. The minor number should be
86 * incremented when a change is introduced that could break scripts that had
87 * previously worked; for example, adding a new built-in variable could break
88 * a script which was already using that identifier. The micro number should
89 * be changed when introducing functionality changes or major bug fixes that
90 * do not affect backward compatibility -- this is merely to make capabilities
91 * easily determined from the version number. Minor bugs do not require any
92 * modification to the version number.
94 #define DT_VERS_1_0 DT_VERSION_NUMBER(1, 0, 0)
95 #define DT_VERS_1_1 DT_VERSION_NUMBER(1, 1, 0)
96 #define DT_VERS_1_2 DT_VERSION_NUMBER(1, 2, 0)
97 #define DT_VERS_1_2_1 DT_VERSION_NUMBER(1, 2, 1)
98 #define DT_VERS_1_2_2 DT_VERSION_NUMBER(1, 2, 2)
99 #define DT_VERS_1_3 DT_VERSION_NUMBER(1, 3, 0)
100 #define DT_VERS_1_4 DT_VERSION_NUMBER(1, 4, 0)
101 #define DT_VERS_1_4_1 DT_VERSION_NUMBER(1, 4, 1)
102 #define DT_VERS_1_5 DT_VERSION_NUMBER(1, 5, 0)
103 #define DT_VERS_1_6 DT_VERSION_NUMBER(1, 6, 0)
104 #define DT_VERS_1_6_1 DT_VERSION_NUMBER(1, 6, 1)
105 #define DT_VERS_1_6_2 DT_VERSION_NUMBER(1, 6, 2)
106 #define DT_VERS_1_6_3 DT_VERSION_NUMBER(1, 6, 3)
107 #define DT_VERS_1_7 DT_VERSION_NUMBER(1, 7, 0)
108 #define DT_VERS_1_7_1 DT_VERSION_NUMBER(1, 7, 1)
109 #define DT_VERS_LATEST DT_VERS_1_7_1
110 #define DT_VERS_STRING "Sun D 1.7.1"
112 const dt_version_t _dtrace_versions
[] = {
113 DT_VERS_1_0
, /* D API 1.0.0 (PSARC 2001/466) Solaris 10 FCS */
114 DT_VERS_1_1
, /* D API 1.1.0 Solaris Express 6/05 */
115 DT_VERS_1_2
, /* D API 1.2.0 Solaris 10 Update 1 */
116 DT_VERS_1_2_1
, /* D API 1.2.1 Solaris Express 4/06 */
117 DT_VERS_1_2_2
, /* D API 1.2.2 Solaris Express 6/06 */
118 DT_VERS_1_3
, /* D API 1.3 Solaris Express 10/06 */
119 DT_VERS_1_4
, /* D API 1.4 Solaris Express 2/07 */
120 DT_VERS_1_4_1
, /* D API 1.4.1 Solaris Express 4/07 */
121 DT_VERS_1_5
, /* D API 1.5 Solaris Express 7/07 */
122 DT_VERS_1_6
, /* D API 1.6 */
123 DT_VERS_1_6_1
, /* D API 1.6.1 */
124 DT_VERS_1_6_2
, /* D API 1.6.2 */
125 DT_VERS_1_6_3
, /* D API 1.6.3 */
126 DT_VERS_1_7
, /* D API 1.7 */
127 DT_VERS_1_7_1
, /* D API 1.7.1 */
132 * Table of global identifiers. This is used to populate the global identifier
133 * hash when a new dtrace client open occurs. For more info see dt_ident.h.
134 * The global identifiers that represent functions use the dt_idops_func ops
135 * and specify the private data pointer as a prototype string which is parsed
136 * when the identifier is first encountered. These prototypes look like ANSI
137 * C function prototypes except that the special symbol "@" can be used as a
138 * wildcard to represent a single parameter of any type (i.e. any dt_node_t).
139 * The standard "..." notation can also be used to represent varargs. An empty
140 * parameter list is taken to mean void (that is, no arguments are permitted).
141 * A parameter enclosed in square brackets (e.g. "[int]") denotes an optional
144 static const dt_ident_t _dtrace_globals
[] = {
145 { "alloca", DT_IDENT_FUNC
, 0, DIF_SUBR_ALLOCA
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
146 &dt_idops_func
, "void *(size_t)" },
147 { "arg0", DT_IDENT_SCALAR
, 0, DIF_VAR_ARG0
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
148 &dt_idops_type
, "int64_t" },
149 { "arg1", DT_IDENT_SCALAR
, 0, DIF_VAR_ARG1
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
150 &dt_idops_type
, "int64_t" },
151 { "arg2", DT_IDENT_SCALAR
, 0, DIF_VAR_ARG2
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
152 &dt_idops_type
, "int64_t" },
153 { "arg3", DT_IDENT_SCALAR
, 0, DIF_VAR_ARG3
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
154 &dt_idops_type
, "int64_t" },
155 { "arg4", DT_IDENT_SCALAR
, 0, DIF_VAR_ARG4
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
156 &dt_idops_type
, "int64_t" },
157 { "arg5", DT_IDENT_SCALAR
, 0, DIF_VAR_ARG5
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
158 &dt_idops_type
, "int64_t" },
159 { "arg6", DT_IDENT_SCALAR
, 0, DIF_VAR_ARG6
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
160 &dt_idops_type
, "int64_t" },
161 { "arg7", DT_IDENT_SCALAR
, 0, DIF_VAR_ARG7
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
162 &dt_idops_type
, "int64_t" },
163 { "arg8", DT_IDENT_SCALAR
, 0, DIF_VAR_ARG8
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
164 &dt_idops_type
, "int64_t" },
165 { "arg9", DT_IDENT_SCALAR
, 0, DIF_VAR_ARG9
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
166 &dt_idops_type
, "int64_t" },
167 { "args", DT_IDENT_ARRAY
, 0, DIF_VAR_ARGS
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
168 &dt_idops_args
, NULL
},
169 { "avg", DT_IDENT_AGGFUNC
, 0, DTRACEAGG_AVG
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
170 &dt_idops_func
, "void(@)" },
171 { "basename", DT_IDENT_FUNC
, 0, DIF_SUBR_BASENAME
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
172 &dt_idops_func
, "string(const char *)" },
173 { "bcopy", DT_IDENT_FUNC
, 0, DIF_SUBR_BCOPY
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
174 &dt_idops_func
, "void(void *, void *, size_t)" },
175 { "breakpoint", DT_IDENT_ACTFUNC
, 0, DT_ACT_BREAKPOINT
,
176 DT_ATTR_STABCMN
, DT_VERS_1_0
,
177 &dt_idops_func
, "void()" },
178 { "caller", DT_IDENT_SCALAR
, 0, DIF_VAR_CALLER
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
179 &dt_idops_type
, "uintptr_t" },
180 { "chill", DT_IDENT_ACTFUNC
, 0, DT_ACT_CHILL
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
181 &dt_idops_func
, "void(int)" },
182 { "cleanpath", DT_IDENT_FUNC
, 0, DIF_SUBR_CLEANPATH
, DT_ATTR_STABCMN
,
183 DT_VERS_1_0
, &dt_idops_func
, "string(const char *)" },
184 { "clear", DT_IDENT_ACTFUNC
, 0, DT_ACT_CLEAR
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
185 &dt_idops_func
, "void(...)" },
186 { "commit", DT_IDENT_ACTFUNC
, 0, DT_ACT_COMMIT
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
187 &dt_idops_func
, "void(int)" },
188 { "copyin", DT_IDENT_FUNC
, 0, DIF_SUBR_COPYIN
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
189 &dt_idops_func
, "void *(uintptr_t, size_t)" },
190 { "copyinstr", DT_IDENT_FUNC
, 0, DIF_SUBR_COPYINSTR
,
191 DT_ATTR_STABCMN
, DT_VERS_1_0
,
192 &dt_idops_func
, "string(uintptr_t, [size_t])" },
193 { "copyinto", DT_IDENT_FUNC
, 0, DIF_SUBR_COPYINTO
, DT_ATTR_STABCMN
,
194 DT_VERS_1_0
, &dt_idops_func
, "void(uintptr_t, size_t, void *)" },
195 { "copyout", DT_IDENT_FUNC
, 0, DIF_SUBR_COPYOUT
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
196 &dt_idops_func
, "void(void *, uintptr_t, size_t)" },
197 { "copyoutstr", DT_IDENT_FUNC
, 0, DIF_SUBR_COPYOUTSTR
,
198 DT_ATTR_STABCMN
, DT_VERS_1_0
,
199 &dt_idops_func
, "void(char *, uintptr_t, size_t)" },
200 { "count", DT_IDENT_AGGFUNC
, 0, DTRACEAGG_COUNT
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
201 &dt_idops_func
, "void()" },
202 { "curthread", DT_IDENT_SCALAR
, 0, DIF_VAR_CURTHREAD
,
203 { DTRACE_STABILITY_STABLE
, DTRACE_STABILITY_PRIVATE
,
204 DTRACE_CLASS_COMMON
}, DT_VERS_1_0
,
205 &dt_idops_type
, "genunix`kthread_t *" },
206 { "ddi_pathname", DT_IDENT_FUNC
, 0, DIF_SUBR_DDI_PATHNAME
,
207 DT_ATTR_EVOLCMN
, DT_VERS_1_0
,
208 &dt_idops_func
, "string(void *, int64_t)" },
209 { "denormalize", DT_IDENT_ACTFUNC
, 0, DT_ACT_DENORMALIZE
, DT_ATTR_STABCMN
,
210 DT_VERS_1_0
, &dt_idops_func
, "void(...)" },
211 { "dirname", DT_IDENT_FUNC
, 0, DIF_SUBR_DIRNAME
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
212 &dt_idops_func
, "string(const char *)" },
213 { "discard", DT_IDENT_ACTFUNC
, 0, DT_ACT_DISCARD
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
214 &dt_idops_func
, "void(int)" },
215 { "epid", DT_IDENT_SCALAR
, 0, DIF_VAR_EPID
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
216 &dt_idops_type
, "uint_t" },
217 { "errno", DT_IDENT_SCALAR
, 0, DIF_VAR_ERRNO
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
218 &dt_idops_type
, "int" },
219 { "execname", DT_IDENT_SCALAR
, 0, DIF_VAR_EXECNAME
,
220 DT_ATTR_STABCMN
, DT_VERS_1_0
, &dt_idops_type
, "string" },
221 { "exit", DT_IDENT_ACTFUNC
, 0, DT_ACT_EXIT
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
222 &dt_idops_func
, "void(int)" },
223 { "freopen", DT_IDENT_ACTFUNC
, 0, DT_ACT_FREOPEN
, DT_ATTR_STABCMN
,
224 DT_VERS_1_1
, &dt_idops_func
, "void(@, ...)" },
225 { "ftruncate", DT_IDENT_ACTFUNC
, 0, DT_ACT_FTRUNCATE
, DT_ATTR_STABCMN
,
226 DT_VERS_1_0
, &dt_idops_func
, "void()" },
227 { "func", DT_IDENT_ACTFUNC
, 0, DT_ACT_SYM
, DT_ATTR_STABCMN
,
228 DT_VERS_1_2
, &dt_idops_func
, "_symaddr(uintptr_t)" },
229 { "getmajor", DT_IDENT_FUNC
, 0, DIF_SUBR_GETMAJOR
,
230 DT_ATTR_EVOLCMN
, DT_VERS_1_0
,
231 &dt_idops_func
, "genunix`major_t(genunix`dev_t)" },
232 { "getminor", DT_IDENT_FUNC
, 0, DIF_SUBR_GETMINOR
,
233 DT_ATTR_EVOLCMN
, DT_VERS_1_0
,
234 &dt_idops_func
, "genunix`minor_t(genunix`dev_t)" },
235 { "htonl", DT_IDENT_FUNC
, 0, DIF_SUBR_HTONL
, DT_ATTR_EVOLCMN
, DT_VERS_1_3
,
236 &dt_idops_func
, "uint32_t(uint32_t)" },
237 { "htonll", DT_IDENT_FUNC
, 0, DIF_SUBR_HTONLL
, DT_ATTR_EVOLCMN
, DT_VERS_1_3
,
238 &dt_idops_func
, "uint64_t(uint64_t)" },
239 { "htons", DT_IDENT_FUNC
, 0, DIF_SUBR_HTONS
, DT_ATTR_EVOLCMN
, DT_VERS_1_3
,
240 &dt_idops_func
, "uint16_t(uint16_t)" },
241 { "gid", DT_IDENT_SCALAR
, 0, DIF_VAR_GID
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
242 &dt_idops_type
, "gid_t" },
243 { "id", DT_IDENT_SCALAR
, 0, DIF_VAR_ID
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
244 &dt_idops_type
, "uint_t" },
245 { "index", DT_IDENT_FUNC
, 0, DIF_SUBR_INDEX
, DT_ATTR_STABCMN
, DT_VERS_1_1
,
246 &dt_idops_func
, "int(const char *, const char *, [int])" },
247 { "inet_ntoa", DT_IDENT_FUNC
, 0, DIF_SUBR_INET_NTOA
, DT_ATTR_STABCMN
,
248 DT_VERS_1_5
, &dt_idops_func
, "string(ipaddr_t *)" },
249 { "inet_ntoa6", DT_IDENT_FUNC
, 0, DIF_SUBR_INET_NTOA6
, DT_ATTR_STABCMN
,
250 DT_VERS_1_5
, &dt_idops_func
, "string(in6_addr_t *)" },
251 { "inet_ntop", DT_IDENT_FUNC
, 0, DIF_SUBR_INET_NTOP
, DT_ATTR_STABCMN
,
252 DT_VERS_1_5
, &dt_idops_func
, "string(int, void *)" },
253 { "ipl", DT_IDENT_SCALAR
, 0, DIF_VAR_IPL
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
254 &dt_idops_type
, "uint_t" },
255 { "jstack", DT_IDENT_ACTFUNC
, 0, DT_ACT_JSTACK
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
256 &dt_idops_func
, "stack(...)" },
257 { "lltostr", DT_IDENT_FUNC
, 0, DIF_SUBR_LLTOSTR
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
258 &dt_idops_func
, "string(int64_t)" },
259 { "llquantize", DT_IDENT_AGGFUNC
, 0, DTRACEAGG_LLQUANTIZE
, DT_ATTR_STABCMN
,
260 DT_VERS_1_7
, &dt_idops_func
,
261 "void(@, int32_t, int32_t, int32_t, int32_t, ...)" },
262 { "lquantize", DT_IDENT_AGGFUNC
, 0, DTRACEAGG_LQUANTIZE
,
263 DT_ATTR_STABCMN
, DT_VERS_1_0
,
264 &dt_idops_func
, "void(@, int32_t, int32_t, ...)" },
265 { "max", DT_IDENT_AGGFUNC
, 0, DTRACEAGG_MAX
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
266 &dt_idops_func
, "void(@)" },
267 { "min", DT_IDENT_AGGFUNC
, 0, DTRACEAGG_MIN
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
268 &dt_idops_func
, "void(@)" },
269 { "mod", DT_IDENT_ACTFUNC
, 0, DT_ACT_MOD
, DT_ATTR_STABCMN
,
270 DT_VERS_1_2
, &dt_idops_func
, "_symaddr(uintptr_t)" },
271 { "msgdsize", DT_IDENT_FUNC
, 0, DIF_SUBR_MSGDSIZE
,
272 DT_ATTR_STABCMN
, DT_VERS_1_0
,
273 &dt_idops_func
, "size_t(mblk_t *)" },
274 { "msgsize", DT_IDENT_FUNC
, 0, DIF_SUBR_MSGSIZE
,
275 DT_ATTR_STABCMN
, DT_VERS_1_0
,
276 &dt_idops_func
, "size_t(mblk_t *)" },
277 { "mutex_owned", DT_IDENT_FUNC
, 0, DIF_SUBR_MUTEX_OWNED
,
278 DT_ATTR_EVOLCMN
, DT_VERS_1_0
,
279 &dt_idops_func
, "int(genunix`kmutex_t *)" },
280 { "mutex_owner", DT_IDENT_FUNC
, 0, DIF_SUBR_MUTEX_OWNER
,
281 DT_ATTR_EVOLCMN
, DT_VERS_1_0
,
282 &dt_idops_func
, "genunix`kthread_t *(genunix`kmutex_t *)" },
283 { "mutex_type_adaptive", DT_IDENT_FUNC
, 0, DIF_SUBR_MUTEX_TYPE_ADAPTIVE
,
284 DT_ATTR_EVOLCMN
, DT_VERS_1_0
,
285 &dt_idops_func
, "int(genunix`kmutex_t *)" },
286 { "mutex_type_spin", DT_IDENT_FUNC
, 0, DIF_SUBR_MUTEX_TYPE_SPIN
,
287 DT_ATTR_EVOLCMN
, DT_VERS_1_0
,
288 &dt_idops_func
, "int(genunix`kmutex_t *)" },
289 { "ntohl", DT_IDENT_FUNC
, 0, DIF_SUBR_NTOHL
, DT_ATTR_EVOLCMN
, DT_VERS_1_3
,
290 &dt_idops_func
, "uint32_t(uint32_t)" },
291 { "ntohll", DT_IDENT_FUNC
, 0, DIF_SUBR_NTOHLL
, DT_ATTR_EVOLCMN
, DT_VERS_1_3
,
292 &dt_idops_func
, "uint64_t(uint64_t)" },
293 { "ntohs", DT_IDENT_FUNC
, 0, DIF_SUBR_NTOHS
, DT_ATTR_EVOLCMN
, DT_VERS_1_3
,
294 &dt_idops_func
, "uint16_t(uint16_t)" },
295 { "normalize", DT_IDENT_ACTFUNC
, 0, DT_ACT_NORMALIZE
, DT_ATTR_STABCMN
,
296 DT_VERS_1_0
, &dt_idops_func
, "void(...)" },
297 { "panic", DT_IDENT_ACTFUNC
, 0, DT_ACT_PANIC
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
298 &dt_idops_func
, "void()" },
299 { "pid", DT_IDENT_SCALAR
, 0, DIF_VAR_PID
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
300 &dt_idops_type
, "pid_t" },
301 { "ppid", DT_IDENT_SCALAR
, 0, DIF_VAR_PPID
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
302 &dt_idops_type
, "pid_t" },
303 { "printa", DT_IDENT_ACTFUNC
, 0, DT_ACT_PRINTA
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
304 &dt_idops_func
, "void(@, ...)" },
305 { "printf", DT_IDENT_ACTFUNC
, 0, DT_ACT_PRINTF
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
306 &dt_idops_func
, "void(@, ...)" },
307 { "probefunc", DT_IDENT_SCALAR
, 0, DIF_VAR_PROBEFUNC
,
308 DT_ATTR_STABCMN
, DT_VERS_1_0
, &dt_idops_type
, "string" },
309 { "probemod", DT_IDENT_SCALAR
, 0, DIF_VAR_PROBEMOD
,
310 DT_ATTR_STABCMN
, DT_VERS_1_0
, &dt_idops_type
, "string" },
311 { "probename", DT_IDENT_SCALAR
, 0, DIF_VAR_PROBENAME
,
312 DT_ATTR_STABCMN
, DT_VERS_1_0
, &dt_idops_type
, "string" },
313 { "probeprov", DT_IDENT_SCALAR
, 0, DIF_VAR_PROBEPROV
,
314 DT_ATTR_STABCMN
, DT_VERS_1_0
, &dt_idops_type
, "string" },
315 { "progenyof", DT_IDENT_FUNC
, 0, DIF_SUBR_PROGENYOF
,
316 DT_ATTR_STABCMN
, DT_VERS_1_0
,
317 &dt_idops_func
, "int(pid_t)" },
318 { "quantize", DT_IDENT_AGGFUNC
, 0, DTRACEAGG_QUANTIZE
,
319 DT_ATTR_STABCMN
, DT_VERS_1_0
,
320 &dt_idops_func
, "void(@, ...)" },
321 { "raise", DT_IDENT_ACTFUNC
, 0, DT_ACT_RAISE
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
322 &dt_idops_func
, "void(int)" },
323 { "rand", DT_IDENT_FUNC
, 0, DIF_SUBR_RAND
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
324 &dt_idops_func
, "int()" },
325 { "rindex", DT_IDENT_FUNC
, 0, DIF_SUBR_RINDEX
, DT_ATTR_STABCMN
, DT_VERS_1_1
,
326 &dt_idops_func
, "int(const char *, const char *, [int])" },
327 { "rw_iswriter", DT_IDENT_FUNC
, 0, DIF_SUBR_RW_ISWRITER
,
328 DT_ATTR_EVOLCMN
, DT_VERS_1_0
,
329 &dt_idops_func
, "int(genunix`krwlock_t *)" },
330 { "rw_read_held", DT_IDENT_FUNC
, 0, DIF_SUBR_RW_READ_HELD
,
331 DT_ATTR_EVOLCMN
, DT_VERS_1_0
,
332 &dt_idops_func
, "int(genunix`krwlock_t *)" },
333 { "rw_write_held", DT_IDENT_FUNC
, 0, DIF_SUBR_RW_WRITE_HELD
,
334 DT_ATTR_EVOLCMN
, DT_VERS_1_0
,
335 &dt_idops_func
, "int(genunix`krwlock_t *)" },
336 { "self", DT_IDENT_PTR
, 0, 0, DT_ATTR_STABCMN
, DT_VERS_1_0
,
337 &dt_idops_type
, "void" },
338 { "setopt", DT_IDENT_ACTFUNC
, 0, DT_ACT_SETOPT
, DT_ATTR_STABCMN
,
339 DT_VERS_1_2
, &dt_idops_func
, "void(const char *, [const char *])" },
340 { "speculate", DT_IDENT_ACTFUNC
, 0, DT_ACT_SPECULATE
,
341 DT_ATTR_STABCMN
, DT_VERS_1_0
,
342 &dt_idops_func
, "void(int)" },
343 { "speculation", DT_IDENT_FUNC
, 0, DIF_SUBR_SPECULATION
,
344 DT_ATTR_STABCMN
, DT_VERS_1_0
,
345 &dt_idops_func
, "int()" },
346 { "stack", DT_IDENT_ACTFUNC
, 0, DT_ACT_STACK
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
347 &dt_idops_func
, "stack(...)" },
348 { "stackdepth", DT_IDENT_SCALAR
, 0, DIF_VAR_STACKDEPTH
,
349 DT_ATTR_STABCMN
, DT_VERS_1_0
,
350 &dt_idops_type
, "uint32_t" },
351 { "stddev", DT_IDENT_AGGFUNC
, 0, DTRACEAGG_STDDEV
, DT_ATTR_STABCMN
,
352 DT_VERS_1_6
, &dt_idops_func
, "void(@)" },
353 { "stop", DT_IDENT_ACTFUNC
, 0, DT_ACT_STOP
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
354 &dt_idops_func
, "void()" },
355 { "strchr", DT_IDENT_FUNC
, 0, DIF_SUBR_STRCHR
, DT_ATTR_STABCMN
, DT_VERS_1_1
,
356 &dt_idops_func
, "string(const char *, char)" },
357 { "strlen", DT_IDENT_FUNC
, 0, DIF_SUBR_STRLEN
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
358 &dt_idops_func
, "size_t(const char *)" },
359 { "strjoin", DT_IDENT_FUNC
, 0, DIF_SUBR_STRJOIN
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
360 &dt_idops_func
, "string(const char *, const char *)" },
361 { "strrchr", DT_IDENT_FUNC
, 0, DIF_SUBR_STRRCHR
, DT_ATTR_STABCMN
, DT_VERS_1_1
,
362 &dt_idops_func
, "string(const char *, char)" },
363 { "strstr", DT_IDENT_FUNC
, 0, DIF_SUBR_STRSTR
, DT_ATTR_STABCMN
, DT_VERS_1_1
,
364 &dt_idops_func
, "string(const char *, const char *)" },
365 { "strtok", DT_IDENT_FUNC
, 0, DIF_SUBR_STRTOK
, DT_ATTR_STABCMN
, DT_VERS_1_1
,
366 &dt_idops_func
, "string(const char *, const char *)" },
367 { "substr", DT_IDENT_FUNC
, 0, DIF_SUBR_SUBSTR
, DT_ATTR_STABCMN
, DT_VERS_1_1
,
368 &dt_idops_func
, "string(const char *, int, [int])" },
369 { "sum", DT_IDENT_AGGFUNC
, 0, DTRACEAGG_SUM
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
370 &dt_idops_func
, "void(@)" },
371 { "sym", DT_IDENT_ACTFUNC
, 0, DT_ACT_SYM
, DT_ATTR_STABCMN
,
372 DT_VERS_1_2
, &dt_idops_func
, "_symaddr(uintptr_t)" },
373 { "system", DT_IDENT_ACTFUNC
, 0, DT_ACT_SYSTEM
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
374 &dt_idops_func
, "void(@, ...)" },
375 { "this", DT_IDENT_PTR
, 0, 0, DT_ATTR_STABCMN
, DT_VERS_1_0
,
376 &dt_idops_type
, "void" },
377 { "tid", DT_IDENT_SCALAR
, 0, DIF_VAR_TID
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
378 &dt_idops_type
, "id_t" },
379 { "timestamp", DT_IDENT_SCALAR
, 0, DIF_VAR_TIMESTAMP
,
380 DT_ATTR_STABCMN
, DT_VERS_1_0
,
381 &dt_idops_type
, "uint64_t" },
382 { "trace", DT_IDENT_ACTFUNC
, 0, DT_ACT_TRACE
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
383 &dt_idops_func
, "void(@)" },
384 { "tracemem", DT_IDENT_ACTFUNC
, 0, DT_ACT_TRACEMEM
,
385 DT_ATTR_STABCMN
, DT_VERS_1_0
,
386 &dt_idops_func
, "void(@, size_t, ...)" },
387 { "trunc", DT_IDENT_ACTFUNC
, 0, DT_ACT_TRUNC
, DT_ATTR_STABCMN
,
388 DT_VERS_1_0
, &dt_idops_func
, "void(...)" },
389 { "uaddr", DT_IDENT_ACTFUNC
, 0, DT_ACT_UADDR
, DT_ATTR_STABCMN
,
390 DT_VERS_1_2
, &dt_idops_func
, "_usymaddr(uintptr_t)" },
391 { "ucaller", DT_IDENT_SCALAR
, 0, DIF_VAR_UCALLER
, DT_ATTR_STABCMN
,
392 DT_VERS_1_2
, &dt_idops_type
, "uint64_t" },
393 { "ufunc", DT_IDENT_ACTFUNC
, 0, DT_ACT_USYM
, DT_ATTR_STABCMN
,
394 DT_VERS_1_2
, &dt_idops_func
, "_usymaddr(uintptr_t)" },
395 { "uid", DT_IDENT_SCALAR
, 0, DIF_VAR_UID
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
396 &dt_idops_type
, "uid_t" },
397 { "umod", DT_IDENT_ACTFUNC
, 0, DT_ACT_UMOD
, DT_ATTR_STABCMN
,
398 DT_VERS_1_2
, &dt_idops_func
, "_usymaddr(uintptr_t)" },
399 { "uregs", DT_IDENT_ARRAY
, 0, DIF_VAR_UREGS
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
400 &dt_idops_regs
, NULL
},
401 { "ustack", DT_IDENT_ACTFUNC
, 0, DT_ACT_USTACK
, DT_ATTR_STABCMN
, DT_VERS_1_0
,
402 &dt_idops_func
, "stack(...)" },
403 { "ustackdepth", DT_IDENT_SCALAR
, 0, DIF_VAR_USTACKDEPTH
,
404 DT_ATTR_STABCMN
, DT_VERS_1_2
,
405 &dt_idops_type
, "uint32_t" },
406 { "usym", DT_IDENT_ACTFUNC
, 0, DT_ACT_USYM
, DT_ATTR_STABCMN
,
407 DT_VERS_1_2
, &dt_idops_func
, "_usymaddr(uintptr_t)" },
408 { "vmregs", DT_IDENT_ARRAY
, 0, DIF_VAR_VMREGS
, DT_ATTR_STABCMN
, DT_VERS_1_7
,
409 &dt_idops_regs
, NULL
},
410 { "vtimestamp", DT_IDENT_SCALAR
, 0, DIF_VAR_VTIMESTAMP
,
411 DT_ATTR_STABCMN
, DT_VERS_1_0
,
412 &dt_idops_type
, "uint64_t" },
413 { "walltimestamp", DT_IDENT_SCALAR
, 0, DIF_VAR_WALLTIMESTAMP
,
414 DT_ATTR_STABCMN
, DT_VERS_1_0
,
415 &dt_idops_type
, "int64_t" },
416 { "zonename", DT_IDENT_SCALAR
, 0, DIF_VAR_ZONENAME
,
417 DT_ATTR_STABCMN
, DT_VERS_1_0
, &dt_idops_type
, "string" },
418 { NULL
, 0, 0, 0, { 0, 0, 0 }, 0, NULL
, NULL
}
422 * Tables of ILP32 intrinsic integer and floating-point type templates to use
423 * to populate the dynamic "C" CTF type container.
425 static const dt_intrinsic_t _dtrace_intrinsics_32
[] = {
426 { "void", { CTF_INT_SIGNED
, 0, 0 }, CTF_K_INTEGER
},
427 { "signed", { CTF_INT_SIGNED
, 0, 32 }, CTF_K_INTEGER
},
428 { "unsigned", { 0, 0, 32 }, CTF_K_INTEGER
},
429 { "char", { CTF_INT_SIGNED
| CTF_INT_CHAR
, 0, 8 }, CTF_K_INTEGER
},
430 { "short", { CTF_INT_SIGNED
, 0, 16 }, CTF_K_INTEGER
},
431 { "int", { CTF_INT_SIGNED
, 0, 32 }, CTF_K_INTEGER
},
432 { "long", { CTF_INT_SIGNED
, 0, 32 }, CTF_K_INTEGER
},
433 { "long long", { CTF_INT_SIGNED
, 0, 64 }, CTF_K_INTEGER
},
434 { "signed char", { CTF_INT_SIGNED
| CTF_INT_CHAR
, 0, 8 }, CTF_K_INTEGER
},
435 { "signed short", { CTF_INT_SIGNED
, 0, 16 }, CTF_K_INTEGER
},
436 { "signed int", { CTF_INT_SIGNED
, 0, 32 }, CTF_K_INTEGER
},
437 { "signed long", { CTF_INT_SIGNED
, 0, 32 }, CTF_K_INTEGER
},
438 { "signed long long", { CTF_INT_SIGNED
, 0, 64 }, CTF_K_INTEGER
},
439 { "unsigned char", { CTF_INT_CHAR
, 0, 8 }, CTF_K_INTEGER
},
440 { "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER
},
441 { "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER
},
442 { "unsigned long", { 0, 0, 32 }, CTF_K_INTEGER
},
443 { "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER
},
444 { "_Bool", { CTF_INT_BOOL
, 0, 8 }, CTF_K_INTEGER
},
445 { "float", { CTF_FP_SINGLE
, 0, 32 }, CTF_K_FLOAT
},
446 { "double", { CTF_FP_DOUBLE
, 0, 64 }, CTF_K_FLOAT
},
447 { "long double", { CTF_FP_LDOUBLE
, 0, 128 }, CTF_K_FLOAT
},
448 { "float imaginary", { CTF_FP_IMAGRY
, 0, 32 }, CTF_K_FLOAT
},
449 { "double imaginary", { CTF_FP_DIMAGRY
, 0, 64 }, CTF_K_FLOAT
},
450 { "long double imaginary", { CTF_FP_LDIMAGRY
, 0, 128 }, CTF_K_FLOAT
},
451 { "float complex", { CTF_FP_CPLX
, 0, 64 }, CTF_K_FLOAT
},
452 { "double complex", { CTF_FP_DCPLX
, 0, 128 }, CTF_K_FLOAT
},
453 { "long double complex", { CTF_FP_LDCPLX
, 0, 256 }, CTF_K_FLOAT
},
454 { NULL
, { 0, 0, 0 }, 0 }
458 * Tables of LP64 intrinsic integer and floating-point type templates to use
459 * to populate the dynamic "C" CTF type container.
461 static const dt_intrinsic_t _dtrace_intrinsics_64
[] = {
462 { "void", { CTF_INT_SIGNED
, 0, 0 }, CTF_K_INTEGER
},
463 { "signed", { CTF_INT_SIGNED
, 0, 32 }, CTF_K_INTEGER
},
464 { "unsigned", { 0, 0, 32 }, CTF_K_INTEGER
},
465 { "char", { CTF_INT_SIGNED
| CTF_INT_CHAR
, 0, 8 }, CTF_K_INTEGER
},
466 { "short", { CTF_INT_SIGNED
, 0, 16 }, CTF_K_INTEGER
},
467 { "int", { CTF_INT_SIGNED
, 0, 32 }, CTF_K_INTEGER
},
468 { "long", { CTF_INT_SIGNED
, 0, 64 }, CTF_K_INTEGER
},
469 { "long long", { CTF_INT_SIGNED
, 0, 64 }, CTF_K_INTEGER
},
470 { "signed char", { CTF_INT_SIGNED
| CTF_INT_CHAR
, 0, 8 }, CTF_K_INTEGER
},
471 { "signed short", { CTF_INT_SIGNED
, 0, 16 }, CTF_K_INTEGER
},
472 { "signed int", { CTF_INT_SIGNED
, 0, 32 }, CTF_K_INTEGER
},
473 { "signed long", { CTF_INT_SIGNED
, 0, 64 }, CTF_K_INTEGER
},
474 { "signed long long", { CTF_INT_SIGNED
, 0, 64 }, CTF_K_INTEGER
},
475 { "unsigned char", { CTF_INT_CHAR
, 0, 8 }, CTF_K_INTEGER
},
476 { "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER
},
477 { "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER
},
478 { "unsigned long", { 0, 0, 64 }, CTF_K_INTEGER
},
479 { "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER
},
480 { "_Bool", { CTF_INT_BOOL
, 0, 8 }, CTF_K_INTEGER
},
481 { "float", { CTF_FP_SINGLE
, 0, 32 }, CTF_K_FLOAT
},
482 { "double", { CTF_FP_DOUBLE
, 0, 64 }, CTF_K_FLOAT
},
483 { "long double", { CTF_FP_LDOUBLE
, 0, 128 }, CTF_K_FLOAT
},
484 { "float imaginary", { CTF_FP_IMAGRY
, 0, 32 }, CTF_K_FLOAT
},
485 { "double imaginary", { CTF_FP_DIMAGRY
, 0, 64 }, CTF_K_FLOAT
},
486 { "long double imaginary", { CTF_FP_LDIMAGRY
, 0, 128 }, CTF_K_FLOAT
},
487 { "float complex", { CTF_FP_CPLX
, 0, 64 }, CTF_K_FLOAT
},
488 { "double complex", { CTF_FP_DCPLX
, 0, 128 }, CTF_K_FLOAT
},
489 { "long double complex", { CTF_FP_LDCPLX
, 0, 256 }, CTF_K_FLOAT
},
490 { NULL
, { 0, 0, 0 }, 0 }
494 * Tables of ILP32 typedefs to use to populate the dynamic "D" CTF container.
495 * These aliases ensure that D definitions can use typical <sys/types.h> names.
497 static const dt_typedef_t _dtrace_typedefs_32
[] = {
498 { "char", "int8_t" },
499 { "short", "int16_t" },
500 { "int", "int32_t" },
501 { "long long", "int64_t" },
502 { "int", "intptr_t" },
503 { "int", "ssize_t" },
504 { "unsigned char", "uint8_t" },
505 { "unsigned short", "uint16_t" },
506 { "unsigned", "uint32_t" },
507 { "unsigned long long", "uint64_t" },
508 { "unsigned char", "uchar_t" },
509 { "unsigned short", "ushort_t" },
510 { "unsigned", "uint_t" },
511 { "unsigned long", "ulong_t" },
512 { "unsigned long long", "u_longlong_t" },
513 { "int", "ptrdiff_t" },
514 { "unsigned", "uintptr_t" },
515 { "unsigned", "size_t" },
522 * Tables of LP64 typedefs to use to populate the dynamic "D" CTF container.
523 * These aliases ensure that D definitions can use typical <sys/types.h> names.
525 static const dt_typedef_t _dtrace_typedefs_64
[] = {
526 { "char", "int8_t" },
527 { "short", "int16_t" },
528 { "int", "int32_t" },
529 { "long", "int64_t" },
530 { "long", "intptr_t" },
531 { "long", "ssize_t" },
532 { "unsigned char", "uint8_t" },
533 { "unsigned short", "uint16_t" },
534 { "unsigned", "uint32_t" },
535 { "unsigned long", "uint64_t" },
536 { "unsigned char", "uchar_t" },
537 { "unsigned short", "ushort_t" },
538 { "unsigned", "uint_t" },
539 { "unsigned long", "ulong_t" },
540 { "unsigned long long", "u_longlong_t" },
541 { "long", "ptrdiff_t" },
542 { "unsigned long", "uintptr_t" },
543 { "unsigned long", "size_t" },
550 * Tables of ILP32 integer type templates used to populate the dtp->dt_ints[]
551 * cache when a new dtrace client open occurs. Values are set by dtrace_open().
553 static const dt_intdesc_t _dtrace_ints_32
[] = {
554 { "int", NULL
, CTF_ERR
, 0x7fffffffULL
},
555 { "unsigned int", NULL
, CTF_ERR
, 0xffffffffULL
},
556 { "long", NULL
, CTF_ERR
, 0x7fffffffULL
},
557 { "unsigned long", NULL
, CTF_ERR
, 0xffffffffULL
},
558 { "long long", NULL
, CTF_ERR
, 0x7fffffffffffffffULL
},
559 { "unsigned long long", NULL
, CTF_ERR
, 0xffffffffffffffffULL
}
563 * Tables of LP64 integer type templates used to populate the dtp->dt_ints[]
564 * cache when a new dtrace client open occurs. Values are set by dtrace_open().
566 static const dt_intdesc_t _dtrace_ints_64
[] = {
567 { "int", NULL
, CTF_ERR
, 0x7fffffffULL
},
568 { "unsigned int", NULL
, CTF_ERR
, 0xffffffffULL
},
569 { "long", NULL
, CTF_ERR
, 0x7fffffffffffffffULL
},
570 { "unsigned long", NULL
, CTF_ERR
, 0xffffffffffffffffULL
},
571 { "long long", NULL
, CTF_ERR
, 0x7fffffffffffffffULL
},
572 { "unsigned long long", NULL
, CTF_ERR
, 0xffffffffffffffffULL
}
576 * Table of macro variable templates used to populate the macro identifier hash
577 * when a new dtrace client open occurs. Values are set by dtrace_update().
579 static const dt_ident_t _dtrace_macros
[] = {
580 { "egid", DT_IDENT_SCALAR
, 0, 0, DT_ATTR_STABCMN
, DT_VERS_1_0
},
581 { "euid", DT_IDENT_SCALAR
, 0, 0, DT_ATTR_STABCMN
, DT_VERS_1_0
},
582 { "gid", DT_IDENT_SCALAR
, 0, 0, DT_ATTR_STABCMN
, DT_VERS_1_0
},
583 { "pid", DT_IDENT_SCALAR
, 0, 0, DT_ATTR_STABCMN
, DT_VERS_1_0
},
584 { "pgid", DT_IDENT_SCALAR
, 0, 0, DT_ATTR_STABCMN
, DT_VERS_1_0
},
585 { "ppid", DT_IDENT_SCALAR
, 0, 0, DT_ATTR_STABCMN
, DT_VERS_1_0
},
586 { "projid", DT_IDENT_SCALAR
, 0, 0, DT_ATTR_STABCMN
, DT_VERS_1_0
},
587 { "sid", DT_IDENT_SCALAR
, 0, 0, DT_ATTR_STABCMN
, DT_VERS_1_0
},
588 { "taskid", DT_IDENT_SCALAR
, 0, 0, DT_ATTR_STABCMN
, DT_VERS_1_0
},
589 { "target", DT_IDENT_SCALAR
, 0, 0, DT_ATTR_STABCMN
, DT_VERS_1_0
},
590 { "uid", DT_IDENT_SCALAR
, 0, 0, DT_ATTR_STABCMN
, DT_VERS_1_0
},
591 { NULL
, 0, 0, 0, { 0, 0, 0 }, 0 }
595 * Hard-wired definition string to be compiled and cached every time a new
596 * DTrace library handle is initialized. This string should only be used to
597 * contain definitions that should be present regardless of DTRACE_O_NOLIBS.
599 static const char _dtrace_hardwire
[] = "\
600 inline long NULL = 0; \n\
601 #pragma D binding \"1.0\" NULL\n\
605 * Default DTrace configuration to use when opening libdtrace DTRACE_O_NODEV.
606 * If DTRACE_O_NODEV is not set, we load the configuration from the kernel.
607 * The use of CTF_MODEL_NATIVE is more subtle than it might appear: we are
608 * relying on the fact that when running dtrace(1M), isaexec will invoke the
609 * binary with the same bitness as the kernel, which is what we want by default
610 * when generating our DIF. The user can override the choice using oflags.
612 static const dtrace_conf_t _dtrace_conf
= {
613 DIF_VERSION
, /* dtc_difversion */
614 DIF_DIR_NREGS
, /* dtc_difintregs */
615 DIF_DTR_NREGS
, /* dtc_diftupregs */
616 CTF_MODEL_NATIVE
/* dtc_ctfmodel */
619 const dtrace_attribute_t _dtrace_maxattr
= {
620 DTRACE_STABILITY_MAX
,
621 DTRACE_STABILITY_MAX
,
625 const dtrace_attribute_t _dtrace_defattr
= {
626 DTRACE_STABILITY_STABLE
,
627 DTRACE_STABILITY_STABLE
,
631 const dtrace_attribute_t _dtrace_symattr
= {
632 DTRACE_STABILITY_PRIVATE
,
633 DTRACE_STABILITY_PRIVATE
,
637 const dtrace_attribute_t _dtrace_typattr
= {
638 DTRACE_STABILITY_PRIVATE
,
639 DTRACE_STABILITY_PRIVATE
,
643 const dtrace_attribute_t _dtrace_prvattr
= {
644 DTRACE_STABILITY_PRIVATE
,
645 DTRACE_STABILITY_PRIVATE
,
649 const dtrace_pattr_t _dtrace_prvdesc
= {
650 { DTRACE_STABILITY_UNSTABLE
, DTRACE_STABILITY_UNSTABLE
, DTRACE_CLASS_COMMON
},
651 { DTRACE_STABILITY_UNSTABLE
, DTRACE_STABILITY_UNSTABLE
, DTRACE_CLASS_COMMON
},
652 { DTRACE_STABILITY_UNSTABLE
, DTRACE_STABILITY_UNSTABLE
, DTRACE_CLASS_COMMON
},
653 { DTRACE_STABILITY_UNSTABLE
, DTRACE_STABILITY_UNSTABLE
, DTRACE_CLASS_COMMON
},
654 { DTRACE_STABILITY_UNSTABLE
, DTRACE_STABILITY_UNSTABLE
, DTRACE_CLASS_COMMON
},
657 const char *_dtrace_defcpp
= "/usr/ccs/lib/cpp"; /* default cpp(1) to invoke */
658 const char *_dtrace_defld
= "/usr/ccs/bin/ld"; /* default ld(1) to invoke */
660 const char *_dtrace_libdir
= "/usr/lib/dtrace"; /* default library directory */
661 const char *_dtrace_provdir
= "/dev/dtrace/provider"; /* provider directory */
663 int _dtrace_strbuckets
= 211; /* default number of hash buckets (prime) */
664 int _dtrace_intbuckets
= 256; /* default number of integer buckets (Pof2) */
665 uint_t _dtrace_strsize
= 256; /* default size of string intrinsic type */
666 uint_t _dtrace_stkindent
= 14; /* default whitespace indent for stack/ustack */
667 uint_t _dtrace_pidbuckets
= 64; /* default number of pid hash buckets */
668 uint_t _dtrace_pidlrulim
= 8; /* default number of pid handles to cache */
669 size_t _dtrace_bufsize
= 512; /* default dt_buf_create() size */
670 int _dtrace_argmax
= 32; /* default maximum number of probe arguments */
672 int _dtrace_debug
= 0; /* debug messages enabled (off) */
673 const char *const _dtrace_version
= DT_VERS_STRING
; /* API version string */
674 int _dtrace_rdvers
= RD_VERSION
; /* rtld_db feature version */
676 typedef struct dt_fdlist
{
677 int *df_fds
; /* array of provider driver file descriptors */
678 uint_t df_ents
; /* number of valid elements in df_fds[] */
679 uint_t df_size
; /* size of df_fds[] */
682 #pragma init(_dtrace_init)
686 _dtrace_debug
= getenv("DTRACE_DEBUG") != NULL
;
688 for (; _dtrace_rdvers
> 0; _dtrace_rdvers
--) {
689 if (rd_init(_dtrace_rdvers
) == RD_OK
)
694 static dtrace_hdl_t
*
695 set_open_errno(dtrace_hdl_t
*dtp
, int *errp
, int err
)
705 dt_provmod_open(dt_provmod_t
**provmod
, dt_fdlist_t
*dfp
)
709 struct dirent
*dp
, *ep
;
713 if ((dirp
= opendir(_dtrace_provdir
)) == NULL
)
714 return; /* failed to open directory; just skip it */
716 ep
= alloca(sizeof (struct dirent
) + PATH_MAX
+ 1);
717 bzero(ep
, sizeof (struct dirent
) + PATH_MAX
+ 1);
719 while (readdir_r(dirp
, ep
, &dp
) == 0 && dp
!= NULL
) {
720 if (dp
->d_name
[0] == '.')
721 continue; /* skip "." and ".." */
723 if (dfp
->df_ents
== dfp
->df_size
) {
724 uint_t size
= dfp
->df_size
? dfp
->df_size
* 2 : 16;
725 int *fds
= realloc(dfp
->df_fds
, size
* sizeof (int));
728 break; /* skip the rest of this directory */
734 (void) snprintf(path
, sizeof (path
), "%s/%s",
735 _dtrace_provdir
, dp
->d_name
);
737 if ((fd
= open(path
, O_RDONLY
)) == -1)
738 continue; /* failed to open driver; just skip it */
740 if (((prov
= malloc(sizeof (dt_provmod_t
))) == NULL
) ||
741 (prov
->dp_name
= malloc(strlen(dp
->d_name
) + 1)) == NULL
) {
747 (void) strcpy(prov
->dp_name
, dp
->d_name
);
748 prov
->dp_next
= *provmod
;
751 dt_dprintf("opened provider %s\n", dp
->d_name
);
752 dfp
->df_fds
[dfp
->df_ents
++] = fd
;
755 (void) closedir(dirp
);
759 dt_provmod_destroy(dt_provmod_t
**provmod
)
761 dt_provmod_t
*next
, *current
;
763 for (current
= *provmod
; current
!= NULL
; current
= next
) {
764 next
= current
->dp_next
;
765 free(current
->dp_name
);
773 dt_get_sysinfo(int cmd
, char *buf
, size_t len
)
775 ssize_t rv
= sysinfo(cmd
, buf
, len
);
778 if (rv
< 0 || rv
> len
)
779 (void) snprintf(buf
, len
, "%s", "Unknown");
781 while ((p
= strchr(p
, '.')) != NULL
)
787 static dtrace_hdl_t
*
788 dt_vopen(int version
, int flags
, int *errp
,
789 const dtrace_vector_t
*vector
, void *arg
)
791 dtrace_hdl_t
*dtp
= NULL
;
792 int dtfd
= -1, ftfd
= -1, fterr
= 0;
795 dt_provmod_t
*provmod
= NULL
;
799 const dt_intrinsic_t
*dinp
;
800 const dt_typedef_t
*dtyp
;
801 const dt_ident_t
*idp
;
803 dtrace_typeinfo_t dtt
;
807 dt_fdlist_t df
= { NULL
, 0, 0 };
809 char isadef
[32], utsdef
[32];
813 return (set_open_errno(dtp
, errp
, EINVAL
));
815 if (version
> DTRACE_VERSION
)
816 return (set_open_errno(dtp
, errp
, EDT_VERSION
));
818 if (version
< DTRACE_VERSION
) {
820 * Currently, increasing the library version number is used to
821 * denote a binary incompatible change. That is, a consumer
822 * of the library cannot run on a version of the library with
823 * a higher DTRACE_VERSION number than the consumer compiled
824 * against. Once the library API has been committed to,
825 * backwards binary compatibility will be required; at that
826 * time, this check should change to return EDT_OVERSION only
827 * if the specified version number is less than the version
828 * number at the time of interface commitment.
830 return (set_open_errno(dtp
, errp
, EDT_OVERSION
));
833 if (flags
& ~DTRACE_O_MASK
)
834 return (set_open_errno(dtp
, errp
, EINVAL
));
836 if ((flags
& DTRACE_O_LP64
) && (flags
& DTRACE_O_ILP32
))
837 return (set_open_errno(dtp
, errp
, EINVAL
));
839 if (vector
== NULL
&& arg
!= NULL
)
840 return (set_open_errno(dtp
, errp
, EINVAL
));
842 if (elf_version(EV_CURRENT
) == EV_NONE
)
843 return (set_open_errno(dtp
, errp
, EDT_ELFVERSION
));
845 if (vector
!= NULL
|| (flags
& DTRACE_O_NODEV
))
846 goto alloc
; /* do not attempt to open dtrace device */
849 * Before we get going, crank our limit on file descriptors up to the
850 * hard limit. This is to allow for the fact that libproc keeps file
851 * descriptors to objects open for the lifetime of the proc handle;
852 * without raising our hard limit, we would have an acceptably small
853 * bound on the number of processes that we could concurrently
854 * instrument with the pid provider.
856 if (getrlimit(RLIMIT_NOFILE
, &rl
) == 0) {
857 rl
.rlim_cur
= rl
.rlim_max
;
858 (void) setrlimit(RLIMIT_NOFILE
, &rl
);
862 * Get the device path of each of the providers. We hold them open
863 * in the df.df_fds list until we open the DTrace driver itself,
864 * allowing us to see all of the probes provided on this system. Once
865 * we have the DTrace driver open, we can safely close all the providers
866 * now that they have registered with the framework.
868 dt_provmod_open(&provmod
, &df
);
870 dtfd
= open("/dev/dtrace/dtrace", O_RDWR
);
871 err
= errno
; /* save errno from opening dtfd */
873 ftfd
= open("/dev/dtrace/provider/fasttrap", O_RDWR
);
874 fterr
= ftfd
== -1 ? errno
: 0; /* save errno from open ftfd */
876 while (df
.df_ents
-- != 0)
877 (void) close(df
.df_fds
[df
.df_ents
]);
882 * If we failed to open the dtrace device, fail dtrace_open().
883 * We convert some kernel errnos to custom libdtrace errnos to
884 * improve the resulting message from the usual strerror().
887 dt_provmod_destroy(&provmod
);
899 return (set_open_errno(dtp
, errp
, err
));
902 (void) fcntl(dtfd
, F_SETFD
, FD_CLOEXEC
);
903 (void) fcntl(ftfd
, F_SETFD
, FD_CLOEXEC
);
906 if ((dtp
= malloc(sizeof (dtrace_hdl_t
))) == NULL
)
907 return (set_open_errno(dtp
, errp
, EDT_NOMEM
));
909 bzero(dtp
, sizeof (dtrace_hdl_t
));
910 dtp
->dt_oflags
= flags
;
911 dtp
->dt_prcmode
= DT_PROC_STOP_PREINIT
;
912 dtp
->dt_linkmode
= DT_LINK_KERNEL
;
913 dtp
->dt_linktype
= DT_LTYP_ELF
;
914 dtp
->dt_xlatemode
= DT_XL_STATIC
;
915 dtp
->dt_stdcmode
= DT_STDC_XA
;
916 dtp
->dt_version
= version
;
919 dtp
->dt_fterr
= fterr
;
920 dtp
->dt_cdefs_fd
= -1;
921 dtp
->dt_ddefs_fd
= -1;
922 dtp
->dt_stdout_fd
= -1;
923 dtp
->dt_modbuckets
= _dtrace_strbuckets
;
924 dtp
->dt_mods
= calloc(dtp
->dt_modbuckets
, sizeof (dt_module_t
*));
925 dtp
->dt_provbuckets
= _dtrace_strbuckets
;
926 dtp
->dt_provs
= calloc(dtp
->dt_provbuckets
, sizeof (dt_provider_t
*));
927 dt_proc_hash_create(dtp
);
928 dtp
->dt_vmax
= DT_VERS_LATEST
;
929 dtp
->dt_cpp_path
= strdup(_dtrace_defcpp
);
930 dtp
->dt_cpp_argv
= malloc(sizeof (char *));
931 dtp
->dt_cpp_argc
= 1;
932 dtp
->dt_cpp_args
= 1;
933 dtp
->dt_ld_path
= strdup(_dtrace_defld
);
934 dtp
->dt_provmod
= provmod
;
935 dtp
->dt_vector
= vector
;
938 (void) uname(&dtp
->dt_uts
);
940 if (dtp
->dt_mods
== NULL
|| dtp
->dt_provs
== NULL
||
941 dtp
->dt_procs
== NULL
|| dtp
->dt_ld_path
== NULL
||
942 dtp
->dt_cpp_path
== NULL
|| dtp
->dt_cpp_argv
== NULL
)
943 return (set_open_errno(dtp
, errp
, EDT_NOMEM
));
945 for (i
= 0; i
< DTRACEOPT_MAX
; i
++)
946 dtp
->dt_options
[i
] = DTRACEOPT_UNSET
;
948 dtp
->dt_cpp_argv
[0] = (char *)strbasename(dtp
->dt_cpp_path
);
950 (void) snprintf(isadef
, sizeof (isadef
), "-D__SUNW_D_%u",
951 (uint_t
)(sizeof (void *) * NBBY
));
953 (void) snprintf(utsdef
, sizeof (utsdef
), "-D__%s_%s",
954 dt_get_sysinfo(SI_SYSNAME
, s1
, sizeof (s1
)),
955 dt_get_sysinfo(SI_RELEASE
, s2
, sizeof (s2
)));
957 if (dt_cpp_add_arg(dtp
, "-D__sun") == NULL
||
958 dt_cpp_add_arg(dtp
, "-D__unix") == NULL
||
959 dt_cpp_add_arg(dtp
, "-D__SVR4") == NULL
||
960 dt_cpp_add_arg(dtp
, "-D__SUNW_D=1") == NULL
||
961 dt_cpp_add_arg(dtp
, isadef
) == NULL
||
962 dt_cpp_add_arg(dtp
, utsdef
) == NULL
)
963 return (set_open_errno(dtp
, errp
, EDT_NOMEM
));
965 if (flags
& DTRACE_O_NODEV
)
966 bcopy(&_dtrace_conf
, &dtp
->dt_conf
, sizeof (_dtrace_conf
));
967 else if (dt_ioctl(dtp
, DTRACEIOC_CONF
, &dtp
->dt_conf
) != 0)
968 return (set_open_errno(dtp
, errp
, errno
));
970 if (flags
& DTRACE_O_LP64
)
971 dtp
->dt_conf
.dtc_ctfmodel
= CTF_MODEL_LP64
;
972 else if (flags
& DTRACE_O_ILP32
)
973 dtp
->dt_conf
.dtc_ctfmodel
= CTF_MODEL_ILP32
;
977 * On SPARC systems, __sparc is always defined for <sys/isa_defs.h>
978 * and __sparcv9 is defined if we are doing a 64-bit compile.
980 if (dt_cpp_add_arg(dtp
, "-D__sparc") == NULL
)
981 return (set_open_errno(dtp
, errp
, EDT_NOMEM
));
983 if (dtp
->dt_conf
.dtc_ctfmodel
== CTF_MODEL_LP64
&&
984 dt_cpp_add_arg(dtp
, "-D__sparcv9") == NULL
)
985 return (set_open_errno(dtp
, errp
, EDT_NOMEM
));
990 * On x86 systems, __i386 is defined for <sys/isa_defs.h> for 32-bit
991 * compiles and __amd64 is defined for 64-bit compiles. Unlike SPARC,
992 * they are defined exclusive of one another (see PSARC 2004/619).
994 if (dtp
->dt_conf
.dtc_ctfmodel
== CTF_MODEL_LP64
) {
995 if (dt_cpp_add_arg(dtp
, "-D__amd64") == NULL
)
996 return (set_open_errno(dtp
, errp
, EDT_NOMEM
));
998 if (dt_cpp_add_arg(dtp
, "-D__i386") == NULL
)
999 return (set_open_errno(dtp
, errp
, EDT_NOMEM
));
1003 if (dtp
->dt_conf
.dtc_difversion
< DIF_VERSION
)
1004 return (set_open_errno(dtp
, errp
, EDT_DIFVERS
));
1006 if (dtp
->dt_conf
.dtc_ctfmodel
== CTF_MODEL_ILP32
)
1007 bcopy(_dtrace_ints_32
, dtp
->dt_ints
, sizeof (_dtrace_ints_32
));
1009 bcopy(_dtrace_ints_64
, dtp
->dt_ints
, sizeof (_dtrace_ints_64
));
1011 dtp
->dt_macros
= dt_idhash_create("macro", NULL
, 0, UINT_MAX
);
1012 dtp
->dt_aggs
= dt_idhash_create("aggregation", NULL
,
1013 DTRACE_AGGVARIDNONE
+ 1, UINT_MAX
);
1015 dtp
->dt_globals
= dt_idhash_create("global", _dtrace_globals
,
1016 DIF_VAR_OTHER_UBASE
, DIF_VAR_OTHER_MAX
);
1018 dtp
->dt_tls
= dt_idhash_create("thread local", NULL
,
1019 DIF_VAR_OTHER_UBASE
, DIF_VAR_OTHER_MAX
);
1021 if (dtp
->dt_macros
== NULL
|| dtp
->dt_aggs
== NULL
||
1022 dtp
->dt_globals
== NULL
|| dtp
->dt_tls
== NULL
)
1023 return (set_open_errno(dtp
, errp
, EDT_NOMEM
));
1026 * Populate the dt_macros identifier hash table by hand: we can't use
1027 * the dt_idhash_populate() mechanism because we're not yet compiling
1028 * and dtrace_update() needs to immediately reference these idents.
1030 for (idp
= _dtrace_macros
; idp
->di_name
!= NULL
; idp
++) {
1031 if (dt_idhash_insert(dtp
->dt_macros
, idp
->di_name
,
1032 idp
->di_kind
, idp
->di_flags
, idp
->di_id
, idp
->di_attr
,
1033 idp
->di_vers
, idp
->di_ops
? idp
->di_ops
: &dt_idops_thaw
,
1034 idp
->di_iarg
, 0) == NULL
)
1035 return (set_open_errno(dtp
, errp
, EDT_NOMEM
));
1039 * Update the module list using /system/object and load the values for
1040 * the macro variable definitions according to the current process.
1045 * Select the intrinsics and typedefs we want based on the data model.
1046 * The intrinsics are under "C". The typedefs are added under "D".
1048 if (dtp
->dt_conf
.dtc_ctfmodel
== CTF_MODEL_ILP32
) {
1049 dinp
= _dtrace_intrinsics_32
;
1050 dtyp
= _dtrace_typedefs_32
;
1052 dinp
= _dtrace_intrinsics_64
;
1053 dtyp
= _dtrace_typedefs_64
;
1057 * Create a dynamic CTF container under the "C" scope for intrinsic
1058 * types and types defined in ANSI-C header files that are included.
1060 if ((dmp
= dtp
->dt_cdefs
= dt_module_create(dtp
, "C")) == NULL
)
1061 return (set_open_errno(dtp
, errp
, EDT_NOMEM
));
1063 if ((dmp
->dm_ctfp
= ctf_create(&dtp
->dt_ctferr
)) == NULL
)
1064 return (set_open_errno(dtp
, errp
, EDT_CTF
));
1066 dt_dprintf("created CTF container for %s (%p)\n",
1067 dmp
->dm_name
, (void *)dmp
->dm_ctfp
);
1069 (void) ctf_setmodel(dmp
->dm_ctfp
, dtp
->dt_conf
.dtc_ctfmodel
);
1070 ctf_setspecific(dmp
->dm_ctfp
, dmp
);
1072 dmp
->dm_flags
= DT_DM_LOADED
; /* fake up loaded bit */
1073 dmp
->dm_modid
= -1; /* no module ID */
1076 * Fill the dynamic "C" CTF container with all of the intrinsic
1077 * integer and floating-point types appropriate for this data model.
1079 for (; dinp
->din_name
!= NULL
; dinp
++) {
1080 if (dinp
->din_kind
== CTF_K_INTEGER
) {
1081 err
= ctf_add_integer(dmp
->dm_ctfp
, CTF_ADD_ROOT
,
1082 dinp
->din_name
, &dinp
->din_data
);
1084 err
= ctf_add_float(dmp
->dm_ctfp
, CTF_ADD_ROOT
,
1085 dinp
->din_name
, &dinp
->din_data
);
1088 if (err
== CTF_ERR
) {
1089 dt_dprintf("failed to add %s to C container: %s\n",
1090 dinp
->din_name
, ctf_errmsg(
1091 ctf_errno(dmp
->dm_ctfp
)));
1092 return (set_open_errno(dtp
, errp
, EDT_CTF
));
1096 if (ctf_update(dmp
->dm_ctfp
) != 0) {
1097 dt_dprintf("failed to update C container: %s\n",
1098 ctf_errmsg(ctf_errno(dmp
->dm_ctfp
)));
1099 return (set_open_errno(dtp
, errp
, EDT_CTF
));
1103 * Add intrinsic pointer types that are needed to initialize printf
1104 * format dictionary types (see table in dt_printf.c).
1106 (void) ctf_add_pointer(dmp
->dm_ctfp
, CTF_ADD_ROOT
,
1107 ctf_lookup_by_name(dmp
->dm_ctfp
, "void"));
1109 (void) ctf_add_pointer(dmp
->dm_ctfp
, CTF_ADD_ROOT
,
1110 ctf_lookup_by_name(dmp
->dm_ctfp
, "char"));
1112 (void) ctf_add_pointer(dmp
->dm_ctfp
, CTF_ADD_ROOT
,
1113 ctf_lookup_by_name(dmp
->dm_ctfp
, "int"));
1115 if (ctf_update(dmp
->dm_ctfp
) != 0) {
1116 dt_dprintf("failed to update C container: %s\n",
1117 ctf_errmsg(ctf_errno(dmp
->dm_ctfp
)));
1118 return (set_open_errno(dtp
, errp
, EDT_CTF
));
1122 * Create a dynamic CTF container under the "D" scope for types that
1123 * are defined by the D program itself or on-the-fly by the D compiler.
1124 * The "D" CTF container is a child of the "C" CTF container.
1126 if ((dmp
= dtp
->dt_ddefs
= dt_module_create(dtp
, "D")) == NULL
)
1127 return (set_open_errno(dtp
, errp
, EDT_NOMEM
));
1129 if ((dmp
->dm_ctfp
= ctf_create(&dtp
->dt_ctferr
)) == NULL
)
1130 return (set_open_errno(dtp
, errp
, EDT_CTF
));
1132 dt_dprintf("created CTF container for %s (%p)\n",
1133 dmp
->dm_name
, (void *)dmp
->dm_ctfp
);
1135 (void) ctf_setmodel(dmp
->dm_ctfp
, dtp
->dt_conf
.dtc_ctfmodel
);
1136 ctf_setspecific(dmp
->dm_ctfp
, dmp
);
1138 dmp
->dm_flags
= DT_DM_LOADED
; /* fake up loaded bit */
1139 dmp
->dm_modid
= -1; /* no module ID */
1141 if (ctf_import(dmp
->dm_ctfp
, dtp
->dt_cdefs
->dm_ctfp
) == CTF_ERR
) {
1142 dt_dprintf("failed to import D parent container: %s\n",
1143 ctf_errmsg(ctf_errno(dmp
->dm_ctfp
)));
1144 return (set_open_errno(dtp
, errp
, EDT_CTF
));
1148 * Fill the dynamic "D" CTF container with all of the built-in typedefs
1149 * that we need to use for our D variable and function definitions.
1150 * This ensures that basic inttypes.h names are always available to us.
1152 for (; dtyp
->dty_src
!= NULL
; dtyp
++) {
1153 if (ctf_add_typedef(dmp
->dm_ctfp
, CTF_ADD_ROOT
,
1154 dtyp
->dty_dst
, ctf_lookup_by_name(dmp
->dm_ctfp
,
1155 dtyp
->dty_src
)) == CTF_ERR
) {
1156 dt_dprintf("failed to add typedef %s %s to D "
1157 "container: %s", dtyp
->dty_src
, dtyp
->dty_dst
,
1158 ctf_errmsg(ctf_errno(dmp
->dm_ctfp
)));
1159 return (set_open_errno(dtp
, errp
, EDT_CTF
));
1164 * Insert a CTF ID corresponding to a pointer to a type of kind
1165 * CTF_K_FUNCTION we can use in the compiler for function pointers.
1166 * CTF treats all function pointers as "int (*)()" so we only need one.
1168 ctc
.ctc_return
= ctf_lookup_by_name(dmp
->dm_ctfp
, "int");
1172 dtp
->dt_type_func
= ctf_add_function(dmp
->dm_ctfp
,
1173 CTF_ADD_ROOT
, &ctc
, NULL
);
1175 dtp
->dt_type_fptr
= ctf_add_pointer(dmp
->dm_ctfp
,
1176 CTF_ADD_ROOT
, dtp
->dt_type_func
);
1179 * We also insert CTF definitions for the special D intrinsic types
1180 * string and <DYN> into the D container. The string type is added
1181 * as a typedef of char[n]. The <DYN> type is an alias for void.
1182 * We compare types to these special CTF ids throughout the compiler.
1184 ctr
.ctr_contents
= ctf_lookup_by_name(dmp
->dm_ctfp
, "char");
1185 ctr
.ctr_index
= ctf_lookup_by_name(dmp
->dm_ctfp
, "long");
1186 ctr
.ctr_nelems
= _dtrace_strsize
;
1188 dtp
->dt_type_str
= ctf_add_typedef(dmp
->dm_ctfp
, CTF_ADD_ROOT
,
1189 "string", ctf_add_array(dmp
->dm_ctfp
, CTF_ADD_ROOT
, &ctr
));
1191 dtp
->dt_type_dyn
= ctf_add_typedef(dmp
->dm_ctfp
, CTF_ADD_ROOT
,
1192 "<DYN>", ctf_lookup_by_name(dmp
->dm_ctfp
, "void"));
1194 dtp
->dt_type_stack
= ctf_add_typedef(dmp
->dm_ctfp
, CTF_ADD_ROOT
,
1195 "stack", ctf_lookup_by_name(dmp
->dm_ctfp
, "void"));
1197 dtp
->dt_type_symaddr
= ctf_add_typedef(dmp
->dm_ctfp
, CTF_ADD_ROOT
,
1198 "_symaddr", ctf_lookup_by_name(dmp
->dm_ctfp
, "void"));
1200 dtp
->dt_type_usymaddr
= ctf_add_typedef(dmp
->dm_ctfp
, CTF_ADD_ROOT
,
1201 "_usymaddr", ctf_lookup_by_name(dmp
->dm_ctfp
, "void"));
1203 if (dtp
->dt_type_func
== CTF_ERR
|| dtp
->dt_type_fptr
== CTF_ERR
||
1204 dtp
->dt_type_str
== CTF_ERR
|| dtp
->dt_type_dyn
== CTF_ERR
||
1205 dtp
->dt_type_stack
== CTF_ERR
|| dtp
->dt_type_symaddr
== CTF_ERR
||
1206 dtp
->dt_type_usymaddr
== CTF_ERR
) {
1207 dt_dprintf("failed to add intrinsic to D container: %s\n",
1208 ctf_errmsg(ctf_errno(dmp
->dm_ctfp
)));
1209 return (set_open_errno(dtp
, errp
, EDT_CTF
));
1212 if (ctf_update(dmp
->dm_ctfp
) != 0) {
1213 dt_dprintf("failed update D container: %s\n",
1214 ctf_errmsg(ctf_errno(dmp
->dm_ctfp
)));
1215 return (set_open_errno(dtp
, errp
, EDT_CTF
));
1219 * Initialize the integer description table used to convert integer
1220 * constants to the appropriate types. Refer to the comments above
1221 * dt_node_int() for a complete description of how this table is used.
1223 for (i
= 0; i
< sizeof (dtp
->dt_ints
) / sizeof (dtp
->dt_ints
[0]); i
++) {
1224 if (dtrace_lookup_by_type(dtp
, DTRACE_OBJ_EVERY
,
1225 dtp
->dt_ints
[i
].did_name
, &dtt
) != 0) {
1226 dt_dprintf("failed to lookup integer type %s: %s\n",
1227 dtp
->dt_ints
[i
].did_name
,
1228 dtrace_errmsg(dtp
, dtrace_errno(dtp
)));
1229 return (set_open_errno(dtp
, errp
, dtp
->dt_errno
));
1231 dtp
->dt_ints
[i
].did_ctfp
= dtt
.dtt_ctfp
;
1232 dtp
->dt_ints
[i
].did_type
= dtt
.dtt_type
;
1236 * Now that we've created the "C" and "D" containers, move them to the
1237 * start of the module list so that these types and symbols are found
1238 * first (for stability) when iterating through the module list.
1240 dt_list_delete(&dtp
->dt_modlist
, dtp
->dt_ddefs
);
1241 dt_list_prepend(&dtp
->dt_modlist
, dtp
->dt_ddefs
);
1243 dt_list_delete(&dtp
->dt_modlist
, dtp
->dt_cdefs
);
1244 dt_list_prepend(&dtp
->dt_modlist
, dtp
->dt_cdefs
);
1246 if (dt_pfdict_create(dtp
) == -1)
1247 return (set_open_errno(dtp
, errp
, dtp
->dt_errno
));
1250 * If we are opening libdtrace DTRACE_O_NODEV enable C_ZDEFS by default
1251 * because without /dev/dtrace open, we will not be able to load the
1252 * names and attributes of any providers or probes from the kernel.
1254 if (flags
& DTRACE_O_NODEV
)
1255 dtp
->dt_cflags
|= DTRACE_C_ZDEFS
;
1258 * Load hard-wired inlines into the definition cache by calling the
1259 * compiler on the raw definition string defined above.
1261 if ((pgp
= dtrace_program_strcompile(dtp
, _dtrace_hardwire
,
1262 DTRACE_PROBESPEC_NONE
, DTRACE_C_EMPTY
, 0, NULL
)) == NULL
) {
1263 dt_dprintf("failed to load hard-wired definitions: %s\n",
1264 dtrace_errmsg(dtp
, dtrace_errno(dtp
)));
1265 return (set_open_errno(dtp
, errp
, EDT_HARDWIRE
));
1268 dt_program_destroy(dtp
, pgp
);
1271 * Set up the default DTrace library path. Once set, the next call to
1272 * dt_compile() will compile all the libraries. We intentionally defer
1273 * library processing to improve overhead for clients that don't ever
1274 * compile, and to provide better error reporting (because the full
1275 * reporting of compiler errors requires dtrace_open() to succeed).
1277 if (dtrace_setopt(dtp
, "libdir", _dtrace_libdir
) != 0)
1278 return (set_open_errno(dtp
, errp
, dtp
->dt_errno
));
1284 dtrace_open(int version
, int flags
, int *errp
)
1286 return (dt_vopen(version
, flags
, errp
, NULL
, NULL
));
1290 dtrace_vopen(int version
, int flags
, int *errp
,
1291 const dtrace_vector_t
*vector
, void *arg
)
1293 return (dt_vopen(version
, flags
, errp
, vector
, arg
));
1297 dtrace_close(dtrace_hdl_t
*dtp
)
1299 dt_ident_t
*idp
, *ndp
;
1307 if (dtp
->dt_procs
!= NULL
)
1308 dt_proc_hash_destroy(dtp
);
1310 while ((pgp
= dt_list_next(&dtp
->dt_programs
)) != NULL
)
1311 dt_program_destroy(dtp
, pgp
);
1313 while ((dxp
= dt_list_next(&dtp
->dt_xlators
)) != NULL
)
1314 dt_xlator_destroy(dtp
, dxp
);
1316 dt_free(dtp
, dtp
->dt_xlatormap
);
1318 for (idp
= dtp
->dt_externs
; idp
!= NULL
; idp
= ndp
) {
1320 dt_ident_destroy(idp
);
1323 if (dtp
->dt_macros
!= NULL
)
1324 dt_idhash_destroy(dtp
->dt_macros
);
1325 if (dtp
->dt_aggs
!= NULL
)
1326 dt_idhash_destroy(dtp
->dt_aggs
);
1327 if (dtp
->dt_globals
!= NULL
)
1328 dt_idhash_destroy(dtp
->dt_globals
);
1329 if (dtp
->dt_tls
!= NULL
)
1330 dt_idhash_destroy(dtp
->dt_tls
);
1332 while ((dmp
= dt_list_next(&dtp
->dt_modlist
)) != NULL
)
1333 dt_module_destroy(dtp
, dmp
);
1335 while ((pvp
= dt_list_next(&dtp
->dt_provlist
)) != NULL
)
1336 dt_provider_destroy(dtp
, pvp
);
1338 if (dtp
->dt_fd
!= -1)
1339 (void) close(dtp
->dt_fd
);
1340 if (dtp
->dt_ftfd
!= -1)
1341 (void) close(dtp
->dt_ftfd
);
1342 if (dtp
->dt_cdefs_fd
!= -1)
1343 (void) close(dtp
->dt_cdefs_fd
);
1344 if (dtp
->dt_ddefs_fd
!= -1)
1345 (void) close(dtp
->dt_ddefs_fd
);
1346 if (dtp
->dt_stdout_fd
!= -1)
1347 (void) close(dtp
->dt_stdout_fd
);
1349 dt_epid_destroy(dtp
);
1350 dt_aggid_destroy(dtp
);
1351 dt_format_destroy(dtp
);
1352 dt_buffered_destroy(dtp
);
1353 dt_aggregate_destroy(dtp
);
1354 free(dtp
->dt_buf
.dtbd_data
);
1355 dt_pfdict_destroy(dtp
);
1356 dt_provmod_destroy(&dtp
->dt_provmod
);
1359 for (i
= 1; i
< dtp
->dt_cpp_argc
; i
++)
1360 free(dtp
->dt_cpp_argv
[i
]);
1362 while ((dirp
= dt_list_next(&dtp
->dt_lib_path
)) != NULL
) {
1363 dt_list_delete(&dtp
->dt_lib_path
, dirp
);
1364 free(dirp
->dir_path
);
1368 free(dtp
->dt_cpp_argv
);
1369 free(dtp
->dt_cpp_path
);
1370 free(dtp
->dt_ld_path
);
1373 free(dtp
->dt_provs
);
1378 dtrace_provider_modules(dtrace_hdl_t
*dtp
, const char **mods
, int nmods
)
1383 for (prov
= dtp
->dt_provmod
; prov
!= NULL
; prov
= prov
->dp_next
, i
++) {
1385 mods
[i
] = prov
->dp_name
;
1392 dtrace_ctlfd(dtrace_hdl_t
*dtp
)
1394 return (dtp
->dt_fd
);