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