17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5351346dbSahl  * Common Development and Distribution License (the "License").
6351346dbSahl  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21351346dbSahl 
227c478bd9Sstevel@tonic-gate /*
239cd928feSAlan Maguire  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24ab618543SJohn Levon  * Copyright (c) 2018, Joyent, Inc.
25c3bd3abdSMatthew Ahrens  * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
307c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
31586d07d0Sbmc #include <sys/resource.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <libelf.h>
347c478bd9Sstevel@tonic-gate #include <strings.h>
357c478bd9Sstevel@tonic-gate #include <alloca.h>
367c478bd9Sstevel@tonic-gate #include <limits.h>
377c478bd9Sstevel@tonic-gate #include <unistd.h>
387c478bd9Sstevel@tonic-gate #include <stdlib.h>
397c478bd9Sstevel@tonic-gate #include <stdio.h>
407c478bd9Sstevel@tonic-gate #include <fcntl.h>
417c478bd9Sstevel@tonic-gate #include <errno.h>
427c478bd9Sstevel@tonic-gate #include <assert.h>
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #define	_POSIX_PTHREAD_SEMANTICS
457c478bd9Sstevel@tonic-gate #include <dirent.h>
467c478bd9Sstevel@tonic-gate #undef	_POSIX_PTHREAD_SEMANTICS
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #include <dt_impl.h>
491a7c1b72Smws #include <dt_program.h>
507c478bd9Sstevel@tonic-gate #include <dt_module.h>
517c478bd9Sstevel@tonic-gate #include <dt_printf.h>
527c478bd9Sstevel@tonic-gate #include <dt_string.h>
537c478bd9Sstevel@tonic-gate #include <dt_provider.h>
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * Stability and versioning definitions.  These #defines are used in the tables
577c478bd9Sstevel@tonic-gate  * of identifiers below to fill in the attribute and version fields associated
587c478bd9Sstevel@tonic-gate  * with each identifier.  The DT_ATTR_* macros are a convenience to permit more
597c478bd9Sstevel@tonic-gate  * concise declarations of common attributes such as Stable/Stable/Common.  The
607c478bd9Sstevel@tonic-gate  * DT_VERS_* macros declare the encoded integer values of all versions used so
617c478bd9Sstevel@tonic-gate  * far.  DT_VERS_LATEST must correspond to the latest version value among all
627c478bd9Sstevel@tonic-gate  * versions exported by the D compiler.  DT_VERS_STRING must be an ASCII string
637c478bd9Sstevel@tonic-gate  * that contains DT_VERS_LATEST within it along with any suffixes (e.g. Beta).
647c478bd9Sstevel@tonic-gate  * You must update DT_VERS_LATEST and DT_VERS_STRING when adding a new version,
657c478bd9Sstevel@tonic-gate  * and then add the new version to the _dtrace_versions[] array declared below.
667c478bd9Sstevel@tonic-gate  * Refer to the Solaris Dynamic Tracing Guide Stability and Versioning chapters
677c478bd9Sstevel@tonic-gate  * respectively for an explanation of these DTrace features and their values.
687c478bd9Sstevel@tonic-gate  *
697c478bd9Sstevel@tonic-gate  * NOTE: Although the DTrace versioning scheme supports the labeling and
707c478bd9Sstevel@tonic-gate  *       introduction of incompatible changes (e.g. dropping an interface in a
717c478bd9Sstevel@tonic-gate  *       major release), the libdtrace code does not currently support this.
727c478bd9Sstevel@tonic-gate  *       All versions are assumed to strictly inherit from one another.  If
737c478bd9Sstevel@tonic-gate  *       we ever need to provide divergent interfaces, this will need work.
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate #define	DT_ATTR_STABCMN	{ DTRACE_STABILITY_STABLE, \
767c478bd9Sstevel@tonic-gate 	DTRACE_STABILITY_STABLE, DTRACE_CLASS_COMMON }
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #define	DT_ATTR_EVOLCMN { DTRACE_STABILITY_EVOLVING, \
797c478bd9Sstevel@tonic-gate 	DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON \
807c478bd9Sstevel@tonic-gate }
817c478bd9Sstevel@tonic-gate 
82351346dbSahl /*
83351346dbSahl  * The version number should be increased for every customer visible release
84e5803b76SAdam H. Leventhal  * of DTrace. The major number should be incremented when a fundamental
85351346dbSahl  * change has been made that would affect all consumers, and would reflect
86351346dbSahl  * sweeping changes to DTrace or the D language. The minor number should be
87351346dbSahl  * incremented when a change is introduced that could break scripts that had
88351346dbSahl  * previously worked; for example, adding a new built-in variable could break
89351346dbSahl  * a script which was already using that identifier. The micro number should
90351346dbSahl  * be changed when introducing functionality changes or major bug fixes that
91351346dbSahl  * do not affect backward compatibility -- this is merely to make capabilities
92351346dbSahl  * easily determined from the version number. Minor bugs do not require any
93351346dbSahl  * modification to the version number.
94351346dbSahl  */
957c478bd9Sstevel@tonic-gate #define	DT_VERS_1_0	DT_VERSION_NUMBER(1, 0, 0)
967c478bd9Sstevel@tonic-gate #define	DT_VERS_1_1	DT_VERSION_NUMBER(1, 1, 0)
970b38a8bdSahl #define	DT_VERS_1_2	DT_VERSION_NUMBER(1, 2, 0)
98351346dbSahl #define	DT_VERS_1_2_1	DT_VERSION_NUMBER(1, 2, 1)
99ac448965Sahl #define	DT_VERS_1_2_2	DT_VERSION_NUMBER(1, 2, 2)
1002b6e762cSahl #define	DT_VERS_1_3	DT_VERSION_NUMBER(1, 3, 0)
101657b1f3dSraf #define	DT_VERS_1_4	DT_VERSION_NUMBER(1, 4, 0)
102b8fac8e1Sjhaslam #define	DT_VERS_1_4_1	DT_VERSION_NUMBER(1, 4, 1)
103b1991c6bSbrendan #define	DT_VERS_1_5	DT_VERSION_NUMBER(1, 5, 0)
1046e0bee74Sjhaslam #define	DT_VERS_1_6	DT_VERSION_NUMBER(1, 6, 0)
1056009dbc6Sahl #define	DT_VERS_1_6_1	DT_VERSION_NUMBER(1, 6, 1)
1060bac14eaSahl #define	DT_VERS_1_6_2	DT_VERSION_NUMBER(1, 6, 2)
1079cd928feSAlan Maguire #define	DT_VERS_1_6_3	DT_VERSION_NUMBER(1, 6, 3)
1082b6389efSBryan Cantrill #define	DT_VERS_1_7	DT_VERSION_NUMBER(1, 7, 0)
1091ea5f93dSBryan Cantrill #define	DT_VERS_1_7_1	DT_VERSION_NUMBER(1, 7, 1)
11014c0b031SBryan Cantrill #define	DT_VERS_1_8	DT_VERSION_NUMBER(1, 8, 0)
1114c943354SBryan Cantrill #define	DT_VERS_1_8_1	DT_VERSION_NUMBER(1, 8, 1)
112deef35fdSEric Schrock #define	DT_VERS_1_9	DT_VERSION_NUMBER(1, 9, 0)
113e5803b76SAdam H. Leventhal #define	DT_VERS_1_9_1	DT_VERSION_NUMBER(1, 9, 1)
114b0f673c4SBryan Cantrill #define	DT_VERS_1_10	DT_VERSION_NUMBER(1, 10, 0)
115f497f9feSJoshua M. Clulow #define	DT_VERS_1_11	DT_VERSION_NUMBER(1, 11, 0)
116a386cc11SRobert Mustacchi #define	DT_VERS_1_12	DT_VERSION_NUMBER(1, 12, 0)
11733093f5bSBryan Cantrill #define	DT_VERS_1_12_1	DT_VERSION_NUMBER(1, 12, 1)
118c3bd3abdSMatthew Ahrens #define	DT_VERS_1_13	DT_VERSION_NUMBER(1, 13, 0)
119ab618543SJohn Levon #define	DT_VERS_1_14	DT_VERSION_NUMBER(1, 14, 0)
120ab618543SJohn Levon #define	DT_VERS_LATEST	DT_VERS_1_14
121ab618543SJohn Levon #define	DT_VERS_STRING	"Sun D 1.14"
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate const dt_version_t _dtrace_versions[] = {
1247c478bd9Sstevel@tonic-gate 	DT_VERS_1_0,	/* D API 1.0.0 (PSARC 2001/466) Solaris 10 FCS */
1250b38a8bdSahl 	DT_VERS_1_1,	/* D API 1.1.0 Solaris Express 6/05 */
1260b38a8bdSahl 	DT_VERS_1_2,	/* D API 1.2.0 Solaris 10 Update 1 */
127351346dbSahl 	DT_VERS_1_2_1,	/* D API 1.2.1 Solaris Express 4/06 */
128ac448965Sahl 	DT_VERS_1_2_2,	/* D API 1.2.2 Solaris Express 6/06 */
1292b6e762cSahl 	DT_VERS_1_3,	/* D API 1.3 Solaris Express 10/06 */
130657b1f3dSraf 	DT_VERS_1_4,	/* D API 1.4 Solaris Express 2/07 */
131b8fac8e1Sjhaslam 	DT_VERS_1_4_1,	/* D API 1.4.1 Solaris Express 4/07 */
132b1991c6bSbrendan 	DT_VERS_1_5,	/* D API 1.5 Solaris Express 7/07 */
1336e0bee74Sjhaslam 	DT_VERS_1_6,	/* D API 1.6 */
1346009dbc6Sahl 	DT_VERS_1_6_1,	/* D API 1.6.1 */
1350bac14eaSahl 	DT_VERS_1_6_2,	/* D API 1.6.2 */
1369cd928feSAlan Maguire 	DT_VERS_1_6_3,	/* D API 1.6.3 */
1372b6389efSBryan Cantrill 	DT_VERS_1_7,	/* D API 1.7 */
1381ea5f93dSBryan Cantrill 	DT_VERS_1_7_1,	/* D API 1.7.1 */
13914c0b031SBryan Cantrill 	DT_VERS_1_8,	/* D API 1.8 */
1404c943354SBryan Cantrill 	DT_VERS_1_8_1,	/* D API 1.8.1 */
141deef35fdSEric Schrock 	DT_VERS_1_9,	/* D API 1.9 */
142e5803b76SAdam H. Leventhal 	DT_VERS_1_9_1,	/* D API 1.9.1 */
143b0f673c4SBryan Cantrill 	DT_VERS_1_10,	/* D API 1.10 */
144f497f9feSJoshua M. Clulow 	DT_VERS_1_11,	/* D API 1.11 */
145a386cc11SRobert Mustacchi 	DT_VERS_1_12,	/* D API 1.12 */
14633093f5bSBryan Cantrill 	DT_VERS_1_12_1,	/* D API 1.12.1 */
147c3bd3abdSMatthew Ahrens 	DT_VERS_1_13,	/* D API 1.13 */
148ab618543SJohn Levon 	DT_VERS_1_14,	/* D API 1.14 */
1497c478bd9Sstevel@tonic-gate 	0
1507c478bd9Sstevel@tonic-gate };
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate /*
1537c478bd9Sstevel@tonic-gate  * Table of global identifiers.  This is used to populate the global identifier
1547c478bd9Sstevel@tonic-gate  * hash when a new dtrace client open occurs.  For more info see dt_ident.h.
1557c478bd9Sstevel@tonic-gate  * The global identifiers that represent functions use the dt_idops_func ops
1567c478bd9Sstevel@tonic-gate  * and specify the private data pointer as a prototype string which is parsed
1577c478bd9Sstevel@tonic-gate  * when the identifier is first encountered.  These prototypes look like ANSI
1587c478bd9Sstevel@tonic-gate  * C function prototypes except that the special symbol "@" can be used as a
1597c478bd9Sstevel@tonic-gate  * wildcard to represent a single parameter of any type (i.e. any dt_node_t).
1607c478bd9Sstevel@tonic-gate  * The standard "..." notation can also be used to represent varargs.  An empty
1617c478bd9Sstevel@tonic-gate  * parameter list is taken to mean void (that is, no arguments are permitted).
1627c478bd9Sstevel@tonic-gate  * A parameter enclosed in square brackets (e.g. "[int]") denotes an optional
1637c478bd9Sstevel@tonic-gate  * argument.
1647c478bd9Sstevel@tonic-gate  */
1657c478bd9Sstevel@tonic-gate static const dt_ident_t _dtrace_globals[] = {
1667c478bd9Sstevel@tonic-gate { "alloca", DT_IDENT_FUNC, 0, DIF_SUBR_ALLOCA, DT_ATTR_STABCMN, DT_VERS_1_0,
1677c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void *(size_t)" },
1687c478bd9Sstevel@tonic-gate { "arg0", DT_IDENT_SCALAR, 0, DIF_VAR_ARG0, DT_ATTR_STABCMN, DT_VERS_1_0,
1697c478bd9Sstevel@tonic-gate 	&dt_idops_type, "int64_t" },
1707c478bd9Sstevel@tonic-gate { "arg1", DT_IDENT_SCALAR, 0, DIF_VAR_ARG1, DT_ATTR_STABCMN, DT_VERS_1_0,
1717c478bd9Sstevel@tonic-gate 	&dt_idops_type, "int64_t" },
1727c478bd9Sstevel@tonic-gate { "arg2", DT_IDENT_SCALAR, 0, DIF_VAR_ARG2, DT_ATTR_STABCMN, DT_VERS_1_0,
1737c478bd9Sstevel@tonic-gate 	&dt_idops_type, "int64_t" },
1747c478bd9Sstevel@tonic-gate { "arg3", DT_IDENT_SCALAR, 0, DIF_VAR_ARG3, DT_ATTR_STABCMN, DT_VERS_1_0,
1757c478bd9Sstevel@tonic-gate 	&dt_idops_type, "int64_t" },
1767c478bd9Sstevel@tonic-gate { "arg4", DT_IDENT_SCALAR, 0, DIF_VAR_ARG4, DT_ATTR_STABCMN, DT_VERS_1_0,
1777c478bd9Sstevel@tonic-gate 	&dt_idops_type, "int64_t" },
1787c478bd9Sstevel@tonic-gate { "arg5", DT_IDENT_SCALAR, 0, DIF_VAR_ARG5, DT_ATTR_STABCMN, DT_VERS_1_0,
1797c478bd9Sstevel@tonic-gate 	&dt_idops_type, "int64_t" },
1807c478bd9Sstevel@tonic-gate { "arg6", DT_IDENT_SCALAR, 0, DIF_VAR_ARG6, DT_ATTR_STABCMN, DT_VERS_1_0,
1817c478bd9Sstevel@tonic-gate 	&dt_idops_type, "int64_t" },
1827c478bd9Sstevel@tonic-gate { "arg7", DT_IDENT_SCALAR, 0, DIF_VAR_ARG7, DT_ATTR_STABCMN, DT_VERS_1_0,
1837c478bd9Sstevel@tonic-gate 	&dt_idops_type, "int64_t" },
1847c478bd9Sstevel@tonic-gate { "arg8", DT_IDENT_SCALAR, 0, DIF_VAR_ARG8, DT_ATTR_STABCMN, DT_VERS_1_0,
1857c478bd9Sstevel@tonic-gate 	&dt_idops_type, "int64_t" },
1867c478bd9Sstevel@tonic-gate { "arg9", DT_IDENT_SCALAR, 0, DIF_VAR_ARG9, DT_ATTR_STABCMN, DT_VERS_1_0,
1877c478bd9Sstevel@tonic-gate 	&dt_idops_type, "int64_t" },
1887c478bd9Sstevel@tonic-gate { "args", DT_IDENT_ARRAY, 0, DIF_VAR_ARGS, DT_ATTR_STABCMN, DT_VERS_1_0,
1897c478bd9Sstevel@tonic-gate 	&dt_idops_args, NULL },
1907c478bd9Sstevel@tonic-gate { "avg", DT_IDENT_AGGFUNC, 0, DTRACEAGG_AVG, DT_ATTR_STABCMN, DT_VERS_1_0,
1917c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(@)" },
1927c478bd9Sstevel@tonic-gate { "basename", DT_IDENT_FUNC, 0, DIF_SUBR_BASENAME, DT_ATTR_STABCMN, DT_VERS_1_0,
1937c478bd9Sstevel@tonic-gate 	&dt_idops_func, "string(const char *)" },
1947c478bd9Sstevel@tonic-gate { "bcopy", DT_IDENT_FUNC, 0, DIF_SUBR_BCOPY, DT_ATTR_STABCMN, DT_VERS_1_0,
1957c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(void *, void *, size_t)" },
1967c478bd9Sstevel@tonic-gate { "breakpoint", DT_IDENT_ACTFUNC, 0, DT_ACT_BREAKPOINT,
1977c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0,
1987c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void()" },
1997c478bd9Sstevel@tonic-gate { "caller", DT_IDENT_SCALAR, 0, DIF_VAR_CALLER, DT_ATTR_STABCMN, DT_VERS_1_0,
2007c478bd9Sstevel@tonic-gate 	&dt_idops_type, "uintptr_t" },
2017c478bd9Sstevel@tonic-gate { "chill", DT_IDENT_ACTFUNC, 0, DT_ACT_CHILL, DT_ATTR_STABCMN, DT_VERS_1_0,
2027c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(int)" },
2037c478bd9Sstevel@tonic-gate { "cleanpath", DT_IDENT_FUNC, 0, DIF_SUBR_CLEANPATH, DT_ATTR_STABCMN,
2047c478bd9Sstevel@tonic-gate 	DT_VERS_1_0, &dt_idops_func, "string(const char *)" },
2057c478bd9Sstevel@tonic-gate { "clear", DT_IDENT_ACTFUNC, 0, DT_ACT_CLEAR, DT_ATTR_STABCMN, DT_VERS_1_0,
2067c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(...)" },
2077c478bd9Sstevel@tonic-gate { "commit", DT_IDENT_ACTFUNC, 0, DT_ACT_COMMIT, DT_ATTR_STABCMN, DT_VERS_1_0,
2087c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(int)" },
2097c478bd9Sstevel@tonic-gate { "copyin", DT_IDENT_FUNC, 0, DIF_SUBR_COPYIN, DT_ATTR_STABCMN, DT_VERS_1_0,
2107c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void *(uintptr_t, size_t)" },
2117c478bd9Sstevel@tonic-gate { "copyinstr", DT_IDENT_FUNC, 0, DIF_SUBR_COPYINSTR,
2127c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0,
2137c478bd9Sstevel@tonic-gate 	&dt_idops_func, "string(uintptr_t, [size_t])" },
2147c478bd9Sstevel@tonic-gate { "copyinto", DT_IDENT_FUNC, 0, DIF_SUBR_COPYINTO, DT_ATTR_STABCMN,
2157c478bd9Sstevel@tonic-gate 	DT_VERS_1_0, &dt_idops_func, "void(uintptr_t, size_t, void *)" },
2167c478bd9Sstevel@tonic-gate { "copyout", DT_IDENT_FUNC, 0, DIF_SUBR_COPYOUT, DT_ATTR_STABCMN, DT_VERS_1_0,
2177c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(void *, uintptr_t, size_t)" },
2187c478bd9Sstevel@tonic-gate { "copyoutstr", DT_IDENT_FUNC, 0, DIF_SUBR_COPYOUTSTR,
2197c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0,
2207c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(char *, uintptr_t, size_t)" },
2217c478bd9Sstevel@tonic-gate { "count", DT_IDENT_AGGFUNC, 0, DTRACEAGG_COUNT, DT_ATTR_STABCMN, DT_VERS_1_0,
2227c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void()" },
2237c478bd9Sstevel@tonic-gate { "curthread", DT_IDENT_SCALAR, 0, DIF_VAR_CURTHREAD,
2247c478bd9Sstevel@tonic-gate 	{ DTRACE_STABILITY_STABLE, DTRACE_STABILITY_PRIVATE,
2257c478bd9Sstevel@tonic-gate 	DTRACE_CLASS_COMMON }, DT_VERS_1_0,
2267c478bd9Sstevel@tonic-gate 	&dt_idops_type, "genunix`kthread_t *" },
2277c478bd9Sstevel@tonic-gate { "ddi_pathname", DT_IDENT_FUNC, 0, DIF_SUBR_DDI_PATHNAME,
2287c478bd9Sstevel@tonic-gate 	DT_ATTR_EVOLCMN, DT_VERS_1_0,
2297c478bd9Sstevel@tonic-gate 	&dt_idops_func, "string(void *, int64_t)" },
2307c478bd9Sstevel@tonic-gate { "denormalize", DT_IDENT_ACTFUNC, 0, DT_ACT_DENORMALIZE, DT_ATTR_STABCMN,
2317c478bd9Sstevel@tonic-gate 	DT_VERS_1_0, &dt_idops_func, "void(...)" },
2327c478bd9Sstevel@tonic-gate { "dirname", DT_IDENT_FUNC, 0, DIF_SUBR_DIRNAME, DT_ATTR_STABCMN, DT_VERS_1_0,
2337c478bd9Sstevel@tonic-gate 	&dt_idops_func, "string(const char *)" },
2347c478bd9Sstevel@tonic-gate { "discard", DT_IDENT_ACTFUNC, 0, DT_ACT_DISCARD, DT_ATTR_STABCMN, DT_VERS_1_0,
2357c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(int)" },
2367c478bd9Sstevel@tonic-gate { "epid", DT_IDENT_SCALAR, 0, DIF_VAR_EPID, DT_ATTR_STABCMN, DT_VERS_1_0,
2377c478bd9Sstevel@tonic-gate 	&dt_idops_type, "uint_t" },
2385518d15bSdp { "errno", DT_IDENT_SCALAR, 0, DIF_VAR_ERRNO, DT_ATTR_STABCMN, DT_VERS_1_0,
2395518d15bSdp 	&dt_idops_type, "int" },
2407c478bd9Sstevel@tonic-gate { "execname", DT_IDENT_SCALAR, 0, DIF_VAR_EXECNAME,
2417c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
2427c478bd9Sstevel@tonic-gate { "exit", DT_IDENT_ACTFUNC, 0, DT_ACT_EXIT, DT_ATTR_STABCMN, DT_VERS_1_0,
2437c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(int)" },
2447c478bd9Sstevel@tonic-gate { "freopen", DT_IDENT_ACTFUNC, 0, DT_ACT_FREOPEN, DT_ATTR_STABCMN,
2457c478bd9Sstevel@tonic-gate 	DT_VERS_1_1, &dt_idops_func, "void(@, ...)" },
2467c478bd9Sstevel@tonic-gate { "ftruncate", DT_IDENT_ACTFUNC, 0, DT_ACT_FTRUNCATE, DT_ATTR_STABCMN,
2477c478bd9Sstevel@tonic-gate 	DT_VERS_1_0, &dt_idops_func, "void()" },
248a1b5e537Sbmc { "func", DT_IDENT_ACTFUNC, 0, DT_ACT_SYM, DT_ATTR_STABCMN,
249a1b5e537Sbmc 	DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" },
2507c478bd9Sstevel@tonic-gate { "getmajor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMAJOR,
2517c478bd9Sstevel@tonic-gate 	DT_ATTR_EVOLCMN, DT_VERS_1_0,
2527c478bd9Sstevel@tonic-gate 	&dt_idops_func, "genunix`major_t(genunix`dev_t)" },
2537c478bd9Sstevel@tonic-gate { "getminor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMINOR,
2547c478bd9Sstevel@tonic-gate 	DT_ATTR_EVOLCMN, DT_VERS_1_0,
2557c478bd9Sstevel@tonic-gate 	&dt_idops_func, "genunix`minor_t(genunix`dev_t)" },
2562b6e762cSahl { "htonl", DT_IDENT_FUNC, 0, DIF_SUBR_HTONL, DT_ATTR_EVOLCMN, DT_VERS_1_3,
2572b6e762cSahl 	&dt_idops_func, "uint32_t(uint32_t)" },
2582b6e762cSahl { "htonll", DT_IDENT_FUNC, 0, DIF_SUBR_HTONLL, DT_ATTR_EVOLCMN, DT_VERS_1_3,
2592b6e762cSahl 	&dt_idops_func, "uint64_t(uint64_t)" },
2602b6e762cSahl { "htons", DT_IDENT_FUNC, 0, DIF_SUBR_HTONS, DT_ATTR_EVOLCMN, DT_VERS_1_3,
2612b6e762cSahl 	&dt_idops_func, "uint16_t(uint16_t)" },
262b0f673c4SBryan Cantrill { "getf", DT_IDENT_FUNC, 0, DIF_SUBR_GETF, DT_ATTR_STABCMN, DT_VERS_1_10,
263b0f673c4SBryan Cantrill 	&dt_idops_func, "file_t *(int)" },
2645518d15bSdp { "gid", DT_IDENT_SCALAR, 0, DIF_VAR_GID, DT_ATTR_STABCMN, DT_VERS_1_0,
2655518d15bSdp 	&dt_idops_type, "gid_t" },
2667c478bd9Sstevel@tonic-gate { "id", DT_IDENT_SCALAR, 0, DIF_VAR_ID, DT_ATTR_STABCMN, DT_VERS_1_0,
2677c478bd9Sstevel@tonic-gate 	&dt_idops_type, "uint_t" },
2687c478bd9Sstevel@tonic-gate { "index", DT_IDENT_FUNC, 0, DIF_SUBR_INDEX, DT_ATTR_STABCMN, DT_VERS_1_1,
2697c478bd9Sstevel@tonic-gate 	&dt_idops_func, "int(const char *, const char *, [int])" },
2704edabff4Sbrendan { "inet_ntoa", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOA, DT_ATTR_STABCMN,
271b1991c6bSbrendan 	DT_VERS_1_5, &dt_idops_func, "string(ipaddr_t *)" },
2724edabff4Sbrendan { "inet_ntoa6", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOA6, DT_ATTR_STABCMN,
273b1991c6bSbrendan 	DT_VERS_1_5, &dt_idops_func, "string(in6_addr_t *)" },
2744edabff4Sbrendan { "inet_ntop", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOP, DT_ATTR_STABCMN,
275b1991c6bSbrendan 	DT_VERS_1_5, &dt_idops_func, "string(int, void *)" },
2767c478bd9Sstevel@tonic-gate { "ipl", DT_IDENT_SCALAR, 0, DIF_VAR_IPL, DT_ATTR_STABCMN, DT_VERS_1_0,
2777c478bd9Sstevel@tonic-gate 	&dt_idops_type, "uint_t" },
278f497f9feSJoshua M. Clulow { "json", DT_IDENT_FUNC, 0, DIF_SUBR_JSON, DT_ATTR_STABCMN, DT_VERS_1_11,
279f497f9feSJoshua M. Clulow 	&dt_idops_func, "string(const char *, const char *)" },
2807c478bd9Sstevel@tonic-gate { "jstack", DT_IDENT_ACTFUNC, 0, DT_ACT_JSTACK, DT_ATTR_STABCMN, DT_VERS_1_0,
2817c478bd9Sstevel@tonic-gate 	&dt_idops_func, "stack(...)" },
2827c478bd9Sstevel@tonic-gate { "lltostr", DT_IDENT_FUNC, 0, DIF_SUBR_LLTOSTR, DT_ATTR_STABCMN, DT_VERS_1_0,
2834c943354SBryan Cantrill 	&dt_idops_func, "string(int64_t, [int])" },
2842b6389efSBryan Cantrill { "llquantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_LLQUANTIZE, DT_ATTR_STABCMN,
2852b6389efSBryan Cantrill 	DT_VERS_1_7, &dt_idops_func,
2862b6389efSBryan Cantrill 	"void(@, int32_t, int32_t, int32_t, int32_t, ...)" },
2877c478bd9Sstevel@tonic-gate { "lquantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_LQUANTIZE,
2887c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0,
2897c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(@, int32_t, int32_t, ...)" },
2907c478bd9Sstevel@tonic-gate { "max", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MAX, DT_ATTR_STABCMN, DT_VERS_1_0,
2917c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(@)" },
2927c478bd9Sstevel@tonic-gate { "min", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MIN, DT_ATTR_STABCMN, DT_VERS_1_0,
2937c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(@)" },
294a1b5e537Sbmc { "mod", DT_IDENT_ACTFUNC, 0, DT_ACT_MOD, DT_ATTR_STABCMN,
295a1b5e537Sbmc 	DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" },
2967c478bd9Sstevel@tonic-gate { "msgdsize", DT_IDENT_FUNC, 0, DIF_SUBR_MSGDSIZE,
2977c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0,
2987c478bd9Sstevel@tonic-gate 	&dt_idops_func, "size_t(mblk_t *)" },
2997c478bd9Sstevel@tonic-gate { "msgsize", DT_IDENT_FUNC, 0, DIF_SUBR_MSGSIZE,
3007c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0,
3017c478bd9Sstevel@tonic-gate 	&dt_idops_func, "size_t(mblk_t *)" },
3027c478bd9Sstevel@tonic-gate { "mutex_owned", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNED,
3037c478bd9Sstevel@tonic-gate 	DT_ATTR_EVOLCMN, DT_VERS_1_0,
3047c478bd9Sstevel@tonic-gate 	&dt_idops_func, "int(genunix`kmutex_t *)" },
3057c478bd9Sstevel@tonic-gate { "mutex_owner", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNER,
3067c478bd9Sstevel@tonic-gate 	DT_ATTR_EVOLCMN, DT_VERS_1_0,
3077c478bd9Sstevel@tonic-gate 	&dt_idops_func, "genunix`kthread_t *(genunix`kmutex_t *)" },
3087c478bd9Sstevel@tonic-gate { "mutex_type_adaptive", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_ADAPTIVE,
3097c478bd9Sstevel@tonic-gate 	DT_ATTR_EVOLCMN, DT_VERS_1_0,
3107c478bd9Sstevel@tonic-gate 	&dt_idops_func, "int(genunix`kmutex_t *)" },
3117c478bd9Sstevel@tonic-gate { "mutex_type_spin", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_SPIN,
3127c478bd9Sstevel@tonic-gate 	DT_ATTR_EVOLCMN, DT_VERS_1_0,
3137c478bd9Sstevel@tonic-gate 	&dt_idops_func, "int(genunix`kmutex_t *)" },
3142b6e762cSahl { "ntohl", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHL, DT_ATTR_EVOLCMN, DT_VERS_1_3,
3152b6e762cSahl 	&dt_idops_func, "uint32_t(uint32_t)" },
3162b6e762cSahl { "ntohll", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHLL, DT_ATTR_EVOLCMN, DT_VERS_1_3,
3172b6e762cSahl 	&dt_idops_func, "uint64_t(uint64_t)" },
3182b6e762cSahl { "ntohs", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHS, DT_ATTR_EVOLCMN, DT_VERS_1_3,
3192b6e762cSahl 	&dt_idops_func, "uint16_t(uint16_t)" },
3207c478bd9Sstevel@tonic-gate { "normalize", DT_IDENT_ACTFUNC, 0, DT_ACT_NORMALIZE, DT_ATTR_STABCMN,
3217c478bd9Sstevel@tonic-gate 	DT_VERS_1_0, &dt_idops_func, "void(...)" },
3227c478bd9Sstevel@tonic-gate { "panic", DT_IDENT_ACTFUNC, 0, DT_ACT_PANIC, DT_ATTR_STABCMN, DT_VERS_1_0,
3237c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void()" },
3247c478bd9Sstevel@tonic-gate { "pid", DT_IDENT_SCALAR, 0, DIF_VAR_PID, DT_ATTR_STABCMN, DT_VERS_1_0,
3257c478bd9Sstevel@tonic-gate 	&dt_idops_type, "pid_t" },
3265518d15bSdp { "ppid", DT_IDENT_SCALAR, 0, DIF_VAR_PPID, DT_ATTR_STABCMN, DT_VERS_1_0,
3275518d15bSdp 	&dt_idops_type, "pid_t" },
328deef35fdSEric Schrock { "print", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINT, DT_ATTR_STABCMN, DT_VERS_1_9,
329deef35fdSEric Schrock 	&dt_idops_func, "void(@)" },
3307c478bd9Sstevel@tonic-gate { "printa", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTA, DT_ATTR_STABCMN, DT_VERS_1_0,
3317c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(@, ...)" },
3327c478bd9Sstevel@tonic-gate { "printf", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTF, DT_ATTR_STABCMN, DT_VERS_1_0,
3337c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(@, ...)" },
3347c478bd9Sstevel@tonic-gate { "probefunc", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEFUNC,
3357c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
3367c478bd9Sstevel@tonic-gate { "probemod", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEMOD,
3377c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
3387c478bd9Sstevel@tonic-gate { "probename", DT_IDENT_SCALAR, 0, DIF_VAR_PROBENAME,
3397c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
3407c478bd9Sstevel@tonic-gate { "probeprov", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEPROV,
3417c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
3427c478bd9Sstevel@tonic-gate { "progenyof", DT_IDENT_FUNC, 0, DIF_SUBR_PROGENYOF,
3437c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0,
3447c478bd9Sstevel@tonic-gate 	&dt_idops_func, "int(pid_t)" },
3457c478bd9Sstevel@tonic-gate { "quantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_QUANTIZE,
3467c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0,
347a1b5e537Sbmc 	&dt_idops_func, "void(@, ...)" },
3487c478bd9Sstevel@tonic-gate { "raise", DT_IDENT_ACTFUNC, 0, DT_ACT_RAISE, DT_ATTR_STABCMN, DT_VERS_1_0,
3497c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(int)" },
3507c478bd9Sstevel@tonic-gate { "rand", DT_IDENT_FUNC, 0, DIF_SUBR_RAND, DT_ATTR_STABCMN, DT_VERS_1_0,
3517c478bd9Sstevel@tonic-gate 	&dt_idops_func, "int()" },
3527c478bd9Sstevel@tonic-gate { "rindex", DT_IDENT_FUNC, 0, DIF_SUBR_RINDEX, DT_ATTR_STABCMN, DT_VERS_1_1,
3537c478bd9Sstevel@tonic-gate 	&dt_idops_func, "int(const char *, const char *, [int])" },
3547c478bd9Sstevel@tonic-gate { "rw_iswriter", DT_IDENT_FUNC, 0, DIF_SUBR_RW_ISWRITER,
3557c478bd9Sstevel@tonic-gate 	DT_ATTR_EVOLCMN, DT_VERS_1_0,
3567c478bd9Sstevel@tonic-gate 	&dt_idops_func, "int(genunix`krwlock_t *)" },
3577c478bd9Sstevel@tonic-gate { "rw_read_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_READ_HELD,
3587c478bd9Sstevel@tonic-gate 	DT_ATTR_EVOLCMN, DT_VERS_1_0,
3597c478bd9Sstevel@tonic-gate 	&dt_idops_func, "int(genunix`krwlock_t *)" },
3607c478bd9Sstevel@tonic-gate { "rw_write_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_WRITE_HELD,
3617c478bd9Sstevel@tonic-gate 	DT_ATTR_EVOLCMN, DT_VERS_1_0,
3627c478bd9Sstevel@tonic-gate 	&dt_idops_func, "int(genunix`krwlock_t *)" },
3637c478bd9Sstevel@tonic-gate { "self", DT_IDENT_PTR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0,
3647c478bd9Sstevel@tonic-gate 	&dt_idops_type, "void" },
365a1b5e537Sbmc { "setopt", DT_IDENT_ACTFUNC, 0, DT_ACT_SETOPT, DT_ATTR_STABCMN,
366a1b5e537Sbmc 	DT_VERS_1_2, &dt_idops_func, "void(const char *, [const char *])" },
3677c478bd9Sstevel@tonic-gate { "speculate", DT_IDENT_ACTFUNC, 0, DT_ACT_SPECULATE,
3687c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0,
3697c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(int)" },
3707c478bd9Sstevel@tonic-gate { "speculation", DT_IDENT_FUNC, 0, DIF_SUBR_SPECULATION,
3717c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0,
3727c478bd9Sstevel@tonic-gate 	&dt_idops_func, "int()" },
3737c478bd9Sstevel@tonic-gate { "stack", DT_IDENT_ACTFUNC, 0, DT_ACT_STACK, DT_ATTR_STABCMN, DT_VERS_1_0,
3747c478bd9Sstevel@tonic-gate 	&dt_idops_func, "stack(...)" },
3757c478bd9Sstevel@tonic-gate { "stackdepth", DT_IDENT_SCALAR, 0, DIF_VAR_STACKDEPTH,
3767c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0,
3777c478bd9Sstevel@tonic-gate 	&dt_idops_type, "uint32_t" },
3786e0bee74Sjhaslam { "stddev", DT_IDENT_AGGFUNC, 0, DTRACEAGG_STDDEV, DT_ATTR_STABCMN,
3796e0bee74Sjhaslam 	DT_VERS_1_6, &dt_idops_func, "void(@)" },
3807c478bd9Sstevel@tonic-gate { "stop", DT_IDENT_ACTFUNC, 0, DT_ACT_STOP, DT_ATTR_STABCMN, DT_VERS_1_0,
3817c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void()" },
3827c478bd9Sstevel@tonic-gate { "strchr", DT_IDENT_FUNC, 0, DIF_SUBR_STRCHR, DT_ATTR_STABCMN, DT_VERS_1_1,
3837c478bd9Sstevel@tonic-gate 	&dt_idops_func, "string(const char *, char)" },
3847c478bd9Sstevel@tonic-gate { "strlen", DT_IDENT_FUNC, 0, DIF_SUBR_STRLEN, DT_ATTR_STABCMN, DT_VERS_1_0,
3857c478bd9Sstevel@tonic-gate 	&dt_idops_func, "size_t(const char *)" },
3867c478bd9Sstevel@tonic-gate { "strjoin", DT_IDENT_FUNC, 0, DIF_SUBR_STRJOIN, DT_ATTR_STABCMN, DT_VERS_1_0,
3877c478bd9Sstevel@tonic-gate 	&dt_idops_func, "string(const char *, const char *)" },
3887c478bd9Sstevel@tonic-gate { "strrchr", DT_IDENT_FUNC, 0, DIF_SUBR_STRRCHR, DT_ATTR_STABCMN, DT_VERS_1_1,
3897c478bd9Sstevel@tonic-gate 	&dt_idops_func, "string(const char *, char)" },
3907c478bd9Sstevel@tonic-gate { "strstr", DT_IDENT_FUNC, 0, DIF_SUBR_STRSTR, DT_ATTR_STABCMN, DT_VERS_1_1,
3917c478bd9Sstevel@tonic-gate 	&dt_idops_func, "string(const char *, const char *)" },
3927c478bd9Sstevel@tonic-gate { "strtok", DT_IDENT_FUNC, 0, DIF_SUBR_STRTOK, DT_ATTR_STABCMN, DT_VERS_1_1,
3937c478bd9Sstevel@tonic-gate 	&dt_idops_func, "string(const char *, const char *)" },
394f497f9feSJoshua M. Clulow { "strtoll", DT_IDENT_FUNC, 0, DIF_SUBR_STRTOLL, DT_ATTR_STABCMN, DT_VERS_1_11,
395f497f9feSJoshua M. Clulow 	&dt_idops_func, "int64_t(const char *, [int])" },
3967c478bd9Sstevel@tonic-gate { "substr", DT_IDENT_FUNC, 0, DIF_SUBR_SUBSTR, DT_ATTR_STABCMN, DT_VERS_1_1,
3977c478bd9Sstevel@tonic-gate 	&dt_idops_func, "string(const char *, int, [int])" },
3987c478bd9Sstevel@tonic-gate { "sum", DT_IDENT_AGGFUNC, 0, DTRACEAGG_SUM, DT_ATTR_STABCMN, DT_VERS_1_0,
3997c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(@)" },
400a1b5e537Sbmc { "sym", DT_IDENT_ACTFUNC, 0, DT_ACT_SYM, DT_ATTR_STABCMN,
401a1b5e537Sbmc 	DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" },
4027c478bd9Sstevel@tonic-gate { "system", DT_IDENT_ACTFUNC, 0, DT_ACT_SYSTEM, DT_ATTR_STABCMN, DT_VERS_1_0,
4037c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(@, ...)" },
4047c478bd9Sstevel@tonic-gate { "this", DT_IDENT_PTR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0,
4057c478bd9Sstevel@tonic-gate 	&dt_idops_type, "void" },
406ab618543SJohn Levon { "threadname", DT_IDENT_SCALAR, 0, DIF_VAR_THREADNAME,
407ab618543SJohn Levon 	DT_ATTR_STABCMN, DT_VERS_1_14, &dt_idops_type, "string" },
4087c478bd9Sstevel@tonic-gate { "tid", DT_IDENT_SCALAR, 0, DIF_VAR_TID, DT_ATTR_STABCMN, DT_VERS_1_0,
4097c478bd9Sstevel@tonic-gate 	&dt_idops_type, "id_t" },
4107c478bd9Sstevel@tonic-gate { "timestamp", DT_IDENT_SCALAR, 0, DIF_VAR_TIMESTAMP,
4117c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0,
4127c478bd9Sstevel@tonic-gate 	&dt_idops_type, "uint64_t" },
41314c0b031SBryan Cantrill { "tolower", DT_IDENT_FUNC, 0, DIF_SUBR_TOLOWER, DT_ATTR_STABCMN, DT_VERS_1_8,
41414c0b031SBryan Cantrill 	&dt_idops_func, "string(const char *)" },
41514c0b031SBryan Cantrill { "toupper", DT_IDENT_FUNC, 0, DIF_SUBR_TOUPPER, DT_ATTR_STABCMN, DT_VERS_1_8,
41614c0b031SBryan Cantrill 	&dt_idops_func, "string(const char *)" },
4177c478bd9Sstevel@tonic-gate { "trace", DT_IDENT_ACTFUNC, 0, DT_ACT_TRACE, DT_ATTR_STABCMN, DT_VERS_1_0,
4187c478bd9Sstevel@tonic-gate 	&dt_idops_func, "void(@)" },
4197c478bd9Sstevel@tonic-gate { "tracemem", DT_IDENT_ACTFUNC, 0, DT_ACT_TRACEMEM,
4207c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0,
4211ea5f93dSBryan Cantrill 	&dt_idops_func, "void(@, size_t, ...)" },
4227c478bd9Sstevel@tonic-gate { "trunc", DT_IDENT_ACTFUNC, 0, DT_ACT_TRUNC, DT_ATTR_STABCMN,
4237c478bd9Sstevel@tonic-gate 	DT_VERS_1_0, &dt_idops_func, "void(...)" },
424a1b5e537Sbmc { "uaddr", DT_IDENT_ACTFUNC, 0, DT_ACT_UADDR, DT_ATTR_STABCMN,
425a1b5e537Sbmc 	DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" },
426a1b5e537Sbmc { "ucaller", DT_IDENT_SCALAR, 0, DIF_VAR_UCALLER, DT_ATTR_STABCMN,
427a1b5e537Sbmc 	DT_VERS_1_2, &dt_idops_type, "uint64_t" },
428a1b5e537Sbmc { "ufunc", DT_IDENT_ACTFUNC, 0, DT_ACT_USYM, DT_ATTR_STABCMN,
429a1b5e537Sbmc 	DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" },
4305518d15bSdp { "uid", DT_IDENT_SCALAR, 0, DIF_VAR_UID, DT_ATTR_STABCMN, DT_VERS_1_0,
4315518d15bSdp 	&dt_idops_type, "uid_t" },
432a1b5e537Sbmc { "umod", DT_IDENT_ACTFUNC, 0, DT_ACT_UMOD, DT_ATTR_STABCMN,
433a1b5e537Sbmc 	DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" },
43456a20711SPatrick Mooney { "uregs", DT_IDENT_ARRAY, DT_IDFLG_WRITE, DIF_VAR_UREGS, DT_ATTR_STABCMN,
43556a20711SPatrick Mooney 	DT_VERS_1_0, &dt_idops_regs, NULL },
4367c478bd9Sstevel@tonic-gate { "ustack", DT_IDENT_ACTFUNC, 0, DT_ACT_USTACK, DT_ATTR_STABCMN, DT_VERS_1_0,
4377c478bd9Sstevel@tonic-gate 	&dt_idops_func, "stack(...)" },
4380b38a8bdSahl { "ustackdepth", DT_IDENT_SCALAR, 0, DIF_VAR_USTACKDEPTH,
4390b38a8bdSahl 	DT_ATTR_STABCMN, DT_VERS_1_2,
4400b38a8bdSahl 	&dt_idops_type, "uint32_t" },
441a1b5e537Sbmc { "usym", DT_IDENT_ACTFUNC, 0, DT_ACT_USYM, DT_ATTR_STABCMN,
442a1b5e537Sbmc 	DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" },
4437aa76ffcSBryan Cantrill { "vmregs", DT_IDENT_ARRAY, 0, DIF_VAR_VMREGS, DT_ATTR_STABCMN, DT_VERS_1_7,
4447aa76ffcSBryan Cantrill 	&dt_idops_regs, NULL },
4457c478bd9Sstevel@tonic-gate { "vtimestamp", DT_IDENT_SCALAR, 0, DIF_VAR_VTIMESTAMP,
4467c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0,
4477c478bd9Sstevel@tonic-gate 	&dt_idops_type, "uint64_t" },
4487c478bd9Sstevel@tonic-gate { "walltimestamp", DT_IDENT_SCALAR, 0, DIF_VAR_WALLTIMESTAMP,
4497c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0,
45030ef842dSbmc 	&dt_idops_type, "int64_t" },
4517c478bd9Sstevel@tonic-gate { "zonename", DT_IDENT_SCALAR, 0, DIF_VAR_ZONENAME,
4527c478bd9Sstevel@tonic-gate 	DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
4537c478bd9Sstevel@tonic-gate { NULL, 0, 0, 0, { 0, 0, 0 }, 0, NULL, NULL }
4547c478bd9Sstevel@tonic-gate };
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate /*
4577c478bd9Sstevel@tonic-gate  * Tables of ILP32 intrinsic integer and floating-point type templates to use
4587c478bd9Sstevel@tonic-gate  * to populate the dynamic "C" CTF type container.
4597c478bd9Sstevel@tonic-gate  */
4607c478bd9Sstevel@tonic-gate static const dt_intrinsic_t _dtrace_intrinsics_32[] = {
4617c478bd9Sstevel@tonic-gate { "void", { CTF_INT_SIGNED, 0, 0 }, CTF_K_INTEGER },
4627c478bd9Sstevel@tonic-gate { "signed", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
4637c478bd9Sstevel@tonic-gate { "unsigned", { 0, 0, 32 }, CTF_K_INTEGER },
4647c478bd9Sstevel@tonic-gate { "char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
4657c478bd9Sstevel@tonic-gate { "short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER },
4667c478bd9Sstevel@tonic-gate { "int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
4677c478bd9Sstevel@tonic-gate { "long", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
4687c478bd9Sstevel@tonic-gate { "long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
4697c478bd9Sstevel@tonic-gate { "signed char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
4707c478bd9Sstevel@tonic-gate { "signed short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER },
4717c478bd9Sstevel@tonic-gate { "signed int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
4727c478bd9Sstevel@tonic-gate { "signed long", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
4737c478bd9Sstevel@tonic-gate { "signed long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
4747c478bd9Sstevel@tonic-gate { "unsigned char", { CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
4757c478bd9Sstevel@tonic-gate { "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER },
4767c478bd9Sstevel@tonic-gate { "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER },
4777c478bd9Sstevel@tonic-gate { "unsigned long", { 0, 0, 32 }, CTF_K_INTEGER },
4787c478bd9Sstevel@tonic-gate { "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER },
4797c478bd9Sstevel@tonic-gate { "_Bool", { CTF_INT_BOOL, 0, 8 }, CTF_K_INTEGER },
4807c478bd9Sstevel@tonic-gate { "float", { CTF_FP_SINGLE, 0, 32 }, CTF_K_FLOAT },
4817c478bd9Sstevel@tonic-gate { "double", { CTF_FP_DOUBLE, 0, 64 }, CTF_K_FLOAT },
4827c478bd9Sstevel@tonic-gate { "long double", { CTF_FP_LDOUBLE, 0, 128 }, CTF_K_FLOAT },
4837c478bd9Sstevel@tonic-gate { "float imaginary", { CTF_FP_IMAGRY, 0, 32 }, CTF_K_FLOAT },
4847c478bd9Sstevel@tonic-gate { "double imaginary", { CTF_FP_DIMAGRY, 0, 64 }, CTF_K_FLOAT },
4857c478bd9Sstevel@tonic-gate { "long double imaginary", { CTF_FP_LDIMAGRY, 0, 128 }, CTF_K_FLOAT },
4867c478bd9Sstevel@tonic-gate { "float complex", { CTF_FP_CPLX, 0, 64 }, CTF_K_FLOAT },
4877c478bd9Sstevel@tonic-gate { "double complex", { CTF_FP_DCPLX, 0, 128 }, CTF_K_FLOAT },
4887c478bd9Sstevel@tonic-gate { "long double complex", { CTF_FP_LDCPLX, 0, 256 }, CTF_K_FLOAT },
4897c478bd9Sstevel@tonic-gate { NULL, { 0, 0, 0 }, 0 }
4907c478bd9Sstevel@tonic-gate };
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate /*
4937c478bd9Sstevel@tonic-gate  * Tables of LP64 intrinsic integer and floating-point type templates to use
4947c478bd9Sstevel@tonic-gate  * to populate the dynamic "C" CTF type container.
4957c478bd9Sstevel@tonic-gate  */
4967c478bd9Sstevel@tonic-gate static const dt_intrinsic_t _dtrace_intrinsics_64[] = {
4977c478bd9Sstevel@tonic-gate { "void", { CTF_INT_SIGNED, 0, 0 }, CTF_K_INTEGER },
4987c478bd9Sstevel@tonic-gate { "signed", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
4997c478bd9Sstevel@tonic-gate { "unsigned", { 0, 0, 32 }, CTF_K_INTEGER },
5007c478bd9Sstevel@tonic-gate { "char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
5017c478bd9Sstevel@tonic-gate { "short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER },
5027c478bd9Sstevel@tonic-gate { "int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
5037c478bd9Sstevel@tonic-gate { "long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
5047c478bd9Sstevel@tonic-gate { "long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
5057c478bd9Sstevel@tonic-gate { "signed char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
5067c478bd9Sstevel@tonic-gate { "signed short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER },
5077c478bd9Sstevel@tonic-gate { "signed int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
5087c478bd9Sstevel@tonic-gate { "signed long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
5097c478bd9Sstevel@tonic-gate { "signed long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
5107c478bd9Sstevel@tonic-gate { "unsigned char", { CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
5117c478bd9Sstevel@tonic-gate { "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER },
5127c478bd9Sstevel@tonic-gate { "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER },
5137c478bd9Sstevel@tonic-gate { "unsigned long", { 0, 0, 64 }, CTF_K_INTEGER },
5147c478bd9Sstevel@tonic-gate { "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER },
5157c478bd9Sstevel@tonic-gate { "_Bool", { CTF_INT_BOOL, 0, 8 }, CTF_K_INTEGER },
5167c478bd9Sstevel@tonic-gate { "float", { CTF_FP_SINGLE, 0, 32 }, CTF_K_FLOAT },
5177c478bd9Sstevel@tonic-gate { "double", { CTF_FP_DOUBLE, 0, 64 }, CTF_K_FLOAT },
5187c478bd9Sstevel@tonic-gate { "long double", { CTF_FP_LDOUBLE, 0, 128 }, CTF_K_FLOAT },
5197c478bd9Sstevel@tonic-gate { "float imaginary", { CTF_FP_IMAGRY, 0, 32 }, CTF_K_FLOAT },
5207c478bd9Sstevel@tonic-gate { "double imaginary", { CTF_FP_DIMAGRY, 0, 64 }, CTF_K_FLOAT },
5217c478bd9Sstevel@tonic-gate { "long double imaginary", { CTF_FP_LDIMAGRY, 0, 128 }, CTF_K_FLOAT },
5227c478bd9Sstevel@tonic-gate { "float complex", { CTF_FP_CPLX, 0, 64 }, CTF_K_FLOAT },
5237c478bd9Sstevel@tonic-gate { "double complex", { CTF_FP_DCPLX, 0, 128 }, CTF_K_FLOAT },
5247c478bd9Sstevel@tonic-gate { "long double complex", { CTF_FP_LDCPLX, 0, 256 }, CTF_K_FLOAT },
5257c478bd9Sstevel@tonic-gate { NULL, { 0, 0, 0 }, 0 }
5267c478bd9Sstevel@tonic-gate };
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate /*
5297c478bd9Sstevel@tonic-gate  * Tables of ILP32 typedefs to use to populate the dynamic "D" CTF container.
5307c478bd9Sstevel@tonic-gate  * These aliases ensure that D definitions can use typical <sys/types.h> names.
5317c478bd9Sstevel@tonic-gate  */
5327c478bd9Sstevel@tonic-gate static const dt_typedef_t _dtrace_typedefs_32[] = {
5337c478bd9Sstevel@tonic-gate { "char", "int8_t" },
5347c478bd9Sstevel@tonic-gate { "short", "int16_t" },
5357c478bd9Sstevel@tonic-gate { "int", "int32_t" },
5367c478bd9Sstevel@tonic-gate { "long long", "int64_t" },
5377c478bd9Sstevel@tonic-gate { "int", "intptr_t" },
5387c478bd9Sstevel@tonic-gate { "int", "ssize_t" },
5397c478bd9Sstevel@tonic-gate { "unsigned char", "uint8_t" },
5407c478bd9Sstevel@tonic-gate { "unsigned short", "uint16_t" },
5417c478bd9Sstevel@tonic-gate { "unsigned", "uint32_t" },
5427c478bd9Sstevel@tonic-gate { "unsigned long long", "uint64_t" },
5437c478bd9Sstevel@tonic-gate { "unsigned char", "uchar_t" },
5447c478bd9Sstevel@tonic-gate { "unsigned short", "ushort_t" },
5457c478bd9Sstevel@tonic-gate { "unsigned", "uint_t" },
5467c478bd9Sstevel@tonic-gate { "unsigned long", "ulong_t" },
5477c478bd9Sstevel@tonic-gate { "unsigned long long", "u_longlong_t" },
5487c478bd9Sstevel@tonic-gate { "int", "ptrdiff_t" },
5497c478bd9Sstevel@tonic-gate { "unsigned", "uintptr_t" },
5507c478bd9Sstevel@tonic-gate { "unsigned", "size_t" },
5517c478bd9Sstevel@tonic-gate { "long", "id_t" },
5527c478bd9Sstevel@tonic-gate { "long", "pid_t" },
5537c478bd9Sstevel@tonic-gate { NULL, NULL }
5547c478bd9Sstevel@tonic-gate };
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate /*
5577c478bd9Sstevel@tonic-gate  * Tables of LP64 typedefs to use to populate the dynamic "D" CTF container.
5587c478bd9Sstevel@tonic-gate  * These aliases ensure that D definitions can use typical <sys/types.h> names.
5597c478bd9Sstevel@tonic-gate  */
5607c478bd9Sstevel@tonic-gate static const dt_typedef_t _dtrace_typedefs_64[] = {
5617c478bd9Sstevel@tonic-gate { "char", "int8_t" },
5627c478bd9Sstevel@tonic-gate { "short", "int16_t" },
5637c478bd9Sstevel@tonic-gate { "int", "int32_t" },
5647c478bd9Sstevel@tonic-gate { "long", "int64_t" },
5657c478bd9Sstevel@tonic-gate { "long", "intptr_t" },
5667c478bd9Sstevel@tonic-gate { "long", "ssize_t" },
5677c478bd9Sstevel@tonic-gate { "unsigned char", "uint8_t" },
5687c478bd9Sstevel@tonic-gate { "unsigned short", "uint16_t" },
5697c478bd9Sstevel@tonic-gate { "unsigned", "uint32_t" },
5707c478bd9Sstevel@tonic-gate { "unsigned long", "uint64_t" },
5717c478bd9Sstevel@tonic-gate { "unsigned char", "uchar_t" },
5727c478bd9Sstevel@tonic-gate { "unsigned short", "ushort_t" },
5737c478bd9Sstevel@tonic-gate { "unsigned", "uint_t" },
5747c478bd9Sstevel@tonic-gate { "unsigned long", "ulong_t" },
5757c478bd9Sstevel@tonic-gate { "unsigned long long", "u_longlong_t" },
5767c478bd9Sstevel@tonic-gate { "long", "ptrdiff_t" },
5777c478bd9Sstevel@tonic-gate { "unsigned long", "uintptr_t" },
5787c478bd9Sstevel@tonic-gate { "unsigned long", "size_t" },
5797c478bd9Sstevel@tonic-gate { "int", "id_t" },
5807c478bd9Sstevel@tonic-gate { "int", "pid_t" },
5817c478bd9Sstevel@tonic-gate { NULL, NULL }
5827c478bd9Sstevel@tonic-gate };
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate /*
5857c478bd9Sstevel@tonic-gate  * Tables of ILP32 integer type templates used to populate the dtp->dt_ints[]
5867c478bd9Sstevel@tonic-gate  * cache when a new dtrace client open occurs.  Values are set by dtrace_open().
5877c478bd9Sstevel@tonic-gate  */
5887c478bd9Sstevel@tonic-gate static const dt_intdesc_t _dtrace_ints_32[] = {
5897c478bd9Sstevel@tonic-gate { "int", NULL, CTF_ERR, 0x7fffffffULL },
5907c478bd9Sstevel@tonic-gate { "unsigned int", NULL, CTF_ERR, 0xffffffffULL },
5917c478bd9Sstevel@tonic-gate { "long", NULL, CTF_ERR, 0x7fffffffULL },
5927c478bd9Sstevel@tonic-gate { "unsigned long", NULL, CTF_ERR, 0xffffffffULL },
5937c478bd9Sstevel@tonic-gate { "long long", NULL, CTF_ERR, 0x7fffffffffffffffULL },
5947c478bd9Sstevel@tonic-gate { "unsigned long long", NULL, CTF_ERR, 0xffffffffffffffffULL }
5957c478bd9Sstevel@tonic-gate };
5967c478bd9Sstevel@tonic-gate 
5977c478bd9Sstevel@tonic-gate /*
5987c478bd9Sstevel@tonic-gate  * Tables of LP64 integer type templates used to populate the dtp->dt_ints[]
5997c478bd9Sstevel@tonic-gate  * cache when a new dtrace client open occurs.  Values are set by dtrace_open().
6007c478bd9Sstevel@tonic-gate  */
6017c478bd9Sstevel@tonic-gate static const dt_intdesc_t _dtrace_ints_64[] = {
6027c478bd9Sstevel@tonic-gate { "int", NULL, CTF_ERR, 0x7fffffffULL },
6037c478bd9Sstevel@tonic-gate { "unsigned int", NULL, CTF_ERR, 0xffffffffULL },
6047c478bd9Sstevel@tonic-gate { "long", NULL, CTF_ERR, 0x7fffffffffffffffULL },
6057c478bd9Sstevel@tonic-gate { "unsigned long", NULL, CTF_ERR, 0xffffffffffffffffULL },
6067c478bd9Sstevel@tonic-gate { "long long", NULL, CTF_ERR, 0x7fffffffffffffffULL },
6077c478bd9Sstevel@tonic-gate { "unsigned long long", NULL, CTF_ERR, 0xffffffffffffffffULL }
6087c478bd9Sstevel@tonic-gate };
6097c478bd9Sstevel@tonic-gate 
6107c478bd9Sstevel@tonic-gate /*
6117c478bd9Sstevel@tonic-gate  * Table of macro variable templates used to populate the macro identifier hash
6127c478bd9Sstevel@tonic-gate  * when a new dtrace client open occurs.  Values are set by dtrace_update().
6137c478bd9Sstevel@tonic-gate  */
6147c478bd9Sstevel@tonic-gate static const dt_ident_t _dtrace_macros[] = {
6157c478bd9Sstevel@tonic-gate { "egid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
6167c478bd9Sstevel@tonic-gate { "euid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
6177c478bd9Sstevel@tonic-gate { "gid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
6187c478bd9Sstevel@tonic-gate { "pid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
6197c478bd9Sstevel@tonic-gate { "pgid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
6207c478bd9Sstevel@tonic-gate { "ppid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
6217c478bd9Sstevel@tonic-gate { "projid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
6227c478bd9Sstevel@tonic-gate { "sid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
6237c478bd9Sstevel@tonic-gate { "taskid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
6247c478bd9Sstevel@tonic-gate { "target", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
6257c478bd9Sstevel@tonic-gate { "uid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
6267c478bd9Sstevel@tonic-gate { NULL, 0, 0, 0, { 0, 0, 0 }, 0 }
6277c478bd9Sstevel@tonic-gate };
6287c478bd9Sstevel@tonic-gate 
6297c478bd9Sstevel@tonic-gate /*
6307c478bd9Sstevel@tonic-gate  * Hard-wired definition string to be compiled and cached every time a new
6317c478bd9Sstevel@tonic-gate  * DTrace library handle is initialized.  This string should only be used to
6327c478bd9Sstevel@tonic-gate  * contain definitions that should be present regardless of DTRACE_O_NOLIBS.
6337c478bd9Sstevel@tonic-gate  */
6347c478bd9Sstevel@tonic-gate static const char _dtrace_hardwire[] = "\
6357c478bd9Sstevel@tonic-gate inline long NULL = 0; \n\
6367c478bd9Sstevel@tonic-gate #pragma D binding \"1.0\" NULL\n\
6377c478bd9Sstevel@tonic-gate ";
6387c478bd9Sstevel@tonic-gate 
6397c478bd9Sstevel@tonic-gate /*
6407c478bd9Sstevel@tonic-gate  * Default DTrace configuration to use when opening libdtrace DTRACE_O_NODEV.
6417c478bd9Sstevel@tonic-gate  * If DTRACE_O_NODEV is not set, we load the configuration from the kernel.
6427c478bd9Sstevel@tonic-gate  * The use of CTF_MODEL_NATIVE is more subtle than it might appear: we are
643*bbf21555SRichard Lowe  * relying on the fact that when running dtrace(8), isaexec will invoke the
6447c478bd9Sstevel@tonic-gate  * binary with the same bitness as the kernel, which is what we want by default
6457c478bd9Sstevel@tonic-gate  * when generating our DIF.  The user can override the choice using oflags.
6467c478bd9Sstevel@tonic-gate  */
6477c478bd9Sstevel@tonic-gate static const dtrace_conf_t _dtrace_conf = {
6487c478bd9Sstevel@tonic-gate 	DIF_VERSION,		/* dtc_difversion */
6497c478bd9Sstevel@tonic-gate 	DIF_DIR_NREGS,		/* dtc_difintregs */
6507c478bd9Sstevel@tonic-gate 	DIF_DTR_NREGS,		/* dtc_diftupregs */
6517c478bd9Sstevel@tonic-gate 	CTF_MODEL_NATIVE	/* dtc_ctfmodel */
6527c478bd9Sstevel@tonic-gate };
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate const dtrace_attribute_t _dtrace_maxattr = {
6557c478bd9Sstevel@tonic-gate 	DTRACE_STABILITY_MAX,
6567c478bd9Sstevel@tonic-gate 	DTRACE_STABILITY_MAX,
6577c478bd9Sstevel@tonic-gate 	DTRACE_CLASS_MAX
6587c478bd9Sstevel@tonic-gate };
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate const dtrace_attribute_t _dtrace_defattr = {
6617c478bd9Sstevel@tonic-gate 	DTRACE_STABILITY_STABLE,
6627c478bd9Sstevel@tonic-gate 	DTRACE_STABILITY_STABLE,
6637c478bd9Sstevel@tonic-gate 	DTRACE_CLASS_COMMON
6647c478bd9Sstevel@tonic-gate };
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate const dtrace_attribute_t _dtrace_symattr = {
6677c478bd9Sstevel@tonic-gate 	DTRACE_STABILITY_PRIVATE,
6687c478bd9Sstevel@tonic-gate 	DTRACE_STABILITY_PRIVATE,
6697c478bd9Sstevel@tonic-gate 	DTRACE_CLASS_UNKNOWN
6707c478bd9Sstevel@tonic-gate };
6717c478bd9Sstevel@tonic-gate 
6727c478bd9Sstevel@tonic-gate const dtrace_attribute_t _dtrace_typattr = {
6737c478bd9Sstevel@tonic-gate 	DTRACE_STABILITY_PRIVATE,
6747c478bd9Sstevel@tonic-gate 	DTRACE_STABILITY_PRIVATE,
6757c478bd9Sstevel@tonic-gate 	DTRACE_CLASS_UNKNOWN
6767c478bd9Sstevel@tonic-gate };
6777c478bd9Sstevel@tonic-gate 
6787c478bd9Sstevel@tonic-gate const dtrace_attribute_t _dtrace_prvattr = {
6797c478bd9Sstevel@tonic-gate 	DTRACE_STABILITY_PRIVATE,
6807c478bd9Sstevel@tonic-gate 	DTRACE_STABILITY_PRIVATE,
6817c478bd9Sstevel@tonic-gate 	DTRACE_CLASS_UNKNOWN
6827c478bd9Sstevel@tonic-gate };
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate const dtrace_pattr_t _dtrace_prvdesc = {
6857c478bd9Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
6867c478bd9Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
6877c478bd9Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
6887c478bd9Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
6897c478bd9Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
6907c478bd9Sstevel@tonic-gate };
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate const char *_dtrace_defcpp = "/usr/ccs/lib/cpp"; /* default cpp(1) to invoke */
6937c478bd9Sstevel@tonic-gate const char *_dtrace_defld = "/usr/ccs/bin/ld";   /* default ld(1) to invoke */
6947c478bd9Sstevel@tonic-gate 
6957c478bd9Sstevel@tonic-gate const char *_dtrace_libdir = "/usr/lib/dtrace"; /* default library directory */
696fb405578Sdp const char *_dtrace_provdir = "/dev/dtrace/provider"; /* provider directory */
6977c478bd9Sstevel@tonic-gate 
6987c478bd9Sstevel@tonic-gate int _dtrace_strbuckets = 211;	/* default number of hash buckets (prime) */
6997c478bd9Sstevel@tonic-gate int _dtrace_intbuckets = 256;	/* default number of integer buckets (Pof2) */
7007c478bd9Sstevel@tonic-gate uint_t _dtrace_strsize = 256;	/* default size of string intrinsic type */
7017c478bd9Sstevel@tonic-gate uint_t _dtrace_stkindent = 14;	/* default whitespace indent for stack/ustack */
7027c478bd9Sstevel@tonic-gate uint_t _dtrace_pidbuckets = 64; /* default number of pid hash buckets */
7037c478bd9Sstevel@tonic-gate uint_t _dtrace_pidlrulim = 8;	/* default number of pid handles to cache */
7047c478bd9Sstevel@tonic-gate size_t _dtrace_bufsize = 512;	/* default dt_buf_create() size */
7057c478bd9Sstevel@tonic-gate int _dtrace_argmax = 32;	/* default maximum number of probe arguments */
7067c478bd9Sstevel@tonic-gate 
7077c478bd9Sstevel@tonic-gate int _dtrace_debug = 0;		/* debug messages enabled (off) */
7087c478bd9Sstevel@tonic-gate const char *const _dtrace_version = DT_VERS_STRING; /* API version string */
7097c478bd9Sstevel@tonic-gate int _dtrace_rdvers = RD_VERSION; /* rtld_db feature version */
7107c478bd9Sstevel@tonic-gate 
7117c478bd9Sstevel@tonic-gate typedef struct dt_fdlist {
7127c478bd9Sstevel@tonic-gate 	int *df_fds;		/* array of provider driver file descriptors */
7137c478bd9Sstevel@tonic-gate 	uint_t df_ents;		/* number of valid elements in df_fds[] */
7147c478bd9Sstevel@tonic-gate 	uint_t df_size;		/* size of df_fds[] */
7157c478bd9Sstevel@tonic-gate } dt_fdlist_t;
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate #pragma init(_dtrace_init)
7187c478bd9Sstevel@tonic-gate void
_dtrace_init(void)7197c478bd9Sstevel@tonic-gate _dtrace_init(void)
7207c478bd9Sstevel@tonic-gate {
7217c478bd9Sstevel@tonic-gate 	_dtrace_debug = getenv("DTRACE_DEBUG") != NULL;
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate 	for (; _dtrace_rdvers > 0; _dtrace_rdvers--) {
7247c478bd9Sstevel@tonic-gate 		if (rd_init(_dtrace_rdvers) == RD_OK)
7257c478bd9Sstevel@tonic-gate 			break;
7267c478bd9Sstevel@tonic-gate 	}
7277c478bd9Sstevel@tonic-gate }
7287c478bd9Sstevel@tonic-gate 
7297c478bd9Sstevel@tonic-gate static dtrace_hdl_t *
set_open_errno(dtrace_hdl_t * dtp,int * errp,int err)7307c478bd9Sstevel@tonic-gate set_open_errno(dtrace_hdl_t *dtp, int *errp, int err)
7317c478bd9Sstevel@tonic-gate {
7327c478bd9Sstevel@tonic-gate 	if (dtp != NULL)
7337c478bd9Sstevel@tonic-gate 		dtrace_close(dtp);
7347c478bd9Sstevel@tonic-gate 	if (errp != NULL)
7357c478bd9Sstevel@tonic-gate 		*errp = err;
7367c478bd9Sstevel@tonic-gate 	return (NULL);
7377c478bd9Sstevel@tonic-gate }
7387c478bd9Sstevel@tonic-gate 
7397c478bd9Sstevel@tonic-gate static void
dt_provmod_open(dt_provmod_t ** provmod,dt_fdlist_t * dfp)740fb405578Sdp dt_provmod_open(dt_provmod_t **provmod, dt_fdlist_t *dfp)
7417c478bd9Sstevel@tonic-gate {
7427c478bd9Sstevel@tonic-gate 	dt_provmod_t *prov;
7437c478bd9Sstevel@tonic-gate 	char path[PATH_MAX];
7447c478bd9Sstevel@tonic-gate 	struct dirent *dp, *ep;
7457c478bd9Sstevel@tonic-gate 	DIR *dirp;
7467c478bd9Sstevel@tonic-gate 	int fd;
7477c478bd9Sstevel@tonic-gate 
748fb405578Sdp 	if ((dirp = opendir(_dtrace_provdir)) == NULL)
7497c478bd9Sstevel@tonic-gate 		return; /* failed to open directory; just skip it */
7507c478bd9Sstevel@tonic-gate 
7517c478bd9Sstevel@tonic-gate 	ep = alloca(sizeof (struct dirent) + PATH_MAX + 1);
7527c478bd9Sstevel@tonic-gate 	bzero(ep, sizeof (struct dirent) + PATH_MAX + 1);
7537c478bd9Sstevel@tonic-gate 
7547c478bd9Sstevel@tonic-gate 	while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) {
7557c478bd9Sstevel@tonic-gate 		if (dp->d_name[0] == '.')
7567c478bd9Sstevel@tonic-gate 			continue; /* skip "." and ".." */
7577c478bd9Sstevel@tonic-gate 
7587c478bd9Sstevel@tonic-gate 		if (dfp->df_ents == dfp->df_size) {
7597c478bd9Sstevel@tonic-gate 			uint_t size = dfp->df_size ? dfp->df_size * 2 : 16;
7607c478bd9Sstevel@tonic-gate 			int *fds = realloc(dfp->df_fds, size * sizeof (int));
7617c478bd9Sstevel@tonic-gate 
7627c478bd9Sstevel@tonic-gate 			if (fds == NULL)
7637c478bd9Sstevel@tonic-gate 				break; /* skip the rest of this directory */
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate 			dfp->df_fds = fds;
7667c478bd9Sstevel@tonic-gate 			dfp->df_size = size;
7677c478bd9Sstevel@tonic-gate 		}
7687c478bd9Sstevel@tonic-gate 
769fb405578Sdp 		(void) snprintf(path, sizeof (path), "%s/%s",
770fb405578Sdp 		    _dtrace_provdir, dp->d_name);
7717c478bd9Sstevel@tonic-gate 
7727c478bd9Sstevel@tonic-gate 		if ((fd = open(path, O_RDONLY)) == -1)
7737c478bd9Sstevel@tonic-gate 			continue; /* failed to open driver; just skip it */
7747c478bd9Sstevel@tonic-gate 
7757c478bd9Sstevel@tonic-gate 		if (((prov = malloc(sizeof (dt_provmod_t))) == NULL) ||
7767c478bd9Sstevel@tonic-gate 		    (prov->dp_name = malloc(strlen(dp->d_name) + 1)) == NULL) {
7777c478bd9Sstevel@tonic-gate 			free(prov);
7787c478bd9Sstevel@tonic-gate 			(void) close(fd);
7797c478bd9Sstevel@tonic-gate 			break;
7807c478bd9Sstevel@tonic-gate 		}
7817c478bd9Sstevel@tonic-gate 
7827c478bd9Sstevel@tonic-gate 		(void) strcpy(prov->dp_name, dp->d_name);
7837c478bd9Sstevel@tonic-gate 		prov->dp_next = *provmod;
7847c478bd9Sstevel@tonic-gate 		*provmod = prov;
7857c478bd9Sstevel@tonic-gate 
7867c478bd9Sstevel@tonic-gate 		dt_dprintf("opened provider %s\n", dp->d_name);
7877c478bd9Sstevel@tonic-gate 		dfp->df_fds[dfp->df_ents++] = fd;
7887c478bd9Sstevel@tonic-gate 	}
7897c478bd9Sstevel@tonic-gate 
7907c478bd9Sstevel@tonic-gate 	(void) closedir(dirp);
7917c478bd9Sstevel@tonic-gate }
7927c478bd9Sstevel@tonic-gate 
7937c478bd9Sstevel@tonic-gate static void
dt_provmod_destroy(dt_provmod_t ** provmod)7947c478bd9Sstevel@tonic-gate dt_provmod_destroy(dt_provmod_t **provmod)
7957c478bd9Sstevel@tonic-gate {
7967c478bd9Sstevel@tonic-gate 	dt_provmod_t *next, *current;
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate 	for (current = *provmod; current != NULL; current = next) {
7997c478bd9Sstevel@tonic-gate 		next = current->dp_next;
8007c478bd9Sstevel@tonic-gate 		free(current->dp_name);
8017c478bd9Sstevel@tonic-gate 		free(current);
8027c478bd9Sstevel@tonic-gate 	}
8037c478bd9Sstevel@tonic-gate 
8047c478bd9Sstevel@tonic-gate 	*provmod = NULL;
8057c478bd9Sstevel@tonic-gate }
8067c478bd9Sstevel@tonic-gate 
8077c478bd9Sstevel@tonic-gate static const char *
dt_get_sysinfo(int cmd,char * buf,size_t len)8087c478bd9Sstevel@tonic-gate dt_get_sysinfo(int cmd, char *buf, size_t len)
8097c478bd9Sstevel@tonic-gate {
8107c478bd9Sstevel@tonic-gate 	ssize_t rv = sysinfo(cmd, buf, len);
8117c478bd9Sstevel@tonic-gate 	char *p = buf;
8127c478bd9Sstevel@tonic-gate 
8137c478bd9Sstevel@tonic-gate 	if (rv < 0 || rv > len)
8147c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, len, "%s", "Unknown");
8157c478bd9Sstevel@tonic-gate 
8167c478bd9Sstevel@tonic-gate 	while ((p = strchr(p, '.')) != NULL)
8177c478bd9Sstevel@tonic-gate 		*p++ = '_';
8187c478bd9Sstevel@tonic-gate 
8197c478bd9Sstevel@tonic-gate 	return (buf);
8207c478bd9Sstevel@tonic-gate }
8217c478bd9Sstevel@tonic-gate 
8227c478bd9Sstevel@tonic-gate static dtrace_hdl_t *
dt_vopen(int version,int flags,int * errp,const dtrace_vector_t * vector,void * arg)8237c478bd9Sstevel@tonic-gate dt_vopen(int version, int flags, int *errp,
8247c478bd9Sstevel@tonic-gate     const dtrace_vector_t *vector, void *arg)
8257c478bd9Sstevel@tonic-gate {
8267c478bd9Sstevel@tonic-gate 	dtrace_hdl_t *dtp = NULL;
8277c478bd9Sstevel@tonic-gate 	int dtfd = -1, ftfd = -1, fterr = 0;
8287c478bd9Sstevel@tonic-gate 	dtrace_prog_t *pgp;
8297c478bd9Sstevel@tonic-gate 	dt_module_t *dmp;
8307c478bd9Sstevel@tonic-gate 	dt_provmod_t *provmod = NULL;
8317c478bd9Sstevel@tonic-gate 	int i, err;
832586d07d0Sbmc 	struct rlimit rl;
8337c478bd9Sstevel@tonic-gate 
8347c478bd9Sstevel@tonic-gate 	const dt_intrinsic_t *dinp;
8357c478bd9Sstevel@tonic-gate 	const dt_typedef_t *dtyp;
8367c478bd9Sstevel@tonic-gate 	const dt_ident_t *idp;
8377c478bd9Sstevel@tonic-gate 
8387c478bd9Sstevel@tonic-gate 	dtrace_typeinfo_t dtt;
8397c478bd9Sstevel@tonic-gate 	ctf_funcinfo_t ctc;
8407c478bd9Sstevel@tonic-gate 	ctf_arinfo_t ctr;
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate 	dt_fdlist_t df = { NULL, 0, 0 };
8437c478bd9Sstevel@tonic-gate 
8447c478bd9Sstevel@tonic-gate 	char isadef[32], utsdef[32];
8457c478bd9Sstevel@tonic-gate 	char s1[64], s2[64];
8467c478bd9Sstevel@tonic-gate 
8477c478bd9Sstevel@tonic-gate 	if (version <= 0)
8487c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EINVAL));
8497c478bd9Sstevel@tonic-gate 
8507c478bd9Sstevel@tonic-gate 	if (version > DTRACE_VERSION)
8517c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_VERSION));
8527c478bd9Sstevel@tonic-gate 
85330ef842dSbmc 	if (version < DTRACE_VERSION) {
85430ef842dSbmc 		/*
85530ef842dSbmc 		 * Currently, increasing the library version number is used to
85630ef842dSbmc 		 * denote a binary incompatible change.  That is, a consumer
85730ef842dSbmc 		 * of the library cannot run on a version of the library with
85830ef842dSbmc 		 * a higher DTRACE_VERSION number than the consumer compiled
85930ef842dSbmc 		 * against.  Once the library API has been committed to,
86030ef842dSbmc 		 * backwards binary compatibility will be required; at that
86130ef842dSbmc 		 * time, this check should change to return EDT_OVERSION only
86230ef842dSbmc 		 * if the specified version number is less than the version
86330ef842dSbmc 		 * number at the time of interface commitment.
86430ef842dSbmc 		 */
86530ef842dSbmc 		return (set_open_errno(dtp, errp, EDT_OVERSION));
86630ef842dSbmc 	}
86730ef842dSbmc 
8687c478bd9Sstevel@tonic-gate 	if (flags & ~DTRACE_O_MASK)
8697c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EINVAL));
8707c478bd9Sstevel@tonic-gate 
8717c478bd9Sstevel@tonic-gate 	if ((flags & DTRACE_O_LP64) && (flags & DTRACE_O_ILP32))
8727c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EINVAL));
8737c478bd9Sstevel@tonic-gate 
8747c478bd9Sstevel@tonic-gate 	if (vector == NULL && arg != NULL)
8757c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EINVAL));
8767c478bd9Sstevel@tonic-gate 
8777c478bd9Sstevel@tonic-gate 	if (elf_version(EV_CURRENT) == EV_NONE)
8787c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_ELFVERSION));
8797c478bd9Sstevel@tonic-gate 
8807c478bd9Sstevel@tonic-gate 	if (vector != NULL || (flags & DTRACE_O_NODEV))
8817c478bd9Sstevel@tonic-gate 		goto alloc; /* do not attempt to open dtrace device */
8827c478bd9Sstevel@tonic-gate 
883586d07d0Sbmc 	/*
884586d07d0Sbmc 	 * Before we get going, crank our limit on file descriptors up to the
885586d07d0Sbmc 	 * hard limit.  This is to allow for the fact that libproc keeps file
886586d07d0Sbmc 	 * descriptors to objects open for the lifetime of the proc handle;
887586d07d0Sbmc 	 * without raising our hard limit, we would have an acceptably small
888586d07d0Sbmc 	 * bound on the number of processes that we could concurrently
889586d07d0Sbmc 	 * instrument with the pid provider.
890586d07d0Sbmc 	 */
891586d07d0Sbmc 	if (getrlimit(RLIMIT_NOFILE, &rl) == 0) {
892586d07d0Sbmc 		rl.rlim_cur = rl.rlim_max;
893586d07d0Sbmc 		(void) setrlimit(RLIMIT_NOFILE, &rl);
894586d07d0Sbmc 	}
895586d07d0Sbmc 
8967c478bd9Sstevel@tonic-gate 	/*
897fb405578Sdp 	 * Get the device path of each of the providers.  We hold them open
898fb405578Sdp 	 * in the df.df_fds list until we open the DTrace driver itself,
899fb405578Sdp 	 * allowing us to see all of the probes provided on this system.  Once
900fb405578Sdp 	 * we have the DTrace driver open, we can safely close all the providers
901fb405578Sdp 	 * now that they have registered with the framework.
9027c478bd9Sstevel@tonic-gate 	 */
903fb405578Sdp 	dt_provmod_open(&provmod, &df);
9047c478bd9Sstevel@tonic-gate 
905fb405578Sdp 	dtfd = open("/dev/dtrace/dtrace", O_RDWR);
9067c478bd9Sstevel@tonic-gate 	err = errno; /* save errno from opening dtfd */
9077c478bd9Sstevel@tonic-gate 
908fb405578Sdp 	ftfd = open("/dev/dtrace/provider/fasttrap", O_RDWR);
9097c478bd9Sstevel@tonic-gate 	fterr = ftfd == -1 ? errno : 0; /* save errno from open ftfd */
9107c478bd9Sstevel@tonic-gate 
9117c478bd9Sstevel@tonic-gate 	while (df.df_ents-- != 0)
9127c478bd9Sstevel@tonic-gate 		(void) close(df.df_fds[df.df_ents]);
9137c478bd9Sstevel@tonic-gate 
9147c478bd9Sstevel@tonic-gate 	free(df.df_fds);
9157c478bd9Sstevel@tonic-gate 
9167c478bd9Sstevel@tonic-gate 	/*
9177c478bd9Sstevel@tonic-gate 	 * If we failed to open the dtrace device, fail dtrace_open().
9187c478bd9Sstevel@tonic-gate 	 * We convert some kernel errnos to custom libdtrace errnos to
9197c478bd9Sstevel@tonic-gate 	 * improve the resulting message from the usual strerror().
9207c478bd9Sstevel@tonic-gate 	 */
9217c478bd9Sstevel@tonic-gate 	if (dtfd == -1) {
9227c478bd9Sstevel@tonic-gate 		dt_provmod_destroy(&provmod);
9237c478bd9Sstevel@tonic-gate 		switch (err) {
9247c478bd9Sstevel@tonic-gate 		case ENOENT:
925ad4023c4Sdp 			err = EDT_NOENT;
9267c478bd9Sstevel@tonic-gate 			break;
9277c478bd9Sstevel@tonic-gate 		case EBUSY:
9287c478bd9Sstevel@tonic-gate 			err = EDT_BUSY;
9297c478bd9Sstevel@tonic-gate 			break;
9307c478bd9Sstevel@tonic-gate 		case EACCES:
9317c478bd9Sstevel@tonic-gate 			err = EDT_ACCESS;
9327c478bd9Sstevel@tonic-gate 			break;
9337c478bd9Sstevel@tonic-gate 		}
9347c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, err));
9357c478bd9Sstevel@tonic-gate 	}
9367c478bd9Sstevel@tonic-gate 
9377c478bd9Sstevel@tonic-gate 	(void) fcntl(dtfd, F_SETFD, FD_CLOEXEC);
9387c478bd9Sstevel@tonic-gate 	(void) fcntl(ftfd, F_SETFD, FD_CLOEXEC);
9397c478bd9Sstevel@tonic-gate 
9407c478bd9Sstevel@tonic-gate alloc:
9417c478bd9Sstevel@tonic-gate 	if ((dtp = malloc(sizeof (dtrace_hdl_t))) == NULL)
9427c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_NOMEM));
9437c478bd9Sstevel@tonic-gate 
9447c478bd9Sstevel@tonic-gate 	bzero(dtp, sizeof (dtrace_hdl_t));
9457c478bd9Sstevel@tonic-gate 	dtp->dt_oflags = flags;
9467c478bd9Sstevel@tonic-gate 	dtp->dt_prcmode = DT_PROC_STOP_PREINIT;
9477c478bd9Sstevel@tonic-gate 	dtp->dt_linkmode = DT_LINK_KERNEL;
9487c478bd9Sstevel@tonic-gate 	dtp->dt_linktype = DT_LTYP_ELF;
9491a7c1b72Smws 	dtp->dt_xlatemode = DT_XL_STATIC;
9507c478bd9Sstevel@tonic-gate 	dtp->dt_stdcmode = DT_STDC_XA;
95133093f5bSBryan Cantrill 	dtp->dt_encoding = DT_ENCODING_UNSET;
9527c478bd9Sstevel@tonic-gate 	dtp->dt_version = version;
9537c478bd9Sstevel@tonic-gate 	dtp->dt_fd = dtfd;
9547c478bd9Sstevel@tonic-gate 	dtp->dt_ftfd = ftfd;
9557c478bd9Sstevel@tonic-gate 	dtp->dt_fterr = fterr;
9567c478bd9Sstevel@tonic-gate 	dtp->dt_cdefs_fd = -1;
9577c478bd9Sstevel@tonic-gate 	dtp->dt_ddefs_fd = -1;
9587c478bd9Sstevel@tonic-gate 	dtp->dt_stdout_fd = -1;
9597c478bd9Sstevel@tonic-gate 	dtp->dt_modbuckets = _dtrace_strbuckets;
9607c478bd9Sstevel@tonic-gate 	dtp->dt_mods = calloc(dtp->dt_modbuckets, sizeof (dt_module_t *));
9617c478bd9Sstevel@tonic-gate 	dtp->dt_provbuckets = _dtrace_strbuckets;
9627c478bd9Sstevel@tonic-gate 	dtp->dt_provs = calloc(dtp->dt_provbuckets, sizeof (dt_provider_t *));
963e5803b76SAdam H. Leventhal 	dt_proc_init(dtp);
9647c478bd9Sstevel@tonic-gate 	dtp->dt_vmax = DT_VERS_LATEST;
9657c478bd9Sstevel@tonic-gate 	dtp->dt_cpp_path = strdup(_dtrace_defcpp);
9667c478bd9Sstevel@tonic-gate 	dtp->dt_cpp_argv = malloc(sizeof (char *));
9677c478bd9Sstevel@tonic-gate 	dtp->dt_cpp_argc = 1;
9687c478bd9Sstevel@tonic-gate 	dtp->dt_cpp_args = 1;
9697c478bd9Sstevel@tonic-gate 	dtp->dt_ld_path = strdup(_dtrace_defld);
9707c478bd9Sstevel@tonic-gate 	dtp->dt_provmod = provmod;
9717c478bd9Sstevel@tonic-gate 	dtp->dt_vector = vector;
9727c478bd9Sstevel@tonic-gate 	dtp->dt_varg = arg;
9737c478bd9Sstevel@tonic-gate 	dt_dof_init(dtp);
9747c478bd9Sstevel@tonic-gate 	(void) uname(&dtp->dt_uts);
9757c478bd9Sstevel@tonic-gate 
9767c478bd9Sstevel@tonic-gate 	if (dtp->dt_mods == NULL || dtp->dt_provs == NULL ||
977e5803b76SAdam H. Leventhal 	    dtp->dt_procs == NULL || dtp->dt_proc_env == NULL ||
978e5803b76SAdam H. Leventhal 	    dtp->dt_ld_path == NULL || dtp->dt_cpp_path == NULL ||
979e5803b76SAdam H. Leventhal 	    dtp->dt_cpp_argv == NULL)
9807c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_NOMEM));
9817c478bd9Sstevel@tonic-gate 
9827c478bd9Sstevel@tonic-gate 	for (i = 0; i < DTRACEOPT_MAX; i++)
9837c478bd9Sstevel@tonic-gate 		dtp->dt_options[i] = DTRACEOPT_UNSET;
9847c478bd9Sstevel@tonic-gate 
9857c478bd9Sstevel@tonic-gate 	dtp->dt_cpp_argv[0] = (char *)strbasename(dtp->dt_cpp_path);
9867c478bd9Sstevel@tonic-gate 
9877c478bd9Sstevel@tonic-gate 	(void) snprintf(isadef, sizeof (isadef), "-D__SUNW_D_%u",
9887c478bd9Sstevel@tonic-gate 	    (uint_t)(sizeof (void *) * NBBY));
9897c478bd9Sstevel@tonic-gate 
9907c478bd9Sstevel@tonic-gate 	(void) snprintf(utsdef, sizeof (utsdef), "-D__%s_%s",
9917c478bd9Sstevel@tonic-gate 	    dt_get_sysinfo(SI_SYSNAME, s1, sizeof (s1)),
9927c478bd9Sstevel@tonic-gate 	    dt_get_sysinfo(SI_RELEASE, s2, sizeof (s2)));
9937c478bd9Sstevel@tonic-gate 
9947c478bd9Sstevel@tonic-gate 	if (dt_cpp_add_arg(dtp, "-D__sun") == NULL ||
9957c478bd9Sstevel@tonic-gate 	    dt_cpp_add_arg(dtp, "-D__unix") == NULL ||
9967c478bd9Sstevel@tonic-gate 	    dt_cpp_add_arg(dtp, "-D__SVR4") == NULL ||
9977c478bd9Sstevel@tonic-gate 	    dt_cpp_add_arg(dtp, "-D__SUNW_D=1") == NULL ||
9987c478bd9Sstevel@tonic-gate 	    dt_cpp_add_arg(dtp, isadef) == NULL ||
9997c478bd9Sstevel@tonic-gate 	    dt_cpp_add_arg(dtp, utsdef) == NULL)
10007c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_NOMEM));
10017c478bd9Sstevel@tonic-gate 
10027c478bd9Sstevel@tonic-gate 	if (flags & DTRACE_O_NODEV)
10037c478bd9Sstevel@tonic-gate 		bcopy(&_dtrace_conf, &dtp->dt_conf, sizeof (_dtrace_conf));
10047c478bd9Sstevel@tonic-gate 	else if (dt_ioctl(dtp, DTRACEIOC_CONF, &dtp->dt_conf) != 0)
10057c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, errno));
10067c478bd9Sstevel@tonic-gate 
10077c478bd9Sstevel@tonic-gate 	if (flags & DTRACE_O_LP64)
10087c478bd9Sstevel@tonic-gate 		dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_LP64;
10097c478bd9Sstevel@tonic-gate 	else if (flags & DTRACE_O_ILP32)
10107c478bd9Sstevel@tonic-gate 		dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_ILP32;
10117c478bd9Sstevel@tonic-gate 
10127c478bd9Sstevel@tonic-gate #ifdef __sparc
10137c478bd9Sstevel@tonic-gate 	/*
10147c478bd9Sstevel@tonic-gate 	 * On SPARC systems, __sparc is always defined for <sys/isa_defs.h>
10157c478bd9Sstevel@tonic-gate 	 * and __sparcv9 is defined if we are doing a 64-bit compile.
10167c478bd9Sstevel@tonic-gate 	 */
10177c478bd9Sstevel@tonic-gate 	if (dt_cpp_add_arg(dtp, "-D__sparc") == NULL)
10187c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_NOMEM));
10197c478bd9Sstevel@tonic-gate 
10207c478bd9Sstevel@tonic-gate 	if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64 &&
10217c478bd9Sstevel@tonic-gate 	    dt_cpp_add_arg(dtp, "-D__sparcv9") == NULL)
10227c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_NOMEM));
10237c478bd9Sstevel@tonic-gate #endif
10247c478bd9Sstevel@tonic-gate 
10257c478bd9Sstevel@tonic-gate #ifdef __x86
10267c478bd9Sstevel@tonic-gate 	/*
10277c478bd9Sstevel@tonic-gate 	 * On x86 systems, __i386 is defined for <sys/isa_defs.h> for 32-bit
10287c478bd9Sstevel@tonic-gate 	 * compiles and __amd64 is defined for 64-bit compiles.  Unlike SPARC,
10297c478bd9Sstevel@tonic-gate 	 * they are defined exclusive of one another (see PSARC 2004/619).
10307c478bd9Sstevel@tonic-gate 	 */
103112564484Sdp 	if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) {
103212564484Sdp 		if (dt_cpp_add_arg(dtp, "-D__amd64") == NULL)
103312564484Sdp 			return (set_open_errno(dtp, errp, EDT_NOMEM));
103412564484Sdp 	} else {
103512564484Sdp 		if (dt_cpp_add_arg(dtp, "-D__i386") == NULL)
103612564484Sdp 			return (set_open_errno(dtp, errp, EDT_NOMEM));
103712564484Sdp 	}
10387c478bd9Sstevel@tonic-gate #endif
10397c478bd9Sstevel@tonic-gate 
10407c478bd9Sstevel@tonic-gate 	if (dtp->dt_conf.dtc_difversion < DIF_VERSION)
10417c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_DIFVERS));
10427c478bd9Sstevel@tonic-gate 
10437c478bd9Sstevel@tonic-gate 	if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32)
10447c478bd9Sstevel@tonic-gate 		bcopy(_dtrace_ints_32, dtp->dt_ints, sizeof (_dtrace_ints_32));
10457c478bd9Sstevel@tonic-gate 	else
10467c478bd9Sstevel@tonic-gate 		bcopy(_dtrace_ints_64, dtp->dt_ints, sizeof (_dtrace_ints_64));
10477c478bd9Sstevel@tonic-gate 
10487c478bd9Sstevel@tonic-gate 	dtp->dt_macros = dt_idhash_create("macro", NULL, 0, UINT_MAX);
104930ef842dSbmc 	dtp->dt_aggs = dt_idhash_create("aggregation", NULL,
105030ef842dSbmc 	    DTRACE_AGGVARIDNONE + 1, UINT_MAX);
10517c478bd9Sstevel@tonic-gate 
10527c478bd9Sstevel@tonic-gate 	dtp->dt_globals = dt_idhash_create("global", _dtrace_globals,
10537c478bd9Sstevel@tonic-gate 	    DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX);
10547c478bd9Sstevel@tonic-gate 
10557c478bd9Sstevel@tonic-gate 	dtp->dt_tls = dt_idhash_create("thread local", NULL,
10567c478bd9Sstevel@tonic-gate 	    DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX);
10577c478bd9Sstevel@tonic-gate 
10587c478bd9Sstevel@tonic-gate 	if (dtp->dt_macros == NULL || dtp->dt_aggs == NULL ||
10597c478bd9Sstevel@tonic-gate 	    dtp->dt_globals == NULL || dtp->dt_tls == NULL)
10607c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_NOMEM));
10617c478bd9Sstevel@tonic-gate 
10627c478bd9Sstevel@tonic-gate 	/*
10637c478bd9Sstevel@tonic-gate 	 * Populate the dt_macros identifier hash table by hand: we can't use
10647c478bd9Sstevel@tonic-gate 	 * the dt_idhash_populate() mechanism because we're not yet compiling
10657c478bd9Sstevel@tonic-gate 	 * and dtrace_update() needs to immediately reference these idents.
10667c478bd9Sstevel@tonic-gate 	 */
10677c478bd9Sstevel@tonic-gate 	for (idp = _dtrace_macros; idp->di_name != NULL; idp++) {
10687c478bd9Sstevel@tonic-gate 		if (dt_idhash_insert(dtp->dt_macros, idp->di_name,
10697c478bd9Sstevel@tonic-gate 		    idp->di_kind, idp->di_flags, idp->di_id, idp->di_attr,
10707c478bd9Sstevel@tonic-gate 		    idp->di_vers, idp->di_ops ? idp->di_ops : &dt_idops_thaw,
10717c478bd9Sstevel@tonic-gate 		    idp->di_iarg, 0) == NULL)
10727c478bd9Sstevel@tonic-gate 			return (set_open_errno(dtp, errp, EDT_NOMEM));
10737c478bd9Sstevel@tonic-gate 	}
10747c478bd9Sstevel@tonic-gate 
10757c478bd9Sstevel@tonic-gate 	/*
10767c478bd9Sstevel@tonic-gate 	 * Update the module list using /system/object and load the values for
10777c478bd9Sstevel@tonic-gate 	 * the macro variable definitions according to the current process.
10787c478bd9Sstevel@tonic-gate 	 */
10797c478bd9Sstevel@tonic-gate 	dtrace_update(dtp);
10807c478bd9Sstevel@tonic-gate 
10817c478bd9Sstevel@tonic-gate 	/*
10827c478bd9Sstevel@tonic-gate 	 * Select the intrinsics and typedefs we want based on the data model.
10837c478bd9Sstevel@tonic-gate 	 * The intrinsics are under "C".  The typedefs are added under "D".
10847c478bd9Sstevel@tonic-gate 	 */
10857c478bd9Sstevel@tonic-gate 	if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32) {
10867c478bd9Sstevel@tonic-gate 		dinp = _dtrace_intrinsics_32;
10877c478bd9Sstevel@tonic-gate 		dtyp = _dtrace_typedefs_32;
10887c478bd9Sstevel@tonic-gate 	} else {
10897c478bd9Sstevel@tonic-gate 		dinp = _dtrace_intrinsics_64;
10907c478bd9Sstevel@tonic-gate 		dtyp = _dtrace_typedefs_64;
10917c478bd9Sstevel@tonic-gate 	}
10927c478bd9Sstevel@tonic-gate 
10937c478bd9Sstevel@tonic-gate 	/*
10947c478bd9Sstevel@tonic-gate 	 * Create a dynamic CTF container under the "C" scope for intrinsic
10957c478bd9Sstevel@tonic-gate 	 * types and types defined in ANSI-C header files that are included.
10967c478bd9Sstevel@tonic-gate 	 */
10977c478bd9Sstevel@tonic-gate 	if ((dmp = dtp->dt_cdefs = dt_module_create(dtp, "C")) == NULL)
10987c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_NOMEM));
10997c478bd9Sstevel@tonic-gate 
11007c478bd9Sstevel@tonic-gate 	if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL)
11017c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_CTF));
11027c478bd9Sstevel@tonic-gate 
11037c478bd9Sstevel@tonic-gate 	dt_dprintf("created CTF container for %s (%p)\n",
11047c478bd9Sstevel@tonic-gate 	    dmp->dm_name, (void *)dmp->dm_ctfp);
11057c478bd9Sstevel@tonic-gate 
11067c478bd9Sstevel@tonic-gate 	(void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel);
11077c478bd9Sstevel@tonic-gate 	ctf_setspecific(dmp->dm_ctfp, dmp);
11087c478bd9Sstevel@tonic-gate 
11097c478bd9Sstevel@tonic-gate 	dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */
11107c478bd9Sstevel@tonic-gate 	dmp->dm_modid = -1; /* no module ID */
11117c478bd9Sstevel@tonic-gate 
11127c478bd9Sstevel@tonic-gate 	/*
11137c478bd9Sstevel@tonic-gate 	 * Fill the dynamic "C" CTF container with all of the intrinsic
11147c478bd9Sstevel@tonic-gate 	 * integer and floating-point types appropriate for this data model.
11157c478bd9Sstevel@tonic-gate 	 */
11167c478bd9Sstevel@tonic-gate 	for (; dinp->din_name != NULL; dinp++) {
11177c478bd9Sstevel@tonic-gate 		if (dinp->din_kind == CTF_K_INTEGER) {
11187c478bd9Sstevel@tonic-gate 			err = ctf_add_integer(dmp->dm_ctfp, CTF_ADD_ROOT,
11197c478bd9Sstevel@tonic-gate 			    dinp->din_name, &dinp->din_data);
11207c478bd9Sstevel@tonic-gate 		} else {
11217c478bd9Sstevel@tonic-gate 			err = ctf_add_float(dmp->dm_ctfp, CTF_ADD_ROOT,
11227c478bd9Sstevel@tonic-gate 			    dinp->din_name, &dinp->din_data);
11237c478bd9Sstevel@tonic-gate 		}
11247c478bd9Sstevel@tonic-gate 
11257c478bd9Sstevel@tonic-gate 		if (err == CTF_ERR) {
11267c478bd9Sstevel@tonic-gate 			dt_dprintf("failed to add %s to C container: %s\n",
11277c478bd9Sstevel@tonic-gate 			    dinp->din_name, ctf_errmsg(
11287c478bd9Sstevel@tonic-gate 			    ctf_errno(dmp->dm_ctfp)));
11297c478bd9Sstevel@tonic-gate 			return (set_open_errno(dtp, errp, EDT_CTF));
11307c478bd9Sstevel@tonic-gate 		}
11317c478bd9Sstevel@tonic-gate 	}
11327c478bd9Sstevel@tonic-gate 
11337c478bd9Sstevel@tonic-gate 	if (ctf_update(dmp->dm_ctfp) != 0) {
11347c478bd9Sstevel@tonic-gate 		dt_dprintf("failed to update C container: %s\n",
11357c478bd9Sstevel@tonic-gate 		    ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
11367c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_CTF));
11377c478bd9Sstevel@tonic-gate 	}
11387c478bd9Sstevel@tonic-gate 
11397c478bd9Sstevel@tonic-gate 	/*
11407c478bd9Sstevel@tonic-gate 	 * Add intrinsic pointer types that are needed to initialize printf
11417c478bd9Sstevel@tonic-gate 	 * format dictionary types (see table in dt_printf.c).
11427c478bd9Sstevel@tonic-gate 	 */
1143bc1f688bSRobert Mustacchi 	(void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, NULL,
11447c478bd9Sstevel@tonic-gate 	    ctf_lookup_by_name(dmp->dm_ctfp, "void"));
11457c478bd9Sstevel@tonic-gate 
1146bc1f688bSRobert Mustacchi 	(void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, NULL,
11477c478bd9Sstevel@tonic-gate 	    ctf_lookup_by_name(dmp->dm_ctfp, "char"));
11487c478bd9Sstevel@tonic-gate 
1149bc1f688bSRobert Mustacchi 	(void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, NULL,
11507c478bd9Sstevel@tonic-gate 	    ctf_lookup_by_name(dmp->dm_ctfp, "int"));
11517c478bd9Sstevel@tonic-gate 
11527c478bd9Sstevel@tonic-gate 	if (ctf_update(dmp->dm_ctfp) != 0) {
11537c478bd9Sstevel@tonic-gate 		dt_dprintf("failed to update C container: %s\n",
11547c478bd9Sstevel@tonic-gate 		    ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
11557c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_CTF));
11567c478bd9Sstevel@tonic-gate 	}
11577c478bd9Sstevel@tonic-gate 
11587c478bd9Sstevel@tonic-gate 	/*
11597c478bd9Sstevel@tonic-gate 	 * Create a dynamic CTF container under the "D" scope for types that
11607c478bd9Sstevel@tonic-gate 	 * are defined by the D program itself or on-the-fly by the D compiler.
11617c478bd9Sstevel@tonic-gate 	 * The "D" CTF container is a child of the "C" CTF container.
11627c478bd9Sstevel@tonic-gate 	 */
11637c478bd9Sstevel@tonic-gate 	if ((dmp = dtp->dt_ddefs = dt_module_create(dtp, "D")) == NULL)
11647c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_NOMEM));
11657c478bd9Sstevel@tonic-gate 
11667c478bd9Sstevel@tonic-gate 	if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL)
11677c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_CTF));
11687c478bd9Sstevel@tonic-gate 
11697c478bd9Sstevel@tonic-gate 	dt_dprintf("created CTF container for %s (%p)\n",
11707c478bd9Sstevel@tonic-gate 	    dmp->dm_name, (void *)dmp->dm_ctfp);
11717c478bd9Sstevel@tonic-gate 
11727c478bd9Sstevel@tonic-gate 	(void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel);
11737c478bd9Sstevel@tonic-gate 	ctf_setspecific(dmp->dm_ctfp, dmp);
11747c478bd9Sstevel@tonic-gate 
11757c478bd9Sstevel@tonic-gate 	dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */
11767c478bd9Sstevel@tonic-gate 	dmp->dm_modid = -1; /* no module ID */
11777c478bd9Sstevel@tonic-gate 
11787c478bd9Sstevel@tonic-gate 	if (ctf_import(dmp->dm_ctfp, dtp->dt_cdefs->dm_ctfp) == CTF_ERR) {
11797c478bd9Sstevel@tonic-gate 		dt_dprintf("failed to import D parent container: %s\n",
11807c478bd9Sstevel@tonic-gate 		    ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
11817c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_CTF));
11827c478bd9Sstevel@tonic-gate 	}
11837c478bd9Sstevel@tonic-gate 
11847c478bd9Sstevel@tonic-gate 	/*
11857c478bd9Sstevel@tonic-gate 	 * Fill the dynamic "D" CTF container with all of the built-in typedefs
11867c478bd9Sstevel@tonic-gate 	 * that we need to use for our D variable and function definitions.
11877c478bd9Sstevel@tonic-gate 	 * This ensures that basic inttypes.h names are always available to us.
11887c478bd9Sstevel@tonic-gate 	 */
11897c478bd9Sstevel@tonic-gate 	for (; dtyp->dty_src != NULL; dtyp++) {
11907c478bd9Sstevel@tonic-gate 		if (ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
11917c478bd9Sstevel@tonic-gate 		    dtyp->dty_dst, ctf_lookup_by_name(dmp->dm_ctfp,
11927c478bd9Sstevel@tonic-gate 		    dtyp->dty_src)) == CTF_ERR) {
11937c478bd9Sstevel@tonic-gate 			dt_dprintf("failed to add typedef %s %s to D "
11947c478bd9Sstevel@tonic-gate 			    "container: %s", dtyp->dty_src, dtyp->dty_dst,
11957c478bd9Sstevel@tonic-gate 			    ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
11967c478bd9Sstevel@tonic-gate 			return (set_open_errno(dtp, errp, EDT_CTF));
11977c478bd9Sstevel@tonic-gate 		}
11987c478bd9Sstevel@tonic-gate 	}
11997c478bd9Sstevel@tonic-gate 
12007c478bd9Sstevel@tonic-gate 	/*
12017c478bd9Sstevel@tonic-gate 	 * Insert a CTF ID corresponding to a pointer to a type of kind
12027c478bd9Sstevel@tonic-gate 	 * CTF_K_FUNCTION we can use in the compiler for function pointers.
12037c478bd9Sstevel@tonic-gate 	 * CTF treats all function pointers as "int (*)()" so we only need one.
12047c478bd9Sstevel@tonic-gate 	 */
12057c478bd9Sstevel@tonic-gate 	ctc.ctc_return = ctf_lookup_by_name(dmp->dm_ctfp, "int");
12067c478bd9Sstevel@tonic-gate 	ctc.ctc_argc = 0;
12077c478bd9Sstevel@tonic-gate 	ctc.ctc_flags = 0;
12087c478bd9Sstevel@tonic-gate 
1209bc1f688bSRobert Mustacchi 	dtp->dt_type_func = ctf_add_funcptr(dmp->dm_ctfp,
12107c478bd9Sstevel@tonic-gate 	    CTF_ADD_ROOT, &ctc, NULL);
12117c478bd9Sstevel@tonic-gate 
1212bc1f688bSRobert Mustacchi 	dtp->dt_type_fptr = ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, NULL,
1213bc1f688bSRobert Mustacchi 	    dtp->dt_type_func);
12147c478bd9Sstevel@tonic-gate 
12157c478bd9Sstevel@tonic-gate 	/*
12167c478bd9Sstevel@tonic-gate 	 * We also insert CTF definitions for the special D intrinsic types
12177c478bd9Sstevel@tonic-gate 	 * string and <DYN> into the D container.  The string type is added
12187c478bd9Sstevel@tonic-gate 	 * as a typedef of char[n].  The <DYN> type is an alias for void.
12197c478bd9Sstevel@tonic-gate 	 * We compare types to these special CTF ids throughout the compiler.
12207c478bd9Sstevel@tonic-gate 	 */
12217c478bd9Sstevel@tonic-gate 	ctr.ctr_contents = ctf_lookup_by_name(dmp->dm_ctfp, "char");
12227c478bd9Sstevel@tonic-gate 	ctr.ctr_index = ctf_lookup_by_name(dmp->dm_ctfp, "long");
12237c478bd9Sstevel@tonic-gate 	ctr.ctr_nelems = _dtrace_strsize;
12247c478bd9Sstevel@tonic-gate 
12257c478bd9Sstevel@tonic-gate 	dtp->dt_type_str = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
12267c478bd9Sstevel@tonic-gate 	    "string", ctf_add_array(dmp->dm_ctfp, CTF_ADD_ROOT, &ctr));
12277c478bd9Sstevel@tonic-gate 
12287c478bd9Sstevel@tonic-gate 	dtp->dt_type_dyn = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
12297c478bd9Sstevel@tonic-gate 	    "<DYN>", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
12307c478bd9Sstevel@tonic-gate 
12317c478bd9Sstevel@tonic-gate 	dtp->dt_type_stack = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
12327c478bd9Sstevel@tonic-gate 	    "stack", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
12337c478bd9Sstevel@tonic-gate 
1234a1b5e537Sbmc 	dtp->dt_type_symaddr = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1235a1b5e537Sbmc 	    "_symaddr", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1236a1b5e537Sbmc 
1237a1b5e537Sbmc 	dtp->dt_type_usymaddr = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1238a1b5e537Sbmc 	    "_usymaddr", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1239a1b5e537Sbmc 
12407c478bd9Sstevel@tonic-gate 	if (dtp->dt_type_func == CTF_ERR || dtp->dt_type_fptr == CTF_ERR ||
12417c478bd9Sstevel@tonic-gate 	    dtp->dt_type_str == CTF_ERR || dtp->dt_type_dyn == CTF_ERR ||
1242a1b5e537Sbmc 	    dtp->dt_type_stack == CTF_ERR || dtp->dt_type_symaddr == CTF_ERR ||
1243a1b5e537Sbmc 	    dtp->dt_type_usymaddr == CTF_ERR) {
12447c478bd9Sstevel@tonic-gate 		dt_dprintf("failed to add intrinsic to D container: %s\n",
12457c478bd9Sstevel@tonic-gate 		    ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
12467c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_CTF));
12477c478bd9Sstevel@tonic-gate 	}
12487c478bd9Sstevel@tonic-gate 
12497c478bd9Sstevel@tonic-gate 	if (ctf_update(dmp->dm_ctfp) != 0) {
12507c478bd9Sstevel@tonic-gate 		dt_dprintf("failed update D container: %s\n",
12517c478bd9Sstevel@tonic-gate 		    ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
12527c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_CTF));
12537c478bd9Sstevel@tonic-gate 	}
12547c478bd9Sstevel@tonic-gate 
12557c478bd9Sstevel@tonic-gate 	/*
12567c478bd9Sstevel@tonic-gate 	 * Initialize the integer description table used to convert integer
12577c478bd9Sstevel@tonic-gate 	 * constants to the appropriate types.  Refer to the comments above
12587c478bd9Sstevel@tonic-gate 	 * dt_node_int() for a complete description of how this table is used.
12597c478bd9Sstevel@tonic-gate 	 */
12607c478bd9Sstevel@tonic-gate 	for (i = 0; i < sizeof (dtp->dt_ints) / sizeof (dtp->dt_ints[0]); i++) {
12617c478bd9Sstevel@tonic-gate 		if (dtrace_lookup_by_type(dtp, DTRACE_OBJ_EVERY,
12627c478bd9Sstevel@tonic-gate 		    dtp->dt_ints[i].did_name, &dtt) != 0) {
12637c478bd9Sstevel@tonic-gate 			dt_dprintf("failed to lookup integer type %s: %s\n",
12647c478bd9Sstevel@tonic-gate 			    dtp->dt_ints[i].did_name,
12657c478bd9Sstevel@tonic-gate 			    dtrace_errmsg(dtp, dtrace_errno(dtp)));
12667c478bd9Sstevel@tonic-gate 			return (set_open_errno(dtp, errp, dtp->dt_errno));
12677c478bd9Sstevel@tonic-gate 		}
12687c478bd9Sstevel@tonic-gate 		dtp->dt_ints[i].did_ctfp = dtt.dtt_ctfp;
12697c478bd9Sstevel@tonic-gate 		dtp->dt_ints[i].did_type = dtt.dtt_type;
12707c478bd9Sstevel@tonic-gate 	}
12717c478bd9Sstevel@tonic-gate 
12727c478bd9Sstevel@tonic-gate 	/*
12737c478bd9Sstevel@tonic-gate 	 * Now that we've created the "C" and "D" containers, move them to the
12747c478bd9Sstevel@tonic-gate 	 * start of the module list so that these types and symbols are found
12757c478bd9Sstevel@tonic-gate 	 * first (for stability) when iterating through the module list.
12767c478bd9Sstevel@tonic-gate 	 */
12777c478bd9Sstevel@tonic-gate 	dt_list_delete(&dtp->dt_modlist, dtp->dt_ddefs);
12787c478bd9Sstevel@tonic-gate 	dt_list_prepend(&dtp->dt_modlist, dtp->dt_ddefs);
12797c478bd9Sstevel@tonic-gate 
12807c478bd9Sstevel@tonic-gate 	dt_list_delete(&dtp->dt_modlist, dtp->dt_cdefs);
12817c478bd9Sstevel@tonic-gate 	dt_list_prepend(&dtp->dt_modlist, dtp->dt_cdefs);
12827c478bd9Sstevel@tonic-gate 
12837c478bd9Sstevel@tonic-gate 	if (dt_pfdict_create(dtp) == -1)
12847c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, dtp->dt_errno));
12857c478bd9Sstevel@tonic-gate 
12867c478bd9Sstevel@tonic-gate 	/*
12877c478bd9Sstevel@tonic-gate 	 * If we are opening libdtrace DTRACE_O_NODEV enable C_ZDEFS by default
12887c478bd9Sstevel@tonic-gate 	 * because without /dev/dtrace open, we will not be able to load the
12897c478bd9Sstevel@tonic-gate 	 * names and attributes of any providers or probes from the kernel.
12907c478bd9Sstevel@tonic-gate 	 */
12917c478bd9Sstevel@tonic-gate 	if (flags & DTRACE_O_NODEV)
12927c478bd9Sstevel@tonic-gate 		dtp->dt_cflags |= DTRACE_C_ZDEFS;
12937c478bd9Sstevel@tonic-gate 
12947c478bd9Sstevel@tonic-gate 	/*
12957c478bd9Sstevel@tonic-gate 	 * Load hard-wired inlines into the definition cache by calling the
12967c478bd9Sstevel@tonic-gate 	 * compiler on the raw definition string defined above.
12977c478bd9Sstevel@tonic-gate 	 */
12987c478bd9Sstevel@tonic-gate 	if ((pgp = dtrace_program_strcompile(dtp, _dtrace_hardwire,
12997c478bd9Sstevel@tonic-gate 	    DTRACE_PROBESPEC_NONE, DTRACE_C_EMPTY, 0, NULL)) == NULL) {
13007c478bd9Sstevel@tonic-gate 		dt_dprintf("failed to load hard-wired definitions: %s\n",
13017c478bd9Sstevel@tonic-gate 		    dtrace_errmsg(dtp, dtrace_errno(dtp)));
13027c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, EDT_HARDWIRE));
13037c478bd9Sstevel@tonic-gate 	}
13047c478bd9Sstevel@tonic-gate 
13051a7c1b72Smws 	dt_program_destroy(dtp, pgp);
13067c478bd9Sstevel@tonic-gate 
13077c478bd9Sstevel@tonic-gate 	/*
13087c478bd9Sstevel@tonic-gate 	 * Set up the default DTrace library path.  Once set, the next call to
13097c478bd9Sstevel@tonic-gate 	 * dt_compile() will compile all the libraries.  We intentionally defer
13107c478bd9Sstevel@tonic-gate 	 * library processing to improve overhead for clients that don't ever
13117c478bd9Sstevel@tonic-gate 	 * compile, and to provide better error reporting (because the full
13127c478bd9Sstevel@tonic-gate 	 * reporting of compiler errors requires dtrace_open() to succeed).
13137c478bd9Sstevel@tonic-gate 	 */
13147c478bd9Sstevel@tonic-gate 	if (dtrace_setopt(dtp, "libdir", _dtrace_libdir) != 0)
13157c478bd9Sstevel@tonic-gate 		return (set_open_errno(dtp, errp, dtp->dt_errno));
13167c478bd9Sstevel@tonic-gate 
13177c478bd9Sstevel@tonic-gate 	return (dtp);
13187c478bd9Sstevel@tonic-gate }
13197c478bd9Sstevel@tonic-gate 
13207c478bd9Sstevel@tonic-gate dtrace_hdl_t *
dtrace_open(int version,int flags,int * errp)13217c478bd9Sstevel@tonic-gate dtrace_open(int version, int flags, int *errp)
13227c478bd9Sstevel@tonic-gate {
13237c478bd9Sstevel@tonic-gate 	return (dt_vopen(version, flags, errp, NULL, NULL));
13247c478bd9Sstevel@tonic-gate }
13257c478bd9Sstevel@tonic-gate 
13267c478bd9Sstevel@tonic-gate dtrace_hdl_t *
dtrace_vopen(int version,int flags,int * errp,const dtrace_vector_t * vector,void * arg)13277c478bd9Sstevel@tonic-gate dtrace_vopen(int version, int flags, int *errp,
13287c478bd9Sstevel@tonic-gate     const dtrace_vector_t *vector, void *arg)
13297c478bd9Sstevel@tonic-gate {
13307c478bd9Sstevel@tonic-gate 	return (dt_vopen(version, flags, errp, vector, arg));
13317c478bd9Sstevel@tonic-gate }
13327c478bd9Sstevel@tonic-gate 
13337c478bd9Sstevel@tonic-gate void
dtrace_close(dtrace_hdl_t * dtp)13347c478bd9Sstevel@tonic-gate dtrace_close(dtrace_hdl_t *dtp)
13357c478bd9Sstevel@tonic-gate {
13367c478bd9Sstevel@tonic-gate 	dt_ident_t *idp, *ndp;
13377c478bd9Sstevel@tonic-gate 	dt_module_t *dmp;
13387c478bd9Sstevel@tonic-gate 	dt_provider_t *pvp;
13397c478bd9Sstevel@tonic-gate 	dtrace_prog_t *pgp;
13407c478bd9Sstevel@tonic-gate 	dt_xlator_t *dxp;
13417c478bd9Sstevel@tonic-gate 	dt_dirpath_t *dirp;
13427c478bd9Sstevel@tonic-gate 	int i;
13437c478bd9Sstevel@tonic-gate 
13446009dbc6Sahl 	if (dtp->dt_procs != NULL)
1345e5803b76SAdam H. Leventhal 		dt_proc_fini(dtp);
13466009dbc6Sahl 
13477c478bd9Sstevel@tonic-gate 	while ((pgp = dt_list_next(&dtp->dt_programs)) != NULL)
13481a7c1b72Smws 		dt_program_destroy(dtp, pgp);
13497c478bd9Sstevel@tonic-gate 
13507c478bd9Sstevel@tonic-gate 	while ((dxp = dt_list_next(&dtp->dt_xlators)) != NULL)
13517c478bd9Sstevel@tonic-gate 		dt_xlator_destroy(dtp, dxp);
13527c478bd9Sstevel@tonic-gate 
13531a7c1b72Smws 	dt_free(dtp, dtp->dt_xlatormap);
13541a7c1b72Smws 
13557c478bd9Sstevel@tonic-gate 	for (idp = dtp->dt_externs; idp != NULL; idp = ndp) {
13567c478bd9Sstevel@tonic-gate 		ndp = idp->di_next;
13577c478bd9Sstevel@tonic-gate 		dt_ident_destroy(idp);
13587c478bd9Sstevel@tonic-gate 	}
13597c478bd9Sstevel@tonic-gate 
13607c478bd9Sstevel@tonic-gate 	if (dtp->dt_macros != NULL)
13617c478bd9Sstevel@tonic-gate 		dt_idhash_destroy(dtp->dt_macros);
13627c478bd9Sstevel@tonic-gate 	if (dtp->dt_aggs != NULL)
13637c478bd9Sstevel@tonic-gate 		dt_idhash_destroy(dtp->dt_aggs);
13647c478bd9Sstevel@tonic-gate 	if (dtp->dt_globals != NULL)
13657c478bd9Sstevel@tonic-gate 		dt_idhash_destroy(dtp->dt_globals);
13667c478bd9Sstevel@tonic-gate 	if (dtp->dt_tls != NULL)
13677c478bd9Sstevel@tonic-gate 		dt_idhash_destroy(dtp->dt_tls);
13687c478bd9Sstevel@tonic-gate 
13697c478bd9Sstevel@tonic-gate 	while ((dmp = dt_list_next(&dtp->dt_modlist)) != NULL)
13707c478bd9Sstevel@tonic-gate 		dt_module_destroy(dtp, dmp);
13717c478bd9Sstevel@tonic-gate 
13727c478bd9Sstevel@tonic-gate 	while ((pvp = dt_list_next(&dtp->dt_provlist)) != NULL)
13737c478bd9Sstevel@tonic-gate 		dt_provider_destroy(dtp, pvp);
13747c478bd9Sstevel@tonic-gate 
13757c478bd9Sstevel@tonic-gate 	if (dtp->dt_fd != -1)
13767c478bd9Sstevel@tonic-gate 		(void) close(dtp->dt_fd);
13777c478bd9Sstevel@tonic-gate 	if (dtp->dt_ftfd != -1)
13787c478bd9Sstevel@tonic-gate 		(void) close(dtp->dt_ftfd);
13797c478bd9Sstevel@tonic-gate 	if (dtp->dt_cdefs_fd != -1)
13807c478bd9Sstevel@tonic-gate 		(void) close(dtp->dt_cdefs_fd);
13817c478bd9Sstevel@tonic-gate 	if (dtp->dt_ddefs_fd != -1)
13827c478bd9Sstevel@tonic-gate 		(void) close(dtp->dt_ddefs_fd);
13837c478bd9Sstevel@tonic-gate 	if (dtp->dt_stdout_fd != -1)
13847c478bd9Sstevel@tonic-gate 		(void) close(dtp->dt_stdout_fd);
13857c478bd9Sstevel@tonic-gate 
13867c478bd9Sstevel@tonic-gate 	dt_epid_destroy(dtp);
13877c478bd9Sstevel@tonic-gate 	dt_aggid_destroy(dtp);
13887c478bd9Sstevel@tonic-gate 	dt_format_destroy(dtp);
1389deef35fdSEric Schrock 	dt_strdata_destroy(dtp);
13907c478bd9Sstevel@tonic-gate 	dt_buffered_destroy(dtp);
13917c478bd9Sstevel@tonic-gate 	dt_aggregate_destroy(dtp);
13927c478bd9Sstevel@tonic-gate 	dt_pfdict_destroy(dtp);
13937c478bd9Sstevel@tonic-gate 	dt_provmod_destroy(&dtp->dt_provmod);
13947c478bd9Sstevel@tonic-gate 	dt_dof_fini(dtp);
13957c478bd9Sstevel@tonic-gate 
13967c478bd9Sstevel@tonic-gate 	for (i = 1; i < dtp->dt_cpp_argc; i++)
13977c478bd9Sstevel@tonic-gate 		free(dtp->dt_cpp_argv[i]);
13987c478bd9Sstevel@tonic-gate 
13997c478bd9Sstevel@tonic-gate 	while ((dirp = dt_list_next(&dtp->dt_lib_path)) != NULL) {
14007c478bd9Sstevel@tonic-gate 		dt_list_delete(&dtp->dt_lib_path, dirp);
14017c478bd9Sstevel@tonic-gate 		free(dirp->dir_path);
14027c478bd9Sstevel@tonic-gate 		free(dirp);
14037c478bd9Sstevel@tonic-gate 	}
14047c478bd9Sstevel@tonic-gate 
14057c478bd9Sstevel@tonic-gate 	free(dtp->dt_cpp_argv);
14067c478bd9Sstevel@tonic-gate 	free(dtp->dt_cpp_path);
14077c478bd9Sstevel@tonic-gate 	free(dtp->dt_ld_path);
14087c478bd9Sstevel@tonic-gate 
14097c478bd9Sstevel@tonic-gate 	free(dtp->dt_mods);
14107c478bd9Sstevel@tonic-gate 	free(dtp->dt_provs);
14117c478bd9Sstevel@tonic-gate 	free(dtp);
14127c478bd9Sstevel@tonic-gate }
14137c478bd9Sstevel@tonic-gate 
14147c478bd9Sstevel@tonic-gate int
dtrace_provider_modules(dtrace_hdl_t * dtp,const char ** mods,int nmods)14157c478bd9Sstevel@tonic-gate dtrace_provider_modules(dtrace_hdl_t *dtp, const char **mods, int nmods)
14167c478bd9Sstevel@tonic-gate {
14177c478bd9Sstevel@tonic-gate 	dt_provmod_t *prov;
14187c478bd9Sstevel@tonic-gate 	int i = 0;
14197c478bd9Sstevel@tonic-gate 
14207c478bd9Sstevel@tonic-gate 	for (prov = dtp->dt_provmod; prov != NULL; prov = prov->dp_next, i++) {
14217c478bd9Sstevel@tonic-gate 		if (i < nmods)
14227c478bd9Sstevel@tonic-gate 			mods[i] = prov->dp_name;
14237c478bd9Sstevel@tonic-gate 	}
14247c478bd9Sstevel@tonic-gate 
14257c478bd9Sstevel@tonic-gate 	return (i);
14267c478bd9Sstevel@tonic-gate }
14277c478bd9Sstevel@tonic-gate 
14287c478bd9Sstevel@tonic-gate int
dtrace_ctlfd(dtrace_hdl_t * dtp)14297c478bd9Sstevel@tonic-gate dtrace_ctlfd(dtrace_hdl_t *dtp)
14307c478bd9Sstevel@tonic-gate {
14317c478bd9Sstevel@tonic-gate 	return (dtp->dt_fd);
14327c478bd9Sstevel@tonic-gate }
1433