10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51464Sahl * Common Development and Distribution License (the "License").
61464Sahl * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
211464Sahl
220Sstevel@tonic-gate /*
23*12507SAlan.Maguire@Sun.COM * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #include <sys/types.h>
270Sstevel@tonic-gate #include <sys/modctl.h>
280Sstevel@tonic-gate #include <sys/systeminfo.h>
291739Sbmc #include <sys/resource.h>
300Sstevel@tonic-gate
310Sstevel@tonic-gate #include <libelf.h>
320Sstevel@tonic-gate #include <strings.h>
330Sstevel@tonic-gate #include <alloca.h>
340Sstevel@tonic-gate #include <limits.h>
350Sstevel@tonic-gate #include <unistd.h>
360Sstevel@tonic-gate #include <stdlib.h>
370Sstevel@tonic-gate #include <stdio.h>
380Sstevel@tonic-gate #include <fcntl.h>
390Sstevel@tonic-gate #include <errno.h>
400Sstevel@tonic-gate #include <assert.h>
410Sstevel@tonic-gate
420Sstevel@tonic-gate #define _POSIX_PTHREAD_SEMANTICS
430Sstevel@tonic-gate #include <dirent.h>
440Sstevel@tonic-gate #undef _POSIX_PTHREAD_SEMANTICS
450Sstevel@tonic-gate
460Sstevel@tonic-gate #include <dt_impl.h>
47265Smws #include <dt_program.h>
480Sstevel@tonic-gate #include <dt_module.h>
490Sstevel@tonic-gate #include <dt_printf.h>
500Sstevel@tonic-gate #include <dt_string.h>
510Sstevel@tonic-gate #include <dt_provider.h>
520Sstevel@tonic-gate
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate * Stability and versioning definitions. These #defines are used in the tables
550Sstevel@tonic-gate * of identifiers below to fill in the attribute and version fields associated
560Sstevel@tonic-gate * with each identifier. The DT_ATTR_* macros are a convenience to permit more
570Sstevel@tonic-gate * concise declarations of common attributes such as Stable/Stable/Common. The
580Sstevel@tonic-gate * DT_VERS_* macros declare the encoded integer values of all versions used so
590Sstevel@tonic-gate * far. DT_VERS_LATEST must correspond to the latest version value among all
600Sstevel@tonic-gate * versions exported by the D compiler. DT_VERS_STRING must be an ASCII string
610Sstevel@tonic-gate * that contains DT_VERS_LATEST within it along with any suffixes (e.g. Beta).
620Sstevel@tonic-gate * You must update DT_VERS_LATEST and DT_VERS_STRING when adding a new version,
630Sstevel@tonic-gate * and then add the new version to the _dtrace_versions[] array declared below.
640Sstevel@tonic-gate * Refer to the Solaris Dynamic Tracing Guide Stability and Versioning chapters
650Sstevel@tonic-gate * respectively for an explanation of these DTrace features and their values.
660Sstevel@tonic-gate *
670Sstevel@tonic-gate * NOTE: Although the DTrace versioning scheme supports the labeling and
680Sstevel@tonic-gate * introduction of incompatible changes (e.g. dropping an interface in a
690Sstevel@tonic-gate * major release), the libdtrace code does not currently support this.
700Sstevel@tonic-gate * All versions are assumed to strictly inherit from one another. If
710Sstevel@tonic-gate * we ever need to provide divergent interfaces, this will need work.
720Sstevel@tonic-gate */
730Sstevel@tonic-gate #define DT_ATTR_STABCMN { DTRACE_STABILITY_STABLE, \
740Sstevel@tonic-gate DTRACE_STABILITY_STABLE, DTRACE_CLASS_COMMON }
750Sstevel@tonic-gate
760Sstevel@tonic-gate #define DT_ATTR_EVOLCMN { DTRACE_STABILITY_EVOLVING, \
770Sstevel@tonic-gate DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON \
780Sstevel@tonic-gate }
790Sstevel@tonic-gate
801464Sahl /*
811464Sahl * The version number should be increased for every customer visible release
821464Sahl * of Solaris. The major number should be incremented when a fundamental
831464Sahl * change has been made that would affect all consumers, and would reflect
841464Sahl * sweeping changes to DTrace or the D language. The minor number should be
851464Sahl * incremented when a change is introduced that could break scripts that had
861464Sahl * previously worked; for example, adding a new built-in variable could break
871464Sahl * a script which was already using that identifier. The micro number should
881464Sahl * be changed when introducing functionality changes or major bug fixes that
891464Sahl * do not affect backward compatibility -- this is merely to make capabilities
901464Sahl * easily determined from the version number. Minor bugs do not require any
911464Sahl * modification to the version number.
921464Sahl */
930Sstevel@tonic-gate #define DT_VERS_1_0 DT_VERSION_NUMBER(1, 0, 0)
940Sstevel@tonic-gate #define DT_VERS_1_1 DT_VERSION_NUMBER(1, 1, 0)
95191Sahl #define DT_VERS_1_2 DT_VERSION_NUMBER(1, 2, 0)
961464Sahl #define DT_VERS_1_2_1 DT_VERSION_NUMBER(1, 2, 1)
971710Sahl #define DT_VERS_1_2_2 DT_VERSION_NUMBER(1, 2, 2)
982769Sahl #define DT_VERS_1_3 DT_VERSION_NUMBER(1, 3, 0)
993235Sraf #define DT_VERS_1_4 DT_VERSION_NUMBER(1, 4, 0)
1003682Sjhaslam #define DT_VERS_1_4_1 DT_VERSION_NUMBER(1, 4, 1)
1014308Sbrendan #define DT_VERS_1_5 DT_VERSION_NUMBER(1, 5, 0)
1025984Sjhaslam #define DT_VERS_1_6 DT_VERSION_NUMBER(1, 6, 0)
1036390Sahl #define DT_VERS_1_6_1 DT_VERSION_NUMBER(1, 6, 1)
1046554Sahl #define DT_VERS_1_6_2 DT_VERSION_NUMBER(1, 6, 2)
105*12507SAlan.Maguire@Sun.COM #define DT_VERS_1_6_3 DT_VERSION_NUMBER(1, 6, 3)
106*12507SAlan.Maguire@Sun.COM #define DT_VERS_LATEST DT_VERS_1_6_3
107*12507SAlan.Maguire@Sun.COM #define DT_VERS_STRING "Sun D 1.6.3"
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate const dt_version_t _dtrace_versions[] = {
1100Sstevel@tonic-gate DT_VERS_1_0, /* D API 1.0.0 (PSARC 2001/466) Solaris 10 FCS */
111191Sahl DT_VERS_1_1, /* D API 1.1.0 Solaris Express 6/05 */
112191Sahl DT_VERS_1_2, /* D API 1.2.0 Solaris 10 Update 1 */
1131464Sahl DT_VERS_1_2_1, /* D API 1.2.1 Solaris Express 4/06 */
1141710Sahl DT_VERS_1_2_2, /* D API 1.2.2 Solaris Express 6/06 */
1152769Sahl DT_VERS_1_3, /* D API 1.3 Solaris Express 10/06 */
1163235Sraf DT_VERS_1_4, /* D API 1.4 Solaris Express 2/07 */
1173682Sjhaslam DT_VERS_1_4_1, /* D API 1.4.1 Solaris Express 4/07 */
1184308Sbrendan DT_VERS_1_5, /* D API 1.5 Solaris Express 7/07 */
1195984Sjhaslam DT_VERS_1_6, /* D API 1.6 */
1206390Sahl DT_VERS_1_6_1, /* D API 1.6.1 */
1216554Sahl DT_VERS_1_6_2, /* D API 1.6.2 */
122*12507SAlan.Maguire@Sun.COM DT_VERS_1_6_3, /* D API 1.6.3 */
1230Sstevel@tonic-gate 0
1240Sstevel@tonic-gate };
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate /*
1270Sstevel@tonic-gate * Table of global identifiers. This is used to populate the global identifier
1280Sstevel@tonic-gate * hash when a new dtrace client open occurs. For more info see dt_ident.h.
1290Sstevel@tonic-gate * The global identifiers that represent functions use the dt_idops_func ops
1300Sstevel@tonic-gate * and specify the private data pointer as a prototype string which is parsed
1310Sstevel@tonic-gate * when the identifier is first encountered. These prototypes look like ANSI
1320Sstevel@tonic-gate * C function prototypes except that the special symbol "@" can be used as a
1330Sstevel@tonic-gate * wildcard to represent a single parameter of any type (i.e. any dt_node_t).
1340Sstevel@tonic-gate * The standard "..." notation can also be used to represent varargs. An empty
1350Sstevel@tonic-gate * parameter list is taken to mean void (that is, no arguments are permitted).
1360Sstevel@tonic-gate * A parameter enclosed in square brackets (e.g. "[int]") denotes an optional
1370Sstevel@tonic-gate * argument.
1380Sstevel@tonic-gate */
1390Sstevel@tonic-gate static const dt_ident_t _dtrace_globals[] = {
1400Sstevel@tonic-gate { "alloca", DT_IDENT_FUNC, 0, DIF_SUBR_ALLOCA, DT_ATTR_STABCMN, DT_VERS_1_0,
1410Sstevel@tonic-gate &dt_idops_func, "void *(size_t)" },
1420Sstevel@tonic-gate { "arg0", DT_IDENT_SCALAR, 0, DIF_VAR_ARG0, DT_ATTR_STABCMN, DT_VERS_1_0,
1430Sstevel@tonic-gate &dt_idops_type, "int64_t" },
1440Sstevel@tonic-gate { "arg1", DT_IDENT_SCALAR, 0, DIF_VAR_ARG1, DT_ATTR_STABCMN, DT_VERS_1_0,
1450Sstevel@tonic-gate &dt_idops_type, "int64_t" },
1460Sstevel@tonic-gate { "arg2", DT_IDENT_SCALAR, 0, DIF_VAR_ARG2, DT_ATTR_STABCMN, DT_VERS_1_0,
1470Sstevel@tonic-gate &dt_idops_type, "int64_t" },
1480Sstevel@tonic-gate { "arg3", DT_IDENT_SCALAR, 0, DIF_VAR_ARG3, DT_ATTR_STABCMN, DT_VERS_1_0,
1490Sstevel@tonic-gate &dt_idops_type, "int64_t" },
1500Sstevel@tonic-gate { "arg4", DT_IDENT_SCALAR, 0, DIF_VAR_ARG4, DT_ATTR_STABCMN, DT_VERS_1_0,
1510Sstevel@tonic-gate &dt_idops_type, "int64_t" },
1520Sstevel@tonic-gate { "arg5", DT_IDENT_SCALAR, 0, DIF_VAR_ARG5, DT_ATTR_STABCMN, DT_VERS_1_0,
1530Sstevel@tonic-gate &dt_idops_type, "int64_t" },
1540Sstevel@tonic-gate { "arg6", DT_IDENT_SCALAR, 0, DIF_VAR_ARG6, DT_ATTR_STABCMN, DT_VERS_1_0,
1550Sstevel@tonic-gate &dt_idops_type, "int64_t" },
1560Sstevel@tonic-gate { "arg7", DT_IDENT_SCALAR, 0, DIF_VAR_ARG7, DT_ATTR_STABCMN, DT_VERS_1_0,
1570Sstevel@tonic-gate &dt_idops_type, "int64_t" },
1580Sstevel@tonic-gate { "arg8", DT_IDENT_SCALAR, 0, DIF_VAR_ARG8, DT_ATTR_STABCMN, DT_VERS_1_0,
1590Sstevel@tonic-gate &dt_idops_type, "int64_t" },
1600Sstevel@tonic-gate { "arg9", DT_IDENT_SCALAR, 0, DIF_VAR_ARG9, DT_ATTR_STABCMN, DT_VERS_1_0,
1610Sstevel@tonic-gate &dt_idops_type, "int64_t" },
1620Sstevel@tonic-gate { "args", DT_IDENT_ARRAY, 0, DIF_VAR_ARGS, DT_ATTR_STABCMN, DT_VERS_1_0,
1630Sstevel@tonic-gate &dt_idops_args, NULL },
1640Sstevel@tonic-gate { "avg", DT_IDENT_AGGFUNC, 0, DTRACEAGG_AVG, DT_ATTR_STABCMN, DT_VERS_1_0,
1650Sstevel@tonic-gate &dt_idops_func, "void(@)" },
1660Sstevel@tonic-gate { "basename", DT_IDENT_FUNC, 0, DIF_SUBR_BASENAME, DT_ATTR_STABCMN, DT_VERS_1_0,
1670Sstevel@tonic-gate &dt_idops_func, "string(const char *)" },
1680Sstevel@tonic-gate { "bcopy", DT_IDENT_FUNC, 0, DIF_SUBR_BCOPY, DT_ATTR_STABCMN, DT_VERS_1_0,
1690Sstevel@tonic-gate &dt_idops_func, "void(void *, void *, size_t)" },
1700Sstevel@tonic-gate { "breakpoint", DT_IDENT_ACTFUNC, 0, DT_ACT_BREAKPOINT,
1710Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0,
1720Sstevel@tonic-gate &dt_idops_func, "void()" },
1730Sstevel@tonic-gate { "caller", DT_IDENT_SCALAR, 0, DIF_VAR_CALLER, DT_ATTR_STABCMN, DT_VERS_1_0,
1740Sstevel@tonic-gate &dt_idops_type, "uintptr_t" },
1750Sstevel@tonic-gate { "chill", DT_IDENT_ACTFUNC, 0, DT_ACT_CHILL, DT_ATTR_STABCMN, DT_VERS_1_0,
1760Sstevel@tonic-gate &dt_idops_func, "void(int)" },
1770Sstevel@tonic-gate { "cleanpath", DT_IDENT_FUNC, 0, DIF_SUBR_CLEANPATH, DT_ATTR_STABCMN,
1780Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "string(const char *)" },
1790Sstevel@tonic-gate { "clear", DT_IDENT_ACTFUNC, 0, DT_ACT_CLEAR, DT_ATTR_STABCMN, DT_VERS_1_0,
1800Sstevel@tonic-gate &dt_idops_func, "void(...)" },
1810Sstevel@tonic-gate { "commit", DT_IDENT_ACTFUNC, 0, DT_ACT_COMMIT, DT_ATTR_STABCMN, DT_VERS_1_0,
1820Sstevel@tonic-gate &dt_idops_func, "void(int)" },
1830Sstevel@tonic-gate { "copyin", DT_IDENT_FUNC, 0, DIF_SUBR_COPYIN, DT_ATTR_STABCMN, DT_VERS_1_0,
1840Sstevel@tonic-gate &dt_idops_func, "void *(uintptr_t, size_t)" },
1850Sstevel@tonic-gate { "copyinstr", DT_IDENT_FUNC, 0, DIF_SUBR_COPYINSTR,
1860Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0,
1870Sstevel@tonic-gate &dt_idops_func, "string(uintptr_t, [size_t])" },
1880Sstevel@tonic-gate { "copyinto", DT_IDENT_FUNC, 0, DIF_SUBR_COPYINTO, DT_ATTR_STABCMN,
1890Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "void(uintptr_t, size_t, void *)" },
1900Sstevel@tonic-gate { "copyout", DT_IDENT_FUNC, 0, DIF_SUBR_COPYOUT, DT_ATTR_STABCMN, DT_VERS_1_0,
1910Sstevel@tonic-gate &dt_idops_func, "void(void *, uintptr_t, size_t)" },
1920Sstevel@tonic-gate { "copyoutstr", DT_IDENT_FUNC, 0, DIF_SUBR_COPYOUTSTR,
1930Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0,
1940Sstevel@tonic-gate &dt_idops_func, "void(char *, uintptr_t, size_t)" },
1950Sstevel@tonic-gate { "count", DT_IDENT_AGGFUNC, 0, DTRACEAGG_COUNT, DT_ATTR_STABCMN, DT_VERS_1_0,
1960Sstevel@tonic-gate &dt_idops_func, "void()" },
1970Sstevel@tonic-gate { "curthread", DT_IDENT_SCALAR, 0, DIF_VAR_CURTHREAD,
1980Sstevel@tonic-gate { DTRACE_STABILITY_STABLE, DTRACE_STABILITY_PRIVATE,
1990Sstevel@tonic-gate DTRACE_CLASS_COMMON }, DT_VERS_1_0,
2000Sstevel@tonic-gate &dt_idops_type, "genunix`kthread_t *" },
2010Sstevel@tonic-gate { "ddi_pathname", DT_IDENT_FUNC, 0, DIF_SUBR_DDI_PATHNAME,
2020Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0,
2030Sstevel@tonic-gate &dt_idops_func, "string(void *, int64_t)" },
2040Sstevel@tonic-gate { "denormalize", DT_IDENT_ACTFUNC, 0, DT_ACT_DENORMALIZE, DT_ATTR_STABCMN,
2050Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "void(...)" },
2060Sstevel@tonic-gate { "dirname", DT_IDENT_FUNC, 0, DIF_SUBR_DIRNAME, DT_ATTR_STABCMN, DT_VERS_1_0,
2070Sstevel@tonic-gate &dt_idops_func, "string(const char *)" },
2080Sstevel@tonic-gate { "discard", DT_IDENT_ACTFUNC, 0, DT_ACT_DISCARD, DT_ATTR_STABCMN, DT_VERS_1_0,
2090Sstevel@tonic-gate &dt_idops_func, "void(int)" },
2100Sstevel@tonic-gate { "epid", DT_IDENT_SCALAR, 0, DIF_VAR_EPID, DT_ATTR_STABCMN, DT_VERS_1_0,
2110Sstevel@tonic-gate &dt_idops_type, "uint_t" },
2122525Sdp { "errno", DT_IDENT_SCALAR, 0, DIF_VAR_ERRNO, DT_ATTR_STABCMN, DT_VERS_1_0,
2132525Sdp &dt_idops_type, "int" },
2140Sstevel@tonic-gate { "execname", DT_IDENT_SCALAR, 0, DIF_VAR_EXECNAME,
2150Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
2160Sstevel@tonic-gate { "exit", DT_IDENT_ACTFUNC, 0, DT_ACT_EXIT, DT_ATTR_STABCMN, DT_VERS_1_0,
2170Sstevel@tonic-gate &dt_idops_func, "void(int)" },
2180Sstevel@tonic-gate { "freopen", DT_IDENT_ACTFUNC, 0, DT_ACT_FREOPEN, DT_ATTR_STABCMN,
2190Sstevel@tonic-gate DT_VERS_1_1, &dt_idops_func, "void(@, ...)" },
2200Sstevel@tonic-gate { "ftruncate", DT_IDENT_ACTFUNC, 0, DT_ACT_FTRUNCATE, DT_ATTR_STABCMN,
2210Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "void()" },
222457Sbmc { "func", DT_IDENT_ACTFUNC, 0, DT_ACT_SYM, DT_ATTR_STABCMN,
223457Sbmc DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" },
2240Sstevel@tonic-gate { "getmajor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMAJOR,
2250Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0,
2260Sstevel@tonic-gate &dt_idops_func, "genunix`major_t(genunix`dev_t)" },
2270Sstevel@tonic-gate { "getminor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMINOR,
2280Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0,
2290Sstevel@tonic-gate &dt_idops_func, "genunix`minor_t(genunix`dev_t)" },
2302769Sahl { "htonl", DT_IDENT_FUNC, 0, DIF_SUBR_HTONL, DT_ATTR_EVOLCMN, DT_VERS_1_3,
2312769Sahl &dt_idops_func, "uint32_t(uint32_t)" },
2322769Sahl { "htonll", DT_IDENT_FUNC, 0, DIF_SUBR_HTONLL, DT_ATTR_EVOLCMN, DT_VERS_1_3,
2332769Sahl &dt_idops_func, "uint64_t(uint64_t)" },
2342769Sahl { "htons", DT_IDENT_FUNC, 0, DIF_SUBR_HTONS, DT_ATTR_EVOLCMN, DT_VERS_1_3,
2352769Sahl &dt_idops_func, "uint16_t(uint16_t)" },
2362525Sdp { "gid", DT_IDENT_SCALAR, 0, DIF_VAR_GID, DT_ATTR_STABCMN, DT_VERS_1_0,
2372525Sdp &dt_idops_type, "gid_t" },
2380Sstevel@tonic-gate { "id", DT_IDENT_SCALAR, 0, DIF_VAR_ID, DT_ATTR_STABCMN, DT_VERS_1_0,
2390Sstevel@tonic-gate &dt_idops_type, "uint_t" },
2400Sstevel@tonic-gate { "index", DT_IDENT_FUNC, 0, DIF_SUBR_INDEX, DT_ATTR_STABCMN, DT_VERS_1_1,
2410Sstevel@tonic-gate &dt_idops_func, "int(const char *, const char *, [int])" },
2424291Sbrendan { "inet_ntoa", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOA, DT_ATTR_STABCMN,
2434308Sbrendan DT_VERS_1_5, &dt_idops_func, "string(ipaddr_t *)" },
2444291Sbrendan { "inet_ntoa6", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOA6, DT_ATTR_STABCMN,
2454308Sbrendan DT_VERS_1_5, &dt_idops_func, "string(in6_addr_t *)" },
2464291Sbrendan { "inet_ntop", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOP, DT_ATTR_STABCMN,
2474308Sbrendan DT_VERS_1_5, &dt_idops_func, "string(int, void *)" },
2480Sstevel@tonic-gate { "ipl", DT_IDENT_SCALAR, 0, DIF_VAR_IPL, DT_ATTR_STABCMN, DT_VERS_1_0,
2490Sstevel@tonic-gate &dt_idops_type, "uint_t" },
2500Sstevel@tonic-gate { "jstack", DT_IDENT_ACTFUNC, 0, DT_ACT_JSTACK, DT_ATTR_STABCMN, DT_VERS_1_0,
2510Sstevel@tonic-gate &dt_idops_func, "stack(...)" },
2520Sstevel@tonic-gate { "lltostr", DT_IDENT_FUNC, 0, DIF_SUBR_LLTOSTR, DT_ATTR_STABCMN, DT_VERS_1_0,
2530Sstevel@tonic-gate &dt_idops_func, "string(int64_t)" },
2540Sstevel@tonic-gate { "lquantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_LQUANTIZE,
2550Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0,
2560Sstevel@tonic-gate &dt_idops_func, "void(@, int32_t, int32_t, ...)" },
2570Sstevel@tonic-gate { "max", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MAX, DT_ATTR_STABCMN, DT_VERS_1_0,
2580Sstevel@tonic-gate &dt_idops_func, "void(@)" },
2590Sstevel@tonic-gate { "min", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MIN, DT_ATTR_STABCMN, DT_VERS_1_0,
2600Sstevel@tonic-gate &dt_idops_func, "void(@)" },
261457Sbmc { "mod", DT_IDENT_ACTFUNC, 0, DT_ACT_MOD, DT_ATTR_STABCMN,
262457Sbmc DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" },
2630Sstevel@tonic-gate { "msgdsize", DT_IDENT_FUNC, 0, DIF_SUBR_MSGDSIZE,
2640Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0,
2650Sstevel@tonic-gate &dt_idops_func, "size_t(mblk_t *)" },
2660Sstevel@tonic-gate { "msgsize", DT_IDENT_FUNC, 0, DIF_SUBR_MSGSIZE,
2670Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0,
2680Sstevel@tonic-gate &dt_idops_func, "size_t(mblk_t *)" },
2690Sstevel@tonic-gate { "mutex_owned", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNED,
2700Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0,
2710Sstevel@tonic-gate &dt_idops_func, "int(genunix`kmutex_t *)" },
2720Sstevel@tonic-gate { "mutex_owner", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNER,
2730Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0,
2740Sstevel@tonic-gate &dt_idops_func, "genunix`kthread_t *(genunix`kmutex_t *)" },
2750Sstevel@tonic-gate { "mutex_type_adaptive", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_ADAPTIVE,
2760Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0,
2770Sstevel@tonic-gate &dt_idops_func, "int(genunix`kmutex_t *)" },
2780Sstevel@tonic-gate { "mutex_type_spin", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_SPIN,
2790Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0,
2800Sstevel@tonic-gate &dt_idops_func, "int(genunix`kmutex_t *)" },
2812769Sahl { "ntohl", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHL, DT_ATTR_EVOLCMN, DT_VERS_1_3,
2822769Sahl &dt_idops_func, "uint32_t(uint32_t)" },
2832769Sahl { "ntohll", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHLL, DT_ATTR_EVOLCMN, DT_VERS_1_3,
2842769Sahl &dt_idops_func, "uint64_t(uint64_t)" },
2852769Sahl { "ntohs", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHS, DT_ATTR_EVOLCMN, DT_VERS_1_3,
2862769Sahl &dt_idops_func, "uint16_t(uint16_t)" },
2870Sstevel@tonic-gate { "normalize", DT_IDENT_ACTFUNC, 0, DT_ACT_NORMALIZE, DT_ATTR_STABCMN,
2880Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "void(...)" },
2890Sstevel@tonic-gate { "panic", DT_IDENT_ACTFUNC, 0, DT_ACT_PANIC, DT_ATTR_STABCMN, DT_VERS_1_0,
2900Sstevel@tonic-gate &dt_idops_func, "void()" },
2910Sstevel@tonic-gate { "pid", DT_IDENT_SCALAR, 0, DIF_VAR_PID, DT_ATTR_STABCMN, DT_VERS_1_0,
2920Sstevel@tonic-gate &dt_idops_type, "pid_t" },
2932525Sdp { "ppid", DT_IDENT_SCALAR, 0, DIF_VAR_PPID, DT_ATTR_STABCMN, DT_VERS_1_0,
2942525Sdp &dt_idops_type, "pid_t" },
2950Sstevel@tonic-gate { "printa", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTA, DT_ATTR_STABCMN, DT_VERS_1_0,
2960Sstevel@tonic-gate &dt_idops_func, "void(@, ...)" },
2970Sstevel@tonic-gate { "printf", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTF, DT_ATTR_STABCMN, DT_VERS_1_0,
2980Sstevel@tonic-gate &dt_idops_func, "void(@, ...)" },
2990Sstevel@tonic-gate { "probefunc", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEFUNC,
3000Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
3010Sstevel@tonic-gate { "probemod", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEMOD,
3020Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
3030Sstevel@tonic-gate { "probename", DT_IDENT_SCALAR, 0, DIF_VAR_PROBENAME,
3040Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
3050Sstevel@tonic-gate { "probeprov", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEPROV,
3060Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
3070Sstevel@tonic-gate { "progenyof", DT_IDENT_FUNC, 0, DIF_SUBR_PROGENYOF,
3080Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0,
3090Sstevel@tonic-gate &dt_idops_func, "int(pid_t)" },
3100Sstevel@tonic-gate { "quantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_QUANTIZE,
3110Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0,
312457Sbmc &dt_idops_func, "void(@, ...)" },
3130Sstevel@tonic-gate { "raise", DT_IDENT_ACTFUNC, 0, DT_ACT_RAISE, DT_ATTR_STABCMN, DT_VERS_1_0,
3140Sstevel@tonic-gate &dt_idops_func, "void(int)" },
3150Sstevel@tonic-gate { "rand", DT_IDENT_FUNC, 0, DIF_SUBR_RAND, DT_ATTR_STABCMN, DT_VERS_1_0,
3160Sstevel@tonic-gate &dt_idops_func, "int()" },
3170Sstevel@tonic-gate { "rindex", DT_IDENT_FUNC, 0, DIF_SUBR_RINDEX, DT_ATTR_STABCMN, DT_VERS_1_1,
3180Sstevel@tonic-gate &dt_idops_func, "int(const char *, const char *, [int])" },
3190Sstevel@tonic-gate { "rw_iswriter", DT_IDENT_FUNC, 0, DIF_SUBR_RW_ISWRITER,
3200Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0,
3210Sstevel@tonic-gate &dt_idops_func, "int(genunix`krwlock_t *)" },
3220Sstevel@tonic-gate { "rw_read_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_READ_HELD,
3230Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0,
3240Sstevel@tonic-gate &dt_idops_func, "int(genunix`krwlock_t *)" },
3250Sstevel@tonic-gate { "rw_write_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_WRITE_HELD,
3260Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0,
3270Sstevel@tonic-gate &dt_idops_func, "int(genunix`krwlock_t *)" },
3280Sstevel@tonic-gate { "self", DT_IDENT_PTR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0,
3290Sstevel@tonic-gate &dt_idops_type, "void" },
330457Sbmc { "setopt", DT_IDENT_ACTFUNC, 0, DT_ACT_SETOPT, DT_ATTR_STABCMN,
331457Sbmc DT_VERS_1_2, &dt_idops_func, "void(const char *, [const char *])" },
3320Sstevel@tonic-gate { "speculate", DT_IDENT_ACTFUNC, 0, DT_ACT_SPECULATE,
3330Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0,
3340Sstevel@tonic-gate &dt_idops_func, "void(int)" },
3350Sstevel@tonic-gate { "speculation", DT_IDENT_FUNC, 0, DIF_SUBR_SPECULATION,
3360Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0,
3370Sstevel@tonic-gate &dt_idops_func, "int()" },
3380Sstevel@tonic-gate { "stack", DT_IDENT_ACTFUNC, 0, DT_ACT_STACK, DT_ATTR_STABCMN, DT_VERS_1_0,
3390Sstevel@tonic-gate &dt_idops_func, "stack(...)" },
3400Sstevel@tonic-gate { "stackdepth", DT_IDENT_SCALAR, 0, DIF_VAR_STACKDEPTH,
3410Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0,
3420Sstevel@tonic-gate &dt_idops_type, "uint32_t" },
3435984Sjhaslam { "stddev", DT_IDENT_AGGFUNC, 0, DTRACEAGG_STDDEV, DT_ATTR_STABCMN,
3445984Sjhaslam DT_VERS_1_6, &dt_idops_func, "void(@)" },
3450Sstevel@tonic-gate { "stop", DT_IDENT_ACTFUNC, 0, DT_ACT_STOP, DT_ATTR_STABCMN, DT_VERS_1_0,
3460Sstevel@tonic-gate &dt_idops_func, "void()" },
3470Sstevel@tonic-gate { "strchr", DT_IDENT_FUNC, 0, DIF_SUBR_STRCHR, DT_ATTR_STABCMN, DT_VERS_1_1,
3480Sstevel@tonic-gate &dt_idops_func, "string(const char *, char)" },
3490Sstevel@tonic-gate { "strlen", DT_IDENT_FUNC, 0, DIF_SUBR_STRLEN, DT_ATTR_STABCMN, DT_VERS_1_0,
3500Sstevel@tonic-gate &dt_idops_func, "size_t(const char *)" },
3510Sstevel@tonic-gate { "strjoin", DT_IDENT_FUNC, 0, DIF_SUBR_STRJOIN, DT_ATTR_STABCMN, DT_VERS_1_0,
3520Sstevel@tonic-gate &dt_idops_func, "string(const char *, const char *)" },
3530Sstevel@tonic-gate { "strrchr", DT_IDENT_FUNC, 0, DIF_SUBR_STRRCHR, DT_ATTR_STABCMN, DT_VERS_1_1,
3540Sstevel@tonic-gate &dt_idops_func, "string(const char *, char)" },
3550Sstevel@tonic-gate { "strstr", DT_IDENT_FUNC, 0, DIF_SUBR_STRSTR, DT_ATTR_STABCMN, DT_VERS_1_1,
3560Sstevel@tonic-gate &dt_idops_func, "string(const char *, const char *)" },
3570Sstevel@tonic-gate { "strtok", DT_IDENT_FUNC, 0, DIF_SUBR_STRTOK, DT_ATTR_STABCMN, DT_VERS_1_1,
3580Sstevel@tonic-gate &dt_idops_func, "string(const char *, const char *)" },
3590Sstevel@tonic-gate { "substr", DT_IDENT_FUNC, 0, DIF_SUBR_SUBSTR, DT_ATTR_STABCMN, DT_VERS_1_1,
3600Sstevel@tonic-gate &dt_idops_func, "string(const char *, int, [int])" },
3610Sstevel@tonic-gate { "sum", DT_IDENT_AGGFUNC, 0, DTRACEAGG_SUM, DT_ATTR_STABCMN, DT_VERS_1_0,
3620Sstevel@tonic-gate &dt_idops_func, "void(@)" },
363457Sbmc { "sym", DT_IDENT_ACTFUNC, 0, DT_ACT_SYM, DT_ATTR_STABCMN,
364457Sbmc DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" },
3650Sstevel@tonic-gate { "system", DT_IDENT_ACTFUNC, 0, DT_ACT_SYSTEM, DT_ATTR_STABCMN, DT_VERS_1_0,
3660Sstevel@tonic-gate &dt_idops_func, "void(@, ...)" },
3670Sstevel@tonic-gate { "this", DT_IDENT_PTR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0,
3680Sstevel@tonic-gate &dt_idops_type, "void" },
3690Sstevel@tonic-gate { "tid", DT_IDENT_SCALAR, 0, DIF_VAR_TID, DT_ATTR_STABCMN, DT_VERS_1_0,
3700Sstevel@tonic-gate &dt_idops_type, "id_t" },
3710Sstevel@tonic-gate { "timestamp", DT_IDENT_SCALAR, 0, DIF_VAR_TIMESTAMP,
3720Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0,
3730Sstevel@tonic-gate &dt_idops_type, "uint64_t" },
3740Sstevel@tonic-gate { "trace", DT_IDENT_ACTFUNC, 0, DT_ACT_TRACE, DT_ATTR_STABCMN, DT_VERS_1_0,
3750Sstevel@tonic-gate &dt_idops_func, "void(@)" },
3760Sstevel@tonic-gate { "tracemem", DT_IDENT_ACTFUNC, 0, DT_ACT_TRACEMEM,
3770Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0,
3780Sstevel@tonic-gate &dt_idops_func, "void(@, size_t)" },
3790Sstevel@tonic-gate { "trunc", DT_IDENT_ACTFUNC, 0, DT_ACT_TRUNC, DT_ATTR_STABCMN,
3800Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "void(...)" },
381457Sbmc { "uaddr", DT_IDENT_ACTFUNC, 0, DT_ACT_UADDR, DT_ATTR_STABCMN,
382457Sbmc DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" },
383457Sbmc { "ucaller", DT_IDENT_SCALAR, 0, DIF_VAR_UCALLER, DT_ATTR_STABCMN,
384457Sbmc DT_VERS_1_2, &dt_idops_type, "uint64_t" },
385457Sbmc { "ufunc", DT_IDENT_ACTFUNC, 0, DT_ACT_USYM, DT_ATTR_STABCMN,
386457Sbmc DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" },
3872525Sdp { "uid", DT_IDENT_SCALAR, 0, DIF_VAR_UID, DT_ATTR_STABCMN, DT_VERS_1_0,
3882525Sdp &dt_idops_type, "uid_t" },
389457Sbmc { "umod", DT_IDENT_ACTFUNC, 0, DT_ACT_UMOD, DT_ATTR_STABCMN,
390457Sbmc DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" },
3910Sstevel@tonic-gate { "uregs", DT_IDENT_ARRAY, 0, DIF_VAR_UREGS, DT_ATTR_STABCMN, DT_VERS_1_0,
3920Sstevel@tonic-gate &dt_idops_regs, NULL },
3930Sstevel@tonic-gate { "ustack", DT_IDENT_ACTFUNC, 0, DT_ACT_USTACK, DT_ATTR_STABCMN, DT_VERS_1_0,
3940Sstevel@tonic-gate &dt_idops_func, "stack(...)" },
395191Sahl { "ustackdepth", DT_IDENT_SCALAR, 0, DIF_VAR_USTACKDEPTH,
396191Sahl DT_ATTR_STABCMN, DT_VERS_1_2,
397191Sahl &dt_idops_type, "uint32_t" },
398457Sbmc { "usym", DT_IDENT_ACTFUNC, 0, DT_ACT_USYM, DT_ATTR_STABCMN,
399457Sbmc DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" },
4000Sstevel@tonic-gate { "vtimestamp", DT_IDENT_SCALAR, 0, DIF_VAR_VTIMESTAMP,
4010Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0,
4020Sstevel@tonic-gate &dt_idops_type, "uint64_t" },
4030Sstevel@tonic-gate { "walltimestamp", DT_IDENT_SCALAR, 0, DIF_VAR_WALLTIMESTAMP,
4040Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0,
4051017Sbmc &dt_idops_type, "int64_t" },
4060Sstevel@tonic-gate { "zonename", DT_IDENT_SCALAR, 0, DIF_VAR_ZONENAME,
4070Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
4080Sstevel@tonic-gate { NULL, 0, 0, 0, { 0, 0, 0 }, 0, NULL, NULL }
4090Sstevel@tonic-gate };
4100Sstevel@tonic-gate
4110Sstevel@tonic-gate /*
4120Sstevel@tonic-gate * Tables of ILP32 intrinsic integer and floating-point type templates to use
4130Sstevel@tonic-gate * to populate the dynamic "C" CTF type container.
4140Sstevel@tonic-gate */
4150Sstevel@tonic-gate static const dt_intrinsic_t _dtrace_intrinsics_32[] = {
4160Sstevel@tonic-gate { "void", { CTF_INT_SIGNED, 0, 0 }, CTF_K_INTEGER },
4170Sstevel@tonic-gate { "signed", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
4180Sstevel@tonic-gate { "unsigned", { 0, 0, 32 }, CTF_K_INTEGER },
4190Sstevel@tonic-gate { "char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
4200Sstevel@tonic-gate { "short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER },
4210Sstevel@tonic-gate { "int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
4220Sstevel@tonic-gate { "long", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
4230Sstevel@tonic-gate { "long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
4240Sstevel@tonic-gate { "signed char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
4250Sstevel@tonic-gate { "signed short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER },
4260Sstevel@tonic-gate { "signed int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
4270Sstevel@tonic-gate { "signed long", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
4280Sstevel@tonic-gate { "signed long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
4290Sstevel@tonic-gate { "unsigned char", { CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
4300Sstevel@tonic-gate { "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER },
4310Sstevel@tonic-gate { "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER },
4320Sstevel@tonic-gate { "unsigned long", { 0, 0, 32 }, CTF_K_INTEGER },
4330Sstevel@tonic-gate { "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER },
4340Sstevel@tonic-gate { "_Bool", { CTF_INT_BOOL, 0, 8 }, CTF_K_INTEGER },
4350Sstevel@tonic-gate { "float", { CTF_FP_SINGLE, 0, 32 }, CTF_K_FLOAT },
4360Sstevel@tonic-gate { "double", { CTF_FP_DOUBLE, 0, 64 }, CTF_K_FLOAT },
4370Sstevel@tonic-gate { "long double", { CTF_FP_LDOUBLE, 0, 128 }, CTF_K_FLOAT },
4380Sstevel@tonic-gate { "float imaginary", { CTF_FP_IMAGRY, 0, 32 }, CTF_K_FLOAT },
4390Sstevel@tonic-gate { "double imaginary", { CTF_FP_DIMAGRY, 0, 64 }, CTF_K_FLOAT },
4400Sstevel@tonic-gate { "long double imaginary", { CTF_FP_LDIMAGRY, 0, 128 }, CTF_K_FLOAT },
4410Sstevel@tonic-gate { "float complex", { CTF_FP_CPLX, 0, 64 }, CTF_K_FLOAT },
4420Sstevel@tonic-gate { "double complex", { CTF_FP_DCPLX, 0, 128 }, CTF_K_FLOAT },
4430Sstevel@tonic-gate { "long double complex", { CTF_FP_LDCPLX, 0, 256 }, CTF_K_FLOAT },
4440Sstevel@tonic-gate { NULL, { 0, 0, 0 }, 0 }
4450Sstevel@tonic-gate };
4460Sstevel@tonic-gate
4470Sstevel@tonic-gate /*
4480Sstevel@tonic-gate * Tables of LP64 intrinsic integer and floating-point type templates to use
4490Sstevel@tonic-gate * to populate the dynamic "C" CTF type container.
4500Sstevel@tonic-gate */
4510Sstevel@tonic-gate static const dt_intrinsic_t _dtrace_intrinsics_64[] = {
4520Sstevel@tonic-gate { "void", { CTF_INT_SIGNED, 0, 0 }, CTF_K_INTEGER },
4530Sstevel@tonic-gate { "signed", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
4540Sstevel@tonic-gate { "unsigned", { 0, 0, 32 }, CTF_K_INTEGER },
4550Sstevel@tonic-gate { "char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
4560Sstevel@tonic-gate { "short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER },
4570Sstevel@tonic-gate { "int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
4580Sstevel@tonic-gate { "long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
4590Sstevel@tonic-gate { "long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
4600Sstevel@tonic-gate { "signed char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
4610Sstevel@tonic-gate { "signed short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER },
4620Sstevel@tonic-gate { "signed int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER },
4630Sstevel@tonic-gate { "signed long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
4640Sstevel@tonic-gate { "signed long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER },
4650Sstevel@tonic-gate { "unsigned char", { CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER },
4660Sstevel@tonic-gate { "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER },
4670Sstevel@tonic-gate { "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER },
4680Sstevel@tonic-gate { "unsigned long", { 0, 0, 64 }, CTF_K_INTEGER },
4690Sstevel@tonic-gate { "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER },
4700Sstevel@tonic-gate { "_Bool", { CTF_INT_BOOL, 0, 8 }, CTF_K_INTEGER },
4710Sstevel@tonic-gate { "float", { CTF_FP_SINGLE, 0, 32 }, CTF_K_FLOAT },
4720Sstevel@tonic-gate { "double", { CTF_FP_DOUBLE, 0, 64 }, CTF_K_FLOAT },
4730Sstevel@tonic-gate { "long double", { CTF_FP_LDOUBLE, 0, 128 }, CTF_K_FLOAT },
4740Sstevel@tonic-gate { "float imaginary", { CTF_FP_IMAGRY, 0, 32 }, CTF_K_FLOAT },
4750Sstevel@tonic-gate { "double imaginary", { CTF_FP_DIMAGRY, 0, 64 }, CTF_K_FLOAT },
4760Sstevel@tonic-gate { "long double imaginary", { CTF_FP_LDIMAGRY, 0, 128 }, CTF_K_FLOAT },
4770Sstevel@tonic-gate { "float complex", { CTF_FP_CPLX, 0, 64 }, CTF_K_FLOAT },
4780Sstevel@tonic-gate { "double complex", { CTF_FP_DCPLX, 0, 128 }, CTF_K_FLOAT },
4790Sstevel@tonic-gate { "long double complex", { CTF_FP_LDCPLX, 0, 256 }, CTF_K_FLOAT },
4800Sstevel@tonic-gate { NULL, { 0, 0, 0 }, 0 }
4810Sstevel@tonic-gate };
4820Sstevel@tonic-gate
4830Sstevel@tonic-gate /*
4840Sstevel@tonic-gate * Tables of ILP32 typedefs to use to populate the dynamic "D" CTF container.
4850Sstevel@tonic-gate * These aliases ensure that D definitions can use typical <sys/types.h> names.
4860Sstevel@tonic-gate */
4870Sstevel@tonic-gate static const dt_typedef_t _dtrace_typedefs_32[] = {
4880Sstevel@tonic-gate { "char", "int8_t" },
4890Sstevel@tonic-gate { "short", "int16_t" },
4900Sstevel@tonic-gate { "int", "int32_t" },
4910Sstevel@tonic-gate { "long long", "int64_t" },
4920Sstevel@tonic-gate { "int", "intptr_t" },
4930Sstevel@tonic-gate { "int", "ssize_t" },
4940Sstevel@tonic-gate { "unsigned char", "uint8_t" },
4950Sstevel@tonic-gate { "unsigned short", "uint16_t" },
4960Sstevel@tonic-gate { "unsigned", "uint32_t" },
4970Sstevel@tonic-gate { "unsigned long long", "uint64_t" },
4980Sstevel@tonic-gate { "unsigned char", "uchar_t" },
4990Sstevel@tonic-gate { "unsigned short", "ushort_t" },
5000Sstevel@tonic-gate { "unsigned", "uint_t" },
5010Sstevel@tonic-gate { "unsigned long", "ulong_t" },
5020Sstevel@tonic-gate { "unsigned long long", "u_longlong_t" },
5030Sstevel@tonic-gate { "int", "ptrdiff_t" },
5040Sstevel@tonic-gate { "unsigned", "uintptr_t" },
5050Sstevel@tonic-gate { "unsigned", "size_t" },
5060Sstevel@tonic-gate { "long", "id_t" },
5070Sstevel@tonic-gate { "long", "pid_t" },
5080Sstevel@tonic-gate { NULL, NULL }
5090Sstevel@tonic-gate };
5100Sstevel@tonic-gate
5110Sstevel@tonic-gate /*
5120Sstevel@tonic-gate * Tables of LP64 typedefs to use to populate the dynamic "D" CTF container.
5130Sstevel@tonic-gate * These aliases ensure that D definitions can use typical <sys/types.h> names.
5140Sstevel@tonic-gate */
5150Sstevel@tonic-gate static const dt_typedef_t _dtrace_typedefs_64[] = {
5160Sstevel@tonic-gate { "char", "int8_t" },
5170Sstevel@tonic-gate { "short", "int16_t" },
5180Sstevel@tonic-gate { "int", "int32_t" },
5190Sstevel@tonic-gate { "long", "int64_t" },
5200Sstevel@tonic-gate { "long", "intptr_t" },
5210Sstevel@tonic-gate { "long", "ssize_t" },
5220Sstevel@tonic-gate { "unsigned char", "uint8_t" },
5230Sstevel@tonic-gate { "unsigned short", "uint16_t" },
5240Sstevel@tonic-gate { "unsigned", "uint32_t" },
5250Sstevel@tonic-gate { "unsigned long", "uint64_t" },
5260Sstevel@tonic-gate { "unsigned char", "uchar_t" },
5270Sstevel@tonic-gate { "unsigned short", "ushort_t" },
5280Sstevel@tonic-gate { "unsigned", "uint_t" },
5290Sstevel@tonic-gate { "unsigned long", "ulong_t" },
5300Sstevel@tonic-gate { "unsigned long long", "u_longlong_t" },
5310Sstevel@tonic-gate { "long", "ptrdiff_t" },
5320Sstevel@tonic-gate { "unsigned long", "uintptr_t" },
5330Sstevel@tonic-gate { "unsigned long", "size_t" },
5340Sstevel@tonic-gate { "int", "id_t" },
5350Sstevel@tonic-gate { "int", "pid_t" },
5360Sstevel@tonic-gate { NULL, NULL }
5370Sstevel@tonic-gate };
5380Sstevel@tonic-gate
5390Sstevel@tonic-gate /*
5400Sstevel@tonic-gate * Tables of ILP32 integer type templates used to populate the dtp->dt_ints[]
5410Sstevel@tonic-gate * cache when a new dtrace client open occurs. Values are set by dtrace_open().
5420Sstevel@tonic-gate */
5430Sstevel@tonic-gate static const dt_intdesc_t _dtrace_ints_32[] = {
5440Sstevel@tonic-gate { "int", NULL, CTF_ERR, 0x7fffffffULL },
5450Sstevel@tonic-gate { "unsigned int", NULL, CTF_ERR, 0xffffffffULL },
5460Sstevel@tonic-gate { "long", NULL, CTF_ERR, 0x7fffffffULL },
5470Sstevel@tonic-gate { "unsigned long", NULL, CTF_ERR, 0xffffffffULL },
5480Sstevel@tonic-gate { "long long", NULL, CTF_ERR, 0x7fffffffffffffffULL },
5490Sstevel@tonic-gate { "unsigned long long", NULL, CTF_ERR, 0xffffffffffffffffULL }
5500Sstevel@tonic-gate };
5510Sstevel@tonic-gate
5520Sstevel@tonic-gate /*
5530Sstevel@tonic-gate * Tables of LP64 integer type templates used to populate the dtp->dt_ints[]
5540Sstevel@tonic-gate * cache when a new dtrace client open occurs. Values are set by dtrace_open().
5550Sstevel@tonic-gate */
5560Sstevel@tonic-gate static const dt_intdesc_t _dtrace_ints_64[] = {
5570Sstevel@tonic-gate { "int", NULL, CTF_ERR, 0x7fffffffULL },
5580Sstevel@tonic-gate { "unsigned int", NULL, CTF_ERR, 0xffffffffULL },
5590Sstevel@tonic-gate { "long", NULL, CTF_ERR, 0x7fffffffffffffffULL },
5600Sstevel@tonic-gate { "unsigned long", NULL, CTF_ERR, 0xffffffffffffffffULL },
5610Sstevel@tonic-gate { "long long", NULL, CTF_ERR, 0x7fffffffffffffffULL },
5620Sstevel@tonic-gate { "unsigned long long", NULL, CTF_ERR, 0xffffffffffffffffULL }
5630Sstevel@tonic-gate };
5640Sstevel@tonic-gate
5650Sstevel@tonic-gate /*
5660Sstevel@tonic-gate * Table of macro variable templates used to populate the macro identifier hash
5670Sstevel@tonic-gate * when a new dtrace client open occurs. Values are set by dtrace_update().
5680Sstevel@tonic-gate */
5690Sstevel@tonic-gate static const dt_ident_t _dtrace_macros[] = {
5700Sstevel@tonic-gate { "egid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
5710Sstevel@tonic-gate { "euid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
5720Sstevel@tonic-gate { "gid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
5730Sstevel@tonic-gate { "pid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
5740Sstevel@tonic-gate { "pgid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
5750Sstevel@tonic-gate { "ppid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
5760Sstevel@tonic-gate { "projid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
5770Sstevel@tonic-gate { "sid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
5780Sstevel@tonic-gate { "taskid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
5790Sstevel@tonic-gate { "target", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
5800Sstevel@tonic-gate { "uid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 },
5810Sstevel@tonic-gate { NULL, 0, 0, 0, { 0, 0, 0 }, 0 }
5820Sstevel@tonic-gate };
5830Sstevel@tonic-gate
5840Sstevel@tonic-gate /*
5850Sstevel@tonic-gate * Hard-wired definition string to be compiled and cached every time a new
5860Sstevel@tonic-gate * DTrace library handle is initialized. This string should only be used to
5870Sstevel@tonic-gate * contain definitions that should be present regardless of DTRACE_O_NOLIBS.
5880Sstevel@tonic-gate */
5890Sstevel@tonic-gate static const char _dtrace_hardwire[] = "\
5900Sstevel@tonic-gate inline long NULL = 0; \n\
5910Sstevel@tonic-gate #pragma D binding \"1.0\" NULL\n\
5920Sstevel@tonic-gate ";
5930Sstevel@tonic-gate
5940Sstevel@tonic-gate /*
5950Sstevel@tonic-gate * Default DTrace configuration to use when opening libdtrace DTRACE_O_NODEV.
5960Sstevel@tonic-gate * If DTRACE_O_NODEV is not set, we load the configuration from the kernel.
5970Sstevel@tonic-gate * The use of CTF_MODEL_NATIVE is more subtle than it might appear: we are
5980Sstevel@tonic-gate * relying on the fact that when running dtrace(1M), isaexec will invoke the
5990Sstevel@tonic-gate * binary with the same bitness as the kernel, which is what we want by default
6000Sstevel@tonic-gate * when generating our DIF. The user can override the choice using oflags.
6010Sstevel@tonic-gate */
6020Sstevel@tonic-gate static const dtrace_conf_t _dtrace_conf = {
6030Sstevel@tonic-gate DIF_VERSION, /* dtc_difversion */
6040Sstevel@tonic-gate DIF_DIR_NREGS, /* dtc_difintregs */
6050Sstevel@tonic-gate DIF_DTR_NREGS, /* dtc_diftupregs */
6060Sstevel@tonic-gate CTF_MODEL_NATIVE /* dtc_ctfmodel */
6070Sstevel@tonic-gate };
6080Sstevel@tonic-gate
6090Sstevel@tonic-gate const dtrace_attribute_t _dtrace_maxattr = {
6100Sstevel@tonic-gate DTRACE_STABILITY_MAX,
6110Sstevel@tonic-gate DTRACE_STABILITY_MAX,
6120Sstevel@tonic-gate DTRACE_CLASS_MAX
6130Sstevel@tonic-gate };
6140Sstevel@tonic-gate
6150Sstevel@tonic-gate const dtrace_attribute_t _dtrace_defattr = {
6160Sstevel@tonic-gate DTRACE_STABILITY_STABLE,
6170Sstevel@tonic-gate DTRACE_STABILITY_STABLE,
6180Sstevel@tonic-gate DTRACE_CLASS_COMMON
6190Sstevel@tonic-gate };
6200Sstevel@tonic-gate
6210Sstevel@tonic-gate const dtrace_attribute_t _dtrace_symattr = {
6220Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE,
6230Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE,
6240Sstevel@tonic-gate DTRACE_CLASS_UNKNOWN
6250Sstevel@tonic-gate };
6260Sstevel@tonic-gate
6270Sstevel@tonic-gate const dtrace_attribute_t _dtrace_typattr = {
6280Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE,
6290Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE,
6300Sstevel@tonic-gate DTRACE_CLASS_UNKNOWN
6310Sstevel@tonic-gate };
6320Sstevel@tonic-gate
6330Sstevel@tonic-gate const dtrace_attribute_t _dtrace_prvattr = {
6340Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE,
6350Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE,
6360Sstevel@tonic-gate DTRACE_CLASS_UNKNOWN
6370Sstevel@tonic-gate };
6380Sstevel@tonic-gate
6390Sstevel@tonic-gate const dtrace_pattr_t _dtrace_prvdesc = {
6400Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
6410Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
6420Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
6430Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
6440Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON },
6450Sstevel@tonic-gate };
6460Sstevel@tonic-gate
6470Sstevel@tonic-gate const char *_dtrace_defcpp = "/usr/ccs/lib/cpp"; /* default cpp(1) to invoke */
6480Sstevel@tonic-gate const char *_dtrace_defld = "/usr/ccs/bin/ld"; /* default ld(1) to invoke */
6490Sstevel@tonic-gate
6500Sstevel@tonic-gate const char *_dtrace_libdir = "/usr/lib/dtrace"; /* default library directory */
6511149Sdp const char *_dtrace_provdir = "/dev/dtrace/provider"; /* provider directory */
6520Sstevel@tonic-gate
6530Sstevel@tonic-gate int _dtrace_strbuckets = 211; /* default number of hash buckets (prime) */
6540Sstevel@tonic-gate int _dtrace_intbuckets = 256; /* default number of integer buckets (Pof2) */
6550Sstevel@tonic-gate uint_t _dtrace_strsize = 256; /* default size of string intrinsic type */
6560Sstevel@tonic-gate uint_t _dtrace_stkindent = 14; /* default whitespace indent for stack/ustack */
6570Sstevel@tonic-gate uint_t _dtrace_pidbuckets = 64; /* default number of pid hash buckets */
6580Sstevel@tonic-gate uint_t _dtrace_pidlrulim = 8; /* default number of pid handles to cache */
6590Sstevel@tonic-gate size_t _dtrace_bufsize = 512; /* default dt_buf_create() size */
6600Sstevel@tonic-gate int _dtrace_argmax = 32; /* default maximum number of probe arguments */
6610Sstevel@tonic-gate
6620Sstevel@tonic-gate int _dtrace_debug = 0; /* debug messages enabled (off) */
6630Sstevel@tonic-gate const char *const _dtrace_version = DT_VERS_STRING; /* API version string */
6640Sstevel@tonic-gate int _dtrace_rdvers = RD_VERSION; /* rtld_db feature version */
6650Sstevel@tonic-gate
6660Sstevel@tonic-gate typedef struct dt_fdlist {
6670Sstevel@tonic-gate int *df_fds; /* array of provider driver file descriptors */
6680Sstevel@tonic-gate uint_t df_ents; /* number of valid elements in df_fds[] */
6690Sstevel@tonic-gate uint_t df_size; /* size of df_fds[] */
6700Sstevel@tonic-gate } dt_fdlist_t;
6710Sstevel@tonic-gate
6720Sstevel@tonic-gate #pragma init(_dtrace_init)
6730Sstevel@tonic-gate void
_dtrace_init(void)6740Sstevel@tonic-gate _dtrace_init(void)
6750Sstevel@tonic-gate {
6760Sstevel@tonic-gate _dtrace_debug = getenv("DTRACE_DEBUG") != NULL;
6770Sstevel@tonic-gate
6780Sstevel@tonic-gate for (; _dtrace_rdvers > 0; _dtrace_rdvers--) {
6790Sstevel@tonic-gate if (rd_init(_dtrace_rdvers) == RD_OK)
6800Sstevel@tonic-gate break;
6810Sstevel@tonic-gate }
6820Sstevel@tonic-gate }
6830Sstevel@tonic-gate
6840Sstevel@tonic-gate static dtrace_hdl_t *
set_open_errno(dtrace_hdl_t * dtp,int * errp,int err)6850Sstevel@tonic-gate set_open_errno(dtrace_hdl_t *dtp, int *errp, int err)
6860Sstevel@tonic-gate {
6870Sstevel@tonic-gate if (dtp != NULL)
6880Sstevel@tonic-gate dtrace_close(dtp);
6890Sstevel@tonic-gate if (errp != NULL)
6900Sstevel@tonic-gate *errp = err;
6910Sstevel@tonic-gate return (NULL);
6920Sstevel@tonic-gate }
6930Sstevel@tonic-gate
6940Sstevel@tonic-gate static void
dt_provmod_open(dt_provmod_t ** provmod,dt_fdlist_t * dfp)6951149Sdp dt_provmod_open(dt_provmod_t **provmod, dt_fdlist_t *dfp)
6960Sstevel@tonic-gate {
6970Sstevel@tonic-gate dt_provmod_t *prov;
6980Sstevel@tonic-gate char path[PATH_MAX];
6990Sstevel@tonic-gate struct dirent *dp, *ep;
7000Sstevel@tonic-gate DIR *dirp;
7010Sstevel@tonic-gate int fd;
7020Sstevel@tonic-gate
7031149Sdp if ((dirp = opendir(_dtrace_provdir)) == NULL)
7040Sstevel@tonic-gate return; /* failed to open directory; just skip it */
7050Sstevel@tonic-gate
7060Sstevel@tonic-gate ep = alloca(sizeof (struct dirent) + PATH_MAX + 1);
7070Sstevel@tonic-gate bzero(ep, sizeof (struct dirent) + PATH_MAX + 1);
7080Sstevel@tonic-gate
7090Sstevel@tonic-gate while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) {
7100Sstevel@tonic-gate if (dp->d_name[0] == '.')
7110Sstevel@tonic-gate continue; /* skip "." and ".." */
7120Sstevel@tonic-gate
7130Sstevel@tonic-gate if (dfp->df_ents == dfp->df_size) {
7140Sstevel@tonic-gate uint_t size = dfp->df_size ? dfp->df_size * 2 : 16;
7150Sstevel@tonic-gate int *fds = realloc(dfp->df_fds, size * sizeof (int));
7160Sstevel@tonic-gate
7170Sstevel@tonic-gate if (fds == NULL)
7180Sstevel@tonic-gate break; /* skip the rest of this directory */
7190Sstevel@tonic-gate
7200Sstevel@tonic-gate dfp->df_fds = fds;
7210Sstevel@tonic-gate dfp->df_size = size;
7220Sstevel@tonic-gate }
7230Sstevel@tonic-gate
7241149Sdp (void) snprintf(path, sizeof (path), "%s/%s",
7251149Sdp _dtrace_provdir, dp->d_name);
7260Sstevel@tonic-gate
7270Sstevel@tonic-gate if ((fd = open(path, O_RDONLY)) == -1)
7280Sstevel@tonic-gate continue; /* failed to open driver; just skip it */
7290Sstevel@tonic-gate
7300Sstevel@tonic-gate if (((prov = malloc(sizeof (dt_provmod_t))) == NULL) ||
7310Sstevel@tonic-gate (prov->dp_name = malloc(strlen(dp->d_name) + 1)) == NULL) {
7320Sstevel@tonic-gate free(prov);
7330Sstevel@tonic-gate (void) close(fd);
7340Sstevel@tonic-gate break;
7350Sstevel@tonic-gate }
7360Sstevel@tonic-gate
7370Sstevel@tonic-gate (void) strcpy(prov->dp_name, dp->d_name);
7380Sstevel@tonic-gate prov->dp_next = *provmod;
7390Sstevel@tonic-gate *provmod = prov;
7400Sstevel@tonic-gate
7410Sstevel@tonic-gate dt_dprintf("opened provider %s\n", dp->d_name);
7420Sstevel@tonic-gate dfp->df_fds[dfp->df_ents++] = fd;
7430Sstevel@tonic-gate }
7440Sstevel@tonic-gate
7450Sstevel@tonic-gate (void) closedir(dirp);
7460Sstevel@tonic-gate }
7470Sstevel@tonic-gate
7480Sstevel@tonic-gate static void
dt_provmod_destroy(dt_provmod_t ** provmod)7490Sstevel@tonic-gate dt_provmod_destroy(dt_provmod_t **provmod)
7500Sstevel@tonic-gate {
7510Sstevel@tonic-gate dt_provmod_t *next, *current;
7520Sstevel@tonic-gate
7530Sstevel@tonic-gate for (current = *provmod; current != NULL; current = next) {
7540Sstevel@tonic-gate next = current->dp_next;
7550Sstevel@tonic-gate free(current->dp_name);
7560Sstevel@tonic-gate free(current);
7570Sstevel@tonic-gate }
7580Sstevel@tonic-gate
7590Sstevel@tonic-gate *provmod = NULL;
7600Sstevel@tonic-gate }
7610Sstevel@tonic-gate
7620Sstevel@tonic-gate static const char *
dt_get_sysinfo(int cmd,char * buf,size_t len)7630Sstevel@tonic-gate dt_get_sysinfo(int cmd, char *buf, size_t len)
7640Sstevel@tonic-gate {
7650Sstevel@tonic-gate ssize_t rv = sysinfo(cmd, buf, len);
7660Sstevel@tonic-gate char *p = buf;
7670Sstevel@tonic-gate
7680Sstevel@tonic-gate if (rv < 0 || rv > len)
7690Sstevel@tonic-gate (void) snprintf(buf, len, "%s", "Unknown");
7700Sstevel@tonic-gate
7710Sstevel@tonic-gate while ((p = strchr(p, '.')) != NULL)
7720Sstevel@tonic-gate *p++ = '_';
7730Sstevel@tonic-gate
7740Sstevel@tonic-gate return (buf);
7750Sstevel@tonic-gate }
7760Sstevel@tonic-gate
7770Sstevel@tonic-gate static dtrace_hdl_t *
dt_vopen(int version,int flags,int * errp,const dtrace_vector_t * vector,void * arg)7780Sstevel@tonic-gate dt_vopen(int version, int flags, int *errp,
7790Sstevel@tonic-gate const dtrace_vector_t *vector, void *arg)
7800Sstevel@tonic-gate {
7810Sstevel@tonic-gate dtrace_hdl_t *dtp = NULL;
7820Sstevel@tonic-gate int dtfd = -1, ftfd = -1, fterr = 0;
7830Sstevel@tonic-gate dtrace_prog_t *pgp;
7840Sstevel@tonic-gate dt_module_t *dmp;
7850Sstevel@tonic-gate dt_provmod_t *provmod = NULL;
7860Sstevel@tonic-gate int i, err;
7871739Sbmc struct rlimit rl;
7880Sstevel@tonic-gate
7890Sstevel@tonic-gate const dt_intrinsic_t *dinp;
7900Sstevel@tonic-gate const dt_typedef_t *dtyp;
7910Sstevel@tonic-gate const dt_ident_t *idp;
7920Sstevel@tonic-gate
7930Sstevel@tonic-gate dtrace_typeinfo_t dtt;
7940Sstevel@tonic-gate ctf_funcinfo_t ctc;
7950Sstevel@tonic-gate ctf_arinfo_t ctr;
7960Sstevel@tonic-gate
7970Sstevel@tonic-gate dt_fdlist_t df = { NULL, 0, 0 };
7980Sstevel@tonic-gate
7990Sstevel@tonic-gate char isadef[32], utsdef[32];
8000Sstevel@tonic-gate char s1[64], s2[64];
8010Sstevel@tonic-gate
8020Sstevel@tonic-gate if (version <= 0)
8030Sstevel@tonic-gate return (set_open_errno(dtp, errp, EINVAL));
8040Sstevel@tonic-gate
8050Sstevel@tonic-gate if (version > DTRACE_VERSION)
8060Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_VERSION));
8070Sstevel@tonic-gate
8081017Sbmc if (version < DTRACE_VERSION) {
8091017Sbmc /*
8101017Sbmc * Currently, increasing the library version number is used to
8111017Sbmc * denote a binary incompatible change. That is, a consumer
8121017Sbmc * of the library cannot run on a version of the library with
8131017Sbmc * a higher DTRACE_VERSION number than the consumer compiled
8141017Sbmc * against. Once the library API has been committed to,
8151017Sbmc * backwards binary compatibility will be required; at that
8161017Sbmc * time, this check should change to return EDT_OVERSION only
8171017Sbmc * if the specified version number is less than the version
8181017Sbmc * number at the time of interface commitment.
8191017Sbmc */
8201017Sbmc return (set_open_errno(dtp, errp, EDT_OVERSION));
8211017Sbmc }
8221017Sbmc
8230Sstevel@tonic-gate if (flags & ~DTRACE_O_MASK)
8240Sstevel@tonic-gate return (set_open_errno(dtp, errp, EINVAL));
8250Sstevel@tonic-gate
8260Sstevel@tonic-gate if ((flags & DTRACE_O_LP64) && (flags & DTRACE_O_ILP32))
8270Sstevel@tonic-gate return (set_open_errno(dtp, errp, EINVAL));
8280Sstevel@tonic-gate
8290Sstevel@tonic-gate if (vector == NULL && arg != NULL)
8300Sstevel@tonic-gate return (set_open_errno(dtp, errp, EINVAL));
8310Sstevel@tonic-gate
8320Sstevel@tonic-gate if (elf_version(EV_CURRENT) == EV_NONE)
8330Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_ELFVERSION));
8340Sstevel@tonic-gate
8350Sstevel@tonic-gate if (vector != NULL || (flags & DTRACE_O_NODEV))
8360Sstevel@tonic-gate goto alloc; /* do not attempt to open dtrace device */
8370Sstevel@tonic-gate
8380Sstevel@tonic-gate /*
8391739Sbmc * Before we get going, crank our limit on file descriptors up to the
8401739Sbmc * hard limit. This is to allow for the fact that libproc keeps file
8411739Sbmc * descriptors to objects open for the lifetime of the proc handle;
8421739Sbmc * without raising our hard limit, we would have an acceptably small
8431739Sbmc * bound on the number of processes that we could concurrently
8441739Sbmc * instrument with the pid provider.
8451739Sbmc */
8461739Sbmc if (getrlimit(RLIMIT_NOFILE, &rl) == 0) {
8471739Sbmc rl.rlim_cur = rl.rlim_max;
8481739Sbmc (void) setrlimit(RLIMIT_NOFILE, &rl);
8491739Sbmc }
8501739Sbmc
8511739Sbmc /*
8521149Sdp * Get the device path of each of the providers. We hold them open
8531149Sdp * in the df.df_fds list until we open the DTrace driver itself,
8541149Sdp * allowing us to see all of the probes provided on this system. Once
8551149Sdp * we have the DTrace driver open, we can safely close all the providers
8561149Sdp * now that they have registered with the framework.
8570Sstevel@tonic-gate */
8581149Sdp dt_provmod_open(&provmod, &df);
8590Sstevel@tonic-gate
8601149Sdp dtfd = open("/dev/dtrace/dtrace", O_RDWR);
8610Sstevel@tonic-gate err = errno; /* save errno from opening dtfd */
8620Sstevel@tonic-gate
8631149Sdp ftfd = open("/dev/dtrace/provider/fasttrap", O_RDWR);
8640Sstevel@tonic-gate fterr = ftfd == -1 ? errno : 0; /* save errno from open ftfd */
8650Sstevel@tonic-gate
8660Sstevel@tonic-gate while (df.df_ents-- != 0)
8670Sstevel@tonic-gate (void) close(df.df_fds[df.df_ents]);
8680Sstevel@tonic-gate
8690Sstevel@tonic-gate free(df.df_fds);
8700Sstevel@tonic-gate
8710Sstevel@tonic-gate /*
8720Sstevel@tonic-gate * If we failed to open the dtrace device, fail dtrace_open().
8730Sstevel@tonic-gate * We convert some kernel errnos to custom libdtrace errnos to
8740Sstevel@tonic-gate * improve the resulting message from the usual strerror().
8750Sstevel@tonic-gate */
8760Sstevel@tonic-gate if (dtfd == -1) {
8770Sstevel@tonic-gate dt_provmod_destroy(&provmod);
8780Sstevel@tonic-gate switch (err) {
8790Sstevel@tonic-gate case ENOENT:
8801677Sdp err = EDT_NOENT;
8810Sstevel@tonic-gate break;
8820Sstevel@tonic-gate case EBUSY:
8830Sstevel@tonic-gate err = EDT_BUSY;
8840Sstevel@tonic-gate break;
8850Sstevel@tonic-gate case EACCES:
8860Sstevel@tonic-gate err = EDT_ACCESS;
8870Sstevel@tonic-gate break;
8880Sstevel@tonic-gate }
8890Sstevel@tonic-gate return (set_open_errno(dtp, errp, err));
8900Sstevel@tonic-gate }
8910Sstevel@tonic-gate
8920Sstevel@tonic-gate (void) fcntl(dtfd, F_SETFD, FD_CLOEXEC);
8930Sstevel@tonic-gate (void) fcntl(ftfd, F_SETFD, FD_CLOEXEC);
8940Sstevel@tonic-gate
8950Sstevel@tonic-gate alloc:
8960Sstevel@tonic-gate if ((dtp = malloc(sizeof (dtrace_hdl_t))) == NULL)
8970Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM));
8980Sstevel@tonic-gate
8990Sstevel@tonic-gate bzero(dtp, sizeof (dtrace_hdl_t));
9000Sstevel@tonic-gate dtp->dt_oflags = flags;
9010Sstevel@tonic-gate dtp->dt_prcmode = DT_PROC_STOP_PREINIT;
9020Sstevel@tonic-gate dtp->dt_linkmode = DT_LINK_KERNEL;
9030Sstevel@tonic-gate dtp->dt_linktype = DT_LTYP_ELF;
904265Smws dtp->dt_xlatemode = DT_XL_STATIC;
9050Sstevel@tonic-gate dtp->dt_stdcmode = DT_STDC_XA;
9060Sstevel@tonic-gate dtp->dt_version = version;
9070Sstevel@tonic-gate dtp->dt_fd = dtfd;
9080Sstevel@tonic-gate dtp->dt_ftfd = ftfd;
9090Sstevel@tonic-gate dtp->dt_fterr = fterr;
9100Sstevel@tonic-gate dtp->dt_cdefs_fd = -1;
9110Sstevel@tonic-gate dtp->dt_ddefs_fd = -1;
9120Sstevel@tonic-gate dtp->dt_stdout_fd = -1;
9130Sstevel@tonic-gate dtp->dt_modbuckets = _dtrace_strbuckets;
9140Sstevel@tonic-gate dtp->dt_mods = calloc(dtp->dt_modbuckets, sizeof (dt_module_t *));
9150Sstevel@tonic-gate dtp->dt_provbuckets = _dtrace_strbuckets;
9160Sstevel@tonic-gate dtp->dt_provs = calloc(dtp->dt_provbuckets, sizeof (dt_provider_t *));
9170Sstevel@tonic-gate dt_proc_hash_create(dtp);
9180Sstevel@tonic-gate dtp->dt_vmax = DT_VERS_LATEST;
9190Sstevel@tonic-gate dtp->dt_cpp_path = strdup(_dtrace_defcpp);
9200Sstevel@tonic-gate dtp->dt_cpp_argv = malloc(sizeof (char *));
9210Sstevel@tonic-gate dtp->dt_cpp_argc = 1;
9220Sstevel@tonic-gate dtp->dt_cpp_args = 1;
9230Sstevel@tonic-gate dtp->dt_ld_path = strdup(_dtrace_defld);
9240Sstevel@tonic-gate dtp->dt_provmod = provmod;
9250Sstevel@tonic-gate dtp->dt_vector = vector;
9260Sstevel@tonic-gate dtp->dt_varg = arg;
9270Sstevel@tonic-gate dt_dof_init(dtp);
9280Sstevel@tonic-gate (void) uname(&dtp->dt_uts);
9290Sstevel@tonic-gate
9300Sstevel@tonic-gate if (dtp->dt_mods == NULL || dtp->dt_provs == NULL ||
9310Sstevel@tonic-gate dtp->dt_procs == NULL || dtp->dt_ld_path == NULL ||
9320Sstevel@tonic-gate dtp->dt_cpp_path == NULL || dtp->dt_cpp_argv == NULL)
9330Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM));
9340Sstevel@tonic-gate
9350Sstevel@tonic-gate for (i = 0; i < DTRACEOPT_MAX; i++)
9360Sstevel@tonic-gate dtp->dt_options[i] = DTRACEOPT_UNSET;
9370Sstevel@tonic-gate
9380Sstevel@tonic-gate dtp->dt_cpp_argv[0] = (char *)strbasename(dtp->dt_cpp_path);
9390Sstevel@tonic-gate
9400Sstevel@tonic-gate (void) snprintf(isadef, sizeof (isadef), "-D__SUNW_D_%u",
9410Sstevel@tonic-gate (uint_t)(sizeof (void *) * NBBY));
9420Sstevel@tonic-gate
9430Sstevel@tonic-gate (void) snprintf(utsdef, sizeof (utsdef), "-D__%s_%s",
9440Sstevel@tonic-gate dt_get_sysinfo(SI_SYSNAME, s1, sizeof (s1)),
9450Sstevel@tonic-gate dt_get_sysinfo(SI_RELEASE, s2, sizeof (s2)));
9460Sstevel@tonic-gate
9470Sstevel@tonic-gate if (dt_cpp_add_arg(dtp, "-D__sun") == NULL ||
9480Sstevel@tonic-gate dt_cpp_add_arg(dtp, "-D__unix") == NULL ||
9490Sstevel@tonic-gate dt_cpp_add_arg(dtp, "-D__SVR4") == NULL ||
9500Sstevel@tonic-gate dt_cpp_add_arg(dtp, "-D__SUNW_D=1") == NULL ||
9510Sstevel@tonic-gate dt_cpp_add_arg(dtp, isadef) == NULL ||
9520Sstevel@tonic-gate dt_cpp_add_arg(dtp, utsdef) == NULL)
9530Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM));
9540Sstevel@tonic-gate
9550Sstevel@tonic-gate if (flags & DTRACE_O_NODEV)
9560Sstevel@tonic-gate bcopy(&_dtrace_conf, &dtp->dt_conf, sizeof (_dtrace_conf));
9570Sstevel@tonic-gate else if (dt_ioctl(dtp, DTRACEIOC_CONF, &dtp->dt_conf) != 0)
9580Sstevel@tonic-gate return (set_open_errno(dtp, errp, errno));
9590Sstevel@tonic-gate
9600Sstevel@tonic-gate if (flags & DTRACE_O_LP64)
9610Sstevel@tonic-gate dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_LP64;
9620Sstevel@tonic-gate else if (flags & DTRACE_O_ILP32)
9630Sstevel@tonic-gate dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_ILP32;
9640Sstevel@tonic-gate
9650Sstevel@tonic-gate #ifdef __sparc
9660Sstevel@tonic-gate /*
9670Sstevel@tonic-gate * On SPARC systems, __sparc is always defined for <sys/isa_defs.h>
9680Sstevel@tonic-gate * and __sparcv9 is defined if we are doing a 64-bit compile.
9690Sstevel@tonic-gate */
9700Sstevel@tonic-gate if (dt_cpp_add_arg(dtp, "-D__sparc") == NULL)
9710Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM));
9720Sstevel@tonic-gate
9730Sstevel@tonic-gate if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64 &&
9740Sstevel@tonic-gate dt_cpp_add_arg(dtp, "-D__sparcv9") == NULL)
9750Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM));
9760Sstevel@tonic-gate #endif
9770Sstevel@tonic-gate
9780Sstevel@tonic-gate #ifdef __x86
9790Sstevel@tonic-gate /*
9800Sstevel@tonic-gate * On x86 systems, __i386 is defined for <sys/isa_defs.h> for 32-bit
9810Sstevel@tonic-gate * compiles and __amd64 is defined for 64-bit compiles. Unlike SPARC,
9820Sstevel@tonic-gate * they are defined exclusive of one another (see PSARC 2004/619).
9830Sstevel@tonic-gate */
9841151Sdp if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) {
9851151Sdp if (dt_cpp_add_arg(dtp, "-D__amd64") == NULL)
9861151Sdp return (set_open_errno(dtp, errp, EDT_NOMEM));
9871151Sdp } else {
9881151Sdp if (dt_cpp_add_arg(dtp, "-D__i386") == NULL)
9891151Sdp return (set_open_errno(dtp, errp, EDT_NOMEM));
9901151Sdp }
9910Sstevel@tonic-gate #endif
9920Sstevel@tonic-gate
9930Sstevel@tonic-gate if (dtp->dt_conf.dtc_difversion < DIF_VERSION)
9940Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_DIFVERS));
9950Sstevel@tonic-gate
9960Sstevel@tonic-gate if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32)
9970Sstevel@tonic-gate bcopy(_dtrace_ints_32, dtp->dt_ints, sizeof (_dtrace_ints_32));
9980Sstevel@tonic-gate else
9990Sstevel@tonic-gate bcopy(_dtrace_ints_64, dtp->dt_ints, sizeof (_dtrace_ints_64));
10000Sstevel@tonic-gate
10010Sstevel@tonic-gate dtp->dt_macros = dt_idhash_create("macro", NULL, 0, UINT_MAX);
10021017Sbmc dtp->dt_aggs = dt_idhash_create("aggregation", NULL,
10031017Sbmc DTRACE_AGGVARIDNONE + 1, UINT_MAX);
10040Sstevel@tonic-gate
10050Sstevel@tonic-gate dtp->dt_globals = dt_idhash_create("global", _dtrace_globals,
10060Sstevel@tonic-gate DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX);
10070Sstevel@tonic-gate
10080Sstevel@tonic-gate dtp->dt_tls = dt_idhash_create("thread local", NULL,
10090Sstevel@tonic-gate DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX);
10100Sstevel@tonic-gate
10110Sstevel@tonic-gate if (dtp->dt_macros == NULL || dtp->dt_aggs == NULL ||
10120Sstevel@tonic-gate dtp->dt_globals == NULL || dtp->dt_tls == NULL)
10130Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM));
10140Sstevel@tonic-gate
10150Sstevel@tonic-gate /*
10160Sstevel@tonic-gate * Populate the dt_macros identifier hash table by hand: we can't use
10170Sstevel@tonic-gate * the dt_idhash_populate() mechanism because we're not yet compiling
10180Sstevel@tonic-gate * and dtrace_update() needs to immediately reference these idents.
10190Sstevel@tonic-gate */
10200Sstevel@tonic-gate for (idp = _dtrace_macros; idp->di_name != NULL; idp++) {
10210Sstevel@tonic-gate if (dt_idhash_insert(dtp->dt_macros, idp->di_name,
10220Sstevel@tonic-gate idp->di_kind, idp->di_flags, idp->di_id, idp->di_attr,
10230Sstevel@tonic-gate idp->di_vers, idp->di_ops ? idp->di_ops : &dt_idops_thaw,
10240Sstevel@tonic-gate idp->di_iarg, 0) == NULL)
10250Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM));
10260Sstevel@tonic-gate }
10270Sstevel@tonic-gate
10280Sstevel@tonic-gate /*
10290Sstevel@tonic-gate * Update the module list using /system/object and load the values for
10300Sstevel@tonic-gate * the macro variable definitions according to the current process.
10310Sstevel@tonic-gate */
10320Sstevel@tonic-gate dtrace_update(dtp);
10330Sstevel@tonic-gate
10340Sstevel@tonic-gate /*
10350Sstevel@tonic-gate * Select the intrinsics and typedefs we want based on the data model.
10360Sstevel@tonic-gate * The intrinsics are under "C". The typedefs are added under "D".
10370Sstevel@tonic-gate */
10380Sstevel@tonic-gate if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32) {
10390Sstevel@tonic-gate dinp = _dtrace_intrinsics_32;
10400Sstevel@tonic-gate dtyp = _dtrace_typedefs_32;
10410Sstevel@tonic-gate } else {
10420Sstevel@tonic-gate dinp = _dtrace_intrinsics_64;
10430Sstevel@tonic-gate dtyp = _dtrace_typedefs_64;
10440Sstevel@tonic-gate }
10450Sstevel@tonic-gate
10460Sstevel@tonic-gate /*
10470Sstevel@tonic-gate * Create a dynamic CTF container under the "C" scope for intrinsic
10480Sstevel@tonic-gate * types and types defined in ANSI-C header files that are included.
10490Sstevel@tonic-gate */
10500Sstevel@tonic-gate if ((dmp = dtp->dt_cdefs = dt_module_create(dtp, "C")) == NULL)
10510Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM));
10520Sstevel@tonic-gate
10530Sstevel@tonic-gate if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL)
10540Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF));
10550Sstevel@tonic-gate
10560Sstevel@tonic-gate dt_dprintf("created CTF container for %s (%p)\n",
10570Sstevel@tonic-gate dmp->dm_name, (void *)dmp->dm_ctfp);
10580Sstevel@tonic-gate
10590Sstevel@tonic-gate (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel);
10600Sstevel@tonic-gate ctf_setspecific(dmp->dm_ctfp, dmp);
10610Sstevel@tonic-gate
10620Sstevel@tonic-gate dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */
10630Sstevel@tonic-gate dmp->dm_modid = -1; /* no module ID */
10640Sstevel@tonic-gate
10650Sstevel@tonic-gate /*
10660Sstevel@tonic-gate * Fill the dynamic "C" CTF container with all of the intrinsic
10670Sstevel@tonic-gate * integer and floating-point types appropriate for this data model.
10680Sstevel@tonic-gate */
10690Sstevel@tonic-gate for (; dinp->din_name != NULL; dinp++) {
10700Sstevel@tonic-gate if (dinp->din_kind == CTF_K_INTEGER) {
10710Sstevel@tonic-gate err = ctf_add_integer(dmp->dm_ctfp, CTF_ADD_ROOT,
10720Sstevel@tonic-gate dinp->din_name, &dinp->din_data);
10730Sstevel@tonic-gate } else {
10740Sstevel@tonic-gate err = ctf_add_float(dmp->dm_ctfp, CTF_ADD_ROOT,
10750Sstevel@tonic-gate dinp->din_name, &dinp->din_data);
10760Sstevel@tonic-gate }
10770Sstevel@tonic-gate
10780Sstevel@tonic-gate if (err == CTF_ERR) {
10790Sstevel@tonic-gate dt_dprintf("failed to add %s to C container: %s\n",
10800Sstevel@tonic-gate dinp->din_name, ctf_errmsg(
10810Sstevel@tonic-gate ctf_errno(dmp->dm_ctfp)));
10820Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF));
10830Sstevel@tonic-gate }
10840Sstevel@tonic-gate }
10850Sstevel@tonic-gate
10860Sstevel@tonic-gate if (ctf_update(dmp->dm_ctfp) != 0) {
10870Sstevel@tonic-gate dt_dprintf("failed to update C container: %s\n",
10880Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
10890Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF));
10900Sstevel@tonic-gate }
10910Sstevel@tonic-gate
10920Sstevel@tonic-gate /*
10930Sstevel@tonic-gate * Add intrinsic pointer types that are needed to initialize printf
10940Sstevel@tonic-gate * format dictionary types (see table in dt_printf.c).
10950Sstevel@tonic-gate */
10960Sstevel@tonic-gate (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT,
10970Sstevel@tonic-gate ctf_lookup_by_name(dmp->dm_ctfp, "void"));
10980Sstevel@tonic-gate
10990Sstevel@tonic-gate (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT,
11000Sstevel@tonic-gate ctf_lookup_by_name(dmp->dm_ctfp, "char"));
11010Sstevel@tonic-gate
11020Sstevel@tonic-gate (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT,
11030Sstevel@tonic-gate ctf_lookup_by_name(dmp->dm_ctfp, "int"));
11040Sstevel@tonic-gate
11050Sstevel@tonic-gate if (ctf_update(dmp->dm_ctfp) != 0) {
11060Sstevel@tonic-gate dt_dprintf("failed to update C container: %s\n",
11070Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
11080Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF));
11090Sstevel@tonic-gate }
11100Sstevel@tonic-gate
11110Sstevel@tonic-gate /*
11120Sstevel@tonic-gate * Create a dynamic CTF container under the "D" scope for types that
11130Sstevel@tonic-gate * are defined by the D program itself or on-the-fly by the D compiler.
11140Sstevel@tonic-gate * The "D" CTF container is a child of the "C" CTF container.
11150Sstevel@tonic-gate */
11160Sstevel@tonic-gate if ((dmp = dtp->dt_ddefs = dt_module_create(dtp, "D")) == NULL)
11170Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM));
11180Sstevel@tonic-gate
11190Sstevel@tonic-gate if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL)
11200Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF));
11210Sstevel@tonic-gate
11220Sstevel@tonic-gate dt_dprintf("created CTF container for %s (%p)\n",
11230Sstevel@tonic-gate dmp->dm_name, (void *)dmp->dm_ctfp);
11240Sstevel@tonic-gate
11250Sstevel@tonic-gate (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel);
11260Sstevel@tonic-gate ctf_setspecific(dmp->dm_ctfp, dmp);
11270Sstevel@tonic-gate
11280Sstevel@tonic-gate dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */
11290Sstevel@tonic-gate dmp->dm_modid = -1; /* no module ID */
11300Sstevel@tonic-gate
11310Sstevel@tonic-gate if (ctf_import(dmp->dm_ctfp, dtp->dt_cdefs->dm_ctfp) == CTF_ERR) {
11320Sstevel@tonic-gate dt_dprintf("failed to import D parent container: %s\n",
11330Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
11340Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF));
11350Sstevel@tonic-gate }
11360Sstevel@tonic-gate
11370Sstevel@tonic-gate /*
11380Sstevel@tonic-gate * Fill the dynamic "D" CTF container with all of the built-in typedefs
11390Sstevel@tonic-gate * that we need to use for our D variable and function definitions.
11400Sstevel@tonic-gate * This ensures that basic inttypes.h names are always available to us.
11410Sstevel@tonic-gate */
11420Sstevel@tonic-gate for (; dtyp->dty_src != NULL; dtyp++) {
11430Sstevel@tonic-gate if (ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
11440Sstevel@tonic-gate dtyp->dty_dst, ctf_lookup_by_name(dmp->dm_ctfp,
11450Sstevel@tonic-gate dtyp->dty_src)) == CTF_ERR) {
11460Sstevel@tonic-gate dt_dprintf("failed to add typedef %s %s to D "
11470Sstevel@tonic-gate "container: %s", dtyp->dty_src, dtyp->dty_dst,
11480Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
11490Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF));
11500Sstevel@tonic-gate }
11510Sstevel@tonic-gate }
11520Sstevel@tonic-gate
11530Sstevel@tonic-gate /*
11540Sstevel@tonic-gate * Insert a CTF ID corresponding to a pointer to a type of kind
11550Sstevel@tonic-gate * CTF_K_FUNCTION we can use in the compiler for function pointers.
11560Sstevel@tonic-gate * CTF treats all function pointers as "int (*)()" so we only need one.
11570Sstevel@tonic-gate */
11580Sstevel@tonic-gate ctc.ctc_return = ctf_lookup_by_name(dmp->dm_ctfp, "int");
11590Sstevel@tonic-gate ctc.ctc_argc = 0;
11600Sstevel@tonic-gate ctc.ctc_flags = 0;
11610Sstevel@tonic-gate
11620Sstevel@tonic-gate dtp->dt_type_func = ctf_add_function(dmp->dm_ctfp,
11630Sstevel@tonic-gate CTF_ADD_ROOT, &ctc, NULL);
11640Sstevel@tonic-gate
11650Sstevel@tonic-gate dtp->dt_type_fptr = ctf_add_pointer(dmp->dm_ctfp,
11660Sstevel@tonic-gate CTF_ADD_ROOT, dtp->dt_type_func);
11670Sstevel@tonic-gate
11680Sstevel@tonic-gate /*
11690Sstevel@tonic-gate * We also insert CTF definitions for the special D intrinsic types
11700Sstevel@tonic-gate * string and <DYN> into the D container. The string type is added
11710Sstevel@tonic-gate * as a typedef of char[n]. The <DYN> type is an alias for void.
11720Sstevel@tonic-gate * We compare types to these special CTF ids throughout the compiler.
11730Sstevel@tonic-gate */
11740Sstevel@tonic-gate ctr.ctr_contents = ctf_lookup_by_name(dmp->dm_ctfp, "char");
11750Sstevel@tonic-gate ctr.ctr_index = ctf_lookup_by_name(dmp->dm_ctfp, "long");
11760Sstevel@tonic-gate ctr.ctr_nelems = _dtrace_strsize;
11770Sstevel@tonic-gate
11780Sstevel@tonic-gate dtp->dt_type_str = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
11790Sstevel@tonic-gate "string", ctf_add_array(dmp->dm_ctfp, CTF_ADD_ROOT, &ctr));
11800Sstevel@tonic-gate
11810Sstevel@tonic-gate dtp->dt_type_dyn = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
11820Sstevel@tonic-gate "<DYN>", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
11830Sstevel@tonic-gate
11840Sstevel@tonic-gate dtp->dt_type_stack = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
11850Sstevel@tonic-gate "stack", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
11860Sstevel@tonic-gate
1187457Sbmc dtp->dt_type_symaddr = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1188457Sbmc "_symaddr", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1189457Sbmc
1190457Sbmc dtp->dt_type_usymaddr = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT,
1191457Sbmc "_usymaddr", ctf_lookup_by_name(dmp->dm_ctfp, "void"));
1192457Sbmc
11930Sstevel@tonic-gate if (dtp->dt_type_func == CTF_ERR || dtp->dt_type_fptr == CTF_ERR ||
11940Sstevel@tonic-gate dtp->dt_type_str == CTF_ERR || dtp->dt_type_dyn == CTF_ERR ||
1195457Sbmc dtp->dt_type_stack == CTF_ERR || dtp->dt_type_symaddr == CTF_ERR ||
1196457Sbmc dtp->dt_type_usymaddr == CTF_ERR) {
11970Sstevel@tonic-gate dt_dprintf("failed to add intrinsic to D container: %s\n",
11980Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
11990Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF));
12000Sstevel@tonic-gate }
12010Sstevel@tonic-gate
12020Sstevel@tonic-gate if (ctf_update(dmp->dm_ctfp) != 0) {
12030Sstevel@tonic-gate dt_dprintf("failed update D container: %s\n",
12040Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
12050Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF));
12060Sstevel@tonic-gate }
12070Sstevel@tonic-gate
12080Sstevel@tonic-gate /*
12090Sstevel@tonic-gate * Initialize the integer description table used to convert integer
12100Sstevel@tonic-gate * constants to the appropriate types. Refer to the comments above
12110Sstevel@tonic-gate * dt_node_int() for a complete description of how this table is used.
12120Sstevel@tonic-gate */
12130Sstevel@tonic-gate for (i = 0; i < sizeof (dtp->dt_ints) / sizeof (dtp->dt_ints[0]); i++) {
12140Sstevel@tonic-gate if (dtrace_lookup_by_type(dtp, DTRACE_OBJ_EVERY,
12150Sstevel@tonic-gate dtp->dt_ints[i].did_name, &dtt) != 0) {
12160Sstevel@tonic-gate dt_dprintf("failed to lookup integer type %s: %s\n",
12170Sstevel@tonic-gate dtp->dt_ints[i].did_name,
12180Sstevel@tonic-gate dtrace_errmsg(dtp, dtrace_errno(dtp)));
12190Sstevel@tonic-gate return (set_open_errno(dtp, errp, dtp->dt_errno));
12200Sstevel@tonic-gate }
12210Sstevel@tonic-gate dtp->dt_ints[i].did_ctfp = dtt.dtt_ctfp;
12220Sstevel@tonic-gate dtp->dt_ints[i].did_type = dtt.dtt_type;
12230Sstevel@tonic-gate }
12240Sstevel@tonic-gate
12250Sstevel@tonic-gate /*
12260Sstevel@tonic-gate * Now that we've created the "C" and "D" containers, move them to the
12270Sstevel@tonic-gate * start of the module list so that these types and symbols are found
12280Sstevel@tonic-gate * first (for stability) when iterating through the module list.
12290Sstevel@tonic-gate */
12300Sstevel@tonic-gate dt_list_delete(&dtp->dt_modlist, dtp->dt_ddefs);
12310Sstevel@tonic-gate dt_list_prepend(&dtp->dt_modlist, dtp->dt_ddefs);
12320Sstevel@tonic-gate
12330Sstevel@tonic-gate dt_list_delete(&dtp->dt_modlist, dtp->dt_cdefs);
12340Sstevel@tonic-gate dt_list_prepend(&dtp->dt_modlist, dtp->dt_cdefs);
12350Sstevel@tonic-gate
12360Sstevel@tonic-gate if (dt_pfdict_create(dtp) == -1)
12370Sstevel@tonic-gate return (set_open_errno(dtp, errp, dtp->dt_errno));
12380Sstevel@tonic-gate
12390Sstevel@tonic-gate /*
12400Sstevel@tonic-gate * If we are opening libdtrace DTRACE_O_NODEV enable C_ZDEFS by default
12410Sstevel@tonic-gate * because without /dev/dtrace open, we will not be able to load the
12420Sstevel@tonic-gate * names and attributes of any providers or probes from the kernel.
12430Sstevel@tonic-gate */
12440Sstevel@tonic-gate if (flags & DTRACE_O_NODEV)
12450Sstevel@tonic-gate dtp->dt_cflags |= DTRACE_C_ZDEFS;
12460Sstevel@tonic-gate
12470Sstevel@tonic-gate /*
12480Sstevel@tonic-gate * Load hard-wired inlines into the definition cache by calling the
12490Sstevel@tonic-gate * compiler on the raw definition string defined above.
12500Sstevel@tonic-gate */
12510Sstevel@tonic-gate if ((pgp = dtrace_program_strcompile(dtp, _dtrace_hardwire,
12520Sstevel@tonic-gate DTRACE_PROBESPEC_NONE, DTRACE_C_EMPTY, 0, NULL)) == NULL) {
12530Sstevel@tonic-gate dt_dprintf("failed to load hard-wired definitions: %s\n",
12540Sstevel@tonic-gate dtrace_errmsg(dtp, dtrace_errno(dtp)));
12550Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_HARDWIRE));
12560Sstevel@tonic-gate }
12570Sstevel@tonic-gate
1258265Smws dt_program_destroy(dtp, pgp);
12590Sstevel@tonic-gate
12600Sstevel@tonic-gate /*
12610Sstevel@tonic-gate * Set up the default DTrace library path. Once set, the next call to
12620Sstevel@tonic-gate * dt_compile() will compile all the libraries. We intentionally defer
12630Sstevel@tonic-gate * library processing to improve overhead for clients that don't ever
12640Sstevel@tonic-gate * compile, and to provide better error reporting (because the full
12650Sstevel@tonic-gate * reporting of compiler errors requires dtrace_open() to succeed).
12660Sstevel@tonic-gate */
12670Sstevel@tonic-gate if (dtrace_setopt(dtp, "libdir", _dtrace_libdir) != 0)
12680Sstevel@tonic-gate return (set_open_errno(dtp, errp, dtp->dt_errno));
12690Sstevel@tonic-gate
12700Sstevel@tonic-gate return (dtp);
12710Sstevel@tonic-gate }
12720Sstevel@tonic-gate
12730Sstevel@tonic-gate dtrace_hdl_t *
dtrace_open(int version,int flags,int * errp)12740Sstevel@tonic-gate dtrace_open(int version, int flags, int *errp)
12750Sstevel@tonic-gate {
12760Sstevel@tonic-gate return (dt_vopen(version, flags, errp, NULL, NULL));
12770Sstevel@tonic-gate }
12780Sstevel@tonic-gate
12790Sstevel@tonic-gate dtrace_hdl_t *
dtrace_vopen(int version,int flags,int * errp,const dtrace_vector_t * vector,void * arg)12800Sstevel@tonic-gate dtrace_vopen(int version, int flags, int *errp,
12810Sstevel@tonic-gate const dtrace_vector_t *vector, void *arg)
12820Sstevel@tonic-gate {
12830Sstevel@tonic-gate return (dt_vopen(version, flags, errp, vector, arg));
12840Sstevel@tonic-gate }
12850Sstevel@tonic-gate
12860Sstevel@tonic-gate void
dtrace_close(dtrace_hdl_t * dtp)12870Sstevel@tonic-gate dtrace_close(dtrace_hdl_t *dtp)
12880Sstevel@tonic-gate {
12890Sstevel@tonic-gate dt_ident_t *idp, *ndp;
12900Sstevel@tonic-gate dt_module_t *dmp;
12910Sstevel@tonic-gate dt_provider_t *pvp;
12920Sstevel@tonic-gate dtrace_prog_t *pgp;
12930Sstevel@tonic-gate dt_xlator_t *dxp;
12940Sstevel@tonic-gate dt_dirpath_t *dirp;
12950Sstevel@tonic-gate int i;
12960Sstevel@tonic-gate
12976390Sahl if (dtp->dt_procs != NULL)
12986390Sahl dt_proc_hash_destroy(dtp);
12996390Sahl
13000Sstevel@tonic-gate while ((pgp = dt_list_next(&dtp->dt_programs)) != NULL)
1301265Smws dt_program_destroy(dtp, pgp);
13020Sstevel@tonic-gate
13030Sstevel@tonic-gate while ((dxp = dt_list_next(&dtp->dt_xlators)) != NULL)
13040Sstevel@tonic-gate dt_xlator_destroy(dtp, dxp);
13050Sstevel@tonic-gate
1306265Smws dt_free(dtp, dtp->dt_xlatormap);
1307265Smws
13080Sstevel@tonic-gate for (idp = dtp->dt_externs; idp != NULL; idp = ndp) {
13090Sstevel@tonic-gate ndp = idp->di_next;
13100Sstevel@tonic-gate dt_ident_destroy(idp);
13110Sstevel@tonic-gate }
13120Sstevel@tonic-gate
13130Sstevel@tonic-gate if (dtp->dt_macros != NULL)
13140Sstevel@tonic-gate dt_idhash_destroy(dtp->dt_macros);
13150Sstevel@tonic-gate if (dtp->dt_aggs != NULL)
13160Sstevel@tonic-gate dt_idhash_destroy(dtp->dt_aggs);
13170Sstevel@tonic-gate if (dtp->dt_globals != NULL)
13180Sstevel@tonic-gate dt_idhash_destroy(dtp->dt_globals);
13190Sstevel@tonic-gate if (dtp->dt_tls != NULL)
13200Sstevel@tonic-gate dt_idhash_destroy(dtp->dt_tls);
13210Sstevel@tonic-gate
13220Sstevel@tonic-gate while ((dmp = dt_list_next(&dtp->dt_modlist)) != NULL)
13230Sstevel@tonic-gate dt_module_destroy(dtp, dmp);
13240Sstevel@tonic-gate
13250Sstevel@tonic-gate while ((pvp = dt_list_next(&dtp->dt_provlist)) != NULL)
13260Sstevel@tonic-gate dt_provider_destroy(dtp, pvp);
13270Sstevel@tonic-gate
13280Sstevel@tonic-gate if (dtp->dt_fd != -1)
13290Sstevel@tonic-gate (void) close(dtp->dt_fd);
13300Sstevel@tonic-gate if (dtp->dt_ftfd != -1)
13310Sstevel@tonic-gate (void) close(dtp->dt_ftfd);
13320Sstevel@tonic-gate if (dtp->dt_cdefs_fd != -1)
13330Sstevel@tonic-gate (void) close(dtp->dt_cdefs_fd);
13340Sstevel@tonic-gate if (dtp->dt_ddefs_fd != -1)
13350Sstevel@tonic-gate (void) close(dtp->dt_ddefs_fd);
13360Sstevel@tonic-gate if (dtp->dt_stdout_fd != -1)
13370Sstevel@tonic-gate (void) close(dtp->dt_stdout_fd);
13380Sstevel@tonic-gate
13390Sstevel@tonic-gate dt_epid_destroy(dtp);
13400Sstevel@tonic-gate dt_aggid_destroy(dtp);
13410Sstevel@tonic-gate dt_format_destroy(dtp);
13420Sstevel@tonic-gate dt_buffered_destroy(dtp);
13430Sstevel@tonic-gate dt_aggregate_destroy(dtp);
13440Sstevel@tonic-gate free(dtp->dt_buf.dtbd_data);
13450Sstevel@tonic-gate dt_pfdict_destroy(dtp);
13460Sstevel@tonic-gate dt_provmod_destroy(&dtp->dt_provmod);
13470Sstevel@tonic-gate dt_dof_fini(dtp);
13480Sstevel@tonic-gate
13490Sstevel@tonic-gate for (i = 1; i < dtp->dt_cpp_argc; i++)
13500Sstevel@tonic-gate free(dtp->dt_cpp_argv[i]);
13510Sstevel@tonic-gate
13520Sstevel@tonic-gate while ((dirp = dt_list_next(&dtp->dt_lib_path)) != NULL) {
13530Sstevel@tonic-gate dt_list_delete(&dtp->dt_lib_path, dirp);
13540Sstevel@tonic-gate free(dirp->dir_path);
13550Sstevel@tonic-gate free(dirp);
13560Sstevel@tonic-gate }
13570Sstevel@tonic-gate
13580Sstevel@tonic-gate free(dtp->dt_cpp_argv);
13590Sstevel@tonic-gate free(dtp->dt_cpp_path);
13600Sstevel@tonic-gate free(dtp->dt_ld_path);
13610Sstevel@tonic-gate
13620Sstevel@tonic-gate free(dtp->dt_mods);
13630Sstevel@tonic-gate free(dtp->dt_provs);
13640Sstevel@tonic-gate free(dtp);
13650Sstevel@tonic-gate }
13660Sstevel@tonic-gate
13670Sstevel@tonic-gate int
dtrace_provider_modules(dtrace_hdl_t * dtp,const char ** mods,int nmods)13680Sstevel@tonic-gate dtrace_provider_modules(dtrace_hdl_t *dtp, const char **mods, int nmods)
13690Sstevel@tonic-gate {
13700Sstevel@tonic-gate dt_provmod_t *prov;
13710Sstevel@tonic-gate int i = 0;
13720Sstevel@tonic-gate
13730Sstevel@tonic-gate for (prov = dtp->dt_provmod; prov != NULL; prov = prov->dp_next, i++) {
13740Sstevel@tonic-gate if (i < nmods)
13750Sstevel@tonic-gate mods[i] = prov->dp_name;
13760Sstevel@tonic-gate }
13770Sstevel@tonic-gate
13780Sstevel@tonic-gate return (i);
13790Sstevel@tonic-gate }
13800Sstevel@tonic-gate
13810Sstevel@tonic-gate int
dtrace_ctlfd(dtrace_hdl_t * dtp)13820Sstevel@tonic-gate dtrace_ctlfd(dtrace_hdl_t *dtp)
13830Sstevel@tonic-gate {
13840Sstevel@tonic-gate return (dtp->dt_fd);
13850Sstevel@tonic-gate }
1386