1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <sys/types.h> 30*0Sstevel@tonic-gate #include <sys/modctl.h> 31*0Sstevel@tonic-gate #include <sys/systeminfo.h> 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #include <libelf.h> 34*0Sstevel@tonic-gate #include <strings.h> 35*0Sstevel@tonic-gate #include <alloca.h> 36*0Sstevel@tonic-gate #include <limits.h> 37*0Sstevel@tonic-gate #include <unistd.h> 38*0Sstevel@tonic-gate #include <stdlib.h> 39*0Sstevel@tonic-gate #include <stdio.h> 40*0Sstevel@tonic-gate #include <fcntl.h> 41*0Sstevel@tonic-gate #include <errno.h> 42*0Sstevel@tonic-gate #include <zone.h> 43*0Sstevel@tonic-gate #include <assert.h> 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gate #define _POSIX_PTHREAD_SEMANTICS 46*0Sstevel@tonic-gate #include <dirent.h> 47*0Sstevel@tonic-gate #undef _POSIX_PTHREAD_SEMANTICS 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate #include <dt_impl.h> 50*0Sstevel@tonic-gate #include <dt_module.h> 51*0Sstevel@tonic-gate #include <dt_printf.h> 52*0Sstevel@tonic-gate #include <dt_string.h> 53*0Sstevel@tonic-gate #include <dt_provider.h> 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate /* 56*0Sstevel@tonic-gate * Stability and versioning definitions. These #defines are used in the tables 57*0Sstevel@tonic-gate * of identifiers below to fill in the attribute and version fields associated 58*0Sstevel@tonic-gate * with each identifier. The DT_ATTR_* macros are a convenience to permit more 59*0Sstevel@tonic-gate * concise declarations of common attributes such as Stable/Stable/Common. The 60*0Sstevel@tonic-gate * DT_VERS_* macros declare the encoded integer values of all versions used so 61*0Sstevel@tonic-gate * far. DT_VERS_LATEST must correspond to the latest version value among all 62*0Sstevel@tonic-gate * versions exported by the D compiler. DT_VERS_STRING must be an ASCII string 63*0Sstevel@tonic-gate * that contains DT_VERS_LATEST within it along with any suffixes (e.g. Beta). 64*0Sstevel@tonic-gate * You must update DT_VERS_LATEST and DT_VERS_STRING when adding a new version, 65*0Sstevel@tonic-gate * and then add the new version to the _dtrace_versions[] array declared below. 66*0Sstevel@tonic-gate * Refer to the Solaris Dynamic Tracing Guide Stability and Versioning chapters 67*0Sstevel@tonic-gate * respectively for an explanation of these DTrace features and their values. 68*0Sstevel@tonic-gate * 69*0Sstevel@tonic-gate * NOTE: Although the DTrace versioning scheme supports the labeling and 70*0Sstevel@tonic-gate * introduction of incompatible changes (e.g. dropping an interface in a 71*0Sstevel@tonic-gate * major release), the libdtrace code does not currently support this. 72*0Sstevel@tonic-gate * All versions are assumed to strictly inherit from one another. If 73*0Sstevel@tonic-gate * we ever need to provide divergent interfaces, this will need work. 74*0Sstevel@tonic-gate */ 75*0Sstevel@tonic-gate #define DT_ATTR_STABCMN { DTRACE_STABILITY_STABLE, \ 76*0Sstevel@tonic-gate DTRACE_STABILITY_STABLE, DTRACE_CLASS_COMMON } 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate #define DT_ATTR_EVOLCMN { DTRACE_STABILITY_EVOLVING, \ 79*0Sstevel@tonic-gate DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON \ 80*0Sstevel@tonic-gate } 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate #define DT_VERS_1_0 DT_VERSION_NUMBER(1, 0, 0) 83*0Sstevel@tonic-gate #define DT_VERS_1_1 DT_VERSION_NUMBER(1, 1, 0) 84*0Sstevel@tonic-gate #define DT_VERS_LATEST DT_VERS_1_1 85*0Sstevel@tonic-gate #define DT_VERS_STRING "Sun D 1.1" 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate const dt_version_t _dtrace_versions[] = { 88*0Sstevel@tonic-gate DT_VERS_1_0, /* D API 1.0.0 (PSARC 2001/466) Solaris 10 FCS */ 89*0Sstevel@tonic-gate DT_VERS_1_1, /* D API 1.1.0 Solaris 10 Update 1 */ 90*0Sstevel@tonic-gate 0 91*0Sstevel@tonic-gate }; 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate /* 94*0Sstevel@tonic-gate * Table of global identifiers. This is used to populate the global identifier 95*0Sstevel@tonic-gate * hash when a new dtrace client open occurs. For more info see dt_ident.h. 96*0Sstevel@tonic-gate * The global identifiers that represent functions use the dt_idops_func ops 97*0Sstevel@tonic-gate * and specify the private data pointer as a prototype string which is parsed 98*0Sstevel@tonic-gate * when the identifier is first encountered. These prototypes look like ANSI 99*0Sstevel@tonic-gate * C function prototypes except that the special symbol "@" can be used as a 100*0Sstevel@tonic-gate * wildcard to represent a single parameter of any type (i.e. any dt_node_t). 101*0Sstevel@tonic-gate * The standard "..." notation can also be used to represent varargs. An empty 102*0Sstevel@tonic-gate * parameter list is taken to mean void (that is, no arguments are permitted). 103*0Sstevel@tonic-gate * A parameter enclosed in square brackets (e.g. "[int]") denotes an optional 104*0Sstevel@tonic-gate * argument. 105*0Sstevel@tonic-gate */ 106*0Sstevel@tonic-gate static const dt_ident_t _dtrace_globals[] = { 107*0Sstevel@tonic-gate { "alloca", DT_IDENT_FUNC, 0, DIF_SUBR_ALLOCA, DT_ATTR_STABCMN, DT_VERS_1_0, 108*0Sstevel@tonic-gate &dt_idops_func, "void *(size_t)" }, 109*0Sstevel@tonic-gate { "arg0", DT_IDENT_SCALAR, 0, DIF_VAR_ARG0, DT_ATTR_STABCMN, DT_VERS_1_0, 110*0Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 111*0Sstevel@tonic-gate { "arg1", DT_IDENT_SCALAR, 0, DIF_VAR_ARG1, DT_ATTR_STABCMN, DT_VERS_1_0, 112*0Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 113*0Sstevel@tonic-gate { "arg2", DT_IDENT_SCALAR, 0, DIF_VAR_ARG2, DT_ATTR_STABCMN, DT_VERS_1_0, 114*0Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 115*0Sstevel@tonic-gate { "arg3", DT_IDENT_SCALAR, 0, DIF_VAR_ARG3, DT_ATTR_STABCMN, DT_VERS_1_0, 116*0Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 117*0Sstevel@tonic-gate { "arg4", DT_IDENT_SCALAR, 0, DIF_VAR_ARG4, DT_ATTR_STABCMN, DT_VERS_1_0, 118*0Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 119*0Sstevel@tonic-gate { "arg5", DT_IDENT_SCALAR, 0, DIF_VAR_ARG5, DT_ATTR_STABCMN, DT_VERS_1_0, 120*0Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 121*0Sstevel@tonic-gate { "arg6", DT_IDENT_SCALAR, 0, DIF_VAR_ARG6, DT_ATTR_STABCMN, DT_VERS_1_0, 122*0Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 123*0Sstevel@tonic-gate { "arg7", DT_IDENT_SCALAR, 0, DIF_VAR_ARG7, DT_ATTR_STABCMN, DT_VERS_1_0, 124*0Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 125*0Sstevel@tonic-gate { "arg8", DT_IDENT_SCALAR, 0, DIF_VAR_ARG8, DT_ATTR_STABCMN, DT_VERS_1_0, 126*0Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 127*0Sstevel@tonic-gate { "arg9", DT_IDENT_SCALAR, 0, DIF_VAR_ARG9, DT_ATTR_STABCMN, DT_VERS_1_0, 128*0Sstevel@tonic-gate &dt_idops_type, "int64_t" }, 129*0Sstevel@tonic-gate { "args", DT_IDENT_ARRAY, 0, DIF_VAR_ARGS, DT_ATTR_STABCMN, DT_VERS_1_0, 130*0Sstevel@tonic-gate &dt_idops_args, NULL }, 131*0Sstevel@tonic-gate { "avg", DT_IDENT_AGGFUNC, 0, DTRACEAGG_AVG, DT_ATTR_STABCMN, DT_VERS_1_0, 132*0Sstevel@tonic-gate &dt_idops_func, "void(@)" }, 133*0Sstevel@tonic-gate { "basename", DT_IDENT_FUNC, 0, DIF_SUBR_BASENAME, DT_ATTR_STABCMN, DT_VERS_1_0, 134*0Sstevel@tonic-gate &dt_idops_func, "string(const char *)" }, 135*0Sstevel@tonic-gate { "bcopy", DT_IDENT_FUNC, 0, DIF_SUBR_BCOPY, DT_ATTR_STABCMN, DT_VERS_1_0, 136*0Sstevel@tonic-gate &dt_idops_func, "void(void *, void *, size_t)" }, 137*0Sstevel@tonic-gate { "breakpoint", DT_IDENT_ACTFUNC, 0, DT_ACT_BREAKPOINT, 138*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 139*0Sstevel@tonic-gate &dt_idops_func, "void()" }, 140*0Sstevel@tonic-gate { "caller", DT_IDENT_SCALAR, 0, DIF_VAR_CALLER, DT_ATTR_STABCMN, DT_VERS_1_0, 141*0Sstevel@tonic-gate &dt_idops_type, "uintptr_t" }, 142*0Sstevel@tonic-gate { "chill", DT_IDENT_ACTFUNC, 0, DT_ACT_CHILL, DT_ATTR_STABCMN, DT_VERS_1_0, 143*0Sstevel@tonic-gate &dt_idops_func, "void(int)" }, 144*0Sstevel@tonic-gate { "cleanpath", DT_IDENT_FUNC, 0, DIF_SUBR_CLEANPATH, DT_ATTR_STABCMN, 145*0Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "string(const char *)" }, 146*0Sstevel@tonic-gate { "clear", DT_IDENT_ACTFUNC, 0, DT_ACT_CLEAR, DT_ATTR_STABCMN, DT_VERS_1_0, 147*0Sstevel@tonic-gate &dt_idops_func, "void(...)" }, 148*0Sstevel@tonic-gate { "commit", DT_IDENT_ACTFUNC, 0, DT_ACT_COMMIT, DT_ATTR_STABCMN, DT_VERS_1_0, 149*0Sstevel@tonic-gate &dt_idops_func, "void(int)" }, 150*0Sstevel@tonic-gate { "copyin", DT_IDENT_FUNC, 0, DIF_SUBR_COPYIN, DT_ATTR_STABCMN, DT_VERS_1_0, 151*0Sstevel@tonic-gate &dt_idops_func, "void *(uintptr_t, size_t)" }, 152*0Sstevel@tonic-gate { "copyinstr", DT_IDENT_FUNC, 0, DIF_SUBR_COPYINSTR, 153*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 154*0Sstevel@tonic-gate &dt_idops_func, "string(uintptr_t, [size_t])" }, 155*0Sstevel@tonic-gate { "copyinto", DT_IDENT_FUNC, 0, DIF_SUBR_COPYINTO, DT_ATTR_STABCMN, 156*0Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "void(uintptr_t, size_t, void *)" }, 157*0Sstevel@tonic-gate { "copyout", DT_IDENT_FUNC, 0, DIF_SUBR_COPYOUT, DT_ATTR_STABCMN, DT_VERS_1_0, 158*0Sstevel@tonic-gate &dt_idops_func, "void(void *, uintptr_t, size_t)" }, 159*0Sstevel@tonic-gate { "copyoutstr", DT_IDENT_FUNC, 0, DIF_SUBR_COPYOUTSTR, 160*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 161*0Sstevel@tonic-gate &dt_idops_func, "void(char *, uintptr_t, size_t)" }, 162*0Sstevel@tonic-gate { "count", DT_IDENT_AGGFUNC, 0, DTRACEAGG_COUNT, DT_ATTR_STABCMN, DT_VERS_1_0, 163*0Sstevel@tonic-gate &dt_idops_func, "void()" }, 164*0Sstevel@tonic-gate { "curthread", DT_IDENT_SCALAR, 0, DIF_VAR_CURTHREAD, 165*0Sstevel@tonic-gate { DTRACE_STABILITY_STABLE, DTRACE_STABILITY_PRIVATE, 166*0Sstevel@tonic-gate DTRACE_CLASS_COMMON }, DT_VERS_1_0, 167*0Sstevel@tonic-gate &dt_idops_type, "genunix`kthread_t *" }, 168*0Sstevel@tonic-gate { "ddi_pathname", DT_IDENT_FUNC, 0, DIF_SUBR_DDI_PATHNAME, 169*0Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 170*0Sstevel@tonic-gate &dt_idops_func, "string(void *, int64_t)" }, 171*0Sstevel@tonic-gate { "denormalize", DT_IDENT_ACTFUNC, 0, DT_ACT_DENORMALIZE, DT_ATTR_STABCMN, 172*0Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "void(...)" }, 173*0Sstevel@tonic-gate { "dirname", DT_IDENT_FUNC, 0, DIF_SUBR_DIRNAME, DT_ATTR_STABCMN, DT_VERS_1_0, 174*0Sstevel@tonic-gate &dt_idops_func, "string(const char *)" }, 175*0Sstevel@tonic-gate { "discard", DT_IDENT_ACTFUNC, 0, DT_ACT_DISCARD, DT_ATTR_STABCMN, DT_VERS_1_0, 176*0Sstevel@tonic-gate &dt_idops_func, "void(int)" }, 177*0Sstevel@tonic-gate { "epid", DT_IDENT_SCALAR, 0, DIF_VAR_EPID, DT_ATTR_STABCMN, DT_VERS_1_0, 178*0Sstevel@tonic-gate &dt_idops_type, "uint_t" }, 179*0Sstevel@tonic-gate { "execname", DT_IDENT_SCALAR, 0, DIF_VAR_EXECNAME, 180*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 181*0Sstevel@tonic-gate { "exit", DT_IDENT_ACTFUNC, 0, DT_ACT_EXIT, DT_ATTR_STABCMN, DT_VERS_1_0, 182*0Sstevel@tonic-gate &dt_idops_func, "void(int)" }, 183*0Sstevel@tonic-gate { "freopen", DT_IDENT_ACTFUNC, 0, DT_ACT_FREOPEN, DT_ATTR_STABCMN, 184*0Sstevel@tonic-gate DT_VERS_1_1, &dt_idops_func, "void(@, ...)" }, 185*0Sstevel@tonic-gate { "ftruncate", DT_IDENT_ACTFUNC, 0, DT_ACT_FTRUNCATE, DT_ATTR_STABCMN, 186*0Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "void()" }, 187*0Sstevel@tonic-gate { "getmajor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMAJOR, 188*0Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 189*0Sstevel@tonic-gate &dt_idops_func, "genunix`major_t(genunix`dev_t)" }, 190*0Sstevel@tonic-gate { "getminor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMINOR, 191*0Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 192*0Sstevel@tonic-gate &dt_idops_func, "genunix`minor_t(genunix`dev_t)" }, 193*0Sstevel@tonic-gate { "id", DT_IDENT_SCALAR, 0, DIF_VAR_ID, DT_ATTR_STABCMN, DT_VERS_1_0, 194*0Sstevel@tonic-gate &dt_idops_type, "uint_t" }, 195*0Sstevel@tonic-gate { "index", DT_IDENT_FUNC, 0, DIF_SUBR_INDEX, DT_ATTR_STABCMN, DT_VERS_1_1, 196*0Sstevel@tonic-gate &dt_idops_func, "int(const char *, const char *, [int])" }, 197*0Sstevel@tonic-gate { "ipl", DT_IDENT_SCALAR, 0, DIF_VAR_IPL, DT_ATTR_STABCMN, DT_VERS_1_0, 198*0Sstevel@tonic-gate &dt_idops_type, "uint_t" }, 199*0Sstevel@tonic-gate { "jstack", DT_IDENT_ACTFUNC, 0, DT_ACT_JSTACK, DT_ATTR_STABCMN, DT_VERS_1_0, 200*0Sstevel@tonic-gate &dt_idops_func, "stack(...)" }, 201*0Sstevel@tonic-gate { "lltostr", DT_IDENT_FUNC, 0, DIF_SUBR_LLTOSTR, DT_ATTR_STABCMN, DT_VERS_1_0, 202*0Sstevel@tonic-gate &dt_idops_func, "string(int64_t)" }, 203*0Sstevel@tonic-gate { "lquantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_LQUANTIZE, 204*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 205*0Sstevel@tonic-gate &dt_idops_func, "void(@, int32_t, int32_t, ...)" }, 206*0Sstevel@tonic-gate { "max", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MAX, DT_ATTR_STABCMN, DT_VERS_1_0, 207*0Sstevel@tonic-gate &dt_idops_func, "void(@)" }, 208*0Sstevel@tonic-gate { "min", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MIN, DT_ATTR_STABCMN, DT_VERS_1_0, 209*0Sstevel@tonic-gate &dt_idops_func, "void(@)" }, 210*0Sstevel@tonic-gate { "msgdsize", DT_IDENT_FUNC, 0, DIF_SUBR_MSGDSIZE, 211*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 212*0Sstevel@tonic-gate &dt_idops_func, "size_t(mblk_t *)" }, 213*0Sstevel@tonic-gate { "msgsize", DT_IDENT_FUNC, 0, DIF_SUBR_MSGSIZE, 214*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 215*0Sstevel@tonic-gate &dt_idops_func, "size_t(mblk_t *)" }, 216*0Sstevel@tonic-gate { "mutex_owned", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNED, 217*0Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 218*0Sstevel@tonic-gate &dt_idops_func, "int(genunix`kmutex_t *)" }, 219*0Sstevel@tonic-gate { "mutex_owner", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNER, 220*0Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 221*0Sstevel@tonic-gate &dt_idops_func, "genunix`kthread_t *(genunix`kmutex_t *)" }, 222*0Sstevel@tonic-gate { "mutex_type_adaptive", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_ADAPTIVE, 223*0Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 224*0Sstevel@tonic-gate &dt_idops_func, "int(genunix`kmutex_t *)" }, 225*0Sstevel@tonic-gate { "mutex_type_spin", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_SPIN, 226*0Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 227*0Sstevel@tonic-gate &dt_idops_func, "int(genunix`kmutex_t *)" }, 228*0Sstevel@tonic-gate { "normalize", DT_IDENT_ACTFUNC, 0, DT_ACT_NORMALIZE, DT_ATTR_STABCMN, 229*0Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "void(...)" }, 230*0Sstevel@tonic-gate { "panic", DT_IDENT_ACTFUNC, 0, DT_ACT_PANIC, DT_ATTR_STABCMN, DT_VERS_1_0, 231*0Sstevel@tonic-gate &dt_idops_func, "void()" }, 232*0Sstevel@tonic-gate { "pid", DT_IDENT_SCALAR, 0, DIF_VAR_PID, DT_ATTR_STABCMN, DT_VERS_1_0, 233*0Sstevel@tonic-gate &dt_idops_type, "pid_t" }, 234*0Sstevel@tonic-gate { "printa", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTA, DT_ATTR_STABCMN, DT_VERS_1_0, 235*0Sstevel@tonic-gate &dt_idops_func, "void(@, ...)" }, 236*0Sstevel@tonic-gate { "printf", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTF, DT_ATTR_STABCMN, DT_VERS_1_0, 237*0Sstevel@tonic-gate &dt_idops_func, "void(@, ...)" }, 238*0Sstevel@tonic-gate { "probefunc", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEFUNC, 239*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 240*0Sstevel@tonic-gate { "probemod", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEMOD, 241*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 242*0Sstevel@tonic-gate { "probename", DT_IDENT_SCALAR, 0, DIF_VAR_PROBENAME, 243*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 244*0Sstevel@tonic-gate { "probeprov", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEPROV, 245*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 246*0Sstevel@tonic-gate { "progenyof", DT_IDENT_FUNC, 0, DIF_SUBR_PROGENYOF, 247*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 248*0Sstevel@tonic-gate &dt_idops_func, "int(pid_t)" }, 249*0Sstevel@tonic-gate { "quantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_QUANTIZE, 250*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 251*0Sstevel@tonic-gate &dt_idops_func, "void(@)" }, 252*0Sstevel@tonic-gate { "raise", DT_IDENT_ACTFUNC, 0, DT_ACT_RAISE, DT_ATTR_STABCMN, DT_VERS_1_0, 253*0Sstevel@tonic-gate &dt_idops_func, "void(int)" }, 254*0Sstevel@tonic-gate { "rand", DT_IDENT_FUNC, 0, DIF_SUBR_RAND, DT_ATTR_STABCMN, DT_VERS_1_0, 255*0Sstevel@tonic-gate &dt_idops_func, "int()" }, 256*0Sstevel@tonic-gate { "rindex", DT_IDENT_FUNC, 0, DIF_SUBR_RINDEX, DT_ATTR_STABCMN, DT_VERS_1_1, 257*0Sstevel@tonic-gate &dt_idops_func, "int(const char *, const char *, [int])" }, 258*0Sstevel@tonic-gate { "rw_iswriter", DT_IDENT_FUNC, 0, DIF_SUBR_RW_ISWRITER, 259*0Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 260*0Sstevel@tonic-gate &dt_idops_func, "int(genunix`krwlock_t *)" }, 261*0Sstevel@tonic-gate { "rw_read_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_READ_HELD, 262*0Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 263*0Sstevel@tonic-gate &dt_idops_func, "int(genunix`krwlock_t *)" }, 264*0Sstevel@tonic-gate { "rw_write_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_WRITE_HELD, 265*0Sstevel@tonic-gate DT_ATTR_EVOLCMN, DT_VERS_1_0, 266*0Sstevel@tonic-gate &dt_idops_func, "int(genunix`krwlock_t *)" }, 267*0Sstevel@tonic-gate { "self", DT_IDENT_PTR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0, 268*0Sstevel@tonic-gate &dt_idops_type, "void" }, 269*0Sstevel@tonic-gate { "speculate", DT_IDENT_ACTFUNC, 0, DT_ACT_SPECULATE, 270*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 271*0Sstevel@tonic-gate &dt_idops_func, "void(int)" }, 272*0Sstevel@tonic-gate { "speculation", DT_IDENT_FUNC, 0, DIF_SUBR_SPECULATION, 273*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 274*0Sstevel@tonic-gate &dt_idops_func, "int()" }, 275*0Sstevel@tonic-gate { "stack", DT_IDENT_ACTFUNC, 0, DT_ACT_STACK, DT_ATTR_STABCMN, DT_VERS_1_0, 276*0Sstevel@tonic-gate &dt_idops_func, "stack(...)" }, 277*0Sstevel@tonic-gate { "stackdepth", DT_IDENT_SCALAR, 0, DIF_VAR_STACKDEPTH, 278*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 279*0Sstevel@tonic-gate &dt_idops_type, "uint32_t" }, 280*0Sstevel@tonic-gate { "stop", DT_IDENT_ACTFUNC, 0, DT_ACT_STOP, DT_ATTR_STABCMN, DT_VERS_1_0, 281*0Sstevel@tonic-gate &dt_idops_func, "void()" }, 282*0Sstevel@tonic-gate { "strchr", DT_IDENT_FUNC, 0, DIF_SUBR_STRCHR, DT_ATTR_STABCMN, DT_VERS_1_1, 283*0Sstevel@tonic-gate &dt_idops_func, "string(const char *, char)" }, 284*0Sstevel@tonic-gate { "strlen", DT_IDENT_FUNC, 0, DIF_SUBR_STRLEN, DT_ATTR_STABCMN, DT_VERS_1_0, 285*0Sstevel@tonic-gate &dt_idops_func, "size_t(const char *)" }, 286*0Sstevel@tonic-gate { "strjoin", DT_IDENT_FUNC, 0, DIF_SUBR_STRJOIN, DT_ATTR_STABCMN, DT_VERS_1_0, 287*0Sstevel@tonic-gate &dt_idops_func, "string(const char *, const char *)" }, 288*0Sstevel@tonic-gate { "strrchr", DT_IDENT_FUNC, 0, DIF_SUBR_STRRCHR, DT_ATTR_STABCMN, DT_VERS_1_1, 289*0Sstevel@tonic-gate &dt_idops_func, "string(const char *, char)" }, 290*0Sstevel@tonic-gate { "strstr", DT_IDENT_FUNC, 0, DIF_SUBR_STRSTR, DT_ATTR_STABCMN, DT_VERS_1_1, 291*0Sstevel@tonic-gate &dt_idops_func, "string(const char *, const char *)" }, 292*0Sstevel@tonic-gate { "strtok", DT_IDENT_FUNC, 0, DIF_SUBR_STRTOK, DT_ATTR_STABCMN, DT_VERS_1_1, 293*0Sstevel@tonic-gate &dt_idops_func, "string(const char *, const char *)" }, 294*0Sstevel@tonic-gate { "substr", DT_IDENT_FUNC, 0, DIF_SUBR_SUBSTR, DT_ATTR_STABCMN, DT_VERS_1_1, 295*0Sstevel@tonic-gate &dt_idops_func, "string(const char *, int, [int])" }, 296*0Sstevel@tonic-gate { "sum", DT_IDENT_AGGFUNC, 0, DTRACEAGG_SUM, DT_ATTR_STABCMN, DT_VERS_1_0, 297*0Sstevel@tonic-gate &dt_idops_func, "void(@)" }, 298*0Sstevel@tonic-gate { "system", DT_IDENT_ACTFUNC, 0, DT_ACT_SYSTEM, DT_ATTR_STABCMN, DT_VERS_1_0, 299*0Sstevel@tonic-gate &dt_idops_func, "void(@, ...)" }, 300*0Sstevel@tonic-gate { "this", DT_IDENT_PTR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0, 301*0Sstevel@tonic-gate &dt_idops_type, "void" }, 302*0Sstevel@tonic-gate { "tid", DT_IDENT_SCALAR, 0, DIF_VAR_TID, DT_ATTR_STABCMN, DT_VERS_1_0, 303*0Sstevel@tonic-gate &dt_idops_type, "id_t" }, 304*0Sstevel@tonic-gate { "timestamp", DT_IDENT_SCALAR, 0, DIF_VAR_TIMESTAMP, 305*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 306*0Sstevel@tonic-gate &dt_idops_type, "uint64_t" }, 307*0Sstevel@tonic-gate { "trace", DT_IDENT_ACTFUNC, 0, DT_ACT_TRACE, DT_ATTR_STABCMN, DT_VERS_1_0, 308*0Sstevel@tonic-gate &dt_idops_func, "void(@)" }, 309*0Sstevel@tonic-gate { "tracemem", DT_IDENT_ACTFUNC, 0, DT_ACT_TRACEMEM, 310*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 311*0Sstevel@tonic-gate &dt_idops_func, "void(@, size_t)" }, 312*0Sstevel@tonic-gate { "trunc", DT_IDENT_ACTFUNC, 0, DT_ACT_TRUNC, DT_ATTR_STABCMN, 313*0Sstevel@tonic-gate DT_VERS_1_0, &dt_idops_func, "void(...)" }, 314*0Sstevel@tonic-gate { "uregs", DT_IDENT_ARRAY, 0, DIF_VAR_UREGS, DT_ATTR_STABCMN, DT_VERS_1_0, 315*0Sstevel@tonic-gate &dt_idops_regs, NULL }, 316*0Sstevel@tonic-gate { "ustack", DT_IDENT_ACTFUNC, 0, DT_ACT_USTACK, DT_ATTR_STABCMN, DT_VERS_1_0, 317*0Sstevel@tonic-gate &dt_idops_func, "stack(...)" }, 318*0Sstevel@tonic-gate { "vtimestamp", DT_IDENT_SCALAR, 0, DIF_VAR_VTIMESTAMP, 319*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 320*0Sstevel@tonic-gate &dt_idops_type, "uint64_t" }, 321*0Sstevel@tonic-gate { "walltimestamp", DT_IDENT_SCALAR, 0, DIF_VAR_WALLTIMESTAMP, 322*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, 323*0Sstevel@tonic-gate &dt_idops_type, "uint64_t" }, 324*0Sstevel@tonic-gate { "zonename", DT_IDENT_SCALAR, 0, DIF_VAR_ZONENAME, 325*0Sstevel@tonic-gate DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 326*0Sstevel@tonic-gate { NULL, 0, 0, 0, { 0, 0, 0 }, 0, NULL, NULL } 327*0Sstevel@tonic-gate }; 328*0Sstevel@tonic-gate 329*0Sstevel@tonic-gate /* 330*0Sstevel@tonic-gate * Tables of ILP32 intrinsic integer and floating-point type templates to use 331*0Sstevel@tonic-gate * to populate the dynamic "C" CTF type container. 332*0Sstevel@tonic-gate */ 333*0Sstevel@tonic-gate static const dt_intrinsic_t _dtrace_intrinsics_32[] = { 334*0Sstevel@tonic-gate { "void", { CTF_INT_SIGNED, 0, 0 }, CTF_K_INTEGER }, 335*0Sstevel@tonic-gate { "signed", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 336*0Sstevel@tonic-gate { "unsigned", { 0, 0, 32 }, CTF_K_INTEGER }, 337*0Sstevel@tonic-gate { "char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 338*0Sstevel@tonic-gate { "short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, 339*0Sstevel@tonic-gate { "int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 340*0Sstevel@tonic-gate { "long", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 341*0Sstevel@tonic-gate { "long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 342*0Sstevel@tonic-gate { "signed char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 343*0Sstevel@tonic-gate { "signed short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, 344*0Sstevel@tonic-gate { "signed int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 345*0Sstevel@tonic-gate { "signed long", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 346*0Sstevel@tonic-gate { "signed long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 347*0Sstevel@tonic-gate { "unsigned char", { CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 348*0Sstevel@tonic-gate { "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER }, 349*0Sstevel@tonic-gate { "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER }, 350*0Sstevel@tonic-gate { "unsigned long", { 0, 0, 32 }, CTF_K_INTEGER }, 351*0Sstevel@tonic-gate { "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER }, 352*0Sstevel@tonic-gate { "_Bool", { CTF_INT_BOOL, 0, 8 }, CTF_K_INTEGER }, 353*0Sstevel@tonic-gate { "float", { CTF_FP_SINGLE, 0, 32 }, CTF_K_FLOAT }, 354*0Sstevel@tonic-gate { "double", { CTF_FP_DOUBLE, 0, 64 }, CTF_K_FLOAT }, 355*0Sstevel@tonic-gate { "long double", { CTF_FP_LDOUBLE, 0, 128 }, CTF_K_FLOAT }, 356*0Sstevel@tonic-gate { "float imaginary", { CTF_FP_IMAGRY, 0, 32 }, CTF_K_FLOAT }, 357*0Sstevel@tonic-gate { "double imaginary", { CTF_FP_DIMAGRY, 0, 64 }, CTF_K_FLOAT }, 358*0Sstevel@tonic-gate { "long double imaginary", { CTF_FP_LDIMAGRY, 0, 128 }, CTF_K_FLOAT }, 359*0Sstevel@tonic-gate { "float complex", { CTF_FP_CPLX, 0, 64 }, CTF_K_FLOAT }, 360*0Sstevel@tonic-gate { "double complex", { CTF_FP_DCPLX, 0, 128 }, CTF_K_FLOAT }, 361*0Sstevel@tonic-gate { "long double complex", { CTF_FP_LDCPLX, 0, 256 }, CTF_K_FLOAT }, 362*0Sstevel@tonic-gate { NULL, { 0, 0, 0 }, 0 } 363*0Sstevel@tonic-gate }; 364*0Sstevel@tonic-gate 365*0Sstevel@tonic-gate /* 366*0Sstevel@tonic-gate * Tables of LP64 intrinsic integer and floating-point type templates to use 367*0Sstevel@tonic-gate * to populate the dynamic "C" CTF type container. 368*0Sstevel@tonic-gate */ 369*0Sstevel@tonic-gate static const dt_intrinsic_t _dtrace_intrinsics_64[] = { 370*0Sstevel@tonic-gate { "void", { CTF_INT_SIGNED, 0, 0 }, CTF_K_INTEGER }, 371*0Sstevel@tonic-gate { "signed", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 372*0Sstevel@tonic-gate { "unsigned", { 0, 0, 32 }, CTF_K_INTEGER }, 373*0Sstevel@tonic-gate { "char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 374*0Sstevel@tonic-gate { "short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, 375*0Sstevel@tonic-gate { "int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 376*0Sstevel@tonic-gate { "long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 377*0Sstevel@tonic-gate { "long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 378*0Sstevel@tonic-gate { "signed char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 379*0Sstevel@tonic-gate { "signed short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, 380*0Sstevel@tonic-gate { "signed int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 381*0Sstevel@tonic-gate { "signed long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 382*0Sstevel@tonic-gate { "signed long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 383*0Sstevel@tonic-gate { "unsigned char", { CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 384*0Sstevel@tonic-gate { "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER }, 385*0Sstevel@tonic-gate { "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER }, 386*0Sstevel@tonic-gate { "unsigned long", { 0, 0, 64 }, CTF_K_INTEGER }, 387*0Sstevel@tonic-gate { "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER }, 388*0Sstevel@tonic-gate { "_Bool", { CTF_INT_BOOL, 0, 8 }, CTF_K_INTEGER }, 389*0Sstevel@tonic-gate { "float", { CTF_FP_SINGLE, 0, 32 }, CTF_K_FLOAT }, 390*0Sstevel@tonic-gate { "double", { CTF_FP_DOUBLE, 0, 64 }, CTF_K_FLOAT }, 391*0Sstevel@tonic-gate { "long double", { CTF_FP_LDOUBLE, 0, 128 }, CTF_K_FLOAT }, 392*0Sstevel@tonic-gate { "float imaginary", { CTF_FP_IMAGRY, 0, 32 }, CTF_K_FLOAT }, 393*0Sstevel@tonic-gate { "double imaginary", { CTF_FP_DIMAGRY, 0, 64 }, CTF_K_FLOAT }, 394*0Sstevel@tonic-gate { "long double imaginary", { CTF_FP_LDIMAGRY, 0, 128 }, CTF_K_FLOAT }, 395*0Sstevel@tonic-gate { "float complex", { CTF_FP_CPLX, 0, 64 }, CTF_K_FLOAT }, 396*0Sstevel@tonic-gate { "double complex", { CTF_FP_DCPLX, 0, 128 }, CTF_K_FLOAT }, 397*0Sstevel@tonic-gate { "long double complex", { CTF_FP_LDCPLX, 0, 256 }, CTF_K_FLOAT }, 398*0Sstevel@tonic-gate { NULL, { 0, 0, 0 }, 0 } 399*0Sstevel@tonic-gate }; 400*0Sstevel@tonic-gate 401*0Sstevel@tonic-gate /* 402*0Sstevel@tonic-gate * Tables of ILP32 typedefs to use to populate the dynamic "D" CTF container. 403*0Sstevel@tonic-gate * These aliases ensure that D definitions can use typical <sys/types.h> names. 404*0Sstevel@tonic-gate */ 405*0Sstevel@tonic-gate static const dt_typedef_t _dtrace_typedefs_32[] = { 406*0Sstevel@tonic-gate { "char", "int8_t" }, 407*0Sstevel@tonic-gate { "short", "int16_t" }, 408*0Sstevel@tonic-gate { "int", "int32_t" }, 409*0Sstevel@tonic-gate { "long long", "int64_t" }, 410*0Sstevel@tonic-gate { "int", "intptr_t" }, 411*0Sstevel@tonic-gate { "int", "ssize_t" }, 412*0Sstevel@tonic-gate { "unsigned char", "uint8_t" }, 413*0Sstevel@tonic-gate { "unsigned short", "uint16_t" }, 414*0Sstevel@tonic-gate { "unsigned", "uint32_t" }, 415*0Sstevel@tonic-gate { "unsigned long long", "uint64_t" }, 416*0Sstevel@tonic-gate { "unsigned char", "uchar_t" }, 417*0Sstevel@tonic-gate { "unsigned short", "ushort_t" }, 418*0Sstevel@tonic-gate { "unsigned", "uint_t" }, 419*0Sstevel@tonic-gate { "unsigned long", "ulong_t" }, 420*0Sstevel@tonic-gate { "unsigned long long", "u_longlong_t" }, 421*0Sstevel@tonic-gate { "int", "ptrdiff_t" }, 422*0Sstevel@tonic-gate { "unsigned", "uintptr_t" }, 423*0Sstevel@tonic-gate { "unsigned", "size_t" }, 424*0Sstevel@tonic-gate { "long", "id_t" }, 425*0Sstevel@tonic-gate { "long", "pid_t" }, 426*0Sstevel@tonic-gate { NULL, NULL } 427*0Sstevel@tonic-gate }; 428*0Sstevel@tonic-gate 429*0Sstevel@tonic-gate /* 430*0Sstevel@tonic-gate * Tables of LP64 typedefs to use to populate the dynamic "D" CTF container. 431*0Sstevel@tonic-gate * These aliases ensure that D definitions can use typical <sys/types.h> names. 432*0Sstevel@tonic-gate */ 433*0Sstevel@tonic-gate static const dt_typedef_t _dtrace_typedefs_64[] = { 434*0Sstevel@tonic-gate { "char", "int8_t" }, 435*0Sstevel@tonic-gate { "short", "int16_t" }, 436*0Sstevel@tonic-gate { "int", "int32_t" }, 437*0Sstevel@tonic-gate { "long", "int64_t" }, 438*0Sstevel@tonic-gate { "long", "intptr_t" }, 439*0Sstevel@tonic-gate { "long", "ssize_t" }, 440*0Sstevel@tonic-gate { "unsigned char", "uint8_t" }, 441*0Sstevel@tonic-gate { "unsigned short", "uint16_t" }, 442*0Sstevel@tonic-gate { "unsigned", "uint32_t" }, 443*0Sstevel@tonic-gate { "unsigned long", "uint64_t" }, 444*0Sstevel@tonic-gate { "unsigned char", "uchar_t" }, 445*0Sstevel@tonic-gate { "unsigned short", "ushort_t" }, 446*0Sstevel@tonic-gate { "unsigned", "uint_t" }, 447*0Sstevel@tonic-gate { "unsigned long", "ulong_t" }, 448*0Sstevel@tonic-gate { "unsigned long long", "u_longlong_t" }, 449*0Sstevel@tonic-gate { "long", "ptrdiff_t" }, 450*0Sstevel@tonic-gate { "unsigned long", "uintptr_t" }, 451*0Sstevel@tonic-gate { "unsigned long", "size_t" }, 452*0Sstevel@tonic-gate { "int", "id_t" }, 453*0Sstevel@tonic-gate { "int", "pid_t" }, 454*0Sstevel@tonic-gate { NULL, NULL } 455*0Sstevel@tonic-gate }; 456*0Sstevel@tonic-gate 457*0Sstevel@tonic-gate /* 458*0Sstevel@tonic-gate * Tables of ILP32 integer type templates used to populate the dtp->dt_ints[] 459*0Sstevel@tonic-gate * cache when a new dtrace client open occurs. Values are set by dtrace_open(). 460*0Sstevel@tonic-gate */ 461*0Sstevel@tonic-gate static const dt_intdesc_t _dtrace_ints_32[] = { 462*0Sstevel@tonic-gate { "int", NULL, CTF_ERR, 0x7fffffffULL }, 463*0Sstevel@tonic-gate { "unsigned int", NULL, CTF_ERR, 0xffffffffULL }, 464*0Sstevel@tonic-gate { "long", NULL, CTF_ERR, 0x7fffffffULL }, 465*0Sstevel@tonic-gate { "unsigned long", NULL, CTF_ERR, 0xffffffffULL }, 466*0Sstevel@tonic-gate { "long long", NULL, CTF_ERR, 0x7fffffffffffffffULL }, 467*0Sstevel@tonic-gate { "unsigned long long", NULL, CTF_ERR, 0xffffffffffffffffULL } 468*0Sstevel@tonic-gate }; 469*0Sstevel@tonic-gate 470*0Sstevel@tonic-gate /* 471*0Sstevel@tonic-gate * Tables of LP64 integer type templates used to populate the dtp->dt_ints[] 472*0Sstevel@tonic-gate * cache when a new dtrace client open occurs. Values are set by dtrace_open(). 473*0Sstevel@tonic-gate */ 474*0Sstevel@tonic-gate static const dt_intdesc_t _dtrace_ints_64[] = { 475*0Sstevel@tonic-gate { "int", NULL, CTF_ERR, 0x7fffffffULL }, 476*0Sstevel@tonic-gate { "unsigned int", NULL, CTF_ERR, 0xffffffffULL }, 477*0Sstevel@tonic-gate { "long", NULL, CTF_ERR, 0x7fffffffffffffffULL }, 478*0Sstevel@tonic-gate { "unsigned long", NULL, CTF_ERR, 0xffffffffffffffffULL }, 479*0Sstevel@tonic-gate { "long long", NULL, CTF_ERR, 0x7fffffffffffffffULL }, 480*0Sstevel@tonic-gate { "unsigned long long", NULL, CTF_ERR, 0xffffffffffffffffULL } 481*0Sstevel@tonic-gate }; 482*0Sstevel@tonic-gate 483*0Sstevel@tonic-gate /* 484*0Sstevel@tonic-gate * Table of macro variable templates used to populate the macro identifier hash 485*0Sstevel@tonic-gate * when a new dtrace client open occurs. Values are set by dtrace_update(). 486*0Sstevel@tonic-gate */ 487*0Sstevel@tonic-gate static const dt_ident_t _dtrace_macros[] = { 488*0Sstevel@tonic-gate { "egid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 489*0Sstevel@tonic-gate { "euid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 490*0Sstevel@tonic-gate { "gid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 491*0Sstevel@tonic-gate { "pid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 492*0Sstevel@tonic-gate { "pgid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 493*0Sstevel@tonic-gate { "ppid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 494*0Sstevel@tonic-gate { "projid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 495*0Sstevel@tonic-gate { "sid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 496*0Sstevel@tonic-gate { "taskid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 497*0Sstevel@tonic-gate { "target", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 498*0Sstevel@tonic-gate { "uid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 499*0Sstevel@tonic-gate { NULL, 0, 0, 0, { 0, 0, 0 }, 0 } 500*0Sstevel@tonic-gate }; 501*0Sstevel@tonic-gate 502*0Sstevel@tonic-gate /* 503*0Sstevel@tonic-gate * Hard-wired definition string to be compiled and cached every time a new 504*0Sstevel@tonic-gate * DTrace library handle is initialized. This string should only be used to 505*0Sstevel@tonic-gate * contain definitions that should be present regardless of DTRACE_O_NOLIBS. 506*0Sstevel@tonic-gate */ 507*0Sstevel@tonic-gate static const char _dtrace_hardwire[] = "\ 508*0Sstevel@tonic-gate inline long NULL = 0; \n\ 509*0Sstevel@tonic-gate #pragma D binding \"1.0\" NULL\n\ 510*0Sstevel@tonic-gate "; 511*0Sstevel@tonic-gate 512*0Sstevel@tonic-gate /* 513*0Sstevel@tonic-gate * Default DTrace configuration to use when opening libdtrace DTRACE_O_NODEV. 514*0Sstevel@tonic-gate * If DTRACE_O_NODEV is not set, we load the configuration from the kernel. 515*0Sstevel@tonic-gate * The use of CTF_MODEL_NATIVE is more subtle than it might appear: we are 516*0Sstevel@tonic-gate * relying on the fact that when running dtrace(1M), isaexec will invoke the 517*0Sstevel@tonic-gate * binary with the same bitness as the kernel, which is what we want by default 518*0Sstevel@tonic-gate * when generating our DIF. The user can override the choice using oflags. 519*0Sstevel@tonic-gate */ 520*0Sstevel@tonic-gate static const dtrace_conf_t _dtrace_conf = { 521*0Sstevel@tonic-gate DIF_VERSION, /* dtc_difversion */ 522*0Sstevel@tonic-gate DIF_DIR_NREGS, /* dtc_difintregs */ 523*0Sstevel@tonic-gate DIF_DTR_NREGS, /* dtc_diftupregs */ 524*0Sstevel@tonic-gate CTF_MODEL_NATIVE /* dtc_ctfmodel */ 525*0Sstevel@tonic-gate }; 526*0Sstevel@tonic-gate 527*0Sstevel@tonic-gate const dtrace_attribute_t _dtrace_maxattr = { 528*0Sstevel@tonic-gate DTRACE_STABILITY_MAX, 529*0Sstevel@tonic-gate DTRACE_STABILITY_MAX, 530*0Sstevel@tonic-gate DTRACE_CLASS_MAX 531*0Sstevel@tonic-gate }; 532*0Sstevel@tonic-gate 533*0Sstevel@tonic-gate const dtrace_attribute_t _dtrace_defattr = { 534*0Sstevel@tonic-gate DTRACE_STABILITY_STABLE, 535*0Sstevel@tonic-gate DTRACE_STABILITY_STABLE, 536*0Sstevel@tonic-gate DTRACE_CLASS_COMMON 537*0Sstevel@tonic-gate }; 538*0Sstevel@tonic-gate 539*0Sstevel@tonic-gate const dtrace_attribute_t _dtrace_symattr = { 540*0Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE, 541*0Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE, 542*0Sstevel@tonic-gate DTRACE_CLASS_UNKNOWN 543*0Sstevel@tonic-gate }; 544*0Sstevel@tonic-gate 545*0Sstevel@tonic-gate const dtrace_attribute_t _dtrace_typattr = { 546*0Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE, 547*0Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE, 548*0Sstevel@tonic-gate DTRACE_CLASS_UNKNOWN 549*0Sstevel@tonic-gate }; 550*0Sstevel@tonic-gate 551*0Sstevel@tonic-gate const dtrace_attribute_t _dtrace_prvattr = { 552*0Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE, 553*0Sstevel@tonic-gate DTRACE_STABILITY_PRIVATE, 554*0Sstevel@tonic-gate DTRACE_CLASS_UNKNOWN 555*0Sstevel@tonic-gate }; 556*0Sstevel@tonic-gate 557*0Sstevel@tonic-gate const dtrace_pattr_t _dtrace_prvdesc = { 558*0Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, 559*0Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, 560*0Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, 561*0Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, 562*0Sstevel@tonic-gate { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, 563*0Sstevel@tonic-gate }; 564*0Sstevel@tonic-gate 565*0Sstevel@tonic-gate const char *_dtrace_defcpp = "/usr/ccs/lib/cpp"; /* default cpp(1) to invoke */ 566*0Sstevel@tonic-gate const char *_dtrace_defld = "/usr/ccs/bin/ld"; /* default ld(1) to invoke */ 567*0Sstevel@tonic-gate 568*0Sstevel@tonic-gate const char *_dtrace_libdir = "/usr/lib/dtrace"; /* default library directory */ 569*0Sstevel@tonic-gate const char *_dtrace_moddir = "dtrace"; /* kernel module directory */ 570*0Sstevel@tonic-gate 571*0Sstevel@tonic-gate int _dtrace_strbuckets = 211; /* default number of hash buckets (prime) */ 572*0Sstevel@tonic-gate int _dtrace_intbuckets = 256; /* default number of integer buckets (Pof2) */ 573*0Sstevel@tonic-gate uint_t _dtrace_strsize = 256; /* default size of string intrinsic type */ 574*0Sstevel@tonic-gate uint_t _dtrace_stkindent = 14; /* default whitespace indent for stack/ustack */ 575*0Sstevel@tonic-gate uint_t _dtrace_pidbuckets = 64; /* default number of pid hash buckets */ 576*0Sstevel@tonic-gate uint_t _dtrace_pidlrulim = 8; /* default number of pid handles to cache */ 577*0Sstevel@tonic-gate size_t _dtrace_bufsize = 512; /* default dt_buf_create() size */ 578*0Sstevel@tonic-gate int _dtrace_argmax = 32; /* default maximum number of probe arguments */ 579*0Sstevel@tonic-gate 580*0Sstevel@tonic-gate int _dtrace_debug = 0; /* debug messages enabled (off) */ 581*0Sstevel@tonic-gate const char *const _dtrace_version = DT_VERS_STRING; /* API version string */ 582*0Sstevel@tonic-gate int _dtrace_rdvers = RD_VERSION; /* rtld_db feature version */ 583*0Sstevel@tonic-gate 584*0Sstevel@tonic-gate typedef struct dt_fdlist { 585*0Sstevel@tonic-gate int *df_fds; /* array of provider driver file descriptors */ 586*0Sstevel@tonic-gate uint_t df_ents; /* number of valid elements in df_fds[] */ 587*0Sstevel@tonic-gate uint_t df_size; /* size of df_fds[] */ 588*0Sstevel@tonic-gate } dt_fdlist_t; 589*0Sstevel@tonic-gate 590*0Sstevel@tonic-gate #pragma init(_dtrace_init) 591*0Sstevel@tonic-gate void 592*0Sstevel@tonic-gate _dtrace_init(void) 593*0Sstevel@tonic-gate { 594*0Sstevel@tonic-gate _dtrace_debug = getenv("DTRACE_DEBUG") != NULL; 595*0Sstevel@tonic-gate 596*0Sstevel@tonic-gate for (; _dtrace_rdvers > 0; _dtrace_rdvers--) { 597*0Sstevel@tonic-gate if (rd_init(_dtrace_rdvers) == RD_OK) 598*0Sstevel@tonic-gate break; 599*0Sstevel@tonic-gate } 600*0Sstevel@tonic-gate } 601*0Sstevel@tonic-gate 602*0Sstevel@tonic-gate static dtrace_hdl_t * 603*0Sstevel@tonic-gate set_open_errno(dtrace_hdl_t *dtp, int *errp, int err) 604*0Sstevel@tonic-gate { 605*0Sstevel@tonic-gate if (dtp != NULL) 606*0Sstevel@tonic-gate dtrace_close(dtp); 607*0Sstevel@tonic-gate if (errp != NULL) 608*0Sstevel@tonic-gate *errp = err; 609*0Sstevel@tonic-gate return (NULL); 610*0Sstevel@tonic-gate } 611*0Sstevel@tonic-gate 612*0Sstevel@tonic-gate static void 613*0Sstevel@tonic-gate dt_provmod_open(dt_provmod_t **provmod, dt_fdlist_t *dfp, const char *dirname, 614*0Sstevel@tonic-gate const char *subdir, const char *isadir) 615*0Sstevel@tonic-gate { 616*0Sstevel@tonic-gate dt_provmod_t *prov; 617*0Sstevel@tonic-gate char path[PATH_MAX]; 618*0Sstevel@tonic-gate struct dirent *dp, *ep; 619*0Sstevel@tonic-gate DIR *dirp; 620*0Sstevel@tonic-gate int fd; 621*0Sstevel@tonic-gate 622*0Sstevel@tonic-gate if (isadir) { 623*0Sstevel@tonic-gate (void) snprintf(path, sizeof (path), "%s/%s/%s", 624*0Sstevel@tonic-gate dirname, subdir, isadir); 625*0Sstevel@tonic-gate } else { 626*0Sstevel@tonic-gate (void) snprintf(path, sizeof (path), "%s/%s", 627*0Sstevel@tonic-gate dirname, subdir); 628*0Sstevel@tonic-gate } 629*0Sstevel@tonic-gate 630*0Sstevel@tonic-gate if ((dirp = opendir(path)) == NULL) 631*0Sstevel@tonic-gate return; /* failed to open directory; just skip it */ 632*0Sstevel@tonic-gate 633*0Sstevel@tonic-gate ep = alloca(sizeof (struct dirent) + PATH_MAX + 1); 634*0Sstevel@tonic-gate bzero(ep, sizeof (struct dirent) + PATH_MAX + 1); 635*0Sstevel@tonic-gate 636*0Sstevel@tonic-gate while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) { 637*0Sstevel@tonic-gate if (dp->d_name[0] == '.') 638*0Sstevel@tonic-gate continue; /* skip "." and ".." */ 639*0Sstevel@tonic-gate 640*0Sstevel@tonic-gate if (dfp->df_ents == dfp->df_size) { 641*0Sstevel@tonic-gate uint_t size = dfp->df_size ? dfp->df_size * 2 : 16; 642*0Sstevel@tonic-gate int *fds = realloc(dfp->df_fds, size * sizeof (int)); 643*0Sstevel@tonic-gate 644*0Sstevel@tonic-gate if (fds == NULL) 645*0Sstevel@tonic-gate break; /* skip the rest of this directory */ 646*0Sstevel@tonic-gate 647*0Sstevel@tonic-gate dfp->df_fds = fds; 648*0Sstevel@tonic-gate dfp->df_size = size; 649*0Sstevel@tonic-gate } 650*0Sstevel@tonic-gate 651*0Sstevel@tonic-gate (void) snprintf(path, sizeof (path), 652*0Sstevel@tonic-gate "/devices/pseudo/%s@0:%s", dp->d_name, dp->d_name); 653*0Sstevel@tonic-gate 654*0Sstevel@tonic-gate if ((fd = open(path, O_RDONLY)) == -1) 655*0Sstevel@tonic-gate continue; /* failed to open driver; just skip it */ 656*0Sstevel@tonic-gate 657*0Sstevel@tonic-gate if (((prov = malloc(sizeof (dt_provmod_t))) == NULL) || 658*0Sstevel@tonic-gate (prov->dp_name = malloc(strlen(dp->d_name) + 1)) == NULL) { 659*0Sstevel@tonic-gate free(prov); 660*0Sstevel@tonic-gate (void) close(fd); 661*0Sstevel@tonic-gate break; 662*0Sstevel@tonic-gate } 663*0Sstevel@tonic-gate 664*0Sstevel@tonic-gate (void) strcpy(prov->dp_name, dp->d_name); 665*0Sstevel@tonic-gate prov->dp_next = *provmod; 666*0Sstevel@tonic-gate *provmod = prov; 667*0Sstevel@tonic-gate 668*0Sstevel@tonic-gate dt_dprintf("opened provider %s\n", dp->d_name); 669*0Sstevel@tonic-gate dfp->df_fds[dfp->df_ents++] = fd; 670*0Sstevel@tonic-gate } 671*0Sstevel@tonic-gate 672*0Sstevel@tonic-gate (void) closedir(dirp); 673*0Sstevel@tonic-gate } 674*0Sstevel@tonic-gate 675*0Sstevel@tonic-gate static void 676*0Sstevel@tonic-gate dt_provmod_destroy(dt_provmod_t **provmod) 677*0Sstevel@tonic-gate { 678*0Sstevel@tonic-gate dt_provmod_t *next, *current; 679*0Sstevel@tonic-gate 680*0Sstevel@tonic-gate for (current = *provmod; current != NULL; current = next) { 681*0Sstevel@tonic-gate next = current->dp_next; 682*0Sstevel@tonic-gate free(current->dp_name); 683*0Sstevel@tonic-gate free(current); 684*0Sstevel@tonic-gate } 685*0Sstevel@tonic-gate 686*0Sstevel@tonic-gate *provmod = NULL; 687*0Sstevel@tonic-gate } 688*0Sstevel@tonic-gate 689*0Sstevel@tonic-gate static const char * 690*0Sstevel@tonic-gate dt_get_sysinfo(int cmd, char *buf, size_t len) 691*0Sstevel@tonic-gate { 692*0Sstevel@tonic-gate ssize_t rv = sysinfo(cmd, buf, len); 693*0Sstevel@tonic-gate char *p = buf; 694*0Sstevel@tonic-gate 695*0Sstevel@tonic-gate if (rv < 0 || rv > len) 696*0Sstevel@tonic-gate (void) snprintf(buf, len, "%s", "Unknown"); 697*0Sstevel@tonic-gate 698*0Sstevel@tonic-gate while ((p = strchr(p, '.')) != NULL) 699*0Sstevel@tonic-gate *p++ = '_'; 700*0Sstevel@tonic-gate 701*0Sstevel@tonic-gate return (buf); 702*0Sstevel@tonic-gate } 703*0Sstevel@tonic-gate 704*0Sstevel@tonic-gate static dtrace_hdl_t * 705*0Sstevel@tonic-gate dt_vopen(int version, int flags, int *errp, 706*0Sstevel@tonic-gate const dtrace_vector_t *vector, void *arg) 707*0Sstevel@tonic-gate { 708*0Sstevel@tonic-gate dtrace_hdl_t *dtp = NULL; 709*0Sstevel@tonic-gate int dtfd = -1, ftfd = -1, fterr = 0; 710*0Sstevel@tonic-gate dtrace_prog_t *pgp; 711*0Sstevel@tonic-gate dt_module_t *dmp; 712*0Sstevel@tonic-gate dt_provmod_t *provmod = NULL; 713*0Sstevel@tonic-gate int i, err; 714*0Sstevel@tonic-gate 715*0Sstevel@tonic-gate const dt_intrinsic_t *dinp; 716*0Sstevel@tonic-gate const dt_typedef_t *dtyp; 717*0Sstevel@tonic-gate const dt_ident_t *idp; 718*0Sstevel@tonic-gate 719*0Sstevel@tonic-gate dtrace_typeinfo_t dtt; 720*0Sstevel@tonic-gate ctf_funcinfo_t ctc; 721*0Sstevel@tonic-gate ctf_arinfo_t ctr; 722*0Sstevel@tonic-gate 723*0Sstevel@tonic-gate dt_fdlist_t df = { NULL, 0, 0 }; 724*0Sstevel@tonic-gate char *p, *q, *path = NULL; 725*0Sstevel@tonic-gate const char *isadir = NULL; 726*0Sstevel@tonic-gate int pathlen; 727*0Sstevel@tonic-gate 728*0Sstevel@tonic-gate char isadef[32], utsdef[32]; 729*0Sstevel@tonic-gate char s1[64], s2[64]; 730*0Sstevel@tonic-gate 731*0Sstevel@tonic-gate if (version <= 0) 732*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EINVAL)); 733*0Sstevel@tonic-gate 734*0Sstevel@tonic-gate if (version > DTRACE_VERSION) 735*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_VERSION)); 736*0Sstevel@tonic-gate 737*0Sstevel@tonic-gate if (flags & ~DTRACE_O_MASK) 738*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EINVAL)); 739*0Sstevel@tonic-gate 740*0Sstevel@tonic-gate if ((flags & DTRACE_O_LP64) && (flags & DTRACE_O_ILP32)) 741*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EINVAL)); 742*0Sstevel@tonic-gate 743*0Sstevel@tonic-gate if (vector == NULL && arg != NULL) 744*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EINVAL)); 745*0Sstevel@tonic-gate 746*0Sstevel@tonic-gate if (elf_version(EV_CURRENT) == EV_NONE) 747*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_ELFVERSION)); 748*0Sstevel@tonic-gate 749*0Sstevel@tonic-gate if (vector != NULL || (flags & DTRACE_O_NODEV)) 750*0Sstevel@tonic-gate goto alloc; /* do not attempt to open dtrace device */ 751*0Sstevel@tonic-gate 752*0Sstevel@tonic-gate /* 753*0Sstevel@tonic-gate * For each directory in the kernel's module path, build the name of 754*0Sstevel@tonic-gate * the corresponding dtrace provider subdirectory and attempt to open a 755*0Sstevel@tonic-gate * pseudo-driver whose name matches the name of each provider therein. 756*0Sstevel@tonic-gate * We hold them open in the df.df_fds list until we open the DTrace 757*0Sstevel@tonic-gate * driver itself, allowing us to see all of the probes provided on this 758*0Sstevel@tonic-gate * system. Once we have the DTrace driver open, we can safely close 759*0Sstevel@tonic-gate * all the providers now that they have registered with the framework. 760*0Sstevel@tonic-gate */ 761*0Sstevel@tonic-gate if (sysinfo(SI_ISALIST, isadef, sizeof (isadef)) > 0) { 762*0Sstevel@tonic-gate if (strstr(isadef, "sparcv9") != NULL) 763*0Sstevel@tonic-gate isadir = "sparcv9"; 764*0Sstevel@tonic-gate else if (strstr(isadef, "amd64") != NULL) 765*0Sstevel@tonic-gate isadir = "amd64"; 766*0Sstevel@tonic-gate } 767*0Sstevel@tonic-gate 768*0Sstevel@tonic-gate if (modctl(MODGETPATHLEN, NULL, &pathlen) == 0 && 769*0Sstevel@tonic-gate (path = malloc(pathlen + 1)) != NULL && 770*0Sstevel@tonic-gate modctl(MODGETPATH, NULL, path) == 0) { 771*0Sstevel@tonic-gate for (p = path; *p != '\0'; p = q) { 772*0Sstevel@tonic-gate if ((q = strchr(p, ' ')) != NULL) 773*0Sstevel@tonic-gate *q++ = '\0'; 774*0Sstevel@tonic-gate else 775*0Sstevel@tonic-gate q = p + strlen(p); 776*0Sstevel@tonic-gate dt_provmod_open(&provmod, &df, p, 777*0Sstevel@tonic-gate _dtrace_moddir, isadir); 778*0Sstevel@tonic-gate } 779*0Sstevel@tonic-gate } 780*0Sstevel@tonic-gate 781*0Sstevel@tonic-gate dtfd = open("/devices/pseudo/dtrace@0:dtrace", O_RDWR); 782*0Sstevel@tonic-gate err = errno; /* save errno from opening dtfd */ 783*0Sstevel@tonic-gate 784*0Sstevel@tonic-gate ftfd = open("/devices/pseudo/fasttrap@0:fasttrap", O_RDWR); 785*0Sstevel@tonic-gate fterr = ftfd == -1 ? errno : 0; /* save errno from open ftfd */ 786*0Sstevel@tonic-gate 787*0Sstevel@tonic-gate while (df.df_ents-- != 0) 788*0Sstevel@tonic-gate (void) close(df.df_fds[df.df_ents]); 789*0Sstevel@tonic-gate 790*0Sstevel@tonic-gate free(df.df_fds); 791*0Sstevel@tonic-gate free(path); 792*0Sstevel@tonic-gate 793*0Sstevel@tonic-gate /* 794*0Sstevel@tonic-gate * If we failed to open the dtrace device, fail dtrace_open(). 795*0Sstevel@tonic-gate * We convert some kernel errnos to custom libdtrace errnos to 796*0Sstevel@tonic-gate * improve the resulting message from the usual strerror(). 797*0Sstevel@tonic-gate */ 798*0Sstevel@tonic-gate if (dtfd == -1) { 799*0Sstevel@tonic-gate dt_provmod_destroy(&provmod); 800*0Sstevel@tonic-gate switch (err) { 801*0Sstevel@tonic-gate case ENOENT: 802*0Sstevel@tonic-gate if (getzoneid() != GLOBAL_ZONEID) 803*0Sstevel@tonic-gate err = EDT_ZNOENT; 804*0Sstevel@tonic-gate else 805*0Sstevel@tonic-gate err = EDT_GNOENT; 806*0Sstevel@tonic-gate break; 807*0Sstevel@tonic-gate case EBUSY: 808*0Sstevel@tonic-gate err = EDT_BUSY; 809*0Sstevel@tonic-gate break; 810*0Sstevel@tonic-gate case EACCES: 811*0Sstevel@tonic-gate err = EDT_ACCESS; 812*0Sstevel@tonic-gate break; 813*0Sstevel@tonic-gate } 814*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, err)); 815*0Sstevel@tonic-gate } 816*0Sstevel@tonic-gate 817*0Sstevel@tonic-gate (void) fcntl(dtfd, F_SETFD, FD_CLOEXEC); 818*0Sstevel@tonic-gate (void) fcntl(ftfd, F_SETFD, FD_CLOEXEC); 819*0Sstevel@tonic-gate 820*0Sstevel@tonic-gate alloc: 821*0Sstevel@tonic-gate if ((dtp = malloc(sizeof (dtrace_hdl_t))) == NULL) 822*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 823*0Sstevel@tonic-gate 824*0Sstevel@tonic-gate bzero(dtp, sizeof (dtrace_hdl_t)); 825*0Sstevel@tonic-gate dtp->dt_oflags = flags; 826*0Sstevel@tonic-gate dtp->dt_prcmode = DT_PROC_STOP_PREINIT; 827*0Sstevel@tonic-gate dtp->dt_linkmode = DT_LINK_KERNEL; 828*0Sstevel@tonic-gate dtp->dt_linktype = DT_LTYP_ELF; 829*0Sstevel@tonic-gate dtp->dt_stdcmode = DT_STDC_XA; 830*0Sstevel@tonic-gate dtp->dt_version = version; 831*0Sstevel@tonic-gate dtp->dt_fd = dtfd; 832*0Sstevel@tonic-gate dtp->dt_ftfd = ftfd; 833*0Sstevel@tonic-gate dtp->dt_fterr = fterr; 834*0Sstevel@tonic-gate dtp->dt_cdefs_fd = -1; 835*0Sstevel@tonic-gate dtp->dt_ddefs_fd = -1; 836*0Sstevel@tonic-gate dtp->dt_stdout_fd = -1; 837*0Sstevel@tonic-gate dtp->dt_modbuckets = _dtrace_strbuckets; 838*0Sstevel@tonic-gate dtp->dt_mods = calloc(dtp->dt_modbuckets, sizeof (dt_module_t *)); 839*0Sstevel@tonic-gate dtp->dt_provbuckets = _dtrace_strbuckets; 840*0Sstevel@tonic-gate dtp->dt_provs = calloc(dtp->dt_provbuckets, sizeof (dt_provider_t *)); 841*0Sstevel@tonic-gate dt_proc_hash_create(dtp); 842*0Sstevel@tonic-gate dtp->dt_vmax = DT_VERS_LATEST; 843*0Sstevel@tonic-gate dtp->dt_cpp_path = strdup(_dtrace_defcpp); 844*0Sstevel@tonic-gate dtp->dt_cpp_argv = malloc(sizeof (char *)); 845*0Sstevel@tonic-gate dtp->dt_cpp_argc = 1; 846*0Sstevel@tonic-gate dtp->dt_cpp_args = 1; 847*0Sstevel@tonic-gate dtp->dt_ld_path = strdup(_dtrace_defld); 848*0Sstevel@tonic-gate dtp->dt_provmod = provmod; 849*0Sstevel@tonic-gate dtp->dt_vector = vector; 850*0Sstevel@tonic-gate dtp->dt_varg = arg; 851*0Sstevel@tonic-gate dt_dof_init(dtp); 852*0Sstevel@tonic-gate (void) uname(&dtp->dt_uts); 853*0Sstevel@tonic-gate 854*0Sstevel@tonic-gate if (dtp->dt_mods == NULL || dtp->dt_provs == NULL || 855*0Sstevel@tonic-gate dtp->dt_procs == NULL || dtp->dt_ld_path == NULL || 856*0Sstevel@tonic-gate dtp->dt_cpp_path == NULL || dtp->dt_cpp_argv == NULL) 857*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 858*0Sstevel@tonic-gate 859*0Sstevel@tonic-gate for (i = 0; i < DTRACEOPT_MAX; i++) 860*0Sstevel@tonic-gate dtp->dt_options[i] = DTRACEOPT_UNSET; 861*0Sstevel@tonic-gate 862*0Sstevel@tonic-gate dtp->dt_cpp_argv[0] = (char *)strbasename(dtp->dt_cpp_path); 863*0Sstevel@tonic-gate 864*0Sstevel@tonic-gate (void) snprintf(isadef, sizeof (isadef), "-D__SUNW_D_%u", 865*0Sstevel@tonic-gate (uint_t)(sizeof (void *) * NBBY)); 866*0Sstevel@tonic-gate 867*0Sstevel@tonic-gate (void) snprintf(utsdef, sizeof (utsdef), "-D__%s_%s", 868*0Sstevel@tonic-gate dt_get_sysinfo(SI_SYSNAME, s1, sizeof (s1)), 869*0Sstevel@tonic-gate dt_get_sysinfo(SI_RELEASE, s2, sizeof (s2))); 870*0Sstevel@tonic-gate 871*0Sstevel@tonic-gate if (dt_cpp_add_arg(dtp, "-D__sun") == NULL || 872*0Sstevel@tonic-gate dt_cpp_add_arg(dtp, "-D__unix") == NULL || 873*0Sstevel@tonic-gate dt_cpp_add_arg(dtp, "-D__SVR4") == NULL || 874*0Sstevel@tonic-gate dt_cpp_add_arg(dtp, "-D__SUNW_D=1") == NULL || 875*0Sstevel@tonic-gate dt_cpp_add_arg(dtp, isadef) == NULL || 876*0Sstevel@tonic-gate dt_cpp_add_arg(dtp, utsdef) == NULL) 877*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 878*0Sstevel@tonic-gate 879*0Sstevel@tonic-gate if (flags & DTRACE_O_NODEV) 880*0Sstevel@tonic-gate bcopy(&_dtrace_conf, &dtp->dt_conf, sizeof (_dtrace_conf)); 881*0Sstevel@tonic-gate else if (dt_ioctl(dtp, DTRACEIOC_CONF, &dtp->dt_conf) != 0) 882*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, errno)); 883*0Sstevel@tonic-gate 884*0Sstevel@tonic-gate if (flags & DTRACE_O_LP64) 885*0Sstevel@tonic-gate dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_LP64; 886*0Sstevel@tonic-gate else if (flags & DTRACE_O_ILP32) 887*0Sstevel@tonic-gate dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_ILP32; 888*0Sstevel@tonic-gate 889*0Sstevel@tonic-gate #ifdef __sparc 890*0Sstevel@tonic-gate /* 891*0Sstevel@tonic-gate * On SPARC systems, __sparc is always defined for <sys/isa_defs.h> 892*0Sstevel@tonic-gate * and __sparcv9 is defined if we are doing a 64-bit compile. 893*0Sstevel@tonic-gate */ 894*0Sstevel@tonic-gate if (dt_cpp_add_arg(dtp, "-D__sparc") == NULL) 895*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 896*0Sstevel@tonic-gate 897*0Sstevel@tonic-gate if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64 && 898*0Sstevel@tonic-gate dt_cpp_add_arg(dtp, "-D__sparcv9") == NULL) 899*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 900*0Sstevel@tonic-gate #endif 901*0Sstevel@tonic-gate 902*0Sstevel@tonic-gate #ifdef __x86 903*0Sstevel@tonic-gate /* 904*0Sstevel@tonic-gate * On x86 systems, __i386 is defined for <sys/isa_defs.h> for 32-bit 905*0Sstevel@tonic-gate * compiles and __amd64 is defined for 64-bit compiles. Unlike SPARC, 906*0Sstevel@tonic-gate * they are defined exclusive of one another (see PSARC 2004/619). 907*0Sstevel@tonic-gate */ 908*0Sstevel@tonic-gate if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) 909*0Sstevel@tonic-gate p = dt_cpp_add_arg(dtp, "-D__amd64"); 910*0Sstevel@tonic-gate else 911*0Sstevel@tonic-gate p = dt_cpp_add_arg(dtp, "-D__i386"); 912*0Sstevel@tonic-gate 913*0Sstevel@tonic-gate if (p == NULL) 914*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 915*0Sstevel@tonic-gate #endif 916*0Sstevel@tonic-gate 917*0Sstevel@tonic-gate if (dtp->dt_conf.dtc_difversion < DIF_VERSION) 918*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_DIFVERS)); 919*0Sstevel@tonic-gate 920*0Sstevel@tonic-gate if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32) 921*0Sstevel@tonic-gate bcopy(_dtrace_ints_32, dtp->dt_ints, sizeof (_dtrace_ints_32)); 922*0Sstevel@tonic-gate else 923*0Sstevel@tonic-gate bcopy(_dtrace_ints_64, dtp->dt_ints, sizeof (_dtrace_ints_64)); 924*0Sstevel@tonic-gate 925*0Sstevel@tonic-gate dtp->dt_macros = dt_idhash_create("macro", NULL, 0, UINT_MAX); 926*0Sstevel@tonic-gate dtp->dt_aggs = dt_idhash_create("aggregation", NULL, 0, UINT_MAX); 927*0Sstevel@tonic-gate 928*0Sstevel@tonic-gate dtp->dt_globals = dt_idhash_create("global", _dtrace_globals, 929*0Sstevel@tonic-gate DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX); 930*0Sstevel@tonic-gate 931*0Sstevel@tonic-gate dtp->dt_tls = dt_idhash_create("thread local", NULL, 932*0Sstevel@tonic-gate DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX); 933*0Sstevel@tonic-gate 934*0Sstevel@tonic-gate if (dtp->dt_macros == NULL || dtp->dt_aggs == NULL || 935*0Sstevel@tonic-gate dtp->dt_globals == NULL || dtp->dt_tls == NULL) 936*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 937*0Sstevel@tonic-gate 938*0Sstevel@tonic-gate /* 939*0Sstevel@tonic-gate * Populate the dt_macros identifier hash table by hand: we can't use 940*0Sstevel@tonic-gate * the dt_idhash_populate() mechanism because we're not yet compiling 941*0Sstevel@tonic-gate * and dtrace_update() needs to immediately reference these idents. 942*0Sstevel@tonic-gate */ 943*0Sstevel@tonic-gate for (idp = _dtrace_macros; idp->di_name != NULL; idp++) { 944*0Sstevel@tonic-gate if (dt_idhash_insert(dtp->dt_macros, idp->di_name, 945*0Sstevel@tonic-gate idp->di_kind, idp->di_flags, idp->di_id, idp->di_attr, 946*0Sstevel@tonic-gate idp->di_vers, idp->di_ops ? idp->di_ops : &dt_idops_thaw, 947*0Sstevel@tonic-gate idp->di_iarg, 0) == NULL) 948*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 949*0Sstevel@tonic-gate } 950*0Sstevel@tonic-gate 951*0Sstevel@tonic-gate /* 952*0Sstevel@tonic-gate * Update the module list using /system/object and load the values for 953*0Sstevel@tonic-gate * the macro variable definitions according to the current process. 954*0Sstevel@tonic-gate */ 955*0Sstevel@tonic-gate dtrace_update(dtp); 956*0Sstevel@tonic-gate 957*0Sstevel@tonic-gate /* 958*0Sstevel@tonic-gate * Select the intrinsics and typedefs we want based on the data model. 959*0Sstevel@tonic-gate * The intrinsics are under "C". The typedefs are added under "D". 960*0Sstevel@tonic-gate */ 961*0Sstevel@tonic-gate if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32) { 962*0Sstevel@tonic-gate dinp = _dtrace_intrinsics_32; 963*0Sstevel@tonic-gate dtyp = _dtrace_typedefs_32; 964*0Sstevel@tonic-gate } else { 965*0Sstevel@tonic-gate dinp = _dtrace_intrinsics_64; 966*0Sstevel@tonic-gate dtyp = _dtrace_typedefs_64; 967*0Sstevel@tonic-gate } 968*0Sstevel@tonic-gate 969*0Sstevel@tonic-gate /* 970*0Sstevel@tonic-gate * Create a dynamic CTF container under the "C" scope for intrinsic 971*0Sstevel@tonic-gate * types and types defined in ANSI-C header files that are included. 972*0Sstevel@tonic-gate */ 973*0Sstevel@tonic-gate if ((dmp = dtp->dt_cdefs = dt_module_create(dtp, "C")) == NULL) 974*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 975*0Sstevel@tonic-gate 976*0Sstevel@tonic-gate if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL) 977*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 978*0Sstevel@tonic-gate 979*0Sstevel@tonic-gate dt_dprintf("created CTF container for %s (%p)\n", 980*0Sstevel@tonic-gate dmp->dm_name, (void *)dmp->dm_ctfp); 981*0Sstevel@tonic-gate 982*0Sstevel@tonic-gate (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel); 983*0Sstevel@tonic-gate ctf_setspecific(dmp->dm_ctfp, dmp); 984*0Sstevel@tonic-gate 985*0Sstevel@tonic-gate dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */ 986*0Sstevel@tonic-gate dmp->dm_modid = -1; /* no module ID */ 987*0Sstevel@tonic-gate 988*0Sstevel@tonic-gate /* 989*0Sstevel@tonic-gate * Fill the dynamic "C" CTF container with all of the intrinsic 990*0Sstevel@tonic-gate * integer and floating-point types appropriate for this data model. 991*0Sstevel@tonic-gate */ 992*0Sstevel@tonic-gate for (; dinp->din_name != NULL; dinp++) { 993*0Sstevel@tonic-gate if (dinp->din_kind == CTF_K_INTEGER) { 994*0Sstevel@tonic-gate err = ctf_add_integer(dmp->dm_ctfp, CTF_ADD_ROOT, 995*0Sstevel@tonic-gate dinp->din_name, &dinp->din_data); 996*0Sstevel@tonic-gate } else { 997*0Sstevel@tonic-gate err = ctf_add_float(dmp->dm_ctfp, CTF_ADD_ROOT, 998*0Sstevel@tonic-gate dinp->din_name, &dinp->din_data); 999*0Sstevel@tonic-gate } 1000*0Sstevel@tonic-gate 1001*0Sstevel@tonic-gate if (err == CTF_ERR) { 1002*0Sstevel@tonic-gate dt_dprintf("failed to add %s to C container: %s\n", 1003*0Sstevel@tonic-gate dinp->din_name, ctf_errmsg( 1004*0Sstevel@tonic-gate ctf_errno(dmp->dm_ctfp))); 1005*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 1006*0Sstevel@tonic-gate } 1007*0Sstevel@tonic-gate } 1008*0Sstevel@tonic-gate 1009*0Sstevel@tonic-gate if (ctf_update(dmp->dm_ctfp) != 0) { 1010*0Sstevel@tonic-gate dt_dprintf("failed to update C container: %s\n", 1011*0Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1012*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 1013*0Sstevel@tonic-gate } 1014*0Sstevel@tonic-gate 1015*0Sstevel@tonic-gate /* 1016*0Sstevel@tonic-gate * Add intrinsic pointer types that are needed to initialize printf 1017*0Sstevel@tonic-gate * format dictionary types (see table in dt_printf.c). 1018*0Sstevel@tonic-gate */ 1019*0Sstevel@tonic-gate (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, 1020*0Sstevel@tonic-gate ctf_lookup_by_name(dmp->dm_ctfp, "void")); 1021*0Sstevel@tonic-gate 1022*0Sstevel@tonic-gate (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, 1023*0Sstevel@tonic-gate ctf_lookup_by_name(dmp->dm_ctfp, "char")); 1024*0Sstevel@tonic-gate 1025*0Sstevel@tonic-gate (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, 1026*0Sstevel@tonic-gate ctf_lookup_by_name(dmp->dm_ctfp, "int")); 1027*0Sstevel@tonic-gate 1028*0Sstevel@tonic-gate if (ctf_update(dmp->dm_ctfp) != 0) { 1029*0Sstevel@tonic-gate dt_dprintf("failed to update C container: %s\n", 1030*0Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1031*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 1032*0Sstevel@tonic-gate } 1033*0Sstevel@tonic-gate 1034*0Sstevel@tonic-gate /* 1035*0Sstevel@tonic-gate * Create a dynamic CTF container under the "D" scope for types that 1036*0Sstevel@tonic-gate * are defined by the D program itself or on-the-fly by the D compiler. 1037*0Sstevel@tonic-gate * The "D" CTF container is a child of the "C" CTF container. 1038*0Sstevel@tonic-gate */ 1039*0Sstevel@tonic-gate if ((dmp = dtp->dt_ddefs = dt_module_create(dtp, "D")) == NULL) 1040*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_NOMEM)); 1041*0Sstevel@tonic-gate 1042*0Sstevel@tonic-gate if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL) 1043*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 1044*0Sstevel@tonic-gate 1045*0Sstevel@tonic-gate dt_dprintf("created CTF container for %s (%p)\n", 1046*0Sstevel@tonic-gate dmp->dm_name, (void *)dmp->dm_ctfp); 1047*0Sstevel@tonic-gate 1048*0Sstevel@tonic-gate (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel); 1049*0Sstevel@tonic-gate ctf_setspecific(dmp->dm_ctfp, dmp); 1050*0Sstevel@tonic-gate 1051*0Sstevel@tonic-gate dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */ 1052*0Sstevel@tonic-gate dmp->dm_modid = -1; /* no module ID */ 1053*0Sstevel@tonic-gate 1054*0Sstevel@tonic-gate if (ctf_import(dmp->dm_ctfp, dtp->dt_cdefs->dm_ctfp) == CTF_ERR) { 1055*0Sstevel@tonic-gate dt_dprintf("failed to import D parent container: %s\n", 1056*0Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1057*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 1058*0Sstevel@tonic-gate } 1059*0Sstevel@tonic-gate 1060*0Sstevel@tonic-gate /* 1061*0Sstevel@tonic-gate * Fill the dynamic "D" CTF container with all of the built-in typedefs 1062*0Sstevel@tonic-gate * that we need to use for our D variable and function definitions. 1063*0Sstevel@tonic-gate * This ensures that basic inttypes.h names are always available to us. 1064*0Sstevel@tonic-gate */ 1065*0Sstevel@tonic-gate for (; dtyp->dty_src != NULL; dtyp++) { 1066*0Sstevel@tonic-gate if (ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 1067*0Sstevel@tonic-gate dtyp->dty_dst, ctf_lookup_by_name(dmp->dm_ctfp, 1068*0Sstevel@tonic-gate dtyp->dty_src)) == CTF_ERR) { 1069*0Sstevel@tonic-gate dt_dprintf("failed to add typedef %s %s to D " 1070*0Sstevel@tonic-gate "container: %s", dtyp->dty_src, dtyp->dty_dst, 1071*0Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1072*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 1073*0Sstevel@tonic-gate } 1074*0Sstevel@tonic-gate } 1075*0Sstevel@tonic-gate 1076*0Sstevel@tonic-gate /* 1077*0Sstevel@tonic-gate * Insert a CTF ID corresponding to a pointer to a type of kind 1078*0Sstevel@tonic-gate * CTF_K_FUNCTION we can use in the compiler for function pointers. 1079*0Sstevel@tonic-gate * CTF treats all function pointers as "int (*)()" so we only need one. 1080*0Sstevel@tonic-gate */ 1081*0Sstevel@tonic-gate ctc.ctc_return = ctf_lookup_by_name(dmp->dm_ctfp, "int"); 1082*0Sstevel@tonic-gate ctc.ctc_argc = 0; 1083*0Sstevel@tonic-gate ctc.ctc_flags = 0; 1084*0Sstevel@tonic-gate 1085*0Sstevel@tonic-gate dtp->dt_type_func = ctf_add_function(dmp->dm_ctfp, 1086*0Sstevel@tonic-gate CTF_ADD_ROOT, &ctc, NULL); 1087*0Sstevel@tonic-gate 1088*0Sstevel@tonic-gate dtp->dt_type_fptr = ctf_add_pointer(dmp->dm_ctfp, 1089*0Sstevel@tonic-gate CTF_ADD_ROOT, dtp->dt_type_func); 1090*0Sstevel@tonic-gate 1091*0Sstevel@tonic-gate /* 1092*0Sstevel@tonic-gate * We also insert CTF definitions for the special D intrinsic types 1093*0Sstevel@tonic-gate * string and <DYN> into the D container. The string type is added 1094*0Sstevel@tonic-gate * as a typedef of char[n]. The <DYN> type is an alias for void. 1095*0Sstevel@tonic-gate * We compare types to these special CTF ids throughout the compiler. 1096*0Sstevel@tonic-gate */ 1097*0Sstevel@tonic-gate ctr.ctr_contents = ctf_lookup_by_name(dmp->dm_ctfp, "char"); 1098*0Sstevel@tonic-gate ctr.ctr_index = ctf_lookup_by_name(dmp->dm_ctfp, "long"); 1099*0Sstevel@tonic-gate ctr.ctr_nelems = _dtrace_strsize; 1100*0Sstevel@tonic-gate 1101*0Sstevel@tonic-gate dtp->dt_type_str = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 1102*0Sstevel@tonic-gate "string", ctf_add_array(dmp->dm_ctfp, CTF_ADD_ROOT, &ctr)); 1103*0Sstevel@tonic-gate 1104*0Sstevel@tonic-gate dtp->dt_type_dyn = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 1105*0Sstevel@tonic-gate "<DYN>", ctf_lookup_by_name(dmp->dm_ctfp, "void")); 1106*0Sstevel@tonic-gate 1107*0Sstevel@tonic-gate dtp->dt_type_stack = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 1108*0Sstevel@tonic-gate "stack", ctf_lookup_by_name(dmp->dm_ctfp, "void")); 1109*0Sstevel@tonic-gate 1110*0Sstevel@tonic-gate if (dtp->dt_type_func == CTF_ERR || dtp->dt_type_fptr == CTF_ERR || 1111*0Sstevel@tonic-gate dtp->dt_type_str == CTF_ERR || dtp->dt_type_dyn == CTF_ERR || 1112*0Sstevel@tonic-gate dtp->dt_type_stack == CTF_ERR) { 1113*0Sstevel@tonic-gate dt_dprintf("failed to add intrinsic to D container: %s\n", 1114*0Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1115*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 1116*0Sstevel@tonic-gate } 1117*0Sstevel@tonic-gate 1118*0Sstevel@tonic-gate if (ctf_update(dmp->dm_ctfp) != 0) { 1119*0Sstevel@tonic-gate dt_dprintf("failed update D container: %s\n", 1120*0Sstevel@tonic-gate ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1121*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_CTF)); 1122*0Sstevel@tonic-gate } 1123*0Sstevel@tonic-gate 1124*0Sstevel@tonic-gate /* 1125*0Sstevel@tonic-gate * Initialize the integer description table used to convert integer 1126*0Sstevel@tonic-gate * constants to the appropriate types. Refer to the comments above 1127*0Sstevel@tonic-gate * dt_node_int() for a complete description of how this table is used. 1128*0Sstevel@tonic-gate */ 1129*0Sstevel@tonic-gate for (i = 0; i < sizeof (dtp->dt_ints) / sizeof (dtp->dt_ints[0]); i++) { 1130*0Sstevel@tonic-gate if (dtrace_lookup_by_type(dtp, DTRACE_OBJ_EVERY, 1131*0Sstevel@tonic-gate dtp->dt_ints[i].did_name, &dtt) != 0) { 1132*0Sstevel@tonic-gate dt_dprintf("failed to lookup integer type %s: %s\n", 1133*0Sstevel@tonic-gate dtp->dt_ints[i].did_name, 1134*0Sstevel@tonic-gate dtrace_errmsg(dtp, dtrace_errno(dtp))); 1135*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, dtp->dt_errno)); 1136*0Sstevel@tonic-gate } 1137*0Sstevel@tonic-gate dtp->dt_ints[i].did_ctfp = dtt.dtt_ctfp; 1138*0Sstevel@tonic-gate dtp->dt_ints[i].did_type = dtt.dtt_type; 1139*0Sstevel@tonic-gate } 1140*0Sstevel@tonic-gate 1141*0Sstevel@tonic-gate /* 1142*0Sstevel@tonic-gate * Now that we've created the "C" and "D" containers, move them to the 1143*0Sstevel@tonic-gate * start of the module list so that these types and symbols are found 1144*0Sstevel@tonic-gate * first (for stability) when iterating through the module list. 1145*0Sstevel@tonic-gate */ 1146*0Sstevel@tonic-gate dt_list_delete(&dtp->dt_modlist, dtp->dt_ddefs); 1147*0Sstevel@tonic-gate dt_list_prepend(&dtp->dt_modlist, dtp->dt_ddefs); 1148*0Sstevel@tonic-gate 1149*0Sstevel@tonic-gate dt_list_delete(&dtp->dt_modlist, dtp->dt_cdefs); 1150*0Sstevel@tonic-gate dt_list_prepend(&dtp->dt_modlist, dtp->dt_cdefs); 1151*0Sstevel@tonic-gate 1152*0Sstevel@tonic-gate if (dt_pfdict_create(dtp) == -1) 1153*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, dtp->dt_errno)); 1154*0Sstevel@tonic-gate 1155*0Sstevel@tonic-gate /* 1156*0Sstevel@tonic-gate * If we are opening libdtrace DTRACE_O_NODEV enable C_ZDEFS by default 1157*0Sstevel@tonic-gate * because without /dev/dtrace open, we will not be able to load the 1158*0Sstevel@tonic-gate * names and attributes of any providers or probes from the kernel. 1159*0Sstevel@tonic-gate */ 1160*0Sstevel@tonic-gate if (flags & DTRACE_O_NODEV) 1161*0Sstevel@tonic-gate dtp->dt_cflags |= DTRACE_C_ZDEFS; 1162*0Sstevel@tonic-gate 1163*0Sstevel@tonic-gate /* 1164*0Sstevel@tonic-gate * Load hard-wired inlines into the definition cache by calling the 1165*0Sstevel@tonic-gate * compiler on the raw definition string defined above. 1166*0Sstevel@tonic-gate */ 1167*0Sstevel@tonic-gate if ((pgp = dtrace_program_strcompile(dtp, _dtrace_hardwire, 1168*0Sstevel@tonic-gate DTRACE_PROBESPEC_NONE, DTRACE_C_EMPTY, 0, NULL)) == NULL) { 1169*0Sstevel@tonic-gate dt_dprintf("failed to load hard-wired definitions: %s\n", 1170*0Sstevel@tonic-gate dtrace_errmsg(dtp, dtrace_errno(dtp))); 1171*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, EDT_HARDWIRE)); 1172*0Sstevel@tonic-gate } 1173*0Sstevel@tonic-gate 1174*0Sstevel@tonic-gate dtrace_program_destroy(dtp, pgp); 1175*0Sstevel@tonic-gate 1176*0Sstevel@tonic-gate /* 1177*0Sstevel@tonic-gate * Set up the default DTrace library path. Once set, the next call to 1178*0Sstevel@tonic-gate * dt_compile() will compile all the libraries. We intentionally defer 1179*0Sstevel@tonic-gate * library processing to improve overhead for clients that don't ever 1180*0Sstevel@tonic-gate * compile, and to provide better error reporting (because the full 1181*0Sstevel@tonic-gate * reporting of compiler errors requires dtrace_open() to succeed). 1182*0Sstevel@tonic-gate */ 1183*0Sstevel@tonic-gate if (dtrace_setopt(dtp, "libdir", _dtrace_libdir) != 0) 1184*0Sstevel@tonic-gate return (set_open_errno(dtp, errp, dtp->dt_errno)); 1185*0Sstevel@tonic-gate 1186*0Sstevel@tonic-gate return (dtp); 1187*0Sstevel@tonic-gate } 1188*0Sstevel@tonic-gate 1189*0Sstevel@tonic-gate dtrace_hdl_t * 1190*0Sstevel@tonic-gate dtrace_open(int version, int flags, int *errp) 1191*0Sstevel@tonic-gate { 1192*0Sstevel@tonic-gate return (dt_vopen(version, flags, errp, NULL, NULL)); 1193*0Sstevel@tonic-gate } 1194*0Sstevel@tonic-gate 1195*0Sstevel@tonic-gate dtrace_hdl_t * 1196*0Sstevel@tonic-gate dtrace_vopen(int version, int flags, int *errp, 1197*0Sstevel@tonic-gate const dtrace_vector_t *vector, void *arg) 1198*0Sstevel@tonic-gate { 1199*0Sstevel@tonic-gate return (dt_vopen(version, flags, errp, vector, arg)); 1200*0Sstevel@tonic-gate } 1201*0Sstevel@tonic-gate 1202*0Sstevel@tonic-gate void 1203*0Sstevel@tonic-gate dtrace_close(dtrace_hdl_t *dtp) 1204*0Sstevel@tonic-gate { 1205*0Sstevel@tonic-gate dt_ident_t *idp, *ndp; 1206*0Sstevel@tonic-gate dt_module_t *dmp; 1207*0Sstevel@tonic-gate dt_provider_t *pvp; 1208*0Sstevel@tonic-gate dtrace_prog_t *pgp; 1209*0Sstevel@tonic-gate dt_xlator_t *dxp; 1210*0Sstevel@tonic-gate dt_dirpath_t *dirp; 1211*0Sstevel@tonic-gate int i; 1212*0Sstevel@tonic-gate 1213*0Sstevel@tonic-gate while ((pgp = dt_list_next(&dtp->dt_programs)) != NULL) 1214*0Sstevel@tonic-gate dtrace_program_destroy(dtp, pgp); 1215*0Sstevel@tonic-gate 1216*0Sstevel@tonic-gate while ((dxp = dt_list_next(&dtp->dt_xlators)) != NULL) 1217*0Sstevel@tonic-gate dt_xlator_destroy(dtp, dxp); 1218*0Sstevel@tonic-gate 1219*0Sstevel@tonic-gate for (idp = dtp->dt_externs; idp != NULL; idp = ndp) { 1220*0Sstevel@tonic-gate ndp = idp->di_next; 1221*0Sstevel@tonic-gate dt_ident_destroy(idp); 1222*0Sstevel@tonic-gate } 1223*0Sstevel@tonic-gate 1224*0Sstevel@tonic-gate if (dtp->dt_macros != NULL) 1225*0Sstevel@tonic-gate dt_idhash_destroy(dtp->dt_macros); 1226*0Sstevel@tonic-gate if (dtp->dt_aggs != NULL) 1227*0Sstevel@tonic-gate dt_idhash_destroy(dtp->dt_aggs); 1228*0Sstevel@tonic-gate if (dtp->dt_globals != NULL) 1229*0Sstevel@tonic-gate dt_idhash_destroy(dtp->dt_globals); 1230*0Sstevel@tonic-gate if (dtp->dt_tls != NULL) 1231*0Sstevel@tonic-gate dt_idhash_destroy(dtp->dt_tls); 1232*0Sstevel@tonic-gate 1233*0Sstevel@tonic-gate while ((dmp = dt_list_next(&dtp->dt_modlist)) != NULL) 1234*0Sstevel@tonic-gate dt_module_destroy(dtp, dmp); 1235*0Sstevel@tonic-gate 1236*0Sstevel@tonic-gate while ((pvp = dt_list_next(&dtp->dt_provlist)) != NULL) 1237*0Sstevel@tonic-gate dt_provider_destroy(dtp, pvp); 1238*0Sstevel@tonic-gate 1239*0Sstevel@tonic-gate if (dtp->dt_procs != NULL) 1240*0Sstevel@tonic-gate dt_proc_hash_destroy(dtp); 1241*0Sstevel@tonic-gate 1242*0Sstevel@tonic-gate if (dtp->dt_fd != -1) 1243*0Sstevel@tonic-gate (void) close(dtp->dt_fd); 1244*0Sstevel@tonic-gate if (dtp->dt_ftfd != -1) 1245*0Sstevel@tonic-gate (void) close(dtp->dt_ftfd); 1246*0Sstevel@tonic-gate if (dtp->dt_cdefs_fd != -1) 1247*0Sstevel@tonic-gate (void) close(dtp->dt_cdefs_fd); 1248*0Sstevel@tonic-gate if (dtp->dt_ddefs_fd != -1) 1249*0Sstevel@tonic-gate (void) close(dtp->dt_ddefs_fd); 1250*0Sstevel@tonic-gate if (dtp->dt_stdout_fd != -1) 1251*0Sstevel@tonic-gate (void) close(dtp->dt_stdout_fd); 1252*0Sstevel@tonic-gate 1253*0Sstevel@tonic-gate dt_epid_destroy(dtp); 1254*0Sstevel@tonic-gate dt_aggid_destroy(dtp); 1255*0Sstevel@tonic-gate dt_format_destroy(dtp); 1256*0Sstevel@tonic-gate dt_buffered_destroy(dtp); 1257*0Sstevel@tonic-gate dt_aggregate_destroy(dtp); 1258*0Sstevel@tonic-gate free(dtp->dt_buf.dtbd_data); 1259*0Sstevel@tonic-gate dt_pfdict_destroy(dtp); 1260*0Sstevel@tonic-gate dt_provmod_destroy(&dtp->dt_provmod); 1261*0Sstevel@tonic-gate dt_dof_fini(dtp); 1262*0Sstevel@tonic-gate 1263*0Sstevel@tonic-gate for (i = 1; i < dtp->dt_cpp_argc; i++) 1264*0Sstevel@tonic-gate free(dtp->dt_cpp_argv[i]); 1265*0Sstevel@tonic-gate 1266*0Sstevel@tonic-gate while ((dirp = dt_list_next(&dtp->dt_lib_path)) != NULL) { 1267*0Sstevel@tonic-gate dt_list_delete(&dtp->dt_lib_path, dirp); 1268*0Sstevel@tonic-gate free(dirp->dir_path); 1269*0Sstevel@tonic-gate free(dirp); 1270*0Sstevel@tonic-gate } 1271*0Sstevel@tonic-gate 1272*0Sstevel@tonic-gate free(dtp->dt_cpp_argv); 1273*0Sstevel@tonic-gate free(dtp->dt_cpp_path); 1274*0Sstevel@tonic-gate free(dtp->dt_ld_path); 1275*0Sstevel@tonic-gate 1276*0Sstevel@tonic-gate free(dtp->dt_mods); 1277*0Sstevel@tonic-gate free(dtp->dt_provs); 1278*0Sstevel@tonic-gate free(dtp); 1279*0Sstevel@tonic-gate } 1280*0Sstevel@tonic-gate 1281*0Sstevel@tonic-gate int 1282*0Sstevel@tonic-gate dtrace_go(dtrace_hdl_t *dtp) 1283*0Sstevel@tonic-gate { 1284*0Sstevel@tonic-gate void *dof; 1285*0Sstevel@tonic-gate int err; 1286*0Sstevel@tonic-gate 1287*0Sstevel@tonic-gate if (dtp->dt_active) 1288*0Sstevel@tonic-gate return (dt_set_errno(dtp, EINVAL)); 1289*0Sstevel@tonic-gate 1290*0Sstevel@tonic-gate /* 1291*0Sstevel@tonic-gate * If a dtrace:::ERROR program and callback are registered, enable the 1292*0Sstevel@tonic-gate * program before we start tracing. If this fails for a vector open 1293*0Sstevel@tonic-gate * with ENOTTY, we permit dtrace_go() to succeed so that vector clients 1294*0Sstevel@tonic-gate * such as mdb's dtrace module can execute the rest of dtrace_go() even 1295*0Sstevel@tonic-gate * though they do not provide support for the DTRACEIOC_ENABLE ioctl. 1296*0Sstevel@tonic-gate */ 1297*0Sstevel@tonic-gate if (dtp->dt_errprog != NULL && 1298*0Sstevel@tonic-gate dtrace_program_exec(dtp, dtp->dt_errprog, NULL) == -1 && ( 1299*0Sstevel@tonic-gate dtp->dt_errno != ENOTTY || dtp->dt_vector == NULL)) 1300*0Sstevel@tonic-gate return (-1); /* dt_errno has been set for us */ 1301*0Sstevel@tonic-gate 1302*0Sstevel@tonic-gate if ((dof = dtrace_getopt_dof(dtp)) == NULL) 1303*0Sstevel@tonic-gate return (-1); /* dt_errno has been set for us */ 1304*0Sstevel@tonic-gate 1305*0Sstevel@tonic-gate err = dt_ioctl(dtp, DTRACEIOC_ENABLE, dof); 1306*0Sstevel@tonic-gate dtrace_dof_destroy(dtp, dof); 1307*0Sstevel@tonic-gate 1308*0Sstevel@tonic-gate if (err == -1 && (errno != ENOTTY || dtp->dt_vector == NULL)) 1309*0Sstevel@tonic-gate return (dt_set_errno(dtp, errno)); 1310*0Sstevel@tonic-gate 1311*0Sstevel@tonic-gate if (dt_ioctl(dtp, DTRACEIOC_GO, &dtp->dt_beganon) == -1) { 1312*0Sstevel@tonic-gate if (errno == EACCES) 1313*0Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_DESTRUCTIVE)); 1314*0Sstevel@tonic-gate 1315*0Sstevel@tonic-gate if (errno == EALREADY) 1316*0Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_ISANON)); 1317*0Sstevel@tonic-gate 1318*0Sstevel@tonic-gate if (errno == ENOENT) 1319*0Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_NOANON)); 1320*0Sstevel@tonic-gate 1321*0Sstevel@tonic-gate if (errno == E2BIG) 1322*0Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_ENDTOOBIG)); 1323*0Sstevel@tonic-gate 1324*0Sstevel@tonic-gate if (errno == ENOSPC) 1325*0Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_BUFTOOSMALL)); 1326*0Sstevel@tonic-gate 1327*0Sstevel@tonic-gate return (dt_set_errno(dtp, errno)); 1328*0Sstevel@tonic-gate } 1329*0Sstevel@tonic-gate 1330*0Sstevel@tonic-gate dtp->dt_active = 1; 1331*0Sstevel@tonic-gate 1332*0Sstevel@tonic-gate if (dt_options_load(dtp) == -1) 1333*0Sstevel@tonic-gate return (dt_set_errno(dtp, errno)); 1334*0Sstevel@tonic-gate 1335*0Sstevel@tonic-gate return (dt_aggregate_go(dtp)); 1336*0Sstevel@tonic-gate } 1337*0Sstevel@tonic-gate 1338*0Sstevel@tonic-gate int 1339*0Sstevel@tonic-gate dtrace_stop(dtrace_hdl_t *dtp) 1340*0Sstevel@tonic-gate { 1341*0Sstevel@tonic-gate if (dtp->dt_stopped) 1342*0Sstevel@tonic-gate return (0); 1343*0Sstevel@tonic-gate 1344*0Sstevel@tonic-gate if (dt_ioctl(dtp, DTRACEIOC_STOP, &dtp->dt_endedon) == -1) 1345*0Sstevel@tonic-gate return (dt_set_errno(dtp, errno)); 1346*0Sstevel@tonic-gate 1347*0Sstevel@tonic-gate dtp->dt_stopped = 1; 1348*0Sstevel@tonic-gate 1349*0Sstevel@tonic-gate return (0); 1350*0Sstevel@tonic-gate } 1351*0Sstevel@tonic-gate 1352*0Sstevel@tonic-gate int 1353*0Sstevel@tonic-gate dtrace_provider_modules(dtrace_hdl_t *dtp, const char **mods, int nmods) 1354*0Sstevel@tonic-gate { 1355*0Sstevel@tonic-gate dt_provmod_t *prov; 1356*0Sstevel@tonic-gate int i = 0; 1357*0Sstevel@tonic-gate 1358*0Sstevel@tonic-gate for (prov = dtp->dt_provmod; prov != NULL; prov = prov->dp_next, i++) { 1359*0Sstevel@tonic-gate if (i < nmods) 1360*0Sstevel@tonic-gate mods[i] = prov->dp_name; 1361*0Sstevel@tonic-gate } 1362*0Sstevel@tonic-gate 1363*0Sstevel@tonic-gate return (i); 1364*0Sstevel@tonic-gate } 1365*0Sstevel@tonic-gate 1366*0Sstevel@tonic-gate int 1367*0Sstevel@tonic-gate dtrace_ctlfd(dtrace_hdl_t *dtp) 1368*0Sstevel@tonic-gate { 1369*0Sstevel@tonic-gate return (dtp->dt_fd); 1370*0Sstevel@tonic-gate } 1371