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