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_moddir = "dtrace"; /* kernel module 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, const char *dirname, 638 const char *subdir, const char *isadir) 639 { 640 dt_provmod_t *prov; 641 char path[PATH_MAX]; 642 struct dirent *dp, *ep; 643 DIR *dirp; 644 int fd; 645 646 if (isadir) { 647 (void) snprintf(path, sizeof (path), "%s/%s/%s", 648 dirname, subdir, isadir); 649 } else { 650 (void) snprintf(path, sizeof (path), "%s/%s", 651 dirname, subdir); 652 } 653 654 if ((dirp = opendir(path)) == NULL) 655 return; /* failed to open directory; just skip it */ 656 657 ep = alloca(sizeof (struct dirent) + PATH_MAX + 1); 658 bzero(ep, sizeof (struct dirent) + PATH_MAX + 1); 659 660 while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) { 661 if (dp->d_name[0] == '.') 662 continue; /* skip "." and ".." */ 663 664 if (dfp->df_ents == dfp->df_size) { 665 uint_t size = dfp->df_size ? dfp->df_size * 2 : 16; 666 int *fds = realloc(dfp->df_fds, size * sizeof (int)); 667 668 if (fds == NULL) 669 break; /* skip the rest of this directory */ 670 671 dfp->df_fds = fds; 672 dfp->df_size = size; 673 } 674 675 (void) snprintf(path, sizeof (path), 676 "/devices/pseudo/%s@0:%s", dp->d_name, dp->d_name); 677 678 if ((fd = open(path, O_RDONLY)) == -1) 679 continue; /* failed to open driver; just skip it */ 680 681 if (((prov = malloc(sizeof (dt_provmod_t))) == NULL) || 682 (prov->dp_name = malloc(strlen(dp->d_name) + 1)) == NULL) { 683 free(prov); 684 (void) close(fd); 685 break; 686 } 687 688 (void) strcpy(prov->dp_name, dp->d_name); 689 prov->dp_next = *provmod; 690 *provmod = prov; 691 692 dt_dprintf("opened provider %s\n", dp->d_name); 693 dfp->df_fds[dfp->df_ents++] = fd; 694 } 695 696 (void) closedir(dirp); 697 } 698 699 static void 700 dt_provmod_destroy(dt_provmod_t **provmod) 701 { 702 dt_provmod_t *next, *current; 703 704 for (current = *provmod; current != NULL; current = next) { 705 next = current->dp_next; 706 free(current->dp_name); 707 free(current); 708 } 709 710 *provmod = NULL; 711 } 712 713 static const char * 714 dt_get_sysinfo(int cmd, char *buf, size_t len) 715 { 716 ssize_t rv = sysinfo(cmd, buf, len); 717 char *p = buf; 718 719 if (rv < 0 || rv > len) 720 (void) snprintf(buf, len, "%s", "Unknown"); 721 722 while ((p = strchr(p, '.')) != NULL) 723 *p++ = '_'; 724 725 return (buf); 726 } 727 728 static dtrace_hdl_t * 729 dt_vopen(int version, int flags, int *errp, 730 const dtrace_vector_t *vector, void *arg) 731 { 732 dtrace_hdl_t *dtp = NULL; 733 int dtfd = -1, ftfd = -1, fterr = 0; 734 dtrace_prog_t *pgp; 735 dt_module_t *dmp; 736 dt_provmod_t *provmod = NULL; 737 int i, err; 738 739 const dt_intrinsic_t *dinp; 740 const dt_typedef_t *dtyp; 741 const dt_ident_t *idp; 742 743 dtrace_typeinfo_t dtt; 744 ctf_funcinfo_t ctc; 745 ctf_arinfo_t ctr; 746 747 dt_fdlist_t df = { NULL, 0, 0 }; 748 char *p, *q, *path = NULL; 749 const char *isadir = NULL; 750 int pathlen; 751 752 char isadef[32], utsdef[32]; 753 char s1[64], s2[64]; 754 755 if (version <= 0) 756 return (set_open_errno(dtp, errp, EINVAL)); 757 758 if (version > DTRACE_VERSION) 759 return (set_open_errno(dtp, errp, EDT_VERSION)); 760 761 if (version < DTRACE_VERSION) { 762 /* 763 * Currently, increasing the library version number is used to 764 * denote a binary incompatible change. That is, a consumer 765 * of the library cannot run on a version of the library with 766 * a higher DTRACE_VERSION number than the consumer compiled 767 * against. Once the library API has been committed to, 768 * backwards binary compatibility will be required; at that 769 * time, this check should change to return EDT_OVERSION only 770 * if the specified version number is less than the version 771 * number at the time of interface commitment. 772 */ 773 return (set_open_errno(dtp, errp, EDT_OVERSION)); 774 } 775 776 if (flags & ~DTRACE_O_MASK) 777 return (set_open_errno(dtp, errp, EINVAL)); 778 779 if ((flags & DTRACE_O_LP64) && (flags & DTRACE_O_ILP32)) 780 return (set_open_errno(dtp, errp, EINVAL)); 781 782 if (vector == NULL && arg != NULL) 783 return (set_open_errno(dtp, errp, EINVAL)); 784 785 if (elf_version(EV_CURRENT) == EV_NONE) 786 return (set_open_errno(dtp, errp, EDT_ELFVERSION)); 787 788 if (vector != NULL || (flags & DTRACE_O_NODEV)) 789 goto alloc; /* do not attempt to open dtrace device */ 790 791 /* 792 * For each directory in the kernel's module path, build the name of 793 * the corresponding dtrace provider subdirectory and attempt to open a 794 * pseudo-driver whose name matches the name of each provider therein. 795 * We hold them open in the df.df_fds list until we open the DTrace 796 * driver itself, allowing us to see all of the probes provided on this 797 * system. Once we have the DTrace driver open, we can safely close 798 * all the providers now that they have registered with the framework. 799 */ 800 if (sysinfo(SI_ISALIST, isadef, sizeof (isadef)) > 0) { 801 if (strstr(isadef, "sparcv9") != NULL) 802 isadir = "sparcv9"; 803 else if (strstr(isadef, "amd64") != NULL) 804 isadir = "amd64"; 805 } 806 807 if (modctl(MODGETPATHLEN, NULL, &pathlen) == 0 && 808 (path = malloc(pathlen + 1)) != NULL && 809 modctl(MODGETPATH, NULL, path) == 0) { 810 for (p = path; *p != '\0'; p = q) { 811 if ((q = strchr(p, ' ')) != NULL) 812 *q++ = '\0'; 813 else 814 q = p + strlen(p); 815 dt_provmod_open(&provmod, &df, p, 816 _dtrace_moddir, isadir); 817 } 818 } 819 820 dtfd = open("/devices/pseudo/dtrace@0:dtrace", O_RDWR); 821 err = errno; /* save errno from opening dtfd */ 822 823 ftfd = open("/devices/pseudo/fasttrap@0:fasttrap", O_RDWR); 824 fterr = ftfd == -1 ? errno : 0; /* save errno from open ftfd */ 825 826 while (df.df_ents-- != 0) 827 (void) close(df.df_fds[df.df_ents]); 828 829 free(df.df_fds); 830 free(path); 831 832 /* 833 * If we failed to open the dtrace device, fail dtrace_open(). 834 * We convert some kernel errnos to custom libdtrace errnos to 835 * improve the resulting message from the usual strerror(). 836 */ 837 if (dtfd == -1) { 838 dt_provmod_destroy(&provmod); 839 switch (err) { 840 case ENOENT: 841 if (getzoneid() != GLOBAL_ZONEID) 842 err = EDT_ZNOENT; 843 else 844 err = EDT_GNOENT; 845 break; 846 case EBUSY: 847 err = EDT_BUSY; 848 break; 849 case EACCES: 850 err = EDT_ACCESS; 851 break; 852 } 853 return (set_open_errno(dtp, errp, err)); 854 } 855 856 (void) fcntl(dtfd, F_SETFD, FD_CLOEXEC); 857 (void) fcntl(ftfd, F_SETFD, FD_CLOEXEC); 858 859 alloc: 860 if ((dtp = malloc(sizeof (dtrace_hdl_t))) == NULL) 861 return (set_open_errno(dtp, errp, EDT_NOMEM)); 862 863 bzero(dtp, sizeof (dtrace_hdl_t)); 864 dtp->dt_oflags = flags; 865 dtp->dt_prcmode = DT_PROC_STOP_PREINIT; 866 dtp->dt_linkmode = DT_LINK_KERNEL; 867 dtp->dt_linktype = DT_LTYP_ELF; 868 dtp->dt_xlatemode = DT_XL_STATIC; 869 dtp->dt_stdcmode = DT_STDC_XA; 870 dtp->dt_version = version; 871 dtp->dt_fd = dtfd; 872 dtp->dt_ftfd = ftfd; 873 dtp->dt_fterr = fterr; 874 dtp->dt_cdefs_fd = -1; 875 dtp->dt_ddefs_fd = -1; 876 dtp->dt_stdout_fd = -1; 877 dtp->dt_modbuckets = _dtrace_strbuckets; 878 dtp->dt_mods = calloc(dtp->dt_modbuckets, sizeof (dt_module_t *)); 879 dtp->dt_provbuckets = _dtrace_strbuckets; 880 dtp->dt_provs = calloc(dtp->dt_provbuckets, sizeof (dt_provider_t *)); 881 dt_proc_hash_create(dtp); 882 dtp->dt_vmax = DT_VERS_LATEST; 883 dtp->dt_cpp_path = strdup(_dtrace_defcpp); 884 dtp->dt_cpp_argv = malloc(sizeof (char *)); 885 dtp->dt_cpp_argc = 1; 886 dtp->dt_cpp_args = 1; 887 dtp->dt_ld_path = strdup(_dtrace_defld); 888 dtp->dt_provmod = provmod; 889 dtp->dt_vector = vector; 890 dtp->dt_varg = arg; 891 dt_dof_init(dtp); 892 (void) uname(&dtp->dt_uts); 893 894 if (dtp->dt_mods == NULL || dtp->dt_provs == NULL || 895 dtp->dt_procs == NULL || dtp->dt_ld_path == NULL || 896 dtp->dt_cpp_path == NULL || dtp->dt_cpp_argv == NULL) 897 return (set_open_errno(dtp, errp, EDT_NOMEM)); 898 899 for (i = 0; i < DTRACEOPT_MAX; i++) 900 dtp->dt_options[i] = DTRACEOPT_UNSET; 901 902 dtp->dt_cpp_argv[0] = (char *)strbasename(dtp->dt_cpp_path); 903 904 (void) snprintf(isadef, sizeof (isadef), "-D__SUNW_D_%u", 905 (uint_t)(sizeof (void *) * NBBY)); 906 907 (void) snprintf(utsdef, sizeof (utsdef), "-D__%s_%s", 908 dt_get_sysinfo(SI_SYSNAME, s1, sizeof (s1)), 909 dt_get_sysinfo(SI_RELEASE, s2, sizeof (s2))); 910 911 if (dt_cpp_add_arg(dtp, "-D__sun") == NULL || 912 dt_cpp_add_arg(dtp, "-D__unix") == NULL || 913 dt_cpp_add_arg(dtp, "-D__SVR4") == NULL || 914 dt_cpp_add_arg(dtp, "-D__SUNW_D=1") == NULL || 915 dt_cpp_add_arg(dtp, isadef) == NULL || 916 dt_cpp_add_arg(dtp, utsdef) == NULL) 917 return (set_open_errno(dtp, errp, EDT_NOMEM)); 918 919 if (flags & DTRACE_O_NODEV) 920 bcopy(&_dtrace_conf, &dtp->dt_conf, sizeof (_dtrace_conf)); 921 else if (dt_ioctl(dtp, DTRACEIOC_CONF, &dtp->dt_conf) != 0) 922 return (set_open_errno(dtp, errp, errno)); 923 924 if (flags & DTRACE_O_LP64) 925 dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_LP64; 926 else if (flags & DTRACE_O_ILP32) 927 dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_ILP32; 928 929 #ifdef __sparc 930 /* 931 * On SPARC systems, __sparc is always defined for <sys/isa_defs.h> 932 * and __sparcv9 is defined if we are doing a 64-bit compile. 933 */ 934 if (dt_cpp_add_arg(dtp, "-D__sparc") == NULL) 935 return (set_open_errno(dtp, errp, EDT_NOMEM)); 936 937 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64 && 938 dt_cpp_add_arg(dtp, "-D__sparcv9") == NULL) 939 return (set_open_errno(dtp, errp, EDT_NOMEM)); 940 #endif 941 942 #ifdef __x86 943 /* 944 * On x86 systems, __i386 is defined for <sys/isa_defs.h> for 32-bit 945 * compiles and __amd64 is defined for 64-bit compiles. Unlike SPARC, 946 * they are defined exclusive of one another (see PSARC 2004/619). 947 */ 948 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) 949 p = dt_cpp_add_arg(dtp, "-D__amd64"); 950 else 951 p = dt_cpp_add_arg(dtp, "-D__i386"); 952 953 if (p == NULL) 954 return (set_open_errno(dtp, errp, EDT_NOMEM)); 955 #endif 956 957 if (dtp->dt_conf.dtc_difversion < DIF_VERSION) 958 return (set_open_errno(dtp, errp, EDT_DIFVERS)); 959 960 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32) 961 bcopy(_dtrace_ints_32, dtp->dt_ints, sizeof (_dtrace_ints_32)); 962 else 963 bcopy(_dtrace_ints_64, dtp->dt_ints, sizeof (_dtrace_ints_64)); 964 965 dtp->dt_macros = dt_idhash_create("macro", NULL, 0, UINT_MAX); 966 dtp->dt_aggs = dt_idhash_create("aggregation", NULL, 967 DTRACE_AGGVARIDNONE + 1, UINT_MAX); 968 969 dtp->dt_globals = dt_idhash_create("global", _dtrace_globals, 970 DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX); 971 972 dtp->dt_tls = dt_idhash_create("thread local", NULL, 973 DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX); 974 975 if (dtp->dt_macros == NULL || dtp->dt_aggs == NULL || 976 dtp->dt_globals == NULL || dtp->dt_tls == NULL) 977 return (set_open_errno(dtp, errp, EDT_NOMEM)); 978 979 /* 980 * Populate the dt_macros identifier hash table by hand: we can't use 981 * the dt_idhash_populate() mechanism because we're not yet compiling 982 * and dtrace_update() needs to immediately reference these idents. 983 */ 984 for (idp = _dtrace_macros; idp->di_name != NULL; idp++) { 985 if (dt_idhash_insert(dtp->dt_macros, idp->di_name, 986 idp->di_kind, idp->di_flags, idp->di_id, idp->di_attr, 987 idp->di_vers, idp->di_ops ? idp->di_ops : &dt_idops_thaw, 988 idp->di_iarg, 0) == NULL) 989 return (set_open_errno(dtp, errp, EDT_NOMEM)); 990 } 991 992 /* 993 * Update the module list using /system/object and load the values for 994 * the macro variable definitions according to the current process. 995 */ 996 dtrace_update(dtp); 997 998 /* 999 * Select the intrinsics and typedefs we want based on the data model. 1000 * The intrinsics are under "C". The typedefs are added under "D". 1001 */ 1002 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32) { 1003 dinp = _dtrace_intrinsics_32; 1004 dtyp = _dtrace_typedefs_32; 1005 } else { 1006 dinp = _dtrace_intrinsics_64; 1007 dtyp = _dtrace_typedefs_64; 1008 } 1009 1010 /* 1011 * Create a dynamic CTF container under the "C" scope for intrinsic 1012 * types and types defined in ANSI-C header files that are included. 1013 */ 1014 if ((dmp = dtp->dt_cdefs = dt_module_create(dtp, "C")) == NULL) 1015 return (set_open_errno(dtp, errp, EDT_NOMEM)); 1016 1017 if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL) 1018 return (set_open_errno(dtp, errp, EDT_CTF)); 1019 1020 dt_dprintf("created CTF container for %s (%p)\n", 1021 dmp->dm_name, (void *)dmp->dm_ctfp); 1022 1023 (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel); 1024 ctf_setspecific(dmp->dm_ctfp, dmp); 1025 1026 dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */ 1027 dmp->dm_modid = -1; /* no module ID */ 1028 1029 /* 1030 * Fill the dynamic "C" CTF container with all of the intrinsic 1031 * integer and floating-point types appropriate for this data model. 1032 */ 1033 for (; dinp->din_name != NULL; dinp++) { 1034 if (dinp->din_kind == CTF_K_INTEGER) { 1035 err = ctf_add_integer(dmp->dm_ctfp, CTF_ADD_ROOT, 1036 dinp->din_name, &dinp->din_data); 1037 } else { 1038 err = ctf_add_float(dmp->dm_ctfp, CTF_ADD_ROOT, 1039 dinp->din_name, &dinp->din_data); 1040 } 1041 1042 if (err == CTF_ERR) { 1043 dt_dprintf("failed to add %s to C container: %s\n", 1044 dinp->din_name, ctf_errmsg( 1045 ctf_errno(dmp->dm_ctfp))); 1046 return (set_open_errno(dtp, errp, EDT_CTF)); 1047 } 1048 } 1049 1050 if (ctf_update(dmp->dm_ctfp) != 0) { 1051 dt_dprintf("failed to update C container: %s\n", 1052 ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1053 return (set_open_errno(dtp, errp, EDT_CTF)); 1054 } 1055 1056 /* 1057 * Add intrinsic pointer types that are needed to initialize printf 1058 * format dictionary types (see table in dt_printf.c). 1059 */ 1060 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, 1061 ctf_lookup_by_name(dmp->dm_ctfp, "void")); 1062 1063 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, 1064 ctf_lookup_by_name(dmp->dm_ctfp, "char")); 1065 1066 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, 1067 ctf_lookup_by_name(dmp->dm_ctfp, "int")); 1068 1069 if (ctf_update(dmp->dm_ctfp) != 0) { 1070 dt_dprintf("failed to update C container: %s\n", 1071 ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1072 return (set_open_errno(dtp, errp, EDT_CTF)); 1073 } 1074 1075 /* 1076 * Create a dynamic CTF container under the "D" scope for types that 1077 * are defined by the D program itself or on-the-fly by the D compiler. 1078 * The "D" CTF container is a child of the "C" CTF container. 1079 */ 1080 if ((dmp = dtp->dt_ddefs = dt_module_create(dtp, "D")) == NULL) 1081 return (set_open_errno(dtp, errp, EDT_NOMEM)); 1082 1083 if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL) 1084 return (set_open_errno(dtp, errp, EDT_CTF)); 1085 1086 dt_dprintf("created CTF container for %s (%p)\n", 1087 dmp->dm_name, (void *)dmp->dm_ctfp); 1088 1089 (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel); 1090 ctf_setspecific(dmp->dm_ctfp, dmp); 1091 1092 dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */ 1093 dmp->dm_modid = -1; /* no module ID */ 1094 1095 if (ctf_import(dmp->dm_ctfp, dtp->dt_cdefs->dm_ctfp) == CTF_ERR) { 1096 dt_dprintf("failed to import D parent container: %s\n", 1097 ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1098 return (set_open_errno(dtp, errp, EDT_CTF)); 1099 } 1100 1101 /* 1102 * Fill the dynamic "D" CTF container with all of the built-in typedefs 1103 * that we need to use for our D variable and function definitions. 1104 * This ensures that basic inttypes.h names are always available to us. 1105 */ 1106 for (; dtyp->dty_src != NULL; dtyp++) { 1107 if (ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 1108 dtyp->dty_dst, ctf_lookup_by_name(dmp->dm_ctfp, 1109 dtyp->dty_src)) == CTF_ERR) { 1110 dt_dprintf("failed to add typedef %s %s to D " 1111 "container: %s", dtyp->dty_src, dtyp->dty_dst, 1112 ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1113 return (set_open_errno(dtp, errp, EDT_CTF)); 1114 } 1115 } 1116 1117 /* 1118 * Insert a CTF ID corresponding to a pointer to a type of kind 1119 * CTF_K_FUNCTION we can use in the compiler for function pointers. 1120 * CTF treats all function pointers as "int (*)()" so we only need one. 1121 */ 1122 ctc.ctc_return = ctf_lookup_by_name(dmp->dm_ctfp, "int"); 1123 ctc.ctc_argc = 0; 1124 ctc.ctc_flags = 0; 1125 1126 dtp->dt_type_func = ctf_add_function(dmp->dm_ctfp, 1127 CTF_ADD_ROOT, &ctc, NULL); 1128 1129 dtp->dt_type_fptr = ctf_add_pointer(dmp->dm_ctfp, 1130 CTF_ADD_ROOT, dtp->dt_type_func); 1131 1132 /* 1133 * We also insert CTF definitions for the special D intrinsic types 1134 * string and <DYN> into the D container. The string type is added 1135 * as a typedef of char[n]. The <DYN> type is an alias for void. 1136 * We compare types to these special CTF ids throughout the compiler. 1137 */ 1138 ctr.ctr_contents = ctf_lookup_by_name(dmp->dm_ctfp, "char"); 1139 ctr.ctr_index = ctf_lookup_by_name(dmp->dm_ctfp, "long"); 1140 ctr.ctr_nelems = _dtrace_strsize; 1141 1142 dtp->dt_type_str = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 1143 "string", ctf_add_array(dmp->dm_ctfp, CTF_ADD_ROOT, &ctr)); 1144 1145 dtp->dt_type_dyn = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 1146 "<DYN>", ctf_lookup_by_name(dmp->dm_ctfp, "void")); 1147 1148 dtp->dt_type_stack = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 1149 "stack", ctf_lookup_by_name(dmp->dm_ctfp, "void")); 1150 1151 dtp->dt_type_symaddr = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 1152 "_symaddr", ctf_lookup_by_name(dmp->dm_ctfp, "void")); 1153 1154 dtp->dt_type_usymaddr = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 1155 "_usymaddr", ctf_lookup_by_name(dmp->dm_ctfp, "void")); 1156 1157 if (dtp->dt_type_func == CTF_ERR || dtp->dt_type_fptr == CTF_ERR || 1158 dtp->dt_type_str == CTF_ERR || dtp->dt_type_dyn == CTF_ERR || 1159 dtp->dt_type_stack == CTF_ERR || dtp->dt_type_symaddr == CTF_ERR || 1160 dtp->dt_type_usymaddr == CTF_ERR) { 1161 dt_dprintf("failed to add intrinsic to D container: %s\n", 1162 ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1163 return (set_open_errno(dtp, errp, EDT_CTF)); 1164 } 1165 1166 if (ctf_update(dmp->dm_ctfp) != 0) { 1167 dt_dprintf("failed update D container: %s\n", 1168 ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1169 return (set_open_errno(dtp, errp, EDT_CTF)); 1170 } 1171 1172 /* 1173 * Initialize the integer description table used to convert integer 1174 * constants to the appropriate types. Refer to the comments above 1175 * dt_node_int() for a complete description of how this table is used. 1176 */ 1177 for (i = 0; i < sizeof (dtp->dt_ints) / sizeof (dtp->dt_ints[0]); i++) { 1178 if (dtrace_lookup_by_type(dtp, DTRACE_OBJ_EVERY, 1179 dtp->dt_ints[i].did_name, &dtt) != 0) { 1180 dt_dprintf("failed to lookup integer type %s: %s\n", 1181 dtp->dt_ints[i].did_name, 1182 dtrace_errmsg(dtp, dtrace_errno(dtp))); 1183 return (set_open_errno(dtp, errp, dtp->dt_errno)); 1184 } 1185 dtp->dt_ints[i].did_ctfp = dtt.dtt_ctfp; 1186 dtp->dt_ints[i].did_type = dtt.dtt_type; 1187 } 1188 1189 /* 1190 * Now that we've created the "C" and "D" containers, move them to the 1191 * start of the module list so that these types and symbols are found 1192 * first (for stability) when iterating through the module list. 1193 */ 1194 dt_list_delete(&dtp->dt_modlist, dtp->dt_ddefs); 1195 dt_list_prepend(&dtp->dt_modlist, dtp->dt_ddefs); 1196 1197 dt_list_delete(&dtp->dt_modlist, dtp->dt_cdefs); 1198 dt_list_prepend(&dtp->dt_modlist, dtp->dt_cdefs); 1199 1200 if (dt_pfdict_create(dtp) == -1) 1201 return (set_open_errno(dtp, errp, dtp->dt_errno)); 1202 1203 /* 1204 * If we are opening libdtrace DTRACE_O_NODEV enable C_ZDEFS by default 1205 * because without /dev/dtrace open, we will not be able to load the 1206 * names and attributes of any providers or probes from the kernel. 1207 */ 1208 if (flags & DTRACE_O_NODEV) 1209 dtp->dt_cflags |= DTRACE_C_ZDEFS; 1210 1211 /* 1212 * Load hard-wired inlines into the definition cache by calling the 1213 * compiler on the raw definition string defined above. 1214 */ 1215 if ((pgp = dtrace_program_strcompile(dtp, _dtrace_hardwire, 1216 DTRACE_PROBESPEC_NONE, DTRACE_C_EMPTY, 0, NULL)) == NULL) { 1217 dt_dprintf("failed to load hard-wired definitions: %s\n", 1218 dtrace_errmsg(dtp, dtrace_errno(dtp))); 1219 return (set_open_errno(dtp, errp, EDT_HARDWIRE)); 1220 } 1221 1222 dt_program_destroy(dtp, pgp); 1223 1224 /* 1225 * Set up the default DTrace library path. Once set, the next call to 1226 * dt_compile() will compile all the libraries. We intentionally defer 1227 * library processing to improve overhead for clients that don't ever 1228 * compile, and to provide better error reporting (because the full 1229 * reporting of compiler errors requires dtrace_open() to succeed). 1230 */ 1231 if (dtrace_setopt(dtp, "libdir", _dtrace_libdir) != 0) 1232 return (set_open_errno(dtp, errp, dtp->dt_errno)); 1233 1234 return (dtp); 1235 } 1236 1237 dtrace_hdl_t * 1238 dtrace_open(int version, int flags, int *errp) 1239 { 1240 return (dt_vopen(version, flags, errp, NULL, NULL)); 1241 } 1242 1243 dtrace_hdl_t * 1244 dtrace_vopen(int version, int flags, int *errp, 1245 const dtrace_vector_t *vector, void *arg) 1246 { 1247 return (dt_vopen(version, flags, errp, vector, arg)); 1248 } 1249 1250 void 1251 dtrace_close(dtrace_hdl_t *dtp) 1252 { 1253 dt_ident_t *idp, *ndp; 1254 dt_module_t *dmp; 1255 dt_provider_t *pvp; 1256 dtrace_prog_t *pgp; 1257 dt_xlator_t *dxp; 1258 dt_dirpath_t *dirp; 1259 int i; 1260 1261 while ((pgp = dt_list_next(&dtp->dt_programs)) != NULL) 1262 dt_program_destroy(dtp, pgp); 1263 1264 while ((dxp = dt_list_next(&dtp->dt_xlators)) != NULL) 1265 dt_xlator_destroy(dtp, dxp); 1266 1267 dt_free(dtp, dtp->dt_xlatormap); 1268 1269 for (idp = dtp->dt_externs; idp != NULL; idp = ndp) { 1270 ndp = idp->di_next; 1271 dt_ident_destroy(idp); 1272 } 1273 1274 if (dtp->dt_macros != NULL) 1275 dt_idhash_destroy(dtp->dt_macros); 1276 if (dtp->dt_aggs != NULL) 1277 dt_idhash_destroy(dtp->dt_aggs); 1278 if (dtp->dt_globals != NULL) 1279 dt_idhash_destroy(dtp->dt_globals); 1280 if (dtp->dt_tls != NULL) 1281 dt_idhash_destroy(dtp->dt_tls); 1282 1283 while ((dmp = dt_list_next(&dtp->dt_modlist)) != NULL) 1284 dt_module_destroy(dtp, dmp); 1285 1286 while ((pvp = dt_list_next(&dtp->dt_provlist)) != NULL) 1287 dt_provider_destroy(dtp, pvp); 1288 1289 if (dtp->dt_procs != NULL) 1290 dt_proc_hash_destroy(dtp); 1291 1292 if (dtp->dt_fd != -1) 1293 (void) close(dtp->dt_fd); 1294 if (dtp->dt_ftfd != -1) 1295 (void) close(dtp->dt_ftfd); 1296 if (dtp->dt_cdefs_fd != -1) 1297 (void) close(dtp->dt_cdefs_fd); 1298 if (dtp->dt_ddefs_fd != -1) 1299 (void) close(dtp->dt_ddefs_fd); 1300 if (dtp->dt_stdout_fd != -1) 1301 (void) close(dtp->dt_stdout_fd); 1302 1303 dt_epid_destroy(dtp); 1304 dt_aggid_destroy(dtp); 1305 dt_format_destroy(dtp); 1306 dt_buffered_destroy(dtp); 1307 dt_aggregate_destroy(dtp); 1308 free(dtp->dt_buf.dtbd_data); 1309 dt_pfdict_destroy(dtp); 1310 dt_provmod_destroy(&dtp->dt_provmod); 1311 dt_dof_fini(dtp); 1312 1313 for (i = 1; i < dtp->dt_cpp_argc; i++) 1314 free(dtp->dt_cpp_argv[i]); 1315 1316 while ((dirp = dt_list_next(&dtp->dt_lib_path)) != NULL) { 1317 dt_list_delete(&dtp->dt_lib_path, dirp); 1318 free(dirp->dir_path); 1319 free(dirp); 1320 } 1321 1322 free(dtp->dt_cpp_argv); 1323 free(dtp->dt_cpp_path); 1324 free(dtp->dt_ld_path); 1325 1326 free(dtp->dt_mods); 1327 free(dtp->dt_provs); 1328 free(dtp); 1329 } 1330 1331 int 1332 dtrace_provider_modules(dtrace_hdl_t *dtp, const char **mods, int nmods) 1333 { 1334 dt_provmod_t *prov; 1335 int i = 0; 1336 1337 for (prov = dtp->dt_provmod; prov != NULL; prov = prov->dp_next, i++) { 1338 if (i < nmods) 1339 mods[i] = prov->dp_name; 1340 } 1341 1342 return (i); 1343 } 1344 1345 int 1346 dtrace_ctlfd(dtrace_hdl_t *dtp) 1347 { 1348 return (dtp->dt_fd); 1349 } 1350