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