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