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