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