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 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 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> 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <libelf.h> 340Sstevel@tonic-gate #include <strings.h> 350Sstevel@tonic-gate #include <alloca.h> 360Sstevel@tonic-gate #include <limits.h> 370Sstevel@tonic-gate #include <unistd.h> 380Sstevel@tonic-gate #include <stdlib.h> 390Sstevel@tonic-gate #include <stdio.h> 400Sstevel@tonic-gate #include <fcntl.h> 410Sstevel@tonic-gate #include <errno.h> 420Sstevel@tonic-gate #include <zone.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> 50*265Smws #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 830Sstevel@tonic-gate #define DT_VERS_1_0 DT_VERSION_NUMBER(1, 0, 0) 840Sstevel@tonic-gate #define DT_VERS_1_1 DT_VERSION_NUMBER(1, 1, 0) 85191Sahl #define DT_VERS_1_2 DT_VERSION_NUMBER(1, 2, 0) 86191Sahl #define DT_VERS_LATEST DT_VERS_1_2 87191Sahl #define DT_VERS_STRING "Sun D 1.2" 880Sstevel@tonic-gate 890Sstevel@tonic-gate const dt_version_t _dtrace_versions[] = { 900Sstevel@tonic-gate DT_VERS_1_0, /* D API 1.0.0 (PSARC 2001/466) Solaris 10 FCS */ 91191Sahl DT_VERS_1_1, /* D API 1.1.0 Solaris Express 6/05 */ 92191Sahl DT_VERS_1_2, /* D API 1.2.0 Solaris 10 Update 1 */ 930Sstevel@tonic-gate 0 940Sstevel@tonic-gate }; 950Sstevel@tonic-gate 960Sstevel@tonic-gate /* 970Sstevel@tonic-gate * Table of global identifiers. This is used to populate the global identifier 980Sstevel@tonic-gate * hash when a new dtrace client open occurs. For more info see dt_ident.h. 990Sstevel@tonic-gate * The global identifiers that represent functions use the dt_idops_func ops 1000Sstevel@tonic-gate * and specify the private data pointer as a prototype string which is parsed 1010Sstevel@tonic-gate * when the identifier is first encountered. These prototypes look like ANSI 1020Sstevel@tonic-gate * C function prototypes except that the special symbol "@" can be used as a 1030Sstevel@tonic-gate * wildcard to represent a single parameter of any type (i.e. any dt_node_t). 1040Sstevel@tonic-gate * The standard "..." notation can also be used to represent varargs. An empty 1050Sstevel@tonic-gate * parameter list is taken to mean void (that is, no arguments are permitted). 1060Sstevel@tonic-gate * A parameter enclosed in square brackets (e.g. "[int]") denotes an optional 1070Sstevel@tonic-gate * argument. 1080Sstevel@tonic-gate */ 1090Sstevel@tonic-gate static const dt_ident_t _dtrace_globals[] = { 1100Sstevel@tonic-gate { "alloca", DT_IDENT_FUNC, 0, DIF_SUBR_ALLOCA, DT_ATTR_STABCMN, DT_VERS_1_0, 1110Sstevel@tonic-gate &dt_idops_func, "void *(size_t)" }, 1120Sstevel@tonic-gate { "arg0", DT_IDENT_SCALAR, 0, DIF_VAR_ARG0, DT_ATTR_STABCMN, DT_VERS_1_0, 1130Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 1140Sstevel@tonic-gate { "arg1", DT_IDENT_SCALAR, 0, DIF_VAR_ARG1, DT_ATTR_STABCMN, DT_VERS_1_0, 1150Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 1160Sstevel@tonic-gate { "arg2", DT_IDENT_SCALAR, 0, DIF_VAR_ARG2, DT_ATTR_STABCMN, DT_VERS_1_0, 1170Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 1180Sstevel@tonic-gate { "arg3", DT_IDENT_SCALAR, 0, DIF_VAR_ARG3, DT_ATTR_STABCMN, DT_VERS_1_0, 1190Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 1200Sstevel@tonic-gate { "arg4", DT_IDENT_SCALAR, 0, DIF_VAR_ARG4, DT_ATTR_STABCMN, DT_VERS_1_0, 1210Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 1220Sstevel@tonic-gate { "arg5", DT_IDENT_SCALAR, 0, DIF_VAR_ARG5, DT_ATTR_STABCMN, DT_VERS_1_0, 1230Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 1240Sstevel@tonic-gate { "arg6", DT_IDENT_SCALAR, 0, DIF_VAR_ARG6, DT_ATTR_STABCMN, DT_VERS_1_0, 1250Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 1260Sstevel@tonic-gate { "arg7", DT_IDENT_SCALAR, 0, DIF_VAR_ARG7, DT_ATTR_STABCMN, DT_VERS_1_0, 1270Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 1280Sstevel@tonic-gate { "arg8", DT_IDENT_SCALAR, 0, DIF_VAR_ARG8, DT_ATTR_STABCMN, DT_VERS_1_0, 1290Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 1300Sstevel@tonic-gate { "arg9", DT_IDENT_SCALAR, 0, DIF_VAR_ARG9, DT_ATTR_STABCMN, DT_VERS_1_0, 1310Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 1320Sstevel@tonic-gate { "args", DT_IDENT_ARRAY, 0, DIF_VAR_ARGS, DT_ATTR_STABCMN, DT_VERS_1_0, 1330Sstevel@tonic-gate &dt_idops_args, NULL }, 1340Sstevel@tonic-gate { "avg", DT_IDENT_AGGFUNC, 0, DTRACEAGG_AVG, DT_ATTR_STABCMN, DT_VERS_1_0, 1350Sstevel@tonic-gate &dt_idops_func, "void(@)" }, 1360Sstevel@tonic-gate { "basename", DT_IDENT_FUNC, 0, DIF_SUBR_BASENAME, DT_ATTR_STABCMN, DT_VERS_1_0, 1370Sstevel@tonic-gate &dt_idops_func, "string(const char *)" }, 1380Sstevel@tonic-gate { "bcopy", DT_IDENT_FUNC, 0, DIF_SUBR_BCOPY, DT_ATTR_STABCMN, DT_VERS_1_0, 1390Sstevel@tonic-gate &dt_idops_func, "void(void *, void *, size_t)" }, 1400Sstevel@tonic-gate { "breakpoint", DT_IDENT_ACTFUNC, 0, DT_ACT_BREAKPOINT, 1410Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 1420Sstevel@tonic-gate &dt_idops_func, "void()" }, 1430Sstevel@tonic-gate { "caller", DT_IDENT_SCALAR, 0, DIF_VAR_CALLER, DT_ATTR_STABCMN, DT_VERS_1_0, 1440Sstevel@tonic-gate &dt_idops_type, "uintptr_t" }, 1450Sstevel@tonic-gate { "chill", DT_IDENT_ACTFUNC, 0, DT_ACT_CHILL, DT_ATTR_STABCMN, DT_VERS_1_0, 1460Sstevel@tonic-gate &dt_idops_func, "void(int)" }, 1470Sstevel@tonic-gate { "cleanpath", DT_IDENT_FUNC, 0, DIF_SUBR_CLEANPATH, DT_ATTR_STABCMN, 1480Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "string(const char *)" }, 1490Sstevel@tonic-gate { "clear", DT_IDENT_ACTFUNC, 0, DT_ACT_CLEAR, DT_ATTR_STABCMN, DT_VERS_1_0, 1500Sstevel@tonic-gate &dt_idops_func, "void(...)" }, 1510Sstevel@tonic-gate { "commit", DT_IDENT_ACTFUNC, 0, DT_ACT_COMMIT, DT_ATTR_STABCMN, DT_VERS_1_0, 1520Sstevel@tonic-gate &dt_idops_func, "void(int)" }, 1530Sstevel@tonic-gate { "copyin", DT_IDENT_FUNC, 0, DIF_SUBR_COPYIN, DT_ATTR_STABCMN, DT_VERS_1_0, 1540Sstevel@tonic-gate &dt_idops_func, "void *(uintptr_t, size_t)" }, 1550Sstevel@tonic-gate { "copyinstr", DT_IDENT_FUNC, 0, DIF_SUBR_COPYINSTR, 1560Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 1570Sstevel@tonic-gate &dt_idops_func, "string(uintptr_t, [size_t])" }, 1580Sstevel@tonic-gate { "copyinto", DT_IDENT_FUNC, 0, DIF_SUBR_COPYINTO, DT_ATTR_STABCMN, 1590Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "void(uintptr_t, size_t, void *)" }, 1600Sstevel@tonic-gate { "copyout", DT_IDENT_FUNC, 0, DIF_SUBR_COPYOUT, DT_ATTR_STABCMN, DT_VERS_1_0, 1610Sstevel@tonic-gate &dt_idops_func, "void(void *, uintptr_t, size_t)" }, 1620Sstevel@tonic-gate { "copyoutstr", DT_IDENT_FUNC, 0, DIF_SUBR_COPYOUTSTR, 1630Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 1640Sstevel@tonic-gate &dt_idops_func, "void(char *, uintptr_t, size_t)" }, 1650Sstevel@tonic-gate { "count", DT_IDENT_AGGFUNC, 0, DTRACEAGG_COUNT, DT_ATTR_STABCMN, DT_VERS_1_0, 1660Sstevel@tonic-gate &dt_idops_func, "void()" }, 1670Sstevel@tonic-gate { "curthread", DT_IDENT_SCALAR, 0, DIF_VAR_CURTHREAD, 1680Sstevel@tonic-gate { DTRACE_STABILITY_STABLE, DTRACE_STABILITY_PRIVATE, 1690Sstevel@tonic-gate DTRACE_CLASS_COMMON }, DT_VERS_1_0, 1700Sstevel@tonic-gate &dt_idops_type, "genunix`kthread_t *" }, 1710Sstevel@tonic-gate { "ddi_pathname", DT_IDENT_FUNC, 0, DIF_SUBR_DDI_PATHNAME, 1720Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 1730Sstevel@tonic-gate &dt_idops_func, "string(void *, int64_t)" }, 1740Sstevel@tonic-gate { "denormalize", DT_IDENT_ACTFUNC, 0, DT_ACT_DENORMALIZE, DT_ATTR_STABCMN, 1750Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "void(...)" }, 1760Sstevel@tonic-gate { "dirname", DT_IDENT_FUNC, 0, DIF_SUBR_DIRNAME, DT_ATTR_STABCMN, DT_VERS_1_0, 1770Sstevel@tonic-gate &dt_idops_func, "string(const char *)" }, 1780Sstevel@tonic-gate { "discard", DT_IDENT_ACTFUNC, 0, DT_ACT_DISCARD, DT_ATTR_STABCMN, DT_VERS_1_0, 1790Sstevel@tonic-gate &dt_idops_func, "void(int)" }, 1800Sstevel@tonic-gate { "epid", DT_IDENT_SCALAR, 0, DIF_VAR_EPID, DT_ATTR_STABCMN, DT_VERS_1_0, 1810Sstevel@tonic-gate &dt_idops_type, "uint_t" }, 1820Sstevel@tonic-gate { "execname", DT_IDENT_SCALAR, 0, DIF_VAR_EXECNAME, 1830Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 1840Sstevel@tonic-gate { "exit", DT_IDENT_ACTFUNC, 0, DT_ACT_EXIT, DT_ATTR_STABCMN, DT_VERS_1_0, 1850Sstevel@tonic-gate &dt_idops_func, "void(int)" }, 1860Sstevel@tonic-gate { "freopen", DT_IDENT_ACTFUNC, 0, DT_ACT_FREOPEN, DT_ATTR_STABCMN, 1870Sstevel@tonic-gate DT_VERS_1_1, &dt_idops_func, "void(@, ...)" }, 1880Sstevel@tonic-gate { "ftruncate", DT_IDENT_ACTFUNC, 0, DT_ACT_FTRUNCATE, DT_ATTR_STABCMN, 1890Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "void()" }, 1900Sstevel@tonic-gate { "getmajor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMAJOR, 1910Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 1920Sstevel@tonic-gate &dt_idops_func, "genunix`major_t(genunix`dev_t)" }, 1930Sstevel@tonic-gate { "getminor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMINOR, 1940Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 1950Sstevel@tonic-gate &dt_idops_func, "genunix`minor_t(genunix`dev_t)" }, 1960Sstevel@tonic-gate { "id", DT_IDENT_SCALAR, 0, DIF_VAR_ID, DT_ATTR_STABCMN, DT_VERS_1_0, 1970Sstevel@tonic-gate &dt_idops_type, "uint_t" }, 1980Sstevel@tonic-gate { "index", DT_IDENT_FUNC, 0, DIF_SUBR_INDEX, DT_ATTR_STABCMN, DT_VERS_1_1, 1990Sstevel@tonic-gate &dt_idops_func, "int(const char *, const char *, [int])" }, 2000Sstevel@tonic-gate { "ipl", DT_IDENT_SCALAR, 0, DIF_VAR_IPL, DT_ATTR_STABCMN, DT_VERS_1_0, 2010Sstevel@tonic-gate &dt_idops_type, "uint_t" }, 2020Sstevel@tonic-gate { "jstack", DT_IDENT_ACTFUNC, 0, DT_ACT_JSTACK, DT_ATTR_STABCMN, DT_VERS_1_0, 2030Sstevel@tonic-gate &dt_idops_func, "stack(...)" }, 2040Sstevel@tonic-gate { "lltostr", DT_IDENT_FUNC, 0, DIF_SUBR_LLTOSTR, DT_ATTR_STABCMN, DT_VERS_1_0, 2050Sstevel@tonic-gate &dt_idops_func, "string(int64_t)" }, 2060Sstevel@tonic-gate { "lquantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_LQUANTIZE, 2070Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 2080Sstevel@tonic-gate &dt_idops_func, "void(@, int32_t, int32_t, ...)" }, 2090Sstevel@tonic-gate { "max", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MAX, DT_ATTR_STABCMN, DT_VERS_1_0, 2100Sstevel@tonic-gate &dt_idops_func, "void(@)" }, 2110Sstevel@tonic-gate { "min", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MIN, DT_ATTR_STABCMN, DT_VERS_1_0, 2120Sstevel@tonic-gate &dt_idops_func, "void(@)" }, 2130Sstevel@tonic-gate { "msgdsize", DT_IDENT_FUNC, 0, DIF_SUBR_MSGDSIZE, 2140Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 2150Sstevel@tonic-gate &dt_idops_func, "size_t(mblk_t *)" }, 2160Sstevel@tonic-gate { "msgsize", DT_IDENT_FUNC, 0, DIF_SUBR_MSGSIZE, 2170Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 2180Sstevel@tonic-gate &dt_idops_func, "size_t(mblk_t *)" }, 2190Sstevel@tonic-gate { "mutex_owned", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNED, 2200Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 2210Sstevel@tonic-gate &dt_idops_func, "int(genunix`kmutex_t *)" }, 2220Sstevel@tonic-gate { "mutex_owner", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNER, 2230Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 2240Sstevel@tonic-gate &dt_idops_func, "genunix`kthread_t *(genunix`kmutex_t *)" }, 2250Sstevel@tonic-gate { "mutex_type_adaptive", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_ADAPTIVE, 2260Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 2270Sstevel@tonic-gate &dt_idops_func, "int(genunix`kmutex_t *)" }, 2280Sstevel@tonic-gate { "mutex_type_spin", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_SPIN, 2290Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 2300Sstevel@tonic-gate &dt_idops_func, "int(genunix`kmutex_t *)" }, 2310Sstevel@tonic-gate { "normalize", DT_IDENT_ACTFUNC, 0, DT_ACT_NORMALIZE, DT_ATTR_STABCMN, 2320Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "void(...)" }, 2330Sstevel@tonic-gate { "panic", DT_IDENT_ACTFUNC, 0, DT_ACT_PANIC, DT_ATTR_STABCMN, DT_VERS_1_0, 2340Sstevel@tonic-gate &dt_idops_func, "void()" }, 2350Sstevel@tonic-gate { "pid", DT_IDENT_SCALAR, 0, DIF_VAR_PID, DT_ATTR_STABCMN, DT_VERS_1_0, 2360Sstevel@tonic-gate &dt_idops_type, "pid_t" }, 2370Sstevel@tonic-gate { "printa", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTA, DT_ATTR_STABCMN, DT_VERS_1_0, 2380Sstevel@tonic-gate &dt_idops_func, "void(@, ...)" }, 2390Sstevel@tonic-gate { "printf", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTF, DT_ATTR_STABCMN, DT_VERS_1_0, 2400Sstevel@tonic-gate &dt_idops_func, "void(@, ...)" }, 2410Sstevel@tonic-gate { "probefunc", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEFUNC, 2420Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 2430Sstevel@tonic-gate { "probemod", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEMOD, 2440Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 2450Sstevel@tonic-gate { "probename", DT_IDENT_SCALAR, 0, DIF_VAR_PROBENAME, 2460Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 2470Sstevel@tonic-gate { "probeprov", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEPROV, 2480Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 2490Sstevel@tonic-gate { "progenyof", DT_IDENT_FUNC, 0, DIF_SUBR_PROGENYOF, 2500Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 2510Sstevel@tonic-gate &dt_idops_func, "int(pid_t)" }, 2520Sstevel@tonic-gate { "quantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_QUANTIZE, 2530Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 2540Sstevel@tonic-gate &dt_idops_func, "void(@)" }, 2550Sstevel@tonic-gate { "raise", DT_IDENT_ACTFUNC, 0, DT_ACT_RAISE, DT_ATTR_STABCMN, DT_VERS_1_0, 2560Sstevel@tonic-gate &dt_idops_func, "void(int)" }, 2570Sstevel@tonic-gate { "rand", DT_IDENT_FUNC, 0, DIF_SUBR_RAND, DT_ATTR_STABCMN, DT_VERS_1_0, 2580Sstevel@tonic-gate &dt_idops_func, "int()" }, 2590Sstevel@tonic-gate { "rindex", DT_IDENT_FUNC, 0, DIF_SUBR_RINDEX, DT_ATTR_STABCMN, DT_VERS_1_1, 2600Sstevel@tonic-gate &dt_idops_func, "int(const char *, const char *, [int])" }, 2610Sstevel@tonic-gate { "rw_iswriter", DT_IDENT_FUNC, 0, DIF_SUBR_RW_ISWRITER, 2620Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 2630Sstevel@tonic-gate &dt_idops_func, "int(genunix`krwlock_t *)" }, 2640Sstevel@tonic-gate { "rw_read_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_READ_HELD, 2650Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 2660Sstevel@tonic-gate &dt_idops_func, "int(genunix`krwlock_t *)" }, 2670Sstevel@tonic-gate { "rw_write_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_WRITE_HELD, 2680Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 2690Sstevel@tonic-gate &dt_idops_func, "int(genunix`krwlock_t *)" }, 2700Sstevel@tonic-gate { "self", DT_IDENT_PTR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0, 2710Sstevel@tonic-gate &dt_idops_type, "void" }, 2720Sstevel@tonic-gate { "speculate", DT_IDENT_ACTFUNC, 0, DT_ACT_SPECULATE, 2730Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 2740Sstevel@tonic-gate &dt_idops_func, "void(int)" }, 2750Sstevel@tonic-gate { "speculation", DT_IDENT_FUNC, 0, DIF_SUBR_SPECULATION, 2760Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 2770Sstevel@tonic-gate &dt_idops_func, "int()" }, 2780Sstevel@tonic-gate { "stack", DT_IDENT_ACTFUNC, 0, DT_ACT_STACK, DT_ATTR_STABCMN, DT_VERS_1_0, 2790Sstevel@tonic-gate &dt_idops_func, "stack(...)" }, 2800Sstevel@tonic-gate { "stackdepth", DT_IDENT_SCALAR, 0, DIF_VAR_STACKDEPTH, 2810Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 2820Sstevel@tonic-gate &dt_idops_type, "uint32_t" }, 2830Sstevel@tonic-gate { "stop", DT_IDENT_ACTFUNC, 0, DT_ACT_STOP, DT_ATTR_STABCMN, DT_VERS_1_0, 2840Sstevel@tonic-gate &dt_idops_func, "void()" }, 2850Sstevel@tonic-gate { "strchr", DT_IDENT_FUNC, 0, DIF_SUBR_STRCHR, DT_ATTR_STABCMN, DT_VERS_1_1, 2860Sstevel@tonic-gate &dt_idops_func, "string(const char *, char)" }, 2870Sstevel@tonic-gate { "strlen", DT_IDENT_FUNC, 0, DIF_SUBR_STRLEN, DT_ATTR_STABCMN, DT_VERS_1_0, 2880Sstevel@tonic-gate &dt_idops_func, "size_t(const char *)" }, 2890Sstevel@tonic-gate { "strjoin", DT_IDENT_FUNC, 0, DIF_SUBR_STRJOIN, DT_ATTR_STABCMN, DT_VERS_1_0, 2900Sstevel@tonic-gate &dt_idops_func, "string(const char *, const char *)" }, 2910Sstevel@tonic-gate { "strrchr", DT_IDENT_FUNC, 0, DIF_SUBR_STRRCHR, DT_ATTR_STABCMN, DT_VERS_1_1, 2920Sstevel@tonic-gate &dt_idops_func, "string(const char *, char)" }, 2930Sstevel@tonic-gate { "strstr", DT_IDENT_FUNC, 0, DIF_SUBR_STRSTR, DT_ATTR_STABCMN, DT_VERS_1_1, 2940Sstevel@tonic-gate &dt_idops_func, "string(const char *, const char *)" }, 2950Sstevel@tonic-gate { "strtok", DT_IDENT_FUNC, 0, DIF_SUBR_STRTOK, DT_ATTR_STABCMN, DT_VERS_1_1, 2960Sstevel@tonic-gate &dt_idops_func, "string(const char *, const char *)" }, 2970Sstevel@tonic-gate { "substr", DT_IDENT_FUNC, 0, DIF_SUBR_SUBSTR, DT_ATTR_STABCMN, DT_VERS_1_1, 2980Sstevel@tonic-gate &dt_idops_func, "string(const char *, int, [int])" }, 2990Sstevel@tonic-gate { "sum", DT_IDENT_AGGFUNC, 0, DTRACEAGG_SUM, DT_ATTR_STABCMN, DT_VERS_1_0, 3000Sstevel@tonic-gate &dt_idops_func, "void(@)" }, 3010Sstevel@tonic-gate { "system", DT_IDENT_ACTFUNC, 0, DT_ACT_SYSTEM, DT_ATTR_STABCMN, DT_VERS_1_0, 3020Sstevel@tonic-gate &dt_idops_func, "void(@, ...)" }, 3030Sstevel@tonic-gate { "this", DT_IDENT_PTR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0, 3040Sstevel@tonic-gate &dt_idops_type, "void" }, 3050Sstevel@tonic-gate { "tid", DT_IDENT_SCALAR, 0, DIF_VAR_TID, DT_ATTR_STABCMN, DT_VERS_1_0, 3060Sstevel@tonic-gate &dt_idops_type, "id_t" }, 3070Sstevel@tonic-gate { "timestamp", DT_IDENT_SCALAR, 0, DIF_VAR_TIMESTAMP, 3080Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 3090Sstevel@tonic-gate &dt_idops_type, "uint64_t" }, 3100Sstevel@tonic-gate { "trace", DT_IDENT_ACTFUNC, 0, DT_ACT_TRACE, DT_ATTR_STABCMN, DT_VERS_1_0, 3110Sstevel@tonic-gate &dt_idops_func, "void(@)" }, 3120Sstevel@tonic-gate { "tracemem", DT_IDENT_ACTFUNC, 0, DT_ACT_TRACEMEM, 3130Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 3140Sstevel@tonic-gate &dt_idops_func, "void(@, size_t)" }, 3150Sstevel@tonic-gate { "trunc", DT_IDENT_ACTFUNC, 0, DT_ACT_TRUNC, DT_ATTR_STABCMN, 3160Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "void(...)" }, 3170Sstevel@tonic-gate { "uregs", DT_IDENT_ARRAY, 0, DIF_VAR_UREGS, DT_ATTR_STABCMN, DT_VERS_1_0, 3180Sstevel@tonic-gate &dt_idops_regs, NULL }, 3190Sstevel@tonic-gate { "ustack", DT_IDENT_ACTFUNC, 0, DT_ACT_USTACK, DT_ATTR_STABCMN, DT_VERS_1_0, 3200Sstevel@tonic-gate &dt_idops_func, "stack(...)" }, 321191Sahl { "ustackdepth", DT_IDENT_SCALAR, 0, DIF_VAR_USTACKDEPTH, 322191Sahl DT_ATTR_STABCMN, DT_VERS_1_2, 323191Sahl &dt_idops_type, "uint32_t" }, 3240Sstevel@tonic-gate { "vtimestamp", DT_IDENT_SCALAR, 0, DIF_VAR_VTIMESTAMP, 3250Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 3260Sstevel@tonic-gate &dt_idops_type, "uint64_t" }, 3270Sstevel@tonic-gate { "walltimestamp", DT_IDENT_SCALAR, 0, DIF_VAR_WALLTIMESTAMP, 3280Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 3290Sstevel@tonic-gate &dt_idops_type, "uint64_t" }, 3300Sstevel@tonic-gate { "zonename", DT_IDENT_SCALAR, 0, DIF_VAR_ZONENAME, 3310Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 3320Sstevel@tonic-gate { NULL, 0, 0, 0, { 0, 0, 0 }, 0, NULL, NULL } 3330Sstevel@tonic-gate }; 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate /* 3360Sstevel@tonic-gate * Tables of ILP32 intrinsic integer and floating-point type templates to use 3370Sstevel@tonic-gate * to populate the dynamic "C" CTF type container. 3380Sstevel@tonic-gate */ 3390Sstevel@tonic-gate static const dt_intrinsic_t _dtrace_intrinsics_32[] = { 3400Sstevel@tonic-gate { "void", { CTF_INT_SIGNED, 0, 0 }, CTF_K_INTEGER }, 3410Sstevel@tonic-gate { "signed", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 3420Sstevel@tonic-gate { "unsigned", { 0, 0, 32 }, CTF_K_INTEGER }, 3430Sstevel@tonic-gate { "char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 3440Sstevel@tonic-gate { "short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, 3450Sstevel@tonic-gate { "int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 3460Sstevel@tonic-gate { "long", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 3470Sstevel@tonic-gate { "long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 3480Sstevel@tonic-gate { "signed char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 3490Sstevel@tonic-gate { "signed short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, 3500Sstevel@tonic-gate { "signed int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 3510Sstevel@tonic-gate { "signed long", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 3520Sstevel@tonic-gate { "signed long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 3530Sstevel@tonic-gate { "unsigned char", { CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 3540Sstevel@tonic-gate { "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER }, 3550Sstevel@tonic-gate { "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER }, 3560Sstevel@tonic-gate { "unsigned long", { 0, 0, 32 }, CTF_K_INTEGER }, 3570Sstevel@tonic-gate { "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER }, 3580Sstevel@tonic-gate { "_Bool", { CTF_INT_BOOL, 0, 8 }, CTF_K_INTEGER }, 3590Sstevel@tonic-gate { "float", { CTF_FP_SINGLE, 0, 32 }, CTF_K_FLOAT }, 3600Sstevel@tonic-gate { "double", { CTF_FP_DOUBLE, 0, 64 }, CTF_K_FLOAT }, 3610Sstevel@tonic-gate { "long double", { CTF_FP_LDOUBLE, 0, 128 }, CTF_K_FLOAT }, 3620Sstevel@tonic-gate { "float imaginary", { CTF_FP_IMAGRY, 0, 32 }, CTF_K_FLOAT }, 3630Sstevel@tonic-gate { "double imaginary", { CTF_FP_DIMAGRY, 0, 64 }, CTF_K_FLOAT }, 3640Sstevel@tonic-gate { "long double imaginary", { CTF_FP_LDIMAGRY, 0, 128 }, CTF_K_FLOAT }, 3650Sstevel@tonic-gate { "float complex", { CTF_FP_CPLX, 0, 64 }, CTF_K_FLOAT }, 3660Sstevel@tonic-gate { "double complex", { CTF_FP_DCPLX, 0, 128 }, CTF_K_FLOAT }, 3670Sstevel@tonic-gate { "long double complex", { CTF_FP_LDCPLX, 0, 256 }, CTF_K_FLOAT }, 3680Sstevel@tonic-gate { NULL, { 0, 0, 0 }, 0 } 3690Sstevel@tonic-gate }; 3700Sstevel@tonic-gate 3710Sstevel@tonic-gate /* 3720Sstevel@tonic-gate * Tables of LP64 intrinsic integer and floating-point type templates to use 3730Sstevel@tonic-gate * to populate the dynamic "C" CTF type container. 3740Sstevel@tonic-gate */ 3750Sstevel@tonic-gate static const dt_intrinsic_t _dtrace_intrinsics_64[] = { 3760Sstevel@tonic-gate { "void", { CTF_INT_SIGNED, 0, 0 }, CTF_K_INTEGER }, 3770Sstevel@tonic-gate { "signed", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 3780Sstevel@tonic-gate { "unsigned", { 0, 0, 32 }, CTF_K_INTEGER }, 3790Sstevel@tonic-gate { "char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 3800Sstevel@tonic-gate { "short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, 3810Sstevel@tonic-gate { "int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 3820Sstevel@tonic-gate { "long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 3830Sstevel@tonic-gate { "long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 3840Sstevel@tonic-gate { "signed char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 3850Sstevel@tonic-gate { "signed short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, 3860Sstevel@tonic-gate { "signed int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 3870Sstevel@tonic-gate { "signed long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 3880Sstevel@tonic-gate { "signed long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 3890Sstevel@tonic-gate { "unsigned char", { CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 3900Sstevel@tonic-gate { "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER }, 3910Sstevel@tonic-gate { "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER }, 3920Sstevel@tonic-gate { "unsigned long", { 0, 0, 64 }, CTF_K_INTEGER }, 3930Sstevel@tonic-gate { "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER }, 3940Sstevel@tonic-gate { "_Bool", { CTF_INT_BOOL, 0, 8 }, CTF_K_INTEGER }, 3950Sstevel@tonic-gate { "float", { CTF_FP_SINGLE, 0, 32 }, CTF_K_FLOAT }, 3960Sstevel@tonic-gate { "double", { CTF_FP_DOUBLE, 0, 64 }, CTF_K_FLOAT }, 3970Sstevel@tonic-gate { "long double", { CTF_FP_LDOUBLE, 0, 128 }, CTF_K_FLOAT }, 3980Sstevel@tonic-gate { "float imaginary", { CTF_FP_IMAGRY, 0, 32 }, CTF_K_FLOAT }, 3990Sstevel@tonic-gate { "double imaginary", { CTF_FP_DIMAGRY, 0, 64 }, CTF_K_FLOAT }, 4000Sstevel@tonic-gate { "long double imaginary", { CTF_FP_LDIMAGRY, 0, 128 }, CTF_K_FLOAT }, 4010Sstevel@tonic-gate { "float complex", { CTF_FP_CPLX, 0, 64 }, CTF_K_FLOAT }, 4020Sstevel@tonic-gate { "double complex", { CTF_FP_DCPLX, 0, 128 }, CTF_K_FLOAT }, 4030Sstevel@tonic-gate { "long double complex", { CTF_FP_LDCPLX, 0, 256 }, CTF_K_FLOAT }, 4040Sstevel@tonic-gate { NULL, { 0, 0, 0 }, 0 } 4050Sstevel@tonic-gate }; 4060Sstevel@tonic-gate 4070Sstevel@tonic-gate /* 4080Sstevel@tonic-gate * Tables of ILP32 typedefs to use to populate the dynamic "D" CTF container. 4090Sstevel@tonic-gate * These aliases ensure that D definitions can use typical <sys/types.h> names. 4100Sstevel@tonic-gate */ 4110Sstevel@tonic-gate static const dt_typedef_t _dtrace_typedefs_32[] = { 4120Sstevel@tonic-gate { "char", "int8_t" }, 4130Sstevel@tonic-gate { "short", "int16_t" }, 4140Sstevel@tonic-gate { "int", "int32_t" }, 4150Sstevel@tonic-gate { "long long", "int64_t" }, 4160Sstevel@tonic-gate { "int", "intptr_t" }, 4170Sstevel@tonic-gate { "int", "ssize_t" }, 4180Sstevel@tonic-gate { "unsigned char", "uint8_t" }, 4190Sstevel@tonic-gate { "unsigned short", "uint16_t" }, 4200Sstevel@tonic-gate { "unsigned", "uint32_t" }, 4210Sstevel@tonic-gate { "unsigned long long", "uint64_t" }, 4220Sstevel@tonic-gate { "unsigned char", "uchar_t" }, 4230Sstevel@tonic-gate { "unsigned short", "ushort_t" }, 4240Sstevel@tonic-gate { "unsigned", "uint_t" }, 4250Sstevel@tonic-gate { "unsigned long", "ulong_t" }, 4260Sstevel@tonic-gate { "unsigned long long", "u_longlong_t" }, 4270Sstevel@tonic-gate { "int", "ptrdiff_t" }, 4280Sstevel@tonic-gate { "unsigned", "uintptr_t" }, 4290Sstevel@tonic-gate { "unsigned", "size_t" }, 4300Sstevel@tonic-gate { "long", "id_t" }, 4310Sstevel@tonic-gate { "long", "pid_t" }, 4320Sstevel@tonic-gate { NULL, NULL } 4330Sstevel@tonic-gate }; 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate /* 4360Sstevel@tonic-gate * Tables of LP64 typedefs to use to populate the dynamic "D" CTF container. 4370Sstevel@tonic-gate * These aliases ensure that D definitions can use typical <sys/types.h> names. 4380Sstevel@tonic-gate */ 4390Sstevel@tonic-gate static const dt_typedef_t _dtrace_typedefs_64[] = { 4400Sstevel@tonic-gate { "char", "int8_t" }, 4410Sstevel@tonic-gate { "short", "int16_t" }, 4420Sstevel@tonic-gate { "int", "int32_t" }, 4430Sstevel@tonic-gate { "long", "int64_t" }, 4440Sstevel@tonic-gate { "long", "intptr_t" }, 4450Sstevel@tonic-gate { "long", "ssize_t" }, 4460Sstevel@tonic-gate { "unsigned char", "uint8_t" }, 4470Sstevel@tonic-gate { "unsigned short", "uint16_t" }, 4480Sstevel@tonic-gate { "unsigned", "uint32_t" }, 4490Sstevel@tonic-gate { "unsigned long", "uint64_t" }, 4500Sstevel@tonic-gate { "unsigned char", "uchar_t" }, 4510Sstevel@tonic-gate { "unsigned short", "ushort_t" }, 4520Sstevel@tonic-gate { "unsigned", "uint_t" }, 4530Sstevel@tonic-gate { "unsigned long", "ulong_t" }, 4540Sstevel@tonic-gate { "unsigned long long", "u_longlong_t" }, 4550Sstevel@tonic-gate { "long", "ptrdiff_t" }, 4560Sstevel@tonic-gate { "unsigned long", "uintptr_t" }, 4570Sstevel@tonic-gate { "unsigned long", "size_t" }, 4580Sstevel@tonic-gate { "int", "id_t" }, 4590Sstevel@tonic-gate { "int", "pid_t" }, 4600Sstevel@tonic-gate { NULL, NULL } 4610Sstevel@tonic-gate }; 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate /* 4640Sstevel@tonic-gate * Tables of ILP32 integer type templates used to populate the dtp->dt_ints[] 4650Sstevel@tonic-gate * cache when a new dtrace client open occurs. Values are set by dtrace_open(). 4660Sstevel@tonic-gate */ 4670Sstevel@tonic-gate static const dt_intdesc_t _dtrace_ints_32[] = { 4680Sstevel@tonic-gate { "int", NULL, CTF_ERR, 0x7fffffffULL }, 4690Sstevel@tonic-gate { "unsigned int", NULL, CTF_ERR, 0xffffffffULL }, 4700Sstevel@tonic-gate { "long", NULL, CTF_ERR, 0x7fffffffULL }, 4710Sstevel@tonic-gate { "unsigned long", NULL, CTF_ERR, 0xffffffffULL }, 4720Sstevel@tonic-gate { "long long", NULL, CTF_ERR, 0x7fffffffffffffffULL }, 4730Sstevel@tonic-gate { "unsigned long long", NULL, CTF_ERR, 0xffffffffffffffffULL } 4740Sstevel@tonic-gate }; 4750Sstevel@tonic-gate 4760Sstevel@tonic-gate /* 4770Sstevel@tonic-gate * Tables of LP64 integer type templates used to populate the dtp->dt_ints[] 4780Sstevel@tonic-gate * cache when a new dtrace client open occurs. Values are set by dtrace_open(). 4790Sstevel@tonic-gate */ 4800Sstevel@tonic-gate static const dt_intdesc_t _dtrace_ints_64[] = { 4810Sstevel@tonic-gate { "int", NULL, CTF_ERR, 0x7fffffffULL }, 4820Sstevel@tonic-gate { "unsigned int", NULL, CTF_ERR, 0xffffffffULL }, 4830Sstevel@tonic-gate { "long", NULL, CTF_ERR, 0x7fffffffffffffffULL }, 4840Sstevel@tonic-gate { "unsigned long", NULL, CTF_ERR, 0xffffffffffffffffULL }, 4850Sstevel@tonic-gate { "long long", NULL, CTF_ERR, 0x7fffffffffffffffULL }, 4860Sstevel@tonic-gate { "unsigned long long", NULL, CTF_ERR, 0xffffffffffffffffULL } 4870Sstevel@tonic-gate }; 4880Sstevel@tonic-gate 4890Sstevel@tonic-gate /* 4900Sstevel@tonic-gate * Table of macro variable templates used to populate the macro identifier hash 4910Sstevel@tonic-gate * when a new dtrace client open occurs. Values are set by dtrace_update(). 4920Sstevel@tonic-gate */ 4930Sstevel@tonic-gate static const dt_ident_t _dtrace_macros[] = { 4940Sstevel@tonic-gate { "egid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 4950Sstevel@tonic-gate { "euid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 4960Sstevel@tonic-gate { "gid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 4970Sstevel@tonic-gate { "pid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 4980Sstevel@tonic-gate { "pgid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 4990Sstevel@tonic-gate { "ppid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 5000Sstevel@tonic-gate { "projid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 5010Sstevel@tonic-gate { "sid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 5020Sstevel@tonic-gate { "taskid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 5030Sstevel@tonic-gate { "target", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 5040Sstevel@tonic-gate { "uid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 5050Sstevel@tonic-gate { NULL, 0, 0, 0, { 0, 0, 0 }, 0 } 5060Sstevel@tonic-gate }; 5070Sstevel@tonic-gate 5080Sstevel@tonic-gate /* 5090Sstevel@tonic-gate * Hard-wired definition string to be compiled and cached every time a new 5100Sstevel@tonic-gate * DTrace library handle is initialized. This string should only be used to 5110Sstevel@tonic-gate * contain definitions that should be present regardless of DTRACE_O_NOLIBS. 5120Sstevel@tonic-gate */ 5130Sstevel@tonic-gate static const char _dtrace_hardwire[] = "\ 5140Sstevel@tonic-gate inline long NULL = 0; \n\ 5150Sstevel@tonic-gate #pragma D binding \"1.0\" NULL\n\ 5160Sstevel@tonic-gate "; 5170Sstevel@tonic-gate 5180Sstevel@tonic-gate /* 5190Sstevel@tonic-gate * Default DTrace configuration to use when opening libdtrace DTRACE_O_NODEV. 5200Sstevel@tonic-gate * If DTRACE_O_NODEV is not set, we load the configuration from the kernel. 5210Sstevel@tonic-gate * The use of CTF_MODEL_NATIVE is more subtle than it might appear: we are 5220Sstevel@tonic-gate * relying on the fact that when running dtrace(1M), isaexec will invoke the 5230Sstevel@tonic-gate * binary with the same bitness as the kernel, which is what we want by default 5240Sstevel@tonic-gate * when generating our DIF. The user can override the choice using oflags. 5250Sstevel@tonic-gate */ 5260Sstevel@tonic-gate static const dtrace_conf_t _dtrace_conf = { 5270Sstevel@tonic-gate DIF_VERSION, /* dtc_difversion */ 5280Sstevel@tonic-gate DIF_DIR_NREGS, /* dtc_difintregs */ 5290Sstevel@tonic-gate DIF_DTR_NREGS, /* dtc_diftupregs */ 5300Sstevel@tonic-gate CTF_MODEL_NATIVE /* dtc_ctfmodel */ 5310Sstevel@tonic-gate }; 5320Sstevel@tonic-gate 5330Sstevel@tonic-gate const dtrace_attribute_t _dtrace_maxattr = { 5340Sstevel@tonic-gate DTRACE_STABILITY_MAX, 5350Sstevel@tonic-gate DTRACE_STABILITY_MAX, 5360Sstevel@tonic-gate DTRACE_CLASS_MAX 5370Sstevel@tonic-gate }; 5380Sstevel@tonic-gate 5390Sstevel@tonic-gate const dtrace_attribute_t _dtrace_defattr = { 5400Sstevel@tonic-gate DTRACE_STABILITY_STABLE, 5410Sstevel@tonic-gate DTRACE_STABILITY_STABLE, 5420Sstevel@tonic-gate DTRACE_CLASS_COMMON 5430Sstevel@tonic-gate }; 5440Sstevel@tonic-gate 5450Sstevel@tonic-gate const dtrace_attribute_t _dtrace_symattr = { 5460Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE, 5470Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE, 5480Sstevel@tonic-gate DTRACE_CLASS_UNKNOWN 5490Sstevel@tonic-gate }; 5500Sstevel@tonic-gate 5510Sstevel@tonic-gate const dtrace_attribute_t _dtrace_typattr = { 5520Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE, 5530Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE, 5540Sstevel@tonic-gate DTRACE_CLASS_UNKNOWN 5550Sstevel@tonic-gate }; 5560Sstevel@tonic-gate 5570Sstevel@tonic-gate const dtrace_attribute_t _dtrace_prvattr = { 5580Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE, 5590Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE, 5600Sstevel@tonic-gate DTRACE_CLASS_UNKNOWN 5610Sstevel@tonic-gate }; 5620Sstevel@tonic-gate 5630Sstevel@tonic-gate const dtrace_pattr_t _dtrace_prvdesc = { 5640Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, 5650Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, 5660Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, 5670Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, 5680Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, 5690Sstevel@tonic-gate }; 5700Sstevel@tonic-gate 5710Sstevel@tonic-gate const char *_dtrace_defcpp = "/usr/ccs/lib/cpp"; /* default cpp(1) to invoke */ 5720Sstevel@tonic-gate const char *_dtrace_defld = "/usr/ccs/bin/ld"; /* default ld(1) to invoke */ 5730Sstevel@tonic-gate 5740Sstevel@tonic-gate const char *_dtrace_libdir = "/usr/lib/dtrace"; /* default library directory */ 5750Sstevel@tonic-gate const char *_dtrace_moddir = "dtrace"; /* kernel module directory */ 5760Sstevel@tonic-gate 5770Sstevel@tonic-gate int _dtrace_strbuckets = 211; /* default number of hash buckets (prime) */ 5780Sstevel@tonic-gate int _dtrace_intbuckets = 256; /* default number of integer buckets (Pof2) */ 5790Sstevel@tonic-gate uint_t _dtrace_strsize = 256; /* default size of string intrinsic type */ 5800Sstevel@tonic-gate uint_t _dtrace_stkindent = 14; /* default whitespace indent for stack/ustack */ 5810Sstevel@tonic-gate uint_t _dtrace_pidbuckets = 64; /* default number of pid hash buckets */ 5820Sstevel@tonic-gate uint_t _dtrace_pidlrulim = 8; /* default number of pid handles to cache */ 5830Sstevel@tonic-gate size_t _dtrace_bufsize = 512; /* default dt_buf_create() size */ 5840Sstevel@tonic-gate int _dtrace_argmax = 32; /* default maximum number of probe arguments */ 5850Sstevel@tonic-gate 5860Sstevel@tonic-gate int _dtrace_debug = 0; /* debug messages enabled (off) */ 5870Sstevel@tonic-gate const char *const _dtrace_version = DT_VERS_STRING; /* API version string */ 5880Sstevel@tonic-gate int _dtrace_rdvers = RD_VERSION; /* rtld_db feature version */ 5890Sstevel@tonic-gate 5900Sstevel@tonic-gate typedef struct dt_fdlist { 5910Sstevel@tonic-gate int *df_fds; /* array of provider driver file descriptors */ 5920Sstevel@tonic-gate uint_t df_ents; /* number of valid elements in df_fds[] */ 5930Sstevel@tonic-gate uint_t df_size; /* size of df_fds[] */ 5940Sstevel@tonic-gate } dt_fdlist_t; 5950Sstevel@tonic-gate 5960Sstevel@tonic-gate #pragma init(_dtrace_init) 5970Sstevel@tonic-gate void 5980Sstevel@tonic-gate _dtrace_init(void) 5990Sstevel@tonic-gate { 6000Sstevel@tonic-gate _dtrace_debug = getenv("DTRACE_DEBUG") != NULL; 6010Sstevel@tonic-gate 6020Sstevel@tonic-gate for (; _dtrace_rdvers > 0; _dtrace_rdvers--) { 6030Sstevel@tonic-gate if (rd_init(_dtrace_rdvers) == RD_OK) 6040Sstevel@tonic-gate break; 6050Sstevel@tonic-gate } 6060Sstevel@tonic-gate } 6070Sstevel@tonic-gate 6080Sstevel@tonic-gate static dtrace_hdl_t * 6090Sstevel@tonic-gate set_open_errno(dtrace_hdl_t *dtp, int *errp, int err) 6100Sstevel@tonic-gate { 6110Sstevel@tonic-gate if (dtp != NULL) 6120Sstevel@tonic-gate dtrace_close(dtp); 6130Sstevel@tonic-gate if (errp != NULL) 6140Sstevel@tonic-gate *errp = err; 6150Sstevel@tonic-gate return (NULL); 6160Sstevel@tonic-gate } 6170Sstevel@tonic-gate 6180Sstevel@tonic-gate static void 6190Sstevel@tonic-gate dt_provmod_open(dt_provmod_t **provmod, dt_fdlist_t *dfp, const char *dirname, 6200Sstevel@tonic-gate const char *subdir, const char *isadir) 6210Sstevel@tonic-gate { 6220Sstevel@tonic-gate dt_provmod_t *prov; 6230Sstevel@tonic-gate char path[PATH_MAX]; 6240Sstevel@tonic-gate struct dirent *dp, *ep; 6250Sstevel@tonic-gate DIR *dirp; 6260Sstevel@tonic-gate int fd; 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate if (isadir) { 6290Sstevel@tonic-gate (void) snprintf(path, sizeof (path), "%s/%s/%s", 6300Sstevel@tonic-gate dirname, subdir, isadir); 6310Sstevel@tonic-gate } else { 6320Sstevel@tonic-gate (void) snprintf(path, sizeof (path), "%s/%s", 6330Sstevel@tonic-gate dirname, subdir); 6340Sstevel@tonic-gate } 6350Sstevel@tonic-gate 6360Sstevel@tonic-gate if ((dirp = opendir(path)) == NULL) 6370Sstevel@tonic-gate return; /* failed to open directory; just skip it */ 6380Sstevel@tonic-gate 6390Sstevel@tonic-gate ep = alloca(sizeof (struct dirent) + PATH_MAX + 1); 6400Sstevel@tonic-gate bzero(ep, sizeof (struct dirent) + PATH_MAX + 1); 6410Sstevel@tonic-gate 6420Sstevel@tonic-gate while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) { 6430Sstevel@tonic-gate if (dp->d_name[0] == '.') 6440Sstevel@tonic-gate continue; /* skip "." and ".." */ 6450Sstevel@tonic-gate 6460Sstevel@tonic-gate if (dfp->df_ents == dfp->df_size) { 6470Sstevel@tonic-gate uint_t size = dfp->df_size ? dfp->df_size * 2 : 16; 6480Sstevel@tonic-gate int *fds = realloc(dfp->df_fds, size * sizeof (int)); 6490Sstevel@tonic-gate 6500Sstevel@tonic-gate if (fds == NULL) 6510Sstevel@tonic-gate break; /* skip the rest of this directory */ 6520Sstevel@tonic-gate 6530Sstevel@tonic-gate dfp->df_fds = fds; 6540Sstevel@tonic-gate dfp->df_size = size; 6550Sstevel@tonic-gate } 6560Sstevel@tonic-gate 6570Sstevel@tonic-gate (void) snprintf(path, sizeof (path), 6580Sstevel@tonic-gate "/devices/pseudo/%s@0:%s", dp->d_name, dp->d_name); 6590Sstevel@tonic-gate 6600Sstevel@tonic-gate if ((fd = open(path, O_RDONLY)) == -1) 6610Sstevel@tonic-gate continue; /* failed to open driver; just skip it */ 6620Sstevel@tonic-gate 6630Sstevel@tonic-gate if (((prov = malloc(sizeof (dt_provmod_t))) == NULL) || 6640Sstevel@tonic-gate (prov->dp_name = malloc(strlen(dp->d_name) + 1)) == NULL) { 6650Sstevel@tonic-gate free(prov); 6660Sstevel@tonic-gate (void) close(fd); 6670Sstevel@tonic-gate break; 6680Sstevel@tonic-gate } 6690Sstevel@tonic-gate 6700Sstevel@tonic-gate (void) strcpy(prov->dp_name, dp->d_name); 6710Sstevel@tonic-gate prov->dp_next = *provmod; 6720Sstevel@tonic-gate *provmod = prov; 6730Sstevel@tonic-gate 6740Sstevel@tonic-gate dt_dprintf("opened provider %s\n", dp->d_name); 6750Sstevel@tonic-gate dfp->df_fds[dfp->df_ents++] = fd; 6760Sstevel@tonic-gate } 6770Sstevel@tonic-gate 6780Sstevel@tonic-gate (void) closedir(dirp); 6790Sstevel@tonic-gate } 6800Sstevel@tonic-gate 6810Sstevel@tonic-gate static void 6820Sstevel@tonic-gate dt_provmod_destroy(dt_provmod_t **provmod) 6830Sstevel@tonic-gate { 6840Sstevel@tonic-gate dt_provmod_t *next, *current; 6850Sstevel@tonic-gate 6860Sstevel@tonic-gate for (current = *provmod; current != NULL; current = next) { 6870Sstevel@tonic-gate next = current->dp_next; 6880Sstevel@tonic-gate free(current->dp_name); 6890Sstevel@tonic-gate free(current); 6900Sstevel@tonic-gate } 6910Sstevel@tonic-gate 6920Sstevel@tonic-gate *provmod = NULL; 6930Sstevel@tonic-gate } 6940Sstevel@tonic-gate 6950Sstevel@tonic-gate static const char * 6960Sstevel@tonic-gate dt_get_sysinfo(int cmd, char *buf, size_t len) 6970Sstevel@tonic-gate { 6980Sstevel@tonic-gate ssize_t rv = sysinfo(cmd, buf, len); 6990Sstevel@tonic-gate char *p = buf; 7000Sstevel@tonic-gate 7010Sstevel@tonic-gate if (rv < 0 || rv > len) 7020Sstevel@tonic-gate (void) snprintf(buf, len, "%s", "Unknown"); 7030Sstevel@tonic-gate 7040Sstevel@tonic-gate while ((p = strchr(p, '.')) != NULL) 7050Sstevel@tonic-gate *p++ = '_'; 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate return (buf); 7080Sstevel@tonic-gate } 7090Sstevel@tonic-gate 7100Sstevel@tonic-gate static dtrace_hdl_t * 7110Sstevel@tonic-gate dt_vopen(int version, int flags, int *errp, 7120Sstevel@tonic-gate const dtrace_vector_t *vector, void *arg) 7130Sstevel@tonic-gate { 7140Sstevel@tonic-gate dtrace_hdl_t *dtp = NULL; 7150Sstevel@tonic-gate int dtfd = -1, ftfd = -1, fterr = 0; 7160Sstevel@tonic-gate dtrace_prog_t *pgp; 7170Sstevel@tonic-gate dt_module_t *dmp; 7180Sstevel@tonic-gate dt_provmod_t *provmod = NULL; 7190Sstevel@tonic-gate int i, err; 7200Sstevel@tonic-gate 7210Sstevel@tonic-gate const dt_intrinsic_t *dinp; 7220Sstevel@tonic-gate const dt_typedef_t *dtyp; 7230Sstevel@tonic-gate const dt_ident_t *idp; 7240Sstevel@tonic-gate 7250Sstevel@tonic-gate dtrace_typeinfo_t dtt; 7260Sstevel@tonic-gate ctf_funcinfo_t ctc; 7270Sstevel@tonic-gate ctf_arinfo_t ctr; 7280Sstevel@tonic-gate 7290Sstevel@tonic-gate dt_fdlist_t df = { NULL, 0, 0 }; 7300Sstevel@tonic-gate char *p, *q, *path = NULL; 7310Sstevel@tonic-gate const char *isadir = NULL; 7320Sstevel@tonic-gate int pathlen; 7330Sstevel@tonic-gate 7340Sstevel@tonic-gate char isadef[32], utsdef[32]; 7350Sstevel@tonic-gate char s1[64], s2[64]; 7360Sstevel@tonic-gate 7370Sstevel@tonic-gate if (version <= 0) 7380Sstevel@tonic-gate return (set_open_errno(dtp, errp, EINVAL)); 7390Sstevel@tonic-gate 7400Sstevel@tonic-gate if (version > DTRACE_VERSION) 7410Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_VERSION)); 7420Sstevel@tonic-gate 7430Sstevel@tonic-gate if (flags & ~DTRACE_O_MASK) 7440Sstevel@tonic-gate return (set_open_errno(dtp, errp, EINVAL)); 7450Sstevel@tonic-gate 7460Sstevel@tonic-gate if ((flags & DTRACE_O_LP64) && (flags & DTRACE_O_ILP32)) 7470Sstevel@tonic-gate return (set_open_errno(dtp, errp, EINVAL)); 7480Sstevel@tonic-gate 7490Sstevel@tonic-gate if (vector == NULL && arg != NULL) 7500Sstevel@tonic-gate return (set_open_errno(dtp, errp, EINVAL)); 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate if (elf_version(EV_CURRENT) == EV_NONE) 7530Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_ELFVERSION)); 7540Sstevel@tonic-gate 7550Sstevel@tonic-gate if (vector != NULL || (flags & DTRACE_O_NODEV)) 7560Sstevel@tonic-gate goto alloc; /* do not attempt to open dtrace device */ 7570Sstevel@tonic-gate 7580Sstevel@tonic-gate /* 7590Sstevel@tonic-gate * For each directory in the kernel's module path, build the name of 7600Sstevel@tonic-gate * the corresponding dtrace provider subdirectory and attempt to open a 7610Sstevel@tonic-gate * pseudo-driver whose name matches the name of each provider therein. 7620Sstevel@tonic-gate * We hold them open in the df.df_fds list until we open the DTrace 7630Sstevel@tonic-gate * driver itself, allowing us to see all of the probes provided on this 7640Sstevel@tonic-gate * system. Once we have the DTrace driver open, we can safely close 7650Sstevel@tonic-gate * all the providers now that they have registered with the framework. 7660Sstevel@tonic-gate */ 7670Sstevel@tonic-gate if (sysinfo(SI_ISALIST, isadef, sizeof (isadef)) > 0) { 7680Sstevel@tonic-gate if (strstr(isadef, "sparcv9") != NULL) 7690Sstevel@tonic-gate isadir = "sparcv9"; 7700Sstevel@tonic-gate else if (strstr(isadef, "amd64") != NULL) 7710Sstevel@tonic-gate isadir = "amd64"; 7720Sstevel@tonic-gate } 7730Sstevel@tonic-gate 7740Sstevel@tonic-gate if (modctl(MODGETPATHLEN, NULL, &pathlen) == 0 && 7750Sstevel@tonic-gate (path = malloc(pathlen + 1)) != NULL && 7760Sstevel@tonic-gate modctl(MODGETPATH, NULL, path) == 0) { 7770Sstevel@tonic-gate for (p = path; *p != '\0'; p = q) { 7780Sstevel@tonic-gate if ((q = strchr(p, ' ')) != NULL) 7790Sstevel@tonic-gate *q++ = '\0'; 7800Sstevel@tonic-gate else 7810Sstevel@tonic-gate q = p + strlen(p); 7820Sstevel@tonic-gate dt_provmod_open(&provmod, &df, p, 7830Sstevel@tonic-gate _dtrace_moddir, isadir); 7840Sstevel@tonic-gate } 7850Sstevel@tonic-gate } 7860Sstevel@tonic-gate 7870Sstevel@tonic-gate dtfd = open("/devices/pseudo/dtrace@0:dtrace", O_RDWR); 7880Sstevel@tonic-gate err = errno; /* save errno from opening dtfd */ 7890Sstevel@tonic-gate 7900Sstevel@tonic-gate ftfd = open("/devices/pseudo/fasttrap@0:fasttrap", O_RDWR); 7910Sstevel@tonic-gate fterr = ftfd == -1 ? errno : 0; /* save errno from open ftfd */ 7920Sstevel@tonic-gate 7930Sstevel@tonic-gate while (df.df_ents-- != 0) 7940Sstevel@tonic-gate (void) close(df.df_fds[df.df_ents]); 7950Sstevel@tonic-gate 7960Sstevel@tonic-gate free(df.df_fds); 7970Sstevel@tonic-gate free(path); 7980Sstevel@tonic-gate 7990Sstevel@tonic-gate /* 8000Sstevel@tonic-gate * If we failed to open the dtrace device, fail dtrace_open(). 8010Sstevel@tonic-gate * We convert some kernel errnos to custom libdtrace errnos to 8020Sstevel@tonic-gate * improve the resulting message from the usual strerror(). 8030Sstevel@tonic-gate */ 8040Sstevel@tonic-gate if (dtfd == -1) { 8050Sstevel@tonic-gate dt_provmod_destroy(&provmod); 8060Sstevel@tonic-gate switch (err) { 8070Sstevel@tonic-gate case ENOENT: 8080Sstevel@tonic-gate if (getzoneid() != GLOBAL_ZONEID) 8090Sstevel@tonic-gate err = EDT_ZNOENT; 8100Sstevel@tonic-gate else 8110Sstevel@tonic-gate err = EDT_GNOENT; 8120Sstevel@tonic-gate break; 8130Sstevel@tonic-gate case EBUSY: 8140Sstevel@tonic-gate err = EDT_BUSY; 8150Sstevel@tonic-gate break; 8160Sstevel@tonic-gate case EACCES: 8170Sstevel@tonic-gate err = EDT_ACCESS; 8180Sstevel@tonic-gate break; 8190Sstevel@tonic-gate } 8200Sstevel@tonic-gate return (set_open_errno(dtp, errp, err)); 8210Sstevel@tonic-gate } 8220Sstevel@tonic-gate 8230Sstevel@tonic-gate (void) fcntl(dtfd, F_SETFD, FD_CLOEXEC); 8240Sstevel@tonic-gate (void) fcntl(ftfd, F_SETFD, FD_CLOEXEC); 8250Sstevel@tonic-gate 8260Sstevel@tonic-gate alloc: 8270Sstevel@tonic-gate if ((dtp = malloc(sizeof (dtrace_hdl_t))) == NULL) 8280Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 8290Sstevel@tonic-gate 8300Sstevel@tonic-gate bzero(dtp, sizeof (dtrace_hdl_t)); 8310Sstevel@tonic-gate dtp->dt_oflags = flags; 8320Sstevel@tonic-gate dtp->dt_prcmode = DT_PROC_STOP_PREINIT; 8330Sstevel@tonic-gate dtp->dt_linkmode = DT_LINK_KERNEL; 8340Sstevel@tonic-gate dtp->dt_linktype = DT_LTYP_ELF; 835*265Smws dtp->dt_xlatemode = DT_XL_STATIC; 8360Sstevel@tonic-gate dtp->dt_stdcmode = DT_STDC_XA; 8370Sstevel@tonic-gate dtp->dt_version = version; 8380Sstevel@tonic-gate dtp->dt_fd = dtfd; 8390Sstevel@tonic-gate dtp->dt_ftfd = ftfd; 8400Sstevel@tonic-gate dtp->dt_fterr = fterr; 8410Sstevel@tonic-gate dtp->dt_cdefs_fd = -1; 8420Sstevel@tonic-gate dtp->dt_ddefs_fd = -1; 8430Sstevel@tonic-gate dtp->dt_stdout_fd = -1; 8440Sstevel@tonic-gate dtp->dt_modbuckets = _dtrace_strbuckets; 8450Sstevel@tonic-gate dtp->dt_mods = calloc(dtp->dt_modbuckets, sizeof (dt_module_t *)); 8460Sstevel@tonic-gate dtp->dt_provbuckets = _dtrace_strbuckets; 8470Sstevel@tonic-gate dtp->dt_provs = calloc(dtp->dt_provbuckets, sizeof (dt_provider_t *)); 8480Sstevel@tonic-gate dt_proc_hash_create(dtp); 8490Sstevel@tonic-gate dtp->dt_vmax = DT_VERS_LATEST; 8500Sstevel@tonic-gate dtp->dt_cpp_path = strdup(_dtrace_defcpp); 8510Sstevel@tonic-gate dtp->dt_cpp_argv = malloc(sizeof (char *)); 8520Sstevel@tonic-gate dtp->dt_cpp_argc = 1; 8530Sstevel@tonic-gate dtp->dt_cpp_args = 1; 8540Sstevel@tonic-gate dtp->dt_ld_path = strdup(_dtrace_defld); 8550Sstevel@tonic-gate dtp->dt_provmod = provmod; 8560Sstevel@tonic-gate dtp->dt_vector = vector; 8570Sstevel@tonic-gate dtp->dt_varg = arg; 8580Sstevel@tonic-gate dt_dof_init(dtp); 8590Sstevel@tonic-gate (void) uname(&dtp->dt_uts); 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate if (dtp->dt_mods == NULL || dtp->dt_provs == NULL || 8620Sstevel@tonic-gate dtp->dt_procs == NULL || dtp->dt_ld_path == NULL || 8630Sstevel@tonic-gate dtp->dt_cpp_path == NULL || dtp->dt_cpp_argv == NULL) 8640Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 8650Sstevel@tonic-gate 8660Sstevel@tonic-gate for (i = 0; i < DTRACEOPT_MAX; i++) 8670Sstevel@tonic-gate dtp->dt_options[i] = DTRACEOPT_UNSET; 8680Sstevel@tonic-gate 8690Sstevel@tonic-gate dtp->dt_cpp_argv[0] = (char *)strbasename(dtp->dt_cpp_path); 8700Sstevel@tonic-gate 8710Sstevel@tonic-gate (void) snprintf(isadef, sizeof (isadef), "-D__SUNW_D_%u", 8720Sstevel@tonic-gate (uint_t)(sizeof (void *) * NBBY)); 8730Sstevel@tonic-gate 8740Sstevel@tonic-gate (void) snprintf(utsdef, sizeof (utsdef), "-D__%s_%s", 8750Sstevel@tonic-gate dt_get_sysinfo(SI_SYSNAME, s1, sizeof (s1)), 8760Sstevel@tonic-gate dt_get_sysinfo(SI_RELEASE, s2, sizeof (s2))); 8770Sstevel@tonic-gate 8780Sstevel@tonic-gate if (dt_cpp_add_arg(dtp, "-D__sun") == NULL || 8790Sstevel@tonic-gate dt_cpp_add_arg(dtp, "-D__unix") == NULL || 8800Sstevel@tonic-gate dt_cpp_add_arg(dtp, "-D__SVR4") == NULL || 8810Sstevel@tonic-gate dt_cpp_add_arg(dtp, "-D__SUNW_D=1") == NULL || 8820Sstevel@tonic-gate dt_cpp_add_arg(dtp, isadef) == NULL || 8830Sstevel@tonic-gate dt_cpp_add_arg(dtp, utsdef) == NULL) 8840Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 8850Sstevel@tonic-gate 8860Sstevel@tonic-gate if (flags & DTRACE_O_NODEV) 8870Sstevel@tonic-gate bcopy(&_dtrace_conf, &dtp->dt_conf, sizeof (_dtrace_conf)); 8880Sstevel@tonic-gate else if (dt_ioctl(dtp, DTRACEIOC_CONF, &dtp->dt_conf) != 0) 8890Sstevel@tonic-gate return (set_open_errno(dtp, errp, errno)); 8900Sstevel@tonic-gate 8910Sstevel@tonic-gate if (flags & DTRACE_O_LP64) 8920Sstevel@tonic-gate dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_LP64; 8930Sstevel@tonic-gate else if (flags & DTRACE_O_ILP32) 8940Sstevel@tonic-gate dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_ILP32; 8950Sstevel@tonic-gate 8960Sstevel@tonic-gate #ifdef __sparc 8970Sstevel@tonic-gate /* 8980Sstevel@tonic-gate * On SPARC systems, __sparc is always defined for <sys/isa_defs.h> 8990Sstevel@tonic-gate * and __sparcv9 is defined if we are doing a 64-bit compile. 9000Sstevel@tonic-gate */ 9010Sstevel@tonic-gate if (dt_cpp_add_arg(dtp, "-D__sparc") == NULL) 9020Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 9030Sstevel@tonic-gate 9040Sstevel@tonic-gate if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64 && 9050Sstevel@tonic-gate dt_cpp_add_arg(dtp, "-D__sparcv9") == NULL) 9060Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 9070Sstevel@tonic-gate #endif 9080Sstevel@tonic-gate 9090Sstevel@tonic-gate #ifdef __x86 9100Sstevel@tonic-gate /* 9110Sstevel@tonic-gate * On x86 systems, __i386 is defined for <sys/isa_defs.h> for 32-bit 9120Sstevel@tonic-gate * compiles and __amd64 is defined for 64-bit compiles. Unlike SPARC, 9130Sstevel@tonic-gate * they are defined exclusive of one another (see PSARC 2004/619). 9140Sstevel@tonic-gate */ 9150Sstevel@tonic-gate if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) 9160Sstevel@tonic-gate p = dt_cpp_add_arg(dtp, "-D__amd64"); 9170Sstevel@tonic-gate else 9180Sstevel@tonic-gate p = dt_cpp_add_arg(dtp, "-D__i386"); 9190Sstevel@tonic-gate 9200Sstevel@tonic-gate if (p == NULL) 9210Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 9220Sstevel@tonic-gate #endif 9230Sstevel@tonic-gate 9240Sstevel@tonic-gate if (dtp->dt_conf.dtc_difversion < DIF_VERSION) 9250Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_DIFVERS)); 9260Sstevel@tonic-gate 9270Sstevel@tonic-gate if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32) 9280Sstevel@tonic-gate bcopy(_dtrace_ints_32, dtp->dt_ints, sizeof (_dtrace_ints_32)); 9290Sstevel@tonic-gate else 9300Sstevel@tonic-gate bcopy(_dtrace_ints_64, dtp->dt_ints, sizeof (_dtrace_ints_64)); 9310Sstevel@tonic-gate 9320Sstevel@tonic-gate dtp->dt_macros = dt_idhash_create("macro", NULL, 0, UINT_MAX); 9330Sstevel@tonic-gate dtp->dt_aggs = dt_idhash_create("aggregation", NULL, 0, UINT_MAX); 9340Sstevel@tonic-gate 9350Sstevel@tonic-gate dtp->dt_globals = dt_idhash_create("global", _dtrace_globals, 9360Sstevel@tonic-gate DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX); 9370Sstevel@tonic-gate 9380Sstevel@tonic-gate dtp->dt_tls = dt_idhash_create("thread local", NULL, 9390Sstevel@tonic-gate DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX); 9400Sstevel@tonic-gate 9410Sstevel@tonic-gate if (dtp->dt_macros == NULL || dtp->dt_aggs == NULL || 9420Sstevel@tonic-gate dtp->dt_globals == NULL || dtp->dt_tls == NULL) 9430Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 9440Sstevel@tonic-gate 9450Sstevel@tonic-gate /* 9460Sstevel@tonic-gate * Populate the dt_macros identifier hash table by hand: we can't use 9470Sstevel@tonic-gate * the dt_idhash_populate() mechanism because we're not yet compiling 9480Sstevel@tonic-gate * and dtrace_update() needs to immediately reference these idents. 9490Sstevel@tonic-gate */ 9500Sstevel@tonic-gate for (idp = _dtrace_macros; idp->di_name != NULL; idp++) { 9510Sstevel@tonic-gate if (dt_idhash_insert(dtp->dt_macros, idp->di_name, 9520Sstevel@tonic-gate idp->di_kind, idp->di_flags, idp->di_id, idp->di_attr, 9530Sstevel@tonic-gate idp->di_vers, idp->di_ops ? idp->di_ops : &dt_idops_thaw, 9540Sstevel@tonic-gate idp->di_iarg, 0) == NULL) 9550Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 9560Sstevel@tonic-gate } 9570Sstevel@tonic-gate 9580Sstevel@tonic-gate /* 9590Sstevel@tonic-gate * Update the module list using /system/object and load the values for 9600Sstevel@tonic-gate * the macro variable definitions according to the current process. 9610Sstevel@tonic-gate */ 9620Sstevel@tonic-gate dtrace_update(dtp); 9630Sstevel@tonic-gate 9640Sstevel@tonic-gate /* 9650Sstevel@tonic-gate * Select the intrinsics and typedefs we want based on the data model. 9660Sstevel@tonic-gate * The intrinsics are under "C". The typedefs are added under "D". 9670Sstevel@tonic-gate */ 9680Sstevel@tonic-gate if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32) { 9690Sstevel@tonic-gate dinp = _dtrace_intrinsics_32; 9700Sstevel@tonic-gate dtyp = _dtrace_typedefs_32; 9710Sstevel@tonic-gate } else { 9720Sstevel@tonic-gate dinp = _dtrace_intrinsics_64; 9730Sstevel@tonic-gate dtyp = _dtrace_typedefs_64; 9740Sstevel@tonic-gate } 9750Sstevel@tonic-gate 9760Sstevel@tonic-gate /* 9770Sstevel@tonic-gate * Create a dynamic CTF container under the "C" scope for intrinsic 9780Sstevel@tonic-gate * types and types defined in ANSI-C header files that are included. 9790Sstevel@tonic-gate */ 9800Sstevel@tonic-gate if ((dmp = dtp->dt_cdefs = dt_module_create(dtp, "C")) == NULL) 9810Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 9820Sstevel@tonic-gate 9830Sstevel@tonic-gate if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL) 9840Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 9850Sstevel@tonic-gate 9860Sstevel@tonic-gate dt_dprintf("created CTF container for %s (%p)\n", 9870Sstevel@tonic-gate dmp->dm_name, (void *)dmp->dm_ctfp); 9880Sstevel@tonic-gate 9890Sstevel@tonic-gate (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel); 9900Sstevel@tonic-gate ctf_setspecific(dmp->dm_ctfp, dmp); 9910Sstevel@tonic-gate 9920Sstevel@tonic-gate dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */ 9930Sstevel@tonic-gate dmp->dm_modid = -1; /* no module ID */ 9940Sstevel@tonic-gate 9950Sstevel@tonic-gate /* 9960Sstevel@tonic-gate * Fill the dynamic "C" CTF container with all of the intrinsic 9970Sstevel@tonic-gate * integer and floating-point types appropriate for this data model. 9980Sstevel@tonic-gate */ 9990Sstevel@tonic-gate for (; dinp->din_name != NULL; dinp++) { 10000Sstevel@tonic-gate if (dinp->din_kind == CTF_K_INTEGER) { 10010Sstevel@tonic-gate err = ctf_add_integer(dmp->dm_ctfp, CTF_ADD_ROOT, 10020Sstevel@tonic-gate dinp->din_name, &dinp->din_data); 10030Sstevel@tonic-gate } else { 10040Sstevel@tonic-gate err = ctf_add_float(dmp->dm_ctfp, CTF_ADD_ROOT, 10050Sstevel@tonic-gate dinp->din_name, &dinp->din_data); 10060Sstevel@tonic-gate } 10070Sstevel@tonic-gate 10080Sstevel@tonic-gate if (err == CTF_ERR) { 10090Sstevel@tonic-gate dt_dprintf("failed to add %s to C container: %s\n", 10100Sstevel@tonic-gate dinp->din_name, ctf_errmsg( 10110Sstevel@tonic-gate ctf_errno(dmp->dm_ctfp))); 10120Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 10130Sstevel@tonic-gate } 10140Sstevel@tonic-gate } 10150Sstevel@tonic-gate 10160Sstevel@tonic-gate if (ctf_update(dmp->dm_ctfp) != 0) { 10170Sstevel@tonic-gate dt_dprintf("failed to update C container: %s\n", 10180Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 10190Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 10200Sstevel@tonic-gate } 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate /* 10230Sstevel@tonic-gate * Add intrinsic pointer types that are needed to initialize printf 10240Sstevel@tonic-gate * format dictionary types (see table in dt_printf.c). 10250Sstevel@tonic-gate */ 10260Sstevel@tonic-gate (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, 10270Sstevel@tonic-gate ctf_lookup_by_name(dmp->dm_ctfp, "void")); 10280Sstevel@tonic-gate 10290Sstevel@tonic-gate (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, 10300Sstevel@tonic-gate ctf_lookup_by_name(dmp->dm_ctfp, "char")); 10310Sstevel@tonic-gate 10320Sstevel@tonic-gate (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, 10330Sstevel@tonic-gate ctf_lookup_by_name(dmp->dm_ctfp, "int")); 10340Sstevel@tonic-gate 10350Sstevel@tonic-gate if (ctf_update(dmp->dm_ctfp) != 0) { 10360Sstevel@tonic-gate dt_dprintf("failed to update C container: %s\n", 10370Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 10380Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 10390Sstevel@tonic-gate } 10400Sstevel@tonic-gate 10410Sstevel@tonic-gate /* 10420Sstevel@tonic-gate * Create a dynamic CTF container under the "D" scope for types that 10430Sstevel@tonic-gate * are defined by the D program itself or on-the-fly by the D compiler. 10440Sstevel@tonic-gate * The "D" CTF container is a child of the "C" CTF container. 10450Sstevel@tonic-gate */ 10460Sstevel@tonic-gate if ((dmp = dtp->dt_ddefs = dt_module_create(dtp, "D")) == NULL) 10470Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 10480Sstevel@tonic-gate 10490Sstevel@tonic-gate if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL) 10500Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 10510Sstevel@tonic-gate 10520Sstevel@tonic-gate dt_dprintf("created CTF container for %s (%p)\n", 10530Sstevel@tonic-gate dmp->dm_name, (void *)dmp->dm_ctfp); 10540Sstevel@tonic-gate 10550Sstevel@tonic-gate (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel); 10560Sstevel@tonic-gate ctf_setspecific(dmp->dm_ctfp, dmp); 10570Sstevel@tonic-gate 10580Sstevel@tonic-gate dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */ 10590Sstevel@tonic-gate dmp->dm_modid = -1; /* no module ID */ 10600Sstevel@tonic-gate 10610Sstevel@tonic-gate if (ctf_import(dmp->dm_ctfp, dtp->dt_cdefs->dm_ctfp) == CTF_ERR) { 10620Sstevel@tonic-gate dt_dprintf("failed to import D parent container: %s\n", 10630Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 10640Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 10650Sstevel@tonic-gate } 10660Sstevel@tonic-gate 10670Sstevel@tonic-gate /* 10680Sstevel@tonic-gate * Fill the dynamic "D" CTF container with all of the built-in typedefs 10690Sstevel@tonic-gate * that we need to use for our D variable and function definitions. 10700Sstevel@tonic-gate * This ensures that basic inttypes.h names are always available to us. 10710Sstevel@tonic-gate */ 10720Sstevel@tonic-gate for (; dtyp->dty_src != NULL; dtyp++) { 10730Sstevel@tonic-gate if (ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 10740Sstevel@tonic-gate dtyp->dty_dst, ctf_lookup_by_name(dmp->dm_ctfp, 10750Sstevel@tonic-gate dtyp->dty_src)) == CTF_ERR) { 10760Sstevel@tonic-gate dt_dprintf("failed to add typedef %s %s to D " 10770Sstevel@tonic-gate "container: %s", dtyp->dty_src, dtyp->dty_dst, 10780Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 10790Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 10800Sstevel@tonic-gate } 10810Sstevel@tonic-gate } 10820Sstevel@tonic-gate 10830Sstevel@tonic-gate /* 10840Sstevel@tonic-gate * Insert a CTF ID corresponding to a pointer to a type of kind 10850Sstevel@tonic-gate * CTF_K_FUNCTION we can use in the compiler for function pointers. 10860Sstevel@tonic-gate * CTF treats all function pointers as "int (*)()" so we only need one. 10870Sstevel@tonic-gate */ 10880Sstevel@tonic-gate ctc.ctc_return = ctf_lookup_by_name(dmp->dm_ctfp, "int"); 10890Sstevel@tonic-gate ctc.ctc_argc = 0; 10900Sstevel@tonic-gate ctc.ctc_flags = 0; 10910Sstevel@tonic-gate 10920Sstevel@tonic-gate dtp->dt_type_func = ctf_add_function(dmp->dm_ctfp, 10930Sstevel@tonic-gate CTF_ADD_ROOT, &ctc, NULL); 10940Sstevel@tonic-gate 10950Sstevel@tonic-gate dtp->dt_type_fptr = ctf_add_pointer(dmp->dm_ctfp, 10960Sstevel@tonic-gate CTF_ADD_ROOT, dtp->dt_type_func); 10970Sstevel@tonic-gate 10980Sstevel@tonic-gate /* 10990Sstevel@tonic-gate * We also insert CTF definitions for the special D intrinsic types 11000Sstevel@tonic-gate * string and <DYN> into the D container. The string type is added 11010Sstevel@tonic-gate * as a typedef of char[n]. The <DYN> type is an alias for void. 11020Sstevel@tonic-gate * We compare types to these special CTF ids throughout the compiler. 11030Sstevel@tonic-gate */ 11040Sstevel@tonic-gate ctr.ctr_contents = ctf_lookup_by_name(dmp->dm_ctfp, "char"); 11050Sstevel@tonic-gate ctr.ctr_index = ctf_lookup_by_name(dmp->dm_ctfp, "long"); 11060Sstevel@tonic-gate ctr.ctr_nelems = _dtrace_strsize; 11070Sstevel@tonic-gate 11080Sstevel@tonic-gate dtp->dt_type_str = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 11090Sstevel@tonic-gate "string", ctf_add_array(dmp->dm_ctfp, CTF_ADD_ROOT, &ctr)); 11100Sstevel@tonic-gate 11110Sstevel@tonic-gate dtp->dt_type_dyn = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 11120Sstevel@tonic-gate "<DYN>", ctf_lookup_by_name(dmp->dm_ctfp, "void")); 11130Sstevel@tonic-gate 11140Sstevel@tonic-gate dtp->dt_type_stack = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 11150Sstevel@tonic-gate "stack", ctf_lookup_by_name(dmp->dm_ctfp, "void")); 11160Sstevel@tonic-gate 11170Sstevel@tonic-gate if (dtp->dt_type_func == CTF_ERR || dtp->dt_type_fptr == CTF_ERR || 11180Sstevel@tonic-gate dtp->dt_type_str == CTF_ERR || dtp->dt_type_dyn == CTF_ERR || 11190Sstevel@tonic-gate dtp->dt_type_stack == CTF_ERR) { 11200Sstevel@tonic-gate dt_dprintf("failed to add intrinsic to D container: %s\n", 11210Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 11220Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 11230Sstevel@tonic-gate } 11240Sstevel@tonic-gate 11250Sstevel@tonic-gate if (ctf_update(dmp->dm_ctfp) != 0) { 11260Sstevel@tonic-gate dt_dprintf("failed update D container: %s\n", 11270Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 11280Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 11290Sstevel@tonic-gate } 11300Sstevel@tonic-gate 11310Sstevel@tonic-gate /* 11320Sstevel@tonic-gate * Initialize the integer description table used to convert integer 11330Sstevel@tonic-gate * constants to the appropriate types. Refer to the comments above 11340Sstevel@tonic-gate * dt_node_int() for a complete description of how this table is used. 11350Sstevel@tonic-gate */ 11360Sstevel@tonic-gate for (i = 0; i < sizeof (dtp->dt_ints) / sizeof (dtp->dt_ints[0]); i++) { 11370Sstevel@tonic-gate if (dtrace_lookup_by_type(dtp, DTRACE_OBJ_EVERY, 11380Sstevel@tonic-gate dtp->dt_ints[i].did_name, &dtt) != 0) { 11390Sstevel@tonic-gate dt_dprintf("failed to lookup integer type %s: %s\n", 11400Sstevel@tonic-gate dtp->dt_ints[i].did_name, 11410Sstevel@tonic-gate dtrace_errmsg(dtp, dtrace_errno(dtp))); 11420Sstevel@tonic-gate return (set_open_errno(dtp, errp, dtp->dt_errno)); 11430Sstevel@tonic-gate } 11440Sstevel@tonic-gate dtp->dt_ints[i].did_ctfp = dtt.dtt_ctfp; 11450Sstevel@tonic-gate dtp->dt_ints[i].did_type = dtt.dtt_type; 11460Sstevel@tonic-gate } 11470Sstevel@tonic-gate 11480Sstevel@tonic-gate /* 11490Sstevel@tonic-gate * Now that we've created the "C" and "D" containers, move them to the 11500Sstevel@tonic-gate * start of the module list so that these types and symbols are found 11510Sstevel@tonic-gate * first (for stability) when iterating through the module list. 11520Sstevel@tonic-gate */ 11530Sstevel@tonic-gate dt_list_delete(&dtp->dt_modlist, dtp->dt_ddefs); 11540Sstevel@tonic-gate dt_list_prepend(&dtp->dt_modlist, dtp->dt_ddefs); 11550Sstevel@tonic-gate 11560Sstevel@tonic-gate dt_list_delete(&dtp->dt_modlist, dtp->dt_cdefs); 11570Sstevel@tonic-gate dt_list_prepend(&dtp->dt_modlist, dtp->dt_cdefs); 11580Sstevel@tonic-gate 11590Sstevel@tonic-gate if (dt_pfdict_create(dtp) == -1) 11600Sstevel@tonic-gate return (set_open_errno(dtp, errp, dtp->dt_errno)); 11610Sstevel@tonic-gate 11620Sstevel@tonic-gate /* 11630Sstevel@tonic-gate * If we are opening libdtrace DTRACE_O_NODEV enable C_ZDEFS by default 11640Sstevel@tonic-gate * because without /dev/dtrace open, we will not be able to load the 11650Sstevel@tonic-gate * names and attributes of any providers or probes from the kernel. 11660Sstevel@tonic-gate */ 11670Sstevel@tonic-gate if (flags & DTRACE_O_NODEV) 11680Sstevel@tonic-gate dtp->dt_cflags |= DTRACE_C_ZDEFS; 11690Sstevel@tonic-gate 11700Sstevel@tonic-gate /* 11710Sstevel@tonic-gate * Load hard-wired inlines into the definition cache by calling the 11720Sstevel@tonic-gate * compiler on the raw definition string defined above. 11730Sstevel@tonic-gate */ 11740Sstevel@tonic-gate if ((pgp = dtrace_program_strcompile(dtp, _dtrace_hardwire, 11750Sstevel@tonic-gate DTRACE_PROBESPEC_NONE, DTRACE_C_EMPTY, 0, NULL)) == NULL) { 11760Sstevel@tonic-gate dt_dprintf("failed to load hard-wired definitions: %s\n", 11770Sstevel@tonic-gate dtrace_errmsg(dtp, dtrace_errno(dtp))); 11780Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_HARDWIRE)); 11790Sstevel@tonic-gate } 11800Sstevel@tonic-gate 1181*265Smws dt_program_destroy(dtp, pgp); 11820Sstevel@tonic-gate 11830Sstevel@tonic-gate /* 11840Sstevel@tonic-gate * Set up the default DTrace library path. Once set, the next call to 11850Sstevel@tonic-gate * dt_compile() will compile all the libraries. We intentionally defer 11860Sstevel@tonic-gate * library processing to improve overhead for clients that don't ever 11870Sstevel@tonic-gate * compile, and to provide better error reporting (because the full 11880Sstevel@tonic-gate * reporting of compiler errors requires dtrace_open() to succeed). 11890Sstevel@tonic-gate */ 11900Sstevel@tonic-gate if (dtrace_setopt(dtp, "libdir", _dtrace_libdir) != 0) 11910Sstevel@tonic-gate return (set_open_errno(dtp, errp, dtp->dt_errno)); 11920Sstevel@tonic-gate 11930Sstevel@tonic-gate return (dtp); 11940Sstevel@tonic-gate } 11950Sstevel@tonic-gate 11960Sstevel@tonic-gate dtrace_hdl_t * 11970Sstevel@tonic-gate dtrace_open(int version, int flags, int *errp) 11980Sstevel@tonic-gate { 11990Sstevel@tonic-gate return (dt_vopen(version, flags, errp, NULL, NULL)); 12000Sstevel@tonic-gate } 12010Sstevel@tonic-gate 12020Sstevel@tonic-gate dtrace_hdl_t * 12030Sstevel@tonic-gate dtrace_vopen(int version, int flags, int *errp, 12040Sstevel@tonic-gate const dtrace_vector_t *vector, void *arg) 12050Sstevel@tonic-gate { 12060Sstevel@tonic-gate return (dt_vopen(version, flags, errp, vector, arg)); 12070Sstevel@tonic-gate } 12080Sstevel@tonic-gate 12090Sstevel@tonic-gate void 12100Sstevel@tonic-gate dtrace_close(dtrace_hdl_t *dtp) 12110Sstevel@tonic-gate { 12120Sstevel@tonic-gate dt_ident_t *idp, *ndp; 12130Sstevel@tonic-gate dt_module_t *dmp; 12140Sstevel@tonic-gate dt_provider_t *pvp; 12150Sstevel@tonic-gate dtrace_prog_t *pgp; 12160Sstevel@tonic-gate dt_xlator_t *dxp; 12170Sstevel@tonic-gate dt_dirpath_t *dirp; 12180Sstevel@tonic-gate int i; 12190Sstevel@tonic-gate 12200Sstevel@tonic-gate while ((pgp = dt_list_next(&dtp->dt_programs)) != NULL) 1221*265Smws dt_program_destroy(dtp, pgp); 12220Sstevel@tonic-gate 12230Sstevel@tonic-gate while ((dxp = dt_list_next(&dtp->dt_xlators)) != NULL) 12240Sstevel@tonic-gate dt_xlator_destroy(dtp, dxp); 12250Sstevel@tonic-gate 1226*265Smws dt_free(dtp, dtp->dt_xlatormap); 1227*265Smws 12280Sstevel@tonic-gate for (idp = dtp->dt_externs; idp != NULL; idp = ndp) { 12290Sstevel@tonic-gate ndp = idp->di_next; 12300Sstevel@tonic-gate dt_ident_destroy(idp); 12310Sstevel@tonic-gate } 12320Sstevel@tonic-gate 12330Sstevel@tonic-gate if (dtp->dt_macros != NULL) 12340Sstevel@tonic-gate dt_idhash_destroy(dtp->dt_macros); 12350Sstevel@tonic-gate if (dtp->dt_aggs != NULL) 12360Sstevel@tonic-gate dt_idhash_destroy(dtp->dt_aggs); 12370Sstevel@tonic-gate if (dtp->dt_globals != NULL) 12380Sstevel@tonic-gate dt_idhash_destroy(dtp->dt_globals); 12390Sstevel@tonic-gate if (dtp->dt_tls != NULL) 12400Sstevel@tonic-gate dt_idhash_destroy(dtp->dt_tls); 12410Sstevel@tonic-gate 12420Sstevel@tonic-gate while ((dmp = dt_list_next(&dtp->dt_modlist)) != NULL) 12430Sstevel@tonic-gate dt_module_destroy(dtp, dmp); 12440Sstevel@tonic-gate 12450Sstevel@tonic-gate while ((pvp = dt_list_next(&dtp->dt_provlist)) != NULL) 12460Sstevel@tonic-gate dt_provider_destroy(dtp, pvp); 12470Sstevel@tonic-gate 12480Sstevel@tonic-gate if (dtp->dt_procs != NULL) 12490Sstevel@tonic-gate dt_proc_hash_destroy(dtp); 12500Sstevel@tonic-gate 12510Sstevel@tonic-gate if (dtp->dt_fd != -1) 12520Sstevel@tonic-gate (void) close(dtp->dt_fd); 12530Sstevel@tonic-gate if (dtp->dt_ftfd != -1) 12540Sstevel@tonic-gate (void) close(dtp->dt_ftfd); 12550Sstevel@tonic-gate if (dtp->dt_cdefs_fd != -1) 12560Sstevel@tonic-gate (void) close(dtp->dt_cdefs_fd); 12570Sstevel@tonic-gate if (dtp->dt_ddefs_fd != -1) 12580Sstevel@tonic-gate (void) close(dtp->dt_ddefs_fd); 12590Sstevel@tonic-gate if (dtp->dt_stdout_fd != -1) 12600Sstevel@tonic-gate (void) close(dtp->dt_stdout_fd); 12610Sstevel@tonic-gate 12620Sstevel@tonic-gate dt_epid_destroy(dtp); 12630Sstevel@tonic-gate dt_aggid_destroy(dtp); 12640Sstevel@tonic-gate dt_format_destroy(dtp); 12650Sstevel@tonic-gate dt_buffered_destroy(dtp); 12660Sstevel@tonic-gate dt_aggregate_destroy(dtp); 12670Sstevel@tonic-gate free(dtp->dt_buf.dtbd_data); 12680Sstevel@tonic-gate dt_pfdict_destroy(dtp); 12690Sstevel@tonic-gate dt_provmod_destroy(&dtp->dt_provmod); 12700Sstevel@tonic-gate dt_dof_fini(dtp); 12710Sstevel@tonic-gate 12720Sstevel@tonic-gate for (i = 1; i < dtp->dt_cpp_argc; i++) 12730Sstevel@tonic-gate free(dtp->dt_cpp_argv[i]); 12740Sstevel@tonic-gate 12750Sstevel@tonic-gate while ((dirp = dt_list_next(&dtp->dt_lib_path)) != NULL) { 12760Sstevel@tonic-gate dt_list_delete(&dtp->dt_lib_path, dirp); 12770Sstevel@tonic-gate free(dirp->dir_path); 12780Sstevel@tonic-gate free(dirp); 12790Sstevel@tonic-gate } 12800Sstevel@tonic-gate 12810Sstevel@tonic-gate free(dtp->dt_cpp_argv); 12820Sstevel@tonic-gate free(dtp->dt_cpp_path); 12830Sstevel@tonic-gate free(dtp->dt_ld_path); 12840Sstevel@tonic-gate 12850Sstevel@tonic-gate free(dtp->dt_mods); 12860Sstevel@tonic-gate free(dtp->dt_provs); 12870Sstevel@tonic-gate free(dtp); 12880Sstevel@tonic-gate } 12890Sstevel@tonic-gate 12900Sstevel@tonic-gate int 12910Sstevel@tonic-gate dtrace_go(dtrace_hdl_t *dtp) 12920Sstevel@tonic-gate { 12930Sstevel@tonic-gate void *dof; 12940Sstevel@tonic-gate int err; 12950Sstevel@tonic-gate 12960Sstevel@tonic-gate if (dtp->dt_active) 12970Sstevel@tonic-gate return (dt_set_errno(dtp, EINVAL)); 12980Sstevel@tonic-gate 12990Sstevel@tonic-gate /* 13000Sstevel@tonic-gate * If a dtrace:::ERROR program and callback are registered, enable the 13010Sstevel@tonic-gate * program before we start tracing. If this fails for a vector open 13020Sstevel@tonic-gate * with ENOTTY, we permit dtrace_go() to succeed so that vector clients 13030Sstevel@tonic-gate * such as mdb's dtrace module can execute the rest of dtrace_go() even 13040Sstevel@tonic-gate * though they do not provide support for the DTRACEIOC_ENABLE ioctl. 13050Sstevel@tonic-gate */ 13060Sstevel@tonic-gate if (dtp->dt_errprog != NULL && 13070Sstevel@tonic-gate dtrace_program_exec(dtp, dtp->dt_errprog, NULL) == -1 && ( 13080Sstevel@tonic-gate dtp->dt_errno != ENOTTY || dtp->dt_vector == NULL)) 13090Sstevel@tonic-gate return (-1); /* dt_errno has been set for us */ 13100Sstevel@tonic-gate 13110Sstevel@tonic-gate if ((dof = dtrace_getopt_dof(dtp)) == NULL) 13120Sstevel@tonic-gate return (-1); /* dt_errno has been set for us */ 13130Sstevel@tonic-gate 13140Sstevel@tonic-gate err = dt_ioctl(dtp, DTRACEIOC_ENABLE, dof); 13150Sstevel@tonic-gate dtrace_dof_destroy(dtp, dof); 13160Sstevel@tonic-gate 13170Sstevel@tonic-gate if (err == -1 && (errno != ENOTTY || dtp->dt_vector == NULL)) 13180Sstevel@tonic-gate return (dt_set_errno(dtp, errno)); 13190Sstevel@tonic-gate 13200Sstevel@tonic-gate if (dt_ioctl(dtp, DTRACEIOC_GO, &dtp->dt_beganon) == -1) { 13210Sstevel@tonic-gate if (errno == EACCES) 13220Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_DESTRUCTIVE)); 13230Sstevel@tonic-gate 13240Sstevel@tonic-gate if (errno == EALREADY) 13250Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_ISANON)); 13260Sstevel@tonic-gate 13270Sstevel@tonic-gate if (errno == ENOENT) 13280Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_NOANON)); 13290Sstevel@tonic-gate 13300Sstevel@tonic-gate if (errno == E2BIG) 13310Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_ENDTOOBIG)); 13320Sstevel@tonic-gate 13330Sstevel@tonic-gate if (errno == ENOSPC) 13340Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_BUFTOOSMALL)); 13350Sstevel@tonic-gate 13360Sstevel@tonic-gate return (dt_set_errno(dtp, errno)); 13370Sstevel@tonic-gate } 13380Sstevel@tonic-gate 13390Sstevel@tonic-gate dtp->dt_active = 1; 13400Sstevel@tonic-gate 13410Sstevel@tonic-gate if (dt_options_load(dtp) == -1) 13420Sstevel@tonic-gate return (dt_set_errno(dtp, errno)); 13430Sstevel@tonic-gate 13440Sstevel@tonic-gate return (dt_aggregate_go(dtp)); 13450Sstevel@tonic-gate } 13460Sstevel@tonic-gate 13470Sstevel@tonic-gate int 13480Sstevel@tonic-gate dtrace_stop(dtrace_hdl_t *dtp) 13490Sstevel@tonic-gate { 13500Sstevel@tonic-gate if (dtp->dt_stopped) 13510Sstevel@tonic-gate return (0); 13520Sstevel@tonic-gate 13530Sstevel@tonic-gate if (dt_ioctl(dtp, DTRACEIOC_STOP, &dtp->dt_endedon) == -1) 13540Sstevel@tonic-gate return (dt_set_errno(dtp, errno)); 13550Sstevel@tonic-gate 13560Sstevel@tonic-gate dtp->dt_stopped = 1; 13570Sstevel@tonic-gate 13580Sstevel@tonic-gate return (0); 13590Sstevel@tonic-gate } 13600Sstevel@tonic-gate 13610Sstevel@tonic-gate int 13620Sstevel@tonic-gate dtrace_provider_modules(dtrace_hdl_t *dtp, const char **mods, int nmods) 13630Sstevel@tonic-gate { 13640Sstevel@tonic-gate dt_provmod_t *prov; 13650Sstevel@tonic-gate int i = 0; 13660Sstevel@tonic-gate 13670Sstevel@tonic-gate for (prov = dtp->dt_provmod; prov != NULL; prov = prov->dp_next, i++) { 13680Sstevel@tonic-gate if (i < nmods) 13690Sstevel@tonic-gate mods[i] = prov->dp_name; 13700Sstevel@tonic-gate } 13710Sstevel@tonic-gate 13720Sstevel@tonic-gate return (i); 13730Sstevel@tonic-gate } 13740Sstevel@tonic-gate 13750Sstevel@tonic-gate int 13760Sstevel@tonic-gate dtrace_ctlfd(dtrace_hdl_t *dtp) 13770Sstevel@tonic-gate { 13780Sstevel@tonic-gate return (dtp->dt_fd); 13790Sstevel@tonic-gate } 1380