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