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