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