Print this page
7085 add support for "if" and "else" statements in dtrace
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libdtrace/common/dt_open.c
+++ new/usr/src/lib/libdtrace/common/dt_open.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
25 25 * Copyright (c) 2012 by Delphix. All rights reserved.
26 26 */
27 27
28 28 #include <sys/types.h>
29 29 #include <sys/modctl.h>
30 30 #include <sys/systeminfo.h>
31 31 #include <sys/resource.h>
32 32
33 33 #include <libelf.h>
34 34 #include <strings.h>
35 35 #include <alloca.h>
36 36 #include <limits.h>
37 37 #include <unistd.h>
38 38 #include <stdlib.h>
39 39 #include <stdio.h>
40 40 #include <fcntl.h>
41 41 #include <errno.h>
42 42 #include <assert.h>
43 43
44 44 #define _POSIX_PTHREAD_SEMANTICS
45 45 #include <dirent.h>
46 46 #undef _POSIX_PTHREAD_SEMANTICS
47 47
48 48 #include <dt_impl.h>
49 49 #include <dt_program.h>
50 50 #include <dt_module.h>
51 51 #include <dt_printf.h>
52 52 #include <dt_string.h>
53 53 #include <dt_provider.h>
54 54
55 55 /*
56 56 * Stability and versioning definitions. These #defines are used in the tables
57 57 * of identifiers below to fill in the attribute and version fields associated
58 58 * with each identifier. The DT_ATTR_* macros are a convenience to permit more
59 59 * concise declarations of common attributes such as Stable/Stable/Common. The
60 60 * DT_VERS_* macros declare the encoded integer values of all versions used so
61 61 * far. DT_VERS_LATEST must correspond to the latest version value among all
62 62 * versions exported by the D compiler. DT_VERS_STRING must be an ASCII string
63 63 * that contains DT_VERS_LATEST within it along with any suffixes (e.g. Beta).
64 64 * You must update DT_VERS_LATEST and DT_VERS_STRING when adding a new version,
65 65 * and then add the new version to the _dtrace_versions[] array declared below.
66 66 * Refer to the Solaris Dynamic Tracing Guide Stability and Versioning chapters
67 67 * respectively for an explanation of these DTrace features and their values.
68 68 *
69 69 * NOTE: Although the DTrace versioning scheme supports the labeling and
70 70 * introduction of incompatible changes (e.g. dropping an interface in a
71 71 * major release), the libdtrace code does not currently support this.
72 72 * All versions are assumed to strictly inherit from one another. If
73 73 * we ever need to provide divergent interfaces, this will need work.
74 74 */
75 75 #define DT_ATTR_STABCMN { DTRACE_STABILITY_STABLE, \
76 76 DTRACE_STABILITY_STABLE, DTRACE_CLASS_COMMON }
77 77
78 78 #define DT_ATTR_EVOLCMN { DTRACE_STABILITY_EVOLVING, \
79 79 DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON \
80 80 }
81 81
82 82 /*
83 83 * The version number should be increased for every customer visible release
84 84 * of DTrace. The major number should be incremented when a fundamental
85 85 * change has been made that would affect all consumers, and would reflect
86 86 * sweeping changes to DTrace or the D language. The minor number should be
87 87 * incremented when a change is introduced that could break scripts that had
88 88 * previously worked; for example, adding a new built-in variable could break
89 89 * a script which was already using that identifier. The micro number should
90 90 * be changed when introducing functionality changes or major bug fixes that
91 91 * do not affect backward compatibility -- this is merely to make capabilities
92 92 * easily determined from the version number. Minor bugs do not require any
93 93 * modification to the version number.
94 94 */
95 95 #define DT_VERS_1_0 DT_VERSION_NUMBER(1, 0, 0)
96 96 #define DT_VERS_1_1 DT_VERSION_NUMBER(1, 1, 0)
97 97 #define DT_VERS_1_2 DT_VERSION_NUMBER(1, 2, 0)
98 98 #define DT_VERS_1_2_1 DT_VERSION_NUMBER(1, 2, 1)
99 99 #define DT_VERS_1_2_2 DT_VERSION_NUMBER(1, 2, 2)
100 100 #define DT_VERS_1_3 DT_VERSION_NUMBER(1, 3, 0)
101 101 #define DT_VERS_1_4 DT_VERSION_NUMBER(1, 4, 0)
102 102 #define DT_VERS_1_4_1 DT_VERSION_NUMBER(1, 4, 1)
103 103 #define DT_VERS_1_5 DT_VERSION_NUMBER(1, 5, 0)
104 104 #define DT_VERS_1_6 DT_VERSION_NUMBER(1, 6, 0)
105 105 #define DT_VERS_1_6_1 DT_VERSION_NUMBER(1, 6, 1)
106 106 #define DT_VERS_1_6_2 DT_VERSION_NUMBER(1, 6, 2)
107 107 #define DT_VERS_1_6_3 DT_VERSION_NUMBER(1, 6, 3)
↓ open down ↓ |
107 lines elided |
↑ open up ↑ |
108 108 #define DT_VERS_1_7 DT_VERSION_NUMBER(1, 7, 0)
109 109 #define DT_VERS_1_7_1 DT_VERSION_NUMBER(1, 7, 1)
110 110 #define DT_VERS_1_8 DT_VERSION_NUMBER(1, 8, 0)
111 111 #define DT_VERS_1_8_1 DT_VERSION_NUMBER(1, 8, 1)
112 112 #define DT_VERS_1_9 DT_VERSION_NUMBER(1, 9, 0)
113 113 #define DT_VERS_1_9_1 DT_VERSION_NUMBER(1, 9, 1)
114 114 #define DT_VERS_1_10 DT_VERSION_NUMBER(1, 10, 0)
115 115 #define DT_VERS_1_11 DT_VERSION_NUMBER(1, 11, 0)
116 116 #define DT_VERS_1_12 DT_VERSION_NUMBER(1, 12, 0)
117 117 #define DT_VERS_1_12_1 DT_VERSION_NUMBER(1, 12, 1)
118 -#define DT_VERS_LATEST DT_VERS_1_12_1
119 -#define DT_VERS_STRING "Sun D 1.12.1"
118 +#define DT_VERS_1_12_2 DT_VERSION_NUMBER(1, 12, 2)
119 +#define DT_VERS_LATEST DT_VERS_1_12_2
120 +#define DT_VERS_STRING "Sun D 1.12.2"
120 121
121 122 const dt_version_t _dtrace_versions[] = {
122 123 DT_VERS_1_0, /* D API 1.0.0 (PSARC 2001/466) Solaris 10 FCS */
123 124 DT_VERS_1_1, /* D API 1.1.0 Solaris Express 6/05 */
124 125 DT_VERS_1_2, /* D API 1.2.0 Solaris 10 Update 1 */
125 126 DT_VERS_1_2_1, /* D API 1.2.1 Solaris Express 4/06 */
126 127 DT_VERS_1_2_2, /* D API 1.2.2 Solaris Express 6/06 */
127 128 DT_VERS_1_3, /* D API 1.3 Solaris Express 10/06 */
128 129 DT_VERS_1_4, /* D API 1.4 Solaris Express 2/07 */
129 130 DT_VERS_1_4_1, /* D API 1.4.1 Solaris Express 4/07 */
130 131 DT_VERS_1_5, /* D API 1.5 Solaris Express 7/07 */
131 132 DT_VERS_1_6, /* D API 1.6 */
132 133 DT_VERS_1_6_1, /* D API 1.6.1 */
133 134 DT_VERS_1_6_2, /* D API 1.6.2 */
134 135 DT_VERS_1_6_3, /* D API 1.6.3 */
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
135 136 DT_VERS_1_7, /* D API 1.7 */
136 137 DT_VERS_1_7_1, /* D API 1.7.1 */
137 138 DT_VERS_1_8, /* D API 1.8 */
138 139 DT_VERS_1_8_1, /* D API 1.8.1 */
139 140 DT_VERS_1_9, /* D API 1.9 */
140 141 DT_VERS_1_9_1, /* D API 1.9.1 */
141 142 DT_VERS_1_10, /* D API 1.10 */
142 143 DT_VERS_1_11, /* D API 1.11 */
143 144 DT_VERS_1_12, /* D API 1.12 */
144 145 DT_VERS_1_12_1, /* D API 1.12.1 */
146 + DT_VERS_1_12_2, /* D API 1.12.2 */
145 147 0
146 148 };
147 149
148 150 /*
149 151 * Table of global identifiers. This is used to populate the global identifier
150 152 * hash when a new dtrace client open occurs. For more info see dt_ident.h.
151 153 * The global identifiers that represent functions use the dt_idops_func ops
152 154 * and specify the private data pointer as a prototype string which is parsed
153 155 * when the identifier is first encountered. These prototypes look like ANSI
154 156 * C function prototypes except that the special symbol "@" can be used as a
155 157 * wildcard to represent a single parameter of any type (i.e. any dt_node_t).
156 158 * The standard "..." notation can also be used to represent varargs. An empty
157 159 * parameter list is taken to mean void (that is, no arguments are permitted).
158 160 * A parameter enclosed in square brackets (e.g. "[int]") denotes an optional
159 161 * argument.
160 162 */
161 163 static const dt_ident_t _dtrace_globals[] = {
162 164 { "alloca", DT_IDENT_FUNC, 0, DIF_SUBR_ALLOCA, DT_ATTR_STABCMN, DT_VERS_1_0,
163 165 &dt_idops_func, "void *(size_t)" },
164 166 { "arg0", DT_IDENT_SCALAR, 0, DIF_VAR_ARG0, DT_ATTR_STABCMN, DT_VERS_1_0,
165 167 &dt_idops_type, "int64_t" },
166 168 { "arg1", DT_IDENT_SCALAR, 0, DIF_VAR_ARG1, DT_ATTR_STABCMN, DT_VERS_1_0,
167 169 &dt_idops_type, "int64_t" },
168 170 { "arg2", DT_IDENT_SCALAR, 0, DIF_VAR_ARG2, DT_ATTR_STABCMN, DT_VERS_1_0,
169 171 &dt_idops_type, "int64_t" },
170 172 { "arg3", DT_IDENT_SCALAR, 0, DIF_VAR_ARG3, DT_ATTR_STABCMN, DT_VERS_1_0,
171 173 &dt_idops_type, "int64_t" },
172 174 { "arg4", DT_IDENT_SCALAR, 0, DIF_VAR_ARG4, DT_ATTR_STABCMN, DT_VERS_1_0,
173 175 &dt_idops_type, "int64_t" },
174 176 { "arg5", DT_IDENT_SCALAR, 0, DIF_VAR_ARG5, DT_ATTR_STABCMN, DT_VERS_1_0,
175 177 &dt_idops_type, "int64_t" },
176 178 { "arg6", DT_IDENT_SCALAR, 0, DIF_VAR_ARG6, DT_ATTR_STABCMN, DT_VERS_1_0,
177 179 &dt_idops_type, "int64_t" },
178 180 { "arg7", DT_IDENT_SCALAR, 0, DIF_VAR_ARG7, DT_ATTR_STABCMN, DT_VERS_1_0,
179 181 &dt_idops_type, "int64_t" },
180 182 { "arg8", DT_IDENT_SCALAR, 0, DIF_VAR_ARG8, DT_ATTR_STABCMN, DT_VERS_1_0,
181 183 &dt_idops_type, "int64_t" },
182 184 { "arg9", DT_IDENT_SCALAR, 0, DIF_VAR_ARG9, DT_ATTR_STABCMN, DT_VERS_1_0,
183 185 &dt_idops_type, "int64_t" },
184 186 { "args", DT_IDENT_ARRAY, 0, DIF_VAR_ARGS, DT_ATTR_STABCMN, DT_VERS_1_0,
185 187 &dt_idops_args, NULL },
186 188 { "avg", DT_IDENT_AGGFUNC, 0, DTRACEAGG_AVG, DT_ATTR_STABCMN, DT_VERS_1_0,
187 189 &dt_idops_func, "void(@)" },
188 190 { "basename", DT_IDENT_FUNC, 0, DIF_SUBR_BASENAME, DT_ATTR_STABCMN, DT_VERS_1_0,
189 191 &dt_idops_func, "string(const char *)" },
190 192 { "bcopy", DT_IDENT_FUNC, 0, DIF_SUBR_BCOPY, DT_ATTR_STABCMN, DT_VERS_1_0,
191 193 &dt_idops_func, "void(void *, void *, size_t)" },
192 194 { "breakpoint", DT_IDENT_ACTFUNC, 0, DT_ACT_BREAKPOINT,
193 195 DT_ATTR_STABCMN, DT_VERS_1_0,
194 196 &dt_idops_func, "void()" },
195 197 { "caller", DT_IDENT_SCALAR, 0, DIF_VAR_CALLER, DT_ATTR_STABCMN, DT_VERS_1_0,
196 198 &dt_idops_type, "uintptr_t" },
197 199 { "chill", DT_IDENT_ACTFUNC, 0, DT_ACT_CHILL, DT_ATTR_STABCMN, DT_VERS_1_0,
198 200 &dt_idops_func, "void(int)" },
199 201 { "cleanpath", DT_IDENT_FUNC, 0, DIF_SUBR_CLEANPATH, DT_ATTR_STABCMN,
200 202 DT_VERS_1_0, &dt_idops_func, "string(const char *)" },
201 203 { "clear", DT_IDENT_ACTFUNC, 0, DT_ACT_CLEAR, DT_ATTR_STABCMN, DT_VERS_1_0,
202 204 &dt_idops_func, "void(...)" },
203 205 { "commit", DT_IDENT_ACTFUNC, 0, DT_ACT_COMMIT, DT_ATTR_STABCMN, DT_VERS_1_0,
204 206 &dt_idops_func, "void(int)" },
205 207 { "copyin", DT_IDENT_FUNC, 0, DIF_SUBR_COPYIN, DT_ATTR_STABCMN, DT_VERS_1_0,
206 208 &dt_idops_func, "void *(uintptr_t, size_t)" },
207 209 { "copyinstr", DT_IDENT_FUNC, 0, DIF_SUBR_COPYINSTR,
208 210 DT_ATTR_STABCMN, DT_VERS_1_0,
209 211 &dt_idops_func, "string(uintptr_t, [size_t])" },
210 212 { "copyinto", DT_IDENT_FUNC, 0, DIF_SUBR_COPYINTO, DT_ATTR_STABCMN,
211 213 DT_VERS_1_0, &dt_idops_func, "void(uintptr_t, size_t, void *)" },
212 214 { "copyout", DT_IDENT_FUNC, 0, DIF_SUBR_COPYOUT, DT_ATTR_STABCMN, DT_VERS_1_0,
213 215 &dt_idops_func, "void(void *, uintptr_t, size_t)" },
214 216 { "copyoutstr", DT_IDENT_FUNC, 0, DIF_SUBR_COPYOUTSTR,
215 217 DT_ATTR_STABCMN, DT_VERS_1_0,
216 218 &dt_idops_func, "void(char *, uintptr_t, size_t)" },
217 219 { "count", DT_IDENT_AGGFUNC, 0, DTRACEAGG_COUNT, DT_ATTR_STABCMN, DT_VERS_1_0,
218 220 &dt_idops_func, "void()" },
219 221 { "curthread", DT_IDENT_SCALAR, 0, DIF_VAR_CURTHREAD,
220 222 { DTRACE_STABILITY_STABLE, DTRACE_STABILITY_PRIVATE,
221 223 DTRACE_CLASS_COMMON }, DT_VERS_1_0,
222 224 &dt_idops_type, "genunix`kthread_t *" },
223 225 { "ddi_pathname", DT_IDENT_FUNC, 0, DIF_SUBR_DDI_PATHNAME,
224 226 DT_ATTR_EVOLCMN, DT_VERS_1_0,
225 227 &dt_idops_func, "string(void *, int64_t)" },
226 228 { "denormalize", DT_IDENT_ACTFUNC, 0, DT_ACT_DENORMALIZE, DT_ATTR_STABCMN,
227 229 DT_VERS_1_0, &dt_idops_func, "void(...)" },
228 230 { "dirname", DT_IDENT_FUNC, 0, DIF_SUBR_DIRNAME, DT_ATTR_STABCMN, DT_VERS_1_0,
229 231 &dt_idops_func, "string(const char *)" },
230 232 { "discard", DT_IDENT_ACTFUNC, 0, DT_ACT_DISCARD, DT_ATTR_STABCMN, DT_VERS_1_0,
231 233 &dt_idops_func, "void(int)" },
232 234 { "epid", DT_IDENT_SCALAR, 0, DIF_VAR_EPID, DT_ATTR_STABCMN, DT_VERS_1_0,
233 235 &dt_idops_type, "uint_t" },
234 236 { "errno", DT_IDENT_SCALAR, 0, DIF_VAR_ERRNO, DT_ATTR_STABCMN, DT_VERS_1_0,
235 237 &dt_idops_type, "int" },
236 238 { "execname", DT_IDENT_SCALAR, 0, DIF_VAR_EXECNAME,
237 239 DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
238 240 { "exit", DT_IDENT_ACTFUNC, 0, DT_ACT_EXIT, DT_ATTR_STABCMN, DT_VERS_1_0,
239 241 &dt_idops_func, "void(int)" },
240 242 { "freopen", DT_IDENT_ACTFUNC, 0, DT_ACT_FREOPEN, DT_ATTR_STABCMN,
241 243 DT_VERS_1_1, &dt_idops_func, "void(@, ...)" },
242 244 { "ftruncate", DT_IDENT_ACTFUNC, 0, DT_ACT_FTRUNCATE, DT_ATTR_STABCMN,
243 245 DT_VERS_1_0, &dt_idops_func, "void()" },
244 246 { "func", DT_IDENT_ACTFUNC, 0, DT_ACT_SYM, DT_ATTR_STABCMN,
245 247 DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" },
246 248 { "getmajor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMAJOR,
247 249 DT_ATTR_EVOLCMN, DT_VERS_1_0,
248 250 &dt_idops_func, "genunix`major_t(genunix`dev_t)" },
249 251 { "getminor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMINOR,
250 252 DT_ATTR_EVOLCMN, DT_VERS_1_0,
251 253 &dt_idops_func, "genunix`minor_t(genunix`dev_t)" },
252 254 { "htonl", DT_IDENT_FUNC, 0, DIF_SUBR_HTONL, DT_ATTR_EVOLCMN, DT_VERS_1_3,
253 255 &dt_idops_func, "uint32_t(uint32_t)" },
254 256 { "htonll", DT_IDENT_FUNC, 0, DIF_SUBR_HTONLL, DT_ATTR_EVOLCMN, DT_VERS_1_3,
255 257 &dt_idops_func, "uint64_t(uint64_t)" },
256 258 { "htons", DT_IDENT_FUNC, 0, DIF_SUBR_HTONS, DT_ATTR_EVOLCMN, DT_VERS_1_3,
257 259 &dt_idops_func, "uint16_t(uint16_t)" },
258 260 { "getf", DT_IDENT_FUNC, 0, DIF_SUBR_GETF, DT_ATTR_STABCMN, DT_VERS_1_10,
259 261 &dt_idops_func, "file_t *(int)" },
260 262 { "gid", DT_IDENT_SCALAR, 0, DIF_VAR_GID, DT_ATTR_STABCMN, DT_VERS_1_0,
261 263 &dt_idops_type, "gid_t" },
262 264 { "id", DT_IDENT_SCALAR, 0, DIF_VAR_ID, DT_ATTR_STABCMN, DT_VERS_1_0,
263 265 &dt_idops_type, "uint_t" },
264 266 { "index", DT_IDENT_FUNC, 0, DIF_SUBR_INDEX, DT_ATTR_STABCMN, DT_VERS_1_1,
265 267 &dt_idops_func, "int(const char *, const char *, [int])" },
266 268 { "inet_ntoa", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOA, DT_ATTR_STABCMN,
267 269 DT_VERS_1_5, &dt_idops_func, "string(ipaddr_t *)" },
268 270 { "inet_ntoa6", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOA6, DT_ATTR_STABCMN,
269 271 DT_VERS_1_5, &dt_idops_func, "string(in6_addr_t *)" },
270 272 { "inet_ntop", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOP, DT_ATTR_STABCMN,
271 273 DT_VERS_1_5, &dt_idops_func, "string(int, void *)" },
272 274 { "ipl", DT_IDENT_SCALAR, 0, DIF_VAR_IPL, DT_ATTR_STABCMN, DT_VERS_1_0,
273 275 &dt_idops_type, "uint_t" },
274 276 { "json", DT_IDENT_FUNC, 0, DIF_SUBR_JSON, DT_ATTR_STABCMN, DT_VERS_1_11,
275 277 &dt_idops_func, "string(const char *, const char *)" },
276 278 { "jstack", DT_IDENT_ACTFUNC, 0, DT_ACT_JSTACK, DT_ATTR_STABCMN, DT_VERS_1_0,
277 279 &dt_idops_func, "stack(...)" },
278 280 { "lltostr", DT_IDENT_FUNC, 0, DIF_SUBR_LLTOSTR, DT_ATTR_STABCMN, DT_VERS_1_0,
279 281 &dt_idops_func, "string(int64_t, [int])" },
280 282 { "llquantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_LLQUANTIZE, DT_ATTR_STABCMN,
281 283 DT_VERS_1_7, &dt_idops_func,
282 284 "void(@, int32_t, int32_t, int32_t, int32_t, ...)" },
283 285 { "lquantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_LQUANTIZE,
284 286 DT_ATTR_STABCMN, DT_VERS_1_0,
285 287 &dt_idops_func, "void(@, int32_t, int32_t, ...)" },
286 288 { "max", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MAX, DT_ATTR_STABCMN, DT_VERS_1_0,
287 289 &dt_idops_func, "void(@)" },
288 290 { "min", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MIN, DT_ATTR_STABCMN, DT_VERS_1_0,
289 291 &dt_idops_func, "void(@)" },
290 292 { "mod", DT_IDENT_ACTFUNC, 0, DT_ACT_MOD, DT_ATTR_STABCMN,
291 293 DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" },
292 294 { "msgdsize", DT_IDENT_FUNC, 0, DIF_SUBR_MSGDSIZE,
293 295 DT_ATTR_STABCMN, DT_VERS_1_0,
294 296 &dt_idops_func, "size_t(mblk_t *)" },
295 297 { "msgsize", DT_IDENT_FUNC, 0, DIF_SUBR_MSGSIZE,
296 298 DT_ATTR_STABCMN, DT_VERS_1_0,
297 299 &dt_idops_func, "size_t(mblk_t *)" },
298 300 { "mutex_owned", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNED,
299 301 DT_ATTR_EVOLCMN, DT_VERS_1_0,
300 302 &dt_idops_func, "int(genunix`kmutex_t *)" },
301 303 { "mutex_owner", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNER,
302 304 DT_ATTR_EVOLCMN, DT_VERS_1_0,
303 305 &dt_idops_func, "genunix`kthread_t *(genunix`kmutex_t *)" },
304 306 { "mutex_type_adaptive", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_ADAPTIVE,
305 307 DT_ATTR_EVOLCMN, DT_VERS_1_0,
306 308 &dt_idops_func, "int(genunix`kmutex_t *)" },
307 309 { "mutex_type_spin", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_SPIN,
308 310 DT_ATTR_EVOLCMN, DT_VERS_1_0,
309 311 &dt_idops_func, "int(genunix`kmutex_t *)" },
310 312 { "ntohl", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHL, DT_ATTR_EVOLCMN, DT_VERS_1_3,
311 313 &dt_idops_func, "uint32_t(uint32_t)" },
312 314 { "ntohll", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHLL, DT_ATTR_EVOLCMN, DT_VERS_1_3,
313 315 &dt_idops_func, "uint64_t(uint64_t)" },
314 316 { "ntohs", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHS, DT_ATTR_EVOLCMN, DT_VERS_1_3,
315 317 &dt_idops_func, "uint16_t(uint16_t)" },
316 318 { "normalize", DT_IDENT_ACTFUNC, 0, DT_ACT_NORMALIZE, DT_ATTR_STABCMN,
317 319 DT_VERS_1_0, &dt_idops_func, "void(...)" },
318 320 { "panic", DT_IDENT_ACTFUNC, 0, DT_ACT_PANIC, DT_ATTR_STABCMN, DT_VERS_1_0,
319 321 &dt_idops_func, "void()" },
320 322 { "pid", DT_IDENT_SCALAR, 0, DIF_VAR_PID, DT_ATTR_STABCMN, DT_VERS_1_0,
321 323 &dt_idops_type, "pid_t" },
322 324 { "ppid", DT_IDENT_SCALAR, 0, DIF_VAR_PPID, DT_ATTR_STABCMN, DT_VERS_1_0,
323 325 &dt_idops_type, "pid_t" },
324 326 { "print", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINT, DT_ATTR_STABCMN, DT_VERS_1_9,
325 327 &dt_idops_func, "void(@)" },
326 328 { "printa", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTA, DT_ATTR_STABCMN, DT_VERS_1_0,
327 329 &dt_idops_func, "void(@, ...)" },
328 330 { "printf", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTF, DT_ATTR_STABCMN, DT_VERS_1_0,
329 331 &dt_idops_func, "void(@, ...)" },
330 332 { "probefunc", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEFUNC,
331 333 DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
332 334 { "probemod", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEMOD,
333 335 DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
334 336 { "probename", DT_IDENT_SCALAR, 0, DIF_VAR_PROBENAME,
335 337 DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
336 338 { "probeprov", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEPROV,
337 339 DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
338 340 { "progenyof", DT_IDENT_FUNC, 0, DIF_SUBR_PROGENYOF,
339 341 DT_ATTR_STABCMN, DT_VERS_1_0,
340 342 &dt_idops_func, "int(pid_t)" },
341 343 { "quantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_QUANTIZE,
342 344 DT_ATTR_STABCMN, DT_VERS_1_0,
343 345 &dt_idops_func, "void(@, ...)" },
344 346 { "raise", DT_IDENT_ACTFUNC, 0, DT_ACT_RAISE, DT_ATTR_STABCMN, DT_VERS_1_0,
345 347 &dt_idops_func, "void(int)" },
346 348 { "rand", DT_IDENT_FUNC, 0, DIF_SUBR_RAND, DT_ATTR_STABCMN, DT_VERS_1_0,
347 349 &dt_idops_func, "int()" },
348 350 { "rindex", DT_IDENT_FUNC, 0, DIF_SUBR_RINDEX, DT_ATTR_STABCMN, DT_VERS_1_1,
349 351 &dt_idops_func, "int(const char *, const char *, [int])" },
350 352 { "rw_iswriter", DT_IDENT_FUNC, 0, DIF_SUBR_RW_ISWRITER,
351 353 DT_ATTR_EVOLCMN, DT_VERS_1_0,
352 354 &dt_idops_func, "int(genunix`krwlock_t *)" },
353 355 { "rw_read_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_READ_HELD,
354 356 DT_ATTR_EVOLCMN, DT_VERS_1_0,
355 357 &dt_idops_func, "int(genunix`krwlock_t *)" },
356 358 { "rw_write_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_WRITE_HELD,
357 359 DT_ATTR_EVOLCMN, DT_VERS_1_0,
358 360 &dt_idops_func, "int(genunix`krwlock_t *)" },
359 361 { "self", DT_IDENT_PTR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0,
360 362 &dt_idops_type, "void" },
361 363 { "setopt", DT_IDENT_ACTFUNC, 0, DT_ACT_SETOPT, DT_ATTR_STABCMN,
362 364 DT_VERS_1_2, &dt_idops_func, "void(const char *, [const char *])" },
363 365 { "speculate", DT_IDENT_ACTFUNC, 0, DT_ACT_SPECULATE,
364 366 DT_ATTR_STABCMN, DT_VERS_1_0,
365 367 &dt_idops_func, "void(int)" },
366 368 { "speculation", DT_IDENT_FUNC, 0, DIF_SUBR_SPECULATION,
367 369 DT_ATTR_STABCMN, DT_VERS_1_0,
368 370 &dt_idops_func, "int()" },
369 371 { "stack", DT_IDENT_ACTFUNC, 0, DT_ACT_STACK, DT_ATTR_STABCMN, DT_VERS_1_0,
370 372 &dt_idops_func, "stack(...)" },
371 373 { "stackdepth", DT_IDENT_SCALAR, 0, DIF_VAR_STACKDEPTH,
372 374 DT_ATTR_STABCMN, DT_VERS_1_0,
373 375 &dt_idops_type, "uint32_t" },
374 376 { "stddev", DT_IDENT_AGGFUNC, 0, DTRACEAGG_STDDEV, DT_ATTR_STABCMN,
375 377 DT_VERS_1_6, &dt_idops_func, "void(@)" },
376 378 { "stop", DT_IDENT_ACTFUNC, 0, DT_ACT_STOP, DT_ATTR_STABCMN, DT_VERS_1_0,
377 379 &dt_idops_func, "void()" },
378 380 { "strchr", DT_IDENT_FUNC, 0, DIF_SUBR_STRCHR, DT_ATTR_STABCMN, DT_VERS_1_1,
379 381 &dt_idops_func, "string(const char *, char)" },
380 382 { "strlen", DT_IDENT_FUNC, 0, DIF_SUBR_STRLEN, DT_ATTR_STABCMN, DT_VERS_1_0,
381 383 &dt_idops_func, "size_t(const char *)" },
382 384 { "strjoin", DT_IDENT_FUNC, 0, DIF_SUBR_STRJOIN, DT_ATTR_STABCMN, DT_VERS_1_0,
383 385 &dt_idops_func, "string(const char *, const char *)" },
384 386 { "strrchr", DT_IDENT_FUNC, 0, DIF_SUBR_STRRCHR, DT_ATTR_STABCMN, DT_VERS_1_1,
385 387 &dt_idops_func, "string(const char *, char)" },
386 388 { "strstr", DT_IDENT_FUNC, 0, DIF_SUBR_STRSTR, DT_ATTR_STABCMN, DT_VERS_1_1,
387 389 &dt_idops_func, "string(const char *, const char *)" },
388 390 { "strtok", DT_IDENT_FUNC, 0, DIF_SUBR_STRTOK, DT_ATTR_STABCMN, DT_VERS_1_1,
389 391 &dt_idops_func, "string(const char *, const char *)" },
390 392 { "strtoll", DT_IDENT_FUNC, 0, DIF_SUBR_STRTOLL, DT_ATTR_STABCMN, DT_VERS_1_11,
391 393 &dt_idops_func, "int64_t(const char *, [int])" },
392 394 { "substr", DT_IDENT_FUNC, 0, DIF_SUBR_SUBSTR, DT_ATTR_STABCMN, DT_VERS_1_1,
393 395 &dt_idops_func, "string(const char *, int, [int])" },
394 396 { "sum", DT_IDENT_AGGFUNC, 0, DTRACEAGG_SUM, DT_ATTR_STABCMN, DT_VERS_1_0,
395 397 &dt_idops_func, "void(@)" },
396 398 { "sym", DT_IDENT_ACTFUNC, 0, DT_ACT_SYM, DT_ATTR_STABCMN,
397 399 DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" },
398 400 { "system", DT_IDENT_ACTFUNC, 0, DT_ACT_SYSTEM, DT_ATTR_STABCMN, DT_VERS_1_0,
399 401 &dt_idops_func, "void(@, ...)" },
400 402 { "this", DT_IDENT_PTR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0,
401 403 &dt_idops_type, "void" },
402 404 { "tid", DT_IDENT_SCALAR, 0, DIF_VAR_TID, DT_ATTR_STABCMN, DT_VERS_1_0,
403 405 &dt_idops_type, "id_t" },
404 406 { "timestamp", DT_IDENT_SCALAR, 0, DIF_VAR_TIMESTAMP,
405 407 DT_ATTR_STABCMN, DT_VERS_1_0,
406 408 &dt_idops_type, "uint64_t" },
407 409 { "tolower", DT_IDENT_FUNC, 0, DIF_SUBR_TOLOWER, DT_ATTR_STABCMN, DT_VERS_1_8,
408 410 &dt_idops_func, "string(const char *)" },
409 411 { "toupper", DT_IDENT_FUNC, 0, DIF_SUBR_TOUPPER, DT_ATTR_STABCMN, DT_VERS_1_8,
410 412 &dt_idops_func, "string(const char *)" },
411 413 { "trace", DT_IDENT_ACTFUNC, 0, DT_ACT_TRACE, DT_ATTR_STABCMN, DT_VERS_1_0,
412 414 &dt_idops_func, "void(@)" },
413 415 { "tracemem", DT_IDENT_ACTFUNC, 0, DT_ACT_TRACEMEM,
414 416 DT_ATTR_STABCMN, DT_VERS_1_0,
415 417 &dt_idops_func, "void(@, size_t, ...)" },
416 418 { "trunc", DT_IDENT_ACTFUNC, 0, DT_ACT_TRUNC, DT_ATTR_STABCMN,
417 419 DT_VERS_1_0, &dt_idops_func, "void(...)" },
418 420 { "uaddr", DT_IDENT_ACTFUNC, 0, DT_ACT_UADDR, DT_ATTR_STABCMN,
419 421 DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" },
420 422 { "ucaller", DT_IDENT_SCALAR, 0, DIF_VAR_UCALLER, DT_ATTR_STABCMN,
421 423 DT_VERS_1_2, &dt_idops_type, "uint64_t" },
422 424 { "ufunc", DT_IDENT_ACTFUNC, 0, DT_ACT_USYM, DT_ATTR_STABCMN,
423 425 DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" },
424 426 { "uid", DT_IDENT_SCALAR, 0, DIF_VAR_UID, DT_ATTR_STABCMN, DT_VERS_1_0,
425 427 &dt_idops_type, "uid_t" },
426 428 { "umod", DT_IDENT_ACTFUNC, 0, DT_ACT_UMOD, DT_ATTR_STABCMN,
427 429 DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" },
428 430 { "uregs", DT_IDENT_ARRAY, 0, DIF_VAR_UREGS, DT_ATTR_STABCMN, DT_VERS_1_0,
429 431 &dt_idops_regs, NULL },
430 432 { "ustack", DT_IDENT_ACTFUNC, 0, DT_ACT_USTACK, DT_ATTR_STABCMN, DT_VERS_1_0,
431 433 &dt_idops_func, "stack(...)" },
432 434 { "ustackdepth", DT_IDENT_SCALAR, 0, DIF_VAR_USTACKDEPTH,
433 435 DT_ATTR_STABCMN, DT_VERS_1_2,
434 436 &dt_idops_type, "uint32_t" },
435 437 { "usym", DT_IDENT_ACTFUNC, 0, DT_ACT_USYM, DT_ATTR_STABCMN,
436 438 DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" },
437 439 { "vmregs", DT_IDENT_ARRAY, 0, DIF_VAR_VMREGS, DT_ATTR_STABCMN, DT_VERS_1_7,
438 440 &dt_idops_regs, NULL },
439 441 { "vtimestamp", DT_IDENT_SCALAR, 0, DIF_VAR_VTIMESTAMP,
440 442 DT_ATTR_STABCMN, DT_VERS_1_0,
441 443 &dt_idops_type, "uint64_t" },
442 444 { "walltimestamp", DT_IDENT_SCALAR, 0, DIF_VAR_WALLTIMESTAMP,
443 445 DT_ATTR_STABCMN, DT_VERS_1_0,
444 446 &dt_idops_type, "int64_t" },
445 447 { "zonename", DT_IDENT_SCALAR, 0, DIF_VAR_ZONENAME,
446 448 DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
447 449 { NULL, 0, 0, 0, { 0, 0, 0 }, 0, NULL, NULL }
448 450 };
449 451
450 452 /*
451 453 * Tables of ILP32 intrinsic integer and floating-point type templates to use
452 454 * to populate the dynamic "C" CTF type container.
453 455 */
454 456 static const dt_intrinsic_t _dtrace_intrinsics_32[] = {
455 457 { "void", { CTF_INT_SIGNED, 0, 0 }, CTF_K_INTEGER },
456 458 { "signed", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
457 459 { "unsigned", { 0, 0, 32 }, CTF_K_INTEGER },
458 460 { "char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
459 461 { "short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER },
460 462 { "int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
461 463 { "long", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
462 464 { "long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
463 465 { "signed char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
464 466 { "signed short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER },
465 467 { "signed int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
466 468 { "signed long", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
467 469 { "signed long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
468 470 { "unsigned char", { CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
469 471 { "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER },
470 472 { "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER },
471 473 { "unsigned long", { 0, 0, 32 }, CTF_K_INTEGER },
472 474 { "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER },
473 475 { "_Bool", { CTF_INT_BOOL, 0, 8 }, CTF_K_INTEGER },
474 476 { "float", { CTF_FP_SINGLE, 0, 32 }, CTF_K_FLOAT },
475 477 { "double", { CTF_FP_DOUBLE, 0, 64 }, CTF_K_FLOAT },
476 478 { "long double", { CTF_FP_LDOUBLE, 0, 128 }, CTF_K_FLOAT },
477 479 { "float imaginary", { CTF_FP_IMAGRY, 0, 32 }, CTF_K_FLOAT },
478 480 { "double imaginary", { CTF_FP_DIMAGRY, 0, 64 }, CTF_K_FLOAT },
479 481 { "long double imaginary", { CTF_FP_LDIMAGRY, 0, 128 }, CTF_K_FLOAT },
480 482 { "float complex", { CTF_FP_CPLX, 0, 64 }, CTF_K_FLOAT },
481 483 { "double complex", { CTF_FP_DCPLX, 0, 128 }, CTF_K_FLOAT },
482 484 { "long double complex", { CTF_FP_LDCPLX, 0, 256 }, CTF_K_FLOAT },
483 485 { NULL, { 0, 0, 0 }, 0 }
484 486 };
485 487
486 488 /*
487 489 * Tables of LP64 intrinsic integer and floating-point type templates to use
488 490 * to populate the dynamic "C" CTF type container.
489 491 */
490 492 static const dt_intrinsic_t _dtrace_intrinsics_64[] = {
491 493 { "void", { CTF_INT_SIGNED, 0, 0 }, CTF_K_INTEGER },
492 494 { "signed", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
493 495 { "unsigned", { 0, 0, 32 }, CTF_K_INTEGER },
494 496 { "char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
495 497 { "short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER },
496 498 { "int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
497 499 { "long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
498 500 { "long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
499 501 { "signed char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
500 502 { "signed short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER },
501 503 { "signed int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
502 504 { "signed long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
503 505 { "signed long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
504 506 { "unsigned char", { CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
505 507 { "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER },
506 508 { "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER },
507 509 { "unsigned long", { 0, 0, 64 }, CTF_K_INTEGER },
508 510 { "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER },
509 511 { "_Bool", { CTF_INT_BOOL, 0, 8 }, CTF_K_INTEGER },
510 512 { "float", { CTF_FP_SINGLE, 0, 32 }, CTF_K_FLOAT },
511 513 { "double", { CTF_FP_DOUBLE, 0, 64 }, CTF_K_FLOAT },
512 514 { "long double", { CTF_FP_LDOUBLE, 0, 128 }, CTF_K_FLOAT },
513 515 { "float imaginary", { CTF_FP_IMAGRY, 0, 32 }, CTF_K_FLOAT },
514 516 { "double imaginary", { CTF_FP_DIMAGRY, 0, 64 }, CTF_K_FLOAT },
515 517 { "long double imaginary", { CTF_FP_LDIMAGRY, 0, 128 }, CTF_K_FLOAT },
516 518 { "float complex", { CTF_FP_CPLX, 0, 64 }, CTF_K_FLOAT },
517 519 { "double complex", { CTF_FP_DCPLX, 0, 128 }, CTF_K_FLOAT },
518 520 { "long double complex", { CTF_FP_LDCPLX, 0, 256 }, CTF_K_FLOAT },
519 521 { NULL, { 0, 0, 0 }, 0 }
520 522 };
521 523
522 524 /*
523 525 * Tables of ILP32 typedefs to use to populate the dynamic "D" CTF container.
524 526 * These aliases ensure that D definitions can use typical <sys/types.h> names.
525 527 */
526 528 static const dt_typedef_t _dtrace_typedefs_32[] = {
527 529 { "char", "int8_t" },
528 530 { "short", "int16_t" },
529 531 { "int", "int32_t" },
530 532 { "long long", "int64_t" },
531 533 { "int", "intptr_t" },
532 534 { "int", "ssize_t" },
533 535 { "unsigned char", "uint8_t" },
534 536 { "unsigned short", "uint16_t" },
535 537 { "unsigned", "uint32_t" },
536 538 { "unsigned long long", "uint64_t" },
537 539 { "unsigned char", "uchar_t" },
538 540 { "unsigned short", "ushort_t" },
539 541 { "unsigned", "uint_t" },
540 542 { "unsigned long", "ulong_t" },
541 543 { "unsigned long long", "u_longlong_t" },
542 544 { "int", "ptrdiff_t" },
543 545 { "unsigned", "uintptr_t" },
544 546 { "unsigned", "size_t" },
545 547 { "long", "id_t" },
546 548 { "long", "pid_t" },
547 549 { NULL, NULL }
548 550 };
549 551
550 552 /*
551 553 * Tables of LP64 typedefs to use to populate the dynamic "D" CTF container.
552 554 * These aliases ensure that D definitions can use typical <sys/types.h> names.
553 555 */
554 556 static const dt_typedef_t _dtrace_typedefs_64[] = {
555 557 { "char", "int8_t" },
556 558 { "short", "int16_t" },
557 559 { "int", "int32_t" },
558 560 { "long", "int64_t" },
559 561 { "long", "intptr_t" },
560 562 { "long", "ssize_t" },
561 563 { "unsigned char", "uint8_t" },
562 564 { "unsigned short", "uint16_t" },
563 565 { "unsigned", "uint32_t" },
564 566 { "unsigned long", "uint64_t" },
565 567 { "unsigned char", "uchar_t" },
566 568 { "unsigned short", "ushort_t" },
567 569 { "unsigned", "uint_t" },
568 570 { "unsigned long", "ulong_t" },
569 571 { "unsigned long long", "u_longlong_t" },
570 572 { "long", "ptrdiff_t" },
571 573 { "unsigned long", "uintptr_t" },
572 574 { "unsigned long", "size_t" },
573 575 { "int", "id_t" },
574 576 { "int", "pid_t" },
575 577 { NULL, NULL }
576 578 };
577 579
578 580 /*
579 581 * Tables of ILP32 integer type templates used to populate the dtp->dt_ints[]
580 582 * cache when a new dtrace client open occurs. Values are set by dtrace_open().
581 583 */
582 584 static const dt_intdesc_t _dtrace_ints_32[] = {
583 585 { "int", NULL, CTF_ERR, 0x7fffffffULL },
584 586 { "unsigned int", NULL, CTF_ERR, 0xffffffffULL },
585 587 { "long", NULL, CTF_ERR, 0x7fffffffULL },
586 588 { "unsigned long", NULL, CTF_ERR, 0xffffffffULL },
587 589 { "long long", NULL, CTF_ERR, 0x7fffffffffffffffULL },
588 590 { "unsigned long long", NULL, CTF_ERR, 0xffffffffffffffffULL }
589 591 };
590 592
591 593 /*
592 594 * Tables of LP64 integer type templates used to populate the dtp->dt_ints[]
593 595 * cache when a new dtrace client open occurs. Values are set by dtrace_open().
594 596 */
595 597 static const dt_intdesc_t _dtrace_ints_64[] = {
596 598 { "int", NULL, CTF_ERR, 0x7fffffffULL },
597 599 { "unsigned int", NULL, CTF_ERR, 0xffffffffULL },
598 600 { "long", NULL, CTF_ERR, 0x7fffffffffffffffULL },
599 601 { "unsigned long", NULL, CTF_ERR, 0xffffffffffffffffULL },
600 602 { "long long", NULL, CTF_ERR, 0x7fffffffffffffffULL },
601 603 { "unsigned long long", NULL, CTF_ERR, 0xffffffffffffffffULL }
602 604 };
603 605
604 606 /*
605 607 * Table of macro variable templates used to populate the macro identifier hash
606 608 * when a new dtrace client open occurs. Values are set by dtrace_update().
607 609 */
608 610 static const dt_ident_t _dtrace_macros[] = {
609 611 { "egid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
610 612 { "euid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
611 613 { "gid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
612 614 { "pid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
613 615 { "pgid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
614 616 { "ppid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
615 617 { "projid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
616 618 { "sid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
617 619 { "taskid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
618 620 { "target", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
619 621 { "uid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
620 622 { NULL, 0, 0, 0, { 0, 0, 0 }, 0 }
621 623 };
622 624
623 625 /*
624 626 * Hard-wired definition string to be compiled and cached every time a new
625 627 * DTrace library handle is initialized. This string should only be used to
626 628 * contain definitions that should be present regardless of DTRACE_O_NOLIBS.
627 629 */
628 630 static const char _dtrace_hardwire[] = "\
629 631 inline long NULL = 0; \n\
630 632 #pragma D binding \"1.0\" NULL\n\
631 633 ";
632 634
633 635 /*
634 636 * Default DTrace configuration to use when opening libdtrace DTRACE_O_NODEV.
635 637 * If DTRACE_O_NODEV is not set, we load the configuration from the kernel.
636 638 * The use of CTF_MODEL_NATIVE is more subtle than it might appear: we are
637 639 * relying on the fact that when running dtrace(1M), isaexec will invoke the
638 640 * binary with the same bitness as the kernel, which is what we want by default
639 641 * when generating our DIF. The user can override the choice using oflags.
640 642 */
641 643 static const dtrace_conf_t _dtrace_conf = {
642 644 DIF_VERSION, /* dtc_difversion */
643 645 DIF_DIR_NREGS, /* dtc_difintregs */
644 646 DIF_DTR_NREGS, /* dtc_diftupregs */
645 647 CTF_MODEL_NATIVE /* dtc_ctfmodel */
646 648 };
647 649
648 650 const dtrace_attribute_t _dtrace_maxattr = {
649 651 DTRACE_STABILITY_MAX,
650 652 DTRACE_STABILITY_MAX,
651 653 DTRACE_CLASS_MAX
652 654 };
653 655
654 656 const dtrace_attribute_t _dtrace_defattr = {
655 657 DTRACE_STABILITY_STABLE,
656 658 DTRACE_STABILITY_STABLE,
657 659 DTRACE_CLASS_COMMON
658 660 };
659 661
660 662 const dtrace_attribute_t _dtrace_symattr = {
661 663 DTRACE_STABILITY_PRIVATE,
662 664 DTRACE_STABILITY_PRIVATE,
663 665 DTRACE_CLASS_UNKNOWN
664 666 };
665 667
666 668 const dtrace_attribute_t _dtrace_typattr = {
667 669 DTRACE_STABILITY_PRIVATE,
668 670 DTRACE_STABILITY_PRIVATE,
669 671 DTRACE_CLASS_UNKNOWN
670 672 };
671 673
672 674 const dtrace_attribute_t _dtrace_prvattr = {
673 675 DTRACE_STABILITY_PRIVATE,
674 676 DTRACE_STABILITY_PRIVATE,
675 677 DTRACE_CLASS_UNKNOWN
676 678 };
677 679
678 680 const dtrace_pattr_t _dtrace_prvdesc = {
679 681 { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
680 682 { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
681 683 { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
682 684 { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
683 685 { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
684 686 };
685 687
686 688 const char *_dtrace_defcpp = "/usr/ccs/lib/cpp"; /* default cpp(1) to invoke */
687 689 const char *_dtrace_defld = "/usr/ccs/bin/ld"; /* default ld(1) to invoke */
688 690
689 691 const char *_dtrace_libdir = "/usr/lib/dtrace"; /* default library directory */
690 692 const char *_dtrace_provdir = "/dev/dtrace/provider"; /* provider directory */
691 693
692 694 int _dtrace_strbuckets = 211; /* default number of hash buckets (prime) */
693 695 int _dtrace_intbuckets = 256; /* default number of integer buckets (Pof2) */
694 696 uint_t _dtrace_strsize = 256; /* default size of string intrinsic type */
695 697 uint_t _dtrace_stkindent = 14; /* default whitespace indent for stack/ustack */
696 698 uint_t _dtrace_pidbuckets = 64; /* default number of pid hash buckets */
697 699 uint_t _dtrace_pidlrulim = 8; /* default number of pid handles to cache */
698 700 size_t _dtrace_bufsize = 512; /* default dt_buf_create() size */
699 701 int _dtrace_argmax = 32; /* default maximum number of probe arguments */
700 702
701 703 int _dtrace_debug = 0; /* debug messages enabled (off) */
702 704 const char *const _dtrace_version = DT_VERS_STRING; /* API version string */
703 705 int _dtrace_rdvers = RD_VERSION; /* rtld_db feature version */
704 706
705 707 typedef struct dt_fdlist {
706 708 int *df_fds; /* array of provider driver file descriptors */
707 709 uint_t df_ents; /* number of valid elements in df_fds[] */
708 710 uint_t df_size; /* size of df_fds[] */
709 711 } dt_fdlist_t;
710 712
711 713 #pragma init(_dtrace_init)
712 714 void
713 715 _dtrace_init(void)
714 716 {
715 717 _dtrace_debug = getenv("DTRACE_DEBUG") != NULL;
716 718
717 719 for (; _dtrace_rdvers > 0; _dtrace_rdvers--) {
718 720 if (rd_init(_dtrace_rdvers) == RD_OK)
719 721 break;
720 722 }
721 723 }
722 724
723 725 static dtrace_hdl_t *
724 726 set_open_errno(dtrace_hdl_t *dtp, int *errp, int err)
725 727 {
726 728 if (dtp != NULL)
727 729 dtrace_close(dtp);
728 730 if (errp != NULL)
729 731 *errp = err;
730 732 return (NULL);
731 733 }
732 734
733 735 static void
734 736 dt_provmod_open(dt_provmod_t **provmod, dt_fdlist_t *dfp)
735 737 {
736 738 dt_provmod_t *prov;
737 739 char path[PATH_MAX];
738 740 struct dirent *dp, *ep;
739 741 DIR *dirp;
740 742 int fd;
741 743
742 744 if ((dirp = opendir(_dtrace_provdir)) == NULL)
743 745 return; /* failed to open directory; just skip it */
744 746
745 747 ep = alloca(sizeof (struct dirent) + PATH_MAX + 1);
746 748 bzero(ep, sizeof (struct dirent) + PATH_MAX + 1);
747 749
748 750 while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) {
749 751 if (dp->d_name[0] == '.')
750 752 continue; /* skip "." and ".." */
751 753
752 754 if (dfp->df_ents == dfp->df_size) {
753 755 uint_t size = dfp->df_size ? dfp->df_size * 2 : 16;
754 756 int *fds = realloc(dfp->df_fds, size * sizeof (int));
755 757
756 758 if (fds == NULL)
757 759 break; /* skip the rest of this directory */
758 760
759 761 dfp->df_fds = fds;
760 762 dfp->df_size = size;
761 763 }
762 764
763 765 (void) snprintf(path, sizeof (path), "%s/%s",
764 766 _dtrace_provdir, dp->d_name);
765 767
766 768 if ((fd = open(path, O_RDONLY)) == -1)
767 769 continue; /* failed to open driver; just skip it */
768 770
769 771 if (((prov = malloc(sizeof (dt_provmod_t))) == NULL) ||
770 772 (prov->dp_name = malloc(strlen(dp->d_name) + 1)) == NULL) {
771 773 free(prov);
772 774 (void) close(fd);
773 775 break;
774 776 }
775 777
776 778 (void) strcpy(prov->dp_name, dp->d_name);
777 779 prov->dp_next = *provmod;
778 780 *provmod = prov;
779 781
780 782 dt_dprintf("opened provider %s\n", dp->d_name);
781 783 dfp->df_fds[dfp->df_ents++] = fd;
782 784 }
783 785
784 786 (void) closedir(dirp);
785 787 }
786 788
787 789 static void
788 790 dt_provmod_destroy(dt_provmod_t **provmod)
789 791 {
790 792 dt_provmod_t *next, *current;
791 793
792 794 for (current = *provmod; current != NULL; current = next) {
793 795 next = current->dp_next;
794 796 free(current->dp_name);
795 797 free(current);
796 798 }
797 799
798 800 *provmod = NULL;
799 801 }
800 802
801 803 static const char *
802 804 dt_get_sysinfo(int cmd, char *buf, size_t len)
803 805 {
804 806 ssize_t rv = sysinfo(cmd, buf, len);
805 807 char *p = buf;
806 808
807 809 if (rv < 0 || rv > len)
808 810 (void) snprintf(buf, len, "%s", "Unknown");
809 811
810 812 while ((p = strchr(p, '.')) != NULL)
811 813 *p++ = '_';
812 814
813 815 return (buf);
814 816 }
815 817
816 818 static dtrace_hdl_t *
817 819 dt_vopen(int version, int flags, int *errp,
818 820 const dtrace_vector_t *vector, void *arg)
819 821 {
820 822 dtrace_hdl_t *dtp = NULL;
821 823 int dtfd = -1, ftfd = -1, fterr = 0;
822 824 dtrace_prog_t *pgp;
823 825 dt_module_t *dmp;
824 826 dt_provmod_t *provmod = NULL;
825 827 int i, err;
826 828 struct rlimit rl;
827 829
828 830 const dt_intrinsic_t *dinp;
829 831 const dt_typedef_t *dtyp;
830 832 const dt_ident_t *idp;
831 833
832 834 dtrace_typeinfo_t dtt;
833 835 ctf_funcinfo_t ctc;
834 836 ctf_arinfo_t ctr;
835 837
836 838 dt_fdlist_t df = { NULL, 0, 0 };
837 839
838 840 char isadef[32], utsdef[32];
839 841 char s1[64], s2[64];
840 842
841 843 if (version <= 0)
842 844 return (set_open_errno(dtp, errp, EINVAL));
843 845
844 846 if (version > DTRACE_VERSION)
845 847 return (set_open_errno(dtp, errp, EDT_VERSION));
846 848
847 849 if (version < DTRACE_VERSION) {
848 850 /*
849 851 * Currently, increasing the library version number is used to
850 852 * denote a binary incompatible change. That is, a consumer
851 853 * of the library cannot run on a version of the library with
852 854 * a higher DTRACE_VERSION number than the consumer compiled
853 855 * against. Once the library API has been committed to,
854 856 * backwards binary compatibility will be required; at that
855 857 * time, this check should change to return EDT_OVERSION only
856 858 * if the specified version number is less than the version
857 859 * number at the time of interface commitment.
858 860 */
859 861 return (set_open_errno(dtp, errp, EDT_OVERSION));
860 862 }
861 863
862 864 if (flags & ~DTRACE_O_MASK)
863 865 return (set_open_errno(dtp, errp, EINVAL));
864 866
865 867 if ((flags & DTRACE_O_LP64) && (flags & DTRACE_O_ILP32))
866 868 return (set_open_errno(dtp, errp, EINVAL));
867 869
868 870 if (vector == NULL && arg != NULL)
869 871 return (set_open_errno(dtp, errp, EINVAL));
870 872
871 873 if (elf_version(EV_CURRENT) == EV_NONE)
872 874 return (set_open_errno(dtp, errp, EDT_ELFVERSION));
873 875
874 876 if (vector != NULL || (flags & DTRACE_O_NODEV))
875 877 goto alloc; /* do not attempt to open dtrace device */
876 878
877 879 /*
878 880 * Before we get going, crank our limit on file descriptors up to the
879 881 * hard limit. This is to allow for the fact that libproc keeps file
880 882 * descriptors to objects open for the lifetime of the proc handle;
881 883 * without raising our hard limit, we would have an acceptably small
882 884 * bound on the number of processes that we could concurrently
883 885 * instrument with the pid provider.
884 886 */
885 887 if (getrlimit(RLIMIT_NOFILE, &rl) == 0) {
886 888 rl.rlim_cur = rl.rlim_max;
887 889 (void) setrlimit(RLIMIT_NOFILE, &rl);
888 890 }
889 891
890 892 /*
891 893 * Get the device path of each of the providers. We hold them open
892 894 * in the df.df_fds list until we open the DTrace driver itself,
893 895 * allowing us to see all of the probes provided on this system. Once
894 896 * we have the DTrace driver open, we can safely close all the providers
895 897 * now that they have registered with the framework.
896 898 */
897 899 dt_provmod_open(&provmod, &df);
898 900
899 901 dtfd = open("/dev/dtrace/dtrace", O_RDWR);
900 902 err = errno; /* save errno from opening dtfd */
901 903
902 904 ftfd = open("/dev/dtrace/provider/fasttrap", O_RDWR);
903 905 fterr = ftfd == -1 ? errno : 0; /* save errno from open ftfd */
904 906
905 907 while (df.df_ents-- != 0)
906 908 (void) close(df.df_fds[df.df_ents]);
907 909
908 910 free(df.df_fds);
909 911
910 912 /*
911 913 * If we failed to open the dtrace device, fail dtrace_open().
912 914 * We convert some kernel errnos to custom libdtrace errnos to
913 915 * improve the resulting message from the usual strerror().
914 916 */
915 917 if (dtfd == -1) {
916 918 dt_provmod_destroy(&provmod);
917 919 switch (err) {
918 920 case ENOENT:
919 921 err = EDT_NOENT;
920 922 break;
921 923 case EBUSY:
922 924 err = EDT_BUSY;
923 925 break;
924 926 case EACCES:
925 927 err = EDT_ACCESS;
926 928 break;
927 929 }
928 930 return (set_open_errno(dtp, errp, err));
929 931 }
930 932
931 933 (void) fcntl(dtfd, F_SETFD, FD_CLOEXEC);
932 934 (void) fcntl(ftfd, F_SETFD, FD_CLOEXEC);
933 935
934 936 alloc:
935 937 if ((dtp = malloc(sizeof (dtrace_hdl_t))) == NULL)
936 938 return (set_open_errno(dtp, errp, EDT_NOMEM));
937 939
938 940 bzero(dtp, sizeof (dtrace_hdl_t));
939 941 dtp->dt_oflags = flags;
940 942 dtp->dt_prcmode = DT_PROC_STOP_PREINIT;
941 943 dtp->dt_linkmode = DT_LINK_KERNEL;
942 944 dtp->dt_linktype = DT_LTYP_ELF;
943 945 dtp->dt_xlatemode = DT_XL_STATIC;
944 946 dtp->dt_stdcmode = DT_STDC_XA;
945 947 dtp->dt_encoding = DT_ENCODING_UNSET;
946 948 dtp->dt_version = version;
947 949 dtp->dt_fd = dtfd;
948 950 dtp->dt_ftfd = ftfd;
949 951 dtp->dt_fterr = fterr;
950 952 dtp->dt_cdefs_fd = -1;
951 953 dtp->dt_ddefs_fd = -1;
952 954 dtp->dt_stdout_fd = -1;
953 955 dtp->dt_modbuckets = _dtrace_strbuckets;
954 956 dtp->dt_mods = calloc(dtp->dt_modbuckets, sizeof (dt_module_t *));
955 957 dtp->dt_provbuckets = _dtrace_strbuckets;
956 958 dtp->dt_provs = calloc(dtp->dt_provbuckets, sizeof (dt_provider_t *));
957 959 dt_proc_init(dtp);
958 960 dtp->dt_vmax = DT_VERS_LATEST;
959 961 dtp->dt_cpp_path = strdup(_dtrace_defcpp);
960 962 dtp->dt_cpp_argv = malloc(sizeof (char *));
961 963 dtp->dt_cpp_argc = 1;
962 964 dtp->dt_cpp_args = 1;
963 965 dtp->dt_ld_path = strdup(_dtrace_defld);
964 966 dtp->dt_provmod = provmod;
965 967 dtp->dt_vector = vector;
966 968 dtp->dt_varg = arg;
967 969 dt_dof_init(dtp);
968 970 (void) uname(&dtp->dt_uts);
969 971
970 972 if (dtp->dt_mods == NULL || dtp->dt_provs == NULL ||
971 973 dtp->dt_procs == NULL || dtp->dt_proc_env == NULL ||
972 974 dtp->dt_ld_path == NULL || dtp->dt_cpp_path == NULL ||
973 975 dtp->dt_cpp_argv == NULL)
974 976 return (set_open_errno(dtp, errp, EDT_NOMEM));
975 977
976 978 for (i = 0; i < DTRACEOPT_MAX; i++)
977 979 dtp->dt_options[i] = DTRACEOPT_UNSET;
978 980
979 981 dtp->dt_cpp_argv[0] = (char *)strbasename(dtp->dt_cpp_path);
980 982
981 983 (void) snprintf(isadef, sizeof (isadef), "-D__SUNW_D_%u",
982 984 (uint_t)(sizeof (void *) * NBBY));
983 985
984 986 (void) snprintf(utsdef, sizeof (utsdef), "-D__%s_%s",
985 987 dt_get_sysinfo(SI_SYSNAME, s1, sizeof (s1)),
986 988 dt_get_sysinfo(SI_RELEASE, s2, sizeof (s2)));
987 989
988 990 if (dt_cpp_add_arg(dtp, "-D__sun") == NULL ||
989 991 dt_cpp_add_arg(dtp, "-D__unix") == NULL ||
990 992 dt_cpp_add_arg(dtp, "-D__SVR4") == NULL ||
991 993 dt_cpp_add_arg(dtp, "-D__SUNW_D=1") == NULL ||
992 994 dt_cpp_add_arg(dtp, isadef) == NULL ||
993 995 dt_cpp_add_arg(dtp, utsdef) == NULL)
994 996 return (set_open_errno(dtp, errp, EDT_NOMEM));
995 997
996 998 if (flags & DTRACE_O_NODEV)
997 999 bcopy(&_dtrace_conf, &dtp->dt_conf, sizeof (_dtrace_conf));
998 1000 else if (dt_ioctl(dtp, DTRACEIOC_CONF, &dtp->dt_conf) != 0)
999 1001 return (set_open_errno(dtp, errp, errno));
1000 1002
1001 1003 if (flags & DTRACE_O_LP64)
1002 1004 dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_LP64;
1003 1005 else if (flags & DTRACE_O_ILP32)
1004 1006 dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_ILP32;
1005 1007
1006 1008 #ifdef __sparc
1007 1009 /*
1008 1010 * On SPARC systems, __sparc is always defined for <sys/isa_defs.h>
1009 1011 * and __sparcv9 is defined if we are doing a 64-bit compile.
1010 1012 */
1011 1013 if (dt_cpp_add_arg(dtp, "-D__sparc") == NULL)
1012 1014 return (set_open_errno(dtp, errp, EDT_NOMEM));
1013 1015
1014 1016 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64 &&
1015 1017 dt_cpp_add_arg(dtp, "-D__sparcv9") == NULL)
1016 1018 return (set_open_errno(dtp, errp, EDT_NOMEM));
1017 1019 #endif
1018 1020
1019 1021 #ifdef __x86
1020 1022 /*
1021 1023 * On x86 systems, __i386 is defined for <sys/isa_defs.h> for 32-bit
1022 1024 * compiles and __amd64 is defined for 64-bit compiles. Unlike SPARC,
1023 1025 * they are defined exclusive of one another (see PSARC 2004/619).
1024 1026 */
1025 1027 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) {
1026 1028 if (dt_cpp_add_arg(dtp, "-D__amd64") == NULL)
1027 1029 return (set_open_errno(dtp, errp, EDT_NOMEM));
1028 1030 } else {
1029 1031 if (dt_cpp_add_arg(dtp, "-D__i386") == NULL)
1030 1032 return (set_open_errno(dtp, errp, EDT_NOMEM));
1031 1033 }
1032 1034 #endif
1033 1035
1034 1036 if (dtp->dt_conf.dtc_difversion < DIF_VERSION)
1035 1037 return (set_open_errno(dtp, errp, EDT_DIFVERS));
1036 1038
1037 1039 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32)
1038 1040 bcopy(_dtrace_ints_32, dtp->dt_ints, sizeof (_dtrace_ints_32));
1039 1041 else
1040 1042 bcopy(_dtrace_ints_64, dtp->dt_ints, sizeof (_dtrace_ints_64));
1041 1043
1042 1044 dtp->dt_macros = dt_idhash_create("macro", NULL, 0, UINT_MAX);
1043 1045 dtp->dt_aggs = dt_idhash_create("aggregation", NULL,
1044 1046 DTRACE_AGGVARIDNONE + 1, UINT_MAX);
1045 1047
1046 1048 dtp->dt_globals = dt_idhash_create("global", _dtrace_globals,
1047 1049 DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX);
1048 1050
1049 1051 dtp->dt_tls = dt_idhash_create("thread local", NULL,
1050 1052 DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX);
1051 1053
1052 1054 if (dtp->dt_macros == NULL || dtp->dt_aggs == NULL ||
1053 1055 dtp->dt_globals == NULL || dtp->dt_tls == NULL)
1054 1056 return (set_open_errno(dtp, errp, EDT_NOMEM));
1055 1057
1056 1058 /*
1057 1059 * Populate the dt_macros identifier hash table by hand: we can't use
1058 1060 * the dt_idhash_populate() mechanism because we're not yet compiling
1059 1061 * and dtrace_update() needs to immediately reference these idents.
1060 1062 */
1061 1063 for (idp = _dtrace_macros; idp->di_name != NULL; idp++) {
1062 1064 if (dt_idhash_insert(dtp->dt_macros, idp->di_name,
1063 1065 idp->di_kind, idp->di_flags, idp->di_id, idp->di_attr,
1064 1066 idp->di_vers, idp->di_ops ? idp->di_ops : &dt_idops_thaw,
1065 1067 idp->di_iarg, 0) == NULL)
1066 1068 return (set_open_errno(dtp, errp, EDT_NOMEM));
1067 1069 }
1068 1070
1069 1071 /*
1070 1072 * Update the module list using /system/object and load the values for
1071 1073 * the macro variable definitions according to the current process.
1072 1074 */
1073 1075 dtrace_update(dtp);
1074 1076
1075 1077 /*
1076 1078 * Select the intrinsics and typedefs we want based on the data model.
1077 1079 * The intrinsics are under "C". The typedefs are added under "D".
1078 1080 */
1079 1081 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32) {
1080 1082 dinp = _dtrace_intrinsics_32;
1081 1083 dtyp = _dtrace_typedefs_32;
1082 1084 } else {
1083 1085 dinp = _dtrace_intrinsics_64;
1084 1086 dtyp = _dtrace_typedefs_64;
1085 1087 }
1086 1088
1087 1089 /*
1088 1090 * Create a dynamic CTF container under the "C" scope for intrinsic
1089 1091 * types and types defined in ANSI-C header files that are included.
1090 1092 */
1091 1093 if ((dmp = dtp->dt_cdefs = dt_module_create(dtp, "C")) == NULL)
1092 1094 return (set_open_errno(dtp, errp, EDT_NOMEM));
1093 1095
1094 1096 if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL)
1095 1097 return (set_open_errno(dtp, errp, EDT_CTF));
1096 1098
1097 1099 dt_dprintf("created CTF container for %s (%p)\n",
1098 1100 dmp->dm_name, (void *)dmp->dm_ctfp);
1099 1101
1100 1102 (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel);
1101 1103 ctf_setspecific(dmp->dm_ctfp, dmp);
1102 1104
1103 1105 dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */
1104 1106 dmp->dm_modid = -1; /* no module ID */
1105 1107
1106 1108 /*
1107 1109 * Fill the dynamic "C" CTF container with all of the intrinsic
1108 1110 * integer and floating-point types appropriate for this data model.
1109 1111 */
1110 1112 for (; dinp->din_name != NULL; dinp++) {
1111 1113 if (dinp->din_kind == CTF_K_INTEGER) {
1112 1114 err = ctf_add_integer(dmp->dm_ctfp, CTF_ADD_ROOT,
1113 1115 dinp->din_name, &dinp->din_data);
1114 1116 } else {
1115 1117 err = ctf_add_float(dmp->dm_ctfp, CTF_ADD_ROOT,
1116 1118 dinp->din_name, &dinp->din_data);
1117 1119 }
1118 1120
1119 1121 if (err == CTF_ERR) {
1120 1122 dt_dprintf("failed to add %s to C container: %s\n",
1121 1123 dinp->din_name, ctf_errmsg(
1122 1124 ctf_errno(dmp->dm_ctfp)));
1123 1125 return (set_open_errno(dtp, errp, EDT_CTF));
1124 1126 }
1125 1127 }
1126 1128
1127 1129 if (ctf_update(dmp->dm_ctfp) != 0) {
1128 1130 dt_dprintf("failed to update C container: %s\n",
1129 1131 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1130 1132 return (set_open_errno(dtp, errp, EDT_CTF));
1131 1133 }
1132 1134
1133 1135 /*
1134 1136 * Add intrinsic pointer types that are needed to initialize printf
1135 1137 * format dictionary types (see table in dt_printf.c).
1136 1138 */
1137 1139 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT,
1138 1140 ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1139 1141
1140 1142 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT,
1141 1143 ctf_lookup_by_name(dmp->dm_ctfp, "char"));
1142 1144
1143 1145 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT,
1144 1146 ctf_lookup_by_name(dmp->dm_ctfp, "int"));
1145 1147
1146 1148 if (ctf_update(dmp->dm_ctfp) != 0) {
1147 1149 dt_dprintf("failed to update C container: %s\n",
1148 1150 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1149 1151 return (set_open_errno(dtp, errp, EDT_CTF));
1150 1152 }
1151 1153
1152 1154 /*
1153 1155 * Create a dynamic CTF container under the "D" scope for types that
1154 1156 * are defined by the D program itself or on-the-fly by the D compiler.
1155 1157 * The "D" CTF container is a child of the "C" CTF container.
1156 1158 */
1157 1159 if ((dmp = dtp->dt_ddefs = dt_module_create(dtp, "D")) == NULL)
1158 1160 return (set_open_errno(dtp, errp, EDT_NOMEM));
1159 1161
1160 1162 if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL)
1161 1163 return (set_open_errno(dtp, errp, EDT_CTF));
1162 1164
1163 1165 dt_dprintf("created CTF container for %s (%p)\n",
1164 1166 dmp->dm_name, (void *)dmp->dm_ctfp);
1165 1167
1166 1168 (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel);
1167 1169 ctf_setspecific(dmp->dm_ctfp, dmp);
1168 1170
1169 1171 dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */
1170 1172 dmp->dm_modid = -1; /* no module ID */
1171 1173
1172 1174 if (ctf_import(dmp->dm_ctfp, dtp->dt_cdefs->dm_ctfp) == CTF_ERR) {
1173 1175 dt_dprintf("failed to import D parent container: %s\n",
1174 1176 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1175 1177 return (set_open_errno(dtp, errp, EDT_CTF));
1176 1178 }
1177 1179
1178 1180 /*
1179 1181 * Fill the dynamic "D" CTF container with all of the built-in typedefs
1180 1182 * that we need to use for our D variable and function definitions.
1181 1183 * This ensures that basic inttypes.h names are always available to us.
1182 1184 */
1183 1185 for (; dtyp->dty_src != NULL; dtyp++) {
1184 1186 if (ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1185 1187 dtyp->dty_dst, ctf_lookup_by_name(dmp->dm_ctfp,
1186 1188 dtyp->dty_src)) == CTF_ERR) {
1187 1189 dt_dprintf("failed to add typedef %s %s to D "
1188 1190 "container: %s", dtyp->dty_src, dtyp->dty_dst,
1189 1191 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1190 1192 return (set_open_errno(dtp, errp, EDT_CTF));
1191 1193 }
1192 1194 }
1193 1195
1194 1196 /*
1195 1197 * Insert a CTF ID corresponding to a pointer to a type of kind
1196 1198 * CTF_K_FUNCTION we can use in the compiler for function pointers.
1197 1199 * CTF treats all function pointers as "int (*)()" so we only need one.
1198 1200 */
1199 1201 ctc.ctc_return = ctf_lookup_by_name(dmp->dm_ctfp, "int");
1200 1202 ctc.ctc_argc = 0;
1201 1203 ctc.ctc_flags = 0;
1202 1204
1203 1205 dtp->dt_type_func = ctf_add_function(dmp->dm_ctfp,
1204 1206 CTF_ADD_ROOT, &ctc, NULL);
1205 1207
1206 1208 dtp->dt_type_fptr = ctf_add_pointer(dmp->dm_ctfp,
1207 1209 CTF_ADD_ROOT, dtp->dt_type_func);
1208 1210
1209 1211 /*
1210 1212 * We also insert CTF definitions for the special D intrinsic types
1211 1213 * string and <DYN> into the D container. The string type is added
1212 1214 * as a typedef of char[n]. The <DYN> type is an alias for void.
1213 1215 * We compare types to these special CTF ids throughout the compiler.
1214 1216 */
1215 1217 ctr.ctr_contents = ctf_lookup_by_name(dmp->dm_ctfp, "char");
1216 1218 ctr.ctr_index = ctf_lookup_by_name(dmp->dm_ctfp, "long");
1217 1219 ctr.ctr_nelems = _dtrace_strsize;
1218 1220
1219 1221 dtp->dt_type_str = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1220 1222 "string", ctf_add_array(dmp->dm_ctfp, CTF_ADD_ROOT, &ctr));
1221 1223
1222 1224 dtp->dt_type_dyn = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1223 1225 "<DYN>", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1224 1226
1225 1227 dtp->dt_type_stack = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1226 1228 "stack", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1227 1229
1228 1230 dtp->dt_type_symaddr = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1229 1231 "_symaddr", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1230 1232
1231 1233 dtp->dt_type_usymaddr = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1232 1234 "_usymaddr", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1233 1235
1234 1236 if (dtp->dt_type_func == CTF_ERR || dtp->dt_type_fptr == CTF_ERR ||
1235 1237 dtp->dt_type_str == CTF_ERR || dtp->dt_type_dyn == CTF_ERR ||
1236 1238 dtp->dt_type_stack == CTF_ERR || dtp->dt_type_symaddr == CTF_ERR ||
1237 1239 dtp->dt_type_usymaddr == CTF_ERR) {
1238 1240 dt_dprintf("failed to add intrinsic to D container: %s\n",
1239 1241 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1240 1242 return (set_open_errno(dtp, errp, EDT_CTF));
1241 1243 }
1242 1244
1243 1245 if (ctf_update(dmp->dm_ctfp) != 0) {
1244 1246 dt_dprintf("failed update D container: %s\n",
1245 1247 ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1246 1248 return (set_open_errno(dtp, errp, EDT_CTF));
1247 1249 }
1248 1250
1249 1251 /*
1250 1252 * Initialize the integer description table used to convert integer
1251 1253 * constants to the appropriate types. Refer to the comments above
1252 1254 * dt_node_int() for a complete description of how this table is used.
1253 1255 */
1254 1256 for (i = 0; i < sizeof (dtp->dt_ints) / sizeof (dtp->dt_ints[0]); i++) {
1255 1257 if (dtrace_lookup_by_type(dtp, DTRACE_OBJ_EVERY,
1256 1258 dtp->dt_ints[i].did_name, &dtt) != 0) {
1257 1259 dt_dprintf("failed to lookup integer type %s: %s\n",
1258 1260 dtp->dt_ints[i].did_name,
1259 1261 dtrace_errmsg(dtp, dtrace_errno(dtp)));
1260 1262 return (set_open_errno(dtp, errp, dtp->dt_errno));
1261 1263 }
1262 1264 dtp->dt_ints[i].did_ctfp = dtt.dtt_ctfp;
1263 1265 dtp->dt_ints[i].did_type = dtt.dtt_type;
1264 1266 }
1265 1267
1266 1268 /*
1267 1269 * Now that we've created the "C" and "D" containers, move them to the
1268 1270 * start of the module list so that these types and symbols are found
1269 1271 * first (for stability) when iterating through the module list.
1270 1272 */
1271 1273 dt_list_delete(&dtp->dt_modlist, dtp->dt_ddefs);
1272 1274 dt_list_prepend(&dtp->dt_modlist, dtp->dt_ddefs);
1273 1275
1274 1276 dt_list_delete(&dtp->dt_modlist, dtp->dt_cdefs);
1275 1277 dt_list_prepend(&dtp->dt_modlist, dtp->dt_cdefs);
1276 1278
1277 1279 if (dt_pfdict_create(dtp) == -1)
1278 1280 return (set_open_errno(dtp, errp, dtp->dt_errno));
1279 1281
1280 1282 /*
1281 1283 * If we are opening libdtrace DTRACE_O_NODEV enable C_ZDEFS by default
1282 1284 * because without /dev/dtrace open, we will not be able to load the
1283 1285 * names and attributes of any providers or probes from the kernel.
1284 1286 */
1285 1287 if (flags & DTRACE_O_NODEV)
1286 1288 dtp->dt_cflags |= DTRACE_C_ZDEFS;
1287 1289
1288 1290 /*
1289 1291 * Load hard-wired inlines into the definition cache by calling the
1290 1292 * compiler on the raw definition string defined above.
1291 1293 */
1292 1294 if ((pgp = dtrace_program_strcompile(dtp, _dtrace_hardwire,
1293 1295 DTRACE_PROBESPEC_NONE, DTRACE_C_EMPTY, 0, NULL)) == NULL) {
1294 1296 dt_dprintf("failed to load hard-wired definitions: %s\n",
1295 1297 dtrace_errmsg(dtp, dtrace_errno(dtp)));
1296 1298 return (set_open_errno(dtp, errp, EDT_HARDWIRE));
1297 1299 }
1298 1300
1299 1301 dt_program_destroy(dtp, pgp);
1300 1302
1301 1303 /*
1302 1304 * Set up the default DTrace library path. Once set, the next call to
1303 1305 * dt_compile() will compile all the libraries. We intentionally defer
1304 1306 * library processing to improve overhead for clients that don't ever
1305 1307 * compile, and to provide better error reporting (because the full
1306 1308 * reporting of compiler errors requires dtrace_open() to succeed).
1307 1309 */
1308 1310 if (dtrace_setopt(dtp, "libdir", _dtrace_libdir) != 0)
1309 1311 return (set_open_errno(dtp, errp, dtp->dt_errno));
1310 1312
1311 1313 return (dtp);
1312 1314 }
1313 1315
1314 1316 dtrace_hdl_t *
1315 1317 dtrace_open(int version, int flags, int *errp)
1316 1318 {
1317 1319 return (dt_vopen(version, flags, errp, NULL, NULL));
1318 1320 }
1319 1321
1320 1322 dtrace_hdl_t *
1321 1323 dtrace_vopen(int version, int flags, int *errp,
1322 1324 const dtrace_vector_t *vector, void *arg)
1323 1325 {
1324 1326 return (dt_vopen(version, flags, errp, vector, arg));
1325 1327 }
1326 1328
1327 1329 void
1328 1330 dtrace_close(dtrace_hdl_t *dtp)
1329 1331 {
1330 1332 dt_ident_t *idp, *ndp;
1331 1333 dt_module_t *dmp;
1332 1334 dt_provider_t *pvp;
1333 1335 dtrace_prog_t *pgp;
1334 1336 dt_xlator_t *dxp;
1335 1337 dt_dirpath_t *dirp;
1336 1338 int i;
1337 1339
1338 1340 if (dtp->dt_procs != NULL)
1339 1341 dt_proc_fini(dtp);
1340 1342
1341 1343 while ((pgp = dt_list_next(&dtp->dt_programs)) != NULL)
1342 1344 dt_program_destroy(dtp, pgp);
1343 1345
1344 1346 while ((dxp = dt_list_next(&dtp->dt_xlators)) != NULL)
1345 1347 dt_xlator_destroy(dtp, dxp);
1346 1348
1347 1349 dt_free(dtp, dtp->dt_xlatormap);
1348 1350
1349 1351 for (idp = dtp->dt_externs; idp != NULL; idp = ndp) {
1350 1352 ndp = idp->di_next;
1351 1353 dt_ident_destroy(idp);
1352 1354 }
1353 1355
1354 1356 if (dtp->dt_macros != NULL)
1355 1357 dt_idhash_destroy(dtp->dt_macros);
1356 1358 if (dtp->dt_aggs != NULL)
1357 1359 dt_idhash_destroy(dtp->dt_aggs);
1358 1360 if (dtp->dt_globals != NULL)
1359 1361 dt_idhash_destroy(dtp->dt_globals);
1360 1362 if (dtp->dt_tls != NULL)
1361 1363 dt_idhash_destroy(dtp->dt_tls);
1362 1364
1363 1365 while ((dmp = dt_list_next(&dtp->dt_modlist)) != NULL)
1364 1366 dt_module_destroy(dtp, dmp);
1365 1367
1366 1368 while ((pvp = dt_list_next(&dtp->dt_provlist)) != NULL)
1367 1369 dt_provider_destroy(dtp, pvp);
1368 1370
1369 1371 if (dtp->dt_fd != -1)
1370 1372 (void) close(dtp->dt_fd);
1371 1373 if (dtp->dt_ftfd != -1)
1372 1374 (void) close(dtp->dt_ftfd);
1373 1375 if (dtp->dt_cdefs_fd != -1)
1374 1376 (void) close(dtp->dt_cdefs_fd);
1375 1377 if (dtp->dt_ddefs_fd != -1)
1376 1378 (void) close(dtp->dt_ddefs_fd);
1377 1379 if (dtp->dt_stdout_fd != -1)
1378 1380 (void) close(dtp->dt_stdout_fd);
1379 1381
1380 1382 dt_epid_destroy(dtp);
1381 1383 dt_aggid_destroy(dtp);
1382 1384 dt_format_destroy(dtp);
1383 1385 dt_strdata_destroy(dtp);
1384 1386 dt_buffered_destroy(dtp);
1385 1387 dt_aggregate_destroy(dtp);
1386 1388 dt_pfdict_destroy(dtp);
1387 1389 dt_provmod_destroy(&dtp->dt_provmod);
1388 1390 dt_dof_fini(dtp);
1389 1391
1390 1392 for (i = 1; i < dtp->dt_cpp_argc; i++)
1391 1393 free(dtp->dt_cpp_argv[i]);
1392 1394
1393 1395 while ((dirp = dt_list_next(&dtp->dt_lib_path)) != NULL) {
1394 1396 dt_list_delete(&dtp->dt_lib_path, dirp);
1395 1397 free(dirp->dir_path);
1396 1398 free(dirp);
1397 1399 }
1398 1400
1399 1401 free(dtp->dt_cpp_argv);
1400 1402 free(dtp->dt_cpp_path);
1401 1403 free(dtp->dt_ld_path);
1402 1404
1403 1405 free(dtp->dt_mods);
1404 1406 free(dtp->dt_provs);
1405 1407 free(dtp);
1406 1408 }
1407 1409
1408 1410 int
1409 1411 dtrace_provider_modules(dtrace_hdl_t *dtp, const char **mods, int nmods)
1410 1412 {
1411 1413 dt_provmod_t *prov;
1412 1414 int i = 0;
1413 1415
1414 1416 for (prov = dtp->dt_provmod; prov != NULL; prov = prov->dp_next, i++) {
1415 1417 if (i < nmods)
1416 1418 mods[i] = prov->dp_name;
1417 1419 }
1418 1420
1419 1421 return (i);
1420 1422 }
1421 1423
1422 1424 int
1423 1425 dtrace_ctlfd(dtrace_hdl_t *dtp)
1424 1426 {
1425 1427 return (dtp->dt_fd);
1426 1428 }
↓ open down ↓ |
1272 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX