dt_open.c revision 178570
1263320Sdim/* 2263320Sdim * CDDL HEADER START 3263320Sdim * 4263320Sdim * The contents of this file are subject to the terms of the 5269012Semaste * Common Development and Distribution License (the "License"). 6263320Sdim * You may not use this file except in compliance with the License. 7263320Sdim * 8263320Sdim * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9263320Sdim * or http://www.opensolaris.org/os/licensing. 10263320Sdim * See the License for the specific language governing permissions 11263320Sdim * and limitations under the License. 12263320Sdim * 13263320Sdim * When distributing Covered Code, include this CDDL HEADER in each 14263320Sdim * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15263320Sdim * If applicable, add the following below this CDDL HEADER, with the 16263320Sdim * fields enclosed by brackets "[]" replaced with your own identifying 17263320Sdim * information: Portions Copyright [yyyy] [name of copyright owner] 18263320Sdim * 19263320Sdim * CDDL HEADER END 20263320Sdim */ 21263320Sdim 22263320Sdim/* 23263320Sdim * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24263320Sdim * Use is subject to license terms. 25263320Sdim */ 26263320Sdim 27263320Sdim#pragma ident "%Z%%M% %I% %E% SMI" 28263320Sdim 29263320Sdim#include <sys/types.h> 30263320Sdim#if defined(sun) 31263320Sdim#include <sys/modctl.h> 32263320Sdim#include <sys/systeminfo.h> 33263320Sdim#endif 34263320Sdim#include <sys/resource.h> 35263320Sdim 36263320Sdim#include <libelf.h> 37263320Sdim#include <strings.h> 38263320Sdim#if defined(sun) 39263320Sdim#include <alloca.h> 40263320Sdim#endif 41263320Sdim#include <limits.h> 42263320Sdim#include <unistd.h> 43263320Sdim#include <stdlib.h> 44263320Sdim#include <stdio.h> 45263320Sdim#include <fcntl.h> 46263320Sdim#include <errno.h> 47263320Sdim#include <assert.h> 48263320Sdim 49263320Sdim#define _POSIX_PTHREAD_SEMANTICS 50263320Sdim#include <dirent.h> 51263320Sdim#undef _POSIX_PTHREAD_SEMANTICS 52263320Sdim 53263320Sdim#include <dt_impl.h> 54263320Sdim#include <dt_program.h> 55263320Sdim#include <dt_module.h> 56263320Sdim#include <dt_printf.h> 57263320Sdim#include <dt_string.h> 58263320Sdim#include <dt_provider.h> 59263320Sdim#if !defined(sun) 60263320Sdim#include <sys/sysctl.h> 61263320Sdim#include <string.h> 62263320Sdim#endif 63263320Sdim#if defined(__i386__) 64263320Sdim#include <ieeefp.h> 65263320Sdim#endif 66263320Sdim 67263320Sdim/* 68263320Sdim * Stability and versioning definitions. These #defines are used in the tables 69263320Sdim * of identifiers below to fill in the attribute and version fields associated 70263320Sdim * with each identifier. The DT_ATTR_* macros are a convenience to permit more 71263320Sdim * concise declarations of common attributes such as Stable/Stable/Common. The 72263320Sdim * DT_VERS_* macros declare the encoded integer values of all versions used so 73263320Sdim * far. DT_VERS_LATEST must correspond to the latest version value among all 74263320Sdim * versions exported by the D compiler. DT_VERS_STRING must be an ASCII string 75263320Sdim * that contains DT_VERS_LATEST within it along with any suffixes (e.g. Beta). 76263320Sdim * You must update DT_VERS_LATEST and DT_VERS_STRING when adding a new version, 77263320Sdim * and then add the new version to the _dtrace_versions[] array declared below. 78263320Sdim * Refer to the Solaris Dynamic Tracing Guide Stability and Versioning chapters 79263320Sdim * respectively for an explanation of these DTrace features and their values. 80263320Sdim * 81263320Sdim * NOTE: Although the DTrace versioning scheme supports the labeling and 82263320Sdim * introduction of incompatible changes (e.g. dropping an interface in a 83263320Sdim * major release), the libdtrace code does not currently support this. 84263320Sdim * All versions are assumed to strictly inherit from one another. If 85263320Sdim * we ever need to provide divergent interfaces, this will need work. 86263320Sdim */ 87263320Sdim#define DT_ATTR_STABCMN { DTRACE_STABILITY_STABLE, \ 88263320Sdim DTRACE_STABILITY_STABLE, DTRACE_CLASS_COMMON } 89263320Sdim 90263320Sdim#define DT_ATTR_EVOLCMN { DTRACE_STABILITY_EVOLVING, \ 91263320Sdim DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON \ 92263320Sdim} 93263320Sdim 94263320Sdim/* 95263320Sdim * The version number should be increased for every customer visible release 96263320Sdim * of Solaris. The major number should be incremented when a fundamental 97263320Sdim * change has been made that would affect all consumers, and would reflect 98263320Sdim * sweeping changes to DTrace or the D language. The minor number should be 99263320Sdim * incremented when a change is introduced that could break scripts that had 100263320Sdim * previously worked; for example, adding a new built-in variable could break 101263320Sdim * a script which was already using that identifier. The micro number should 102263320Sdim * be changed when introducing functionality changes or major bug fixes that 103263320Sdim * do not affect backward compatibility -- this is merely to make capabilities 104263320Sdim * easily determined from the version number. Minor bugs do not require any 105263320Sdim * modification to the version number. 106263320Sdim */ 107263320Sdim#define DT_VERS_1_0 DT_VERSION_NUMBER(1, 0, 0) 108263320Sdim#define DT_VERS_1_1 DT_VERSION_NUMBER(1, 1, 0) 109263320Sdim#define DT_VERS_1_2 DT_VERSION_NUMBER(1, 2, 0) 110263320Sdim#define DT_VERS_1_2_1 DT_VERSION_NUMBER(1, 2, 1) 111263320Sdim#define DT_VERS_1_2_2 DT_VERSION_NUMBER(1, 2, 2) 112263320Sdim#define DT_VERS_1_3 DT_VERSION_NUMBER(1, 3, 0) 113263320Sdim#define DT_VERS_1_4 DT_VERSION_NUMBER(1, 4, 0) 114263320Sdim#define DT_VERS_1_4_1 DT_VERSION_NUMBER(1, 4, 1) 115263320Sdim#define DT_VERS_1_5 DT_VERSION_NUMBER(1, 5, 0) 116263320Sdim#define DT_VERS_1_6 DT_VERSION_NUMBER(1, 6, 0) 117263320Sdim#define DT_VERS_1_6_1 DT_VERSION_NUMBER(1, 6, 1) 118263320Sdim#define DT_VERS_LATEST DT_VERS_1_6_1 119263320Sdim#define DT_VERS_STRING "Sun D 1.6.1" 120263320Sdim 121263320Sdimconst dt_version_t _dtrace_versions[] = { 122263320Sdim DT_VERS_1_0, /* D API 1.0.0 (PSARC 2001/466) Solaris 10 FCS */ 123263320Sdim DT_VERS_1_1, /* D API 1.1.0 Solaris Express 6/05 */ 124263320Sdim DT_VERS_1_2, /* D API 1.2.0 Solaris 10 Update 1 */ 125263320Sdim DT_VERS_1_2_1, /* D API 1.2.1 Solaris Express 4/06 */ 126263320Sdim DT_VERS_1_2_2, /* D API 1.2.2 Solaris Express 6/06 */ 127263320Sdim DT_VERS_1_3, /* D API 1.3 Solaris Express 10/06 */ 128263320Sdim DT_VERS_1_4, /* D API 1.4 Solaris Express 2/07 */ 129263320Sdim DT_VERS_1_4_1, /* D API 1.4.1 Solaris Express 4/07 */ 130263320Sdim DT_VERS_1_5, /* D API 1.5 Solaris Express 7/07 */ 131263320Sdim DT_VERS_1_6, /* D API 1.6 */ 132263320Sdim DT_VERS_1_6_1, /* D API 1.6.1 */ 133263320Sdim 0 134263320Sdim}; 135263320Sdim 136263320Sdim/* 137263320Sdim * Global variables that are formatted on FreeBSD based on the kernel file name. 138263320Sdim */ 139263320Sdim#if !defined(sun) 140263320Sdimstatic char curthread_str[MAXPATHLEN]; 141263320Sdimstatic char intmtx_str[MAXPATHLEN]; 142263320Sdimstatic char threadmtx_str[MAXPATHLEN]; 143263320Sdimstatic char rwlock_str[MAXPATHLEN]; 144263320Sdimstatic char sxlock_str[MAXPATHLEN]; 145263320Sdim#endif 146263320Sdim 147263320Sdim/* 148263320Sdim * Table of global identifiers. This is used to populate the global identifier 149263320Sdim * hash when a new dtrace client open occurs. For more info see dt_ident.h. 150263320Sdim * The global identifiers that represent functions use the dt_idops_func ops 151263320Sdim * and specify the private data pointer as a prototype string which is parsed 152263320Sdim * when the identifier is first encountered. These prototypes look like ANSI 153263320Sdim * C function prototypes except that the special symbol "@" can be used as a 154263320Sdim * wildcard to represent a single parameter of any type (i.e. any dt_node_t). 155263320Sdim * The standard "..." notation can also be used to represent varargs. An empty 156263320Sdim * parameter list is taken to mean void (that is, no arguments are permitted). 157263320Sdim * A parameter enclosed in square brackets (e.g. "[int]") denotes an optional 158263320Sdim * argument. 159263320Sdim */ 160263320Sdimstatic const dt_ident_t _dtrace_globals[] = { 161263320Sdim{ "alloca", DT_IDENT_FUNC, 0, DIF_SUBR_ALLOCA, DT_ATTR_STABCMN, DT_VERS_1_0, 162263320Sdim &dt_idops_func, "void *(size_t)" }, 163263320Sdim{ "arg0", DT_IDENT_SCALAR, 0, DIF_VAR_ARG0, DT_ATTR_STABCMN, DT_VERS_1_0, 164263320Sdim &dt_idops_type, "int64_t" }, 165263320Sdim{ "arg1", DT_IDENT_SCALAR, 0, DIF_VAR_ARG1, DT_ATTR_STABCMN, DT_VERS_1_0, 166263320Sdim &dt_idops_type, "int64_t" }, 167263320Sdim{ "arg2", DT_IDENT_SCALAR, 0, DIF_VAR_ARG2, DT_ATTR_STABCMN, DT_VERS_1_0, 168263320Sdim &dt_idops_type, "int64_t" }, 169263320Sdim{ "arg3", DT_IDENT_SCALAR, 0, DIF_VAR_ARG3, DT_ATTR_STABCMN, DT_VERS_1_0, 170263320Sdim &dt_idops_type, "int64_t" }, 171263320Sdim{ "arg4", DT_IDENT_SCALAR, 0, DIF_VAR_ARG4, DT_ATTR_STABCMN, DT_VERS_1_0, 172263320Sdim &dt_idops_type, "int64_t" }, 173263320Sdim{ "arg5", DT_IDENT_SCALAR, 0, DIF_VAR_ARG5, DT_ATTR_STABCMN, DT_VERS_1_0, 174263320Sdim &dt_idops_type, "int64_t" }, 175263320Sdim{ "arg6", DT_IDENT_SCALAR, 0, DIF_VAR_ARG6, DT_ATTR_STABCMN, DT_VERS_1_0, 176263320Sdim &dt_idops_type, "int64_t" }, 177263320Sdim{ "arg7", DT_IDENT_SCALAR, 0, DIF_VAR_ARG7, DT_ATTR_STABCMN, DT_VERS_1_0, 178263320Sdim &dt_idops_type, "int64_t" }, 179263320Sdim{ "arg8", DT_IDENT_SCALAR, 0, DIF_VAR_ARG8, DT_ATTR_STABCMN, DT_VERS_1_0, 180263320Sdim &dt_idops_type, "int64_t" }, 181263320Sdim{ "arg9", DT_IDENT_SCALAR, 0, DIF_VAR_ARG9, DT_ATTR_STABCMN, DT_VERS_1_0, 182263320Sdim &dt_idops_type, "int64_t" }, 183263320Sdim{ "args", DT_IDENT_ARRAY, 0, DIF_VAR_ARGS, DT_ATTR_STABCMN, DT_VERS_1_0, 184263320Sdim &dt_idops_args, NULL }, 185263320Sdim{ "avg", DT_IDENT_AGGFUNC, 0, DTRACEAGG_AVG, DT_ATTR_STABCMN, DT_VERS_1_0, 186263320Sdim &dt_idops_func, "void(@)" }, 187263320Sdim{ "basename", DT_IDENT_FUNC, 0, DIF_SUBR_BASENAME, DT_ATTR_STABCMN, DT_VERS_1_0, 188263320Sdim &dt_idops_func, "string(const char *)" }, 189263320Sdim{ "bcopy", DT_IDENT_FUNC, 0, DIF_SUBR_BCOPY, DT_ATTR_STABCMN, DT_VERS_1_0, 190263320Sdim &dt_idops_func, "void(void *, void *, size_t)" }, 191263320Sdim{ "breakpoint", DT_IDENT_ACTFUNC, 0, DT_ACT_BREAKPOINT, 192263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, 193263320Sdim &dt_idops_func, "void()" }, 194263320Sdim{ "caller", DT_IDENT_SCALAR, 0, DIF_VAR_CALLER, DT_ATTR_STABCMN, DT_VERS_1_0, 195263320Sdim &dt_idops_type, "uintptr_t" }, 196263320Sdim{ "chill", DT_IDENT_ACTFUNC, 0, DT_ACT_CHILL, DT_ATTR_STABCMN, DT_VERS_1_0, 197263320Sdim &dt_idops_func, "void(int)" }, 198263320Sdim{ "cleanpath", DT_IDENT_FUNC, 0, DIF_SUBR_CLEANPATH, DT_ATTR_STABCMN, 199263320Sdim DT_VERS_1_0, &dt_idops_func, "string(const char *)" }, 200263320Sdim{ "clear", DT_IDENT_ACTFUNC, 0, DT_ACT_CLEAR, DT_ATTR_STABCMN, DT_VERS_1_0, 201263320Sdim &dt_idops_func, "void(...)" }, 202263320Sdim{ "commit", DT_IDENT_ACTFUNC, 0, DT_ACT_COMMIT, DT_ATTR_STABCMN, DT_VERS_1_0, 203263320Sdim &dt_idops_func, "void(int)" }, 204263320Sdim{ "copyin", DT_IDENT_FUNC, 0, DIF_SUBR_COPYIN, DT_ATTR_STABCMN, DT_VERS_1_0, 205263320Sdim &dt_idops_func, "void *(uintptr_t, size_t)" }, 206263320Sdim{ "copyinstr", DT_IDENT_FUNC, 0, DIF_SUBR_COPYINSTR, 207263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, 208263320Sdim &dt_idops_func, "string(uintptr_t, [size_t])" }, 209263320Sdim{ "copyinto", DT_IDENT_FUNC, 0, DIF_SUBR_COPYINTO, DT_ATTR_STABCMN, 210263320Sdim DT_VERS_1_0, &dt_idops_func, "void(uintptr_t, size_t, void *)" }, 211263320Sdim{ "copyout", DT_IDENT_FUNC, 0, DIF_SUBR_COPYOUT, DT_ATTR_STABCMN, DT_VERS_1_0, 212263320Sdim &dt_idops_func, "void(void *, uintptr_t, size_t)" }, 213263320Sdim{ "copyoutstr", DT_IDENT_FUNC, 0, DIF_SUBR_COPYOUTSTR, 214263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, 215263320Sdim &dt_idops_func, "void(char *, uintptr_t, size_t)" }, 216263320Sdim{ "count", DT_IDENT_AGGFUNC, 0, DTRACEAGG_COUNT, DT_ATTR_STABCMN, DT_VERS_1_0, 217263320Sdim &dt_idops_func, "void()" }, 218263320Sdim{ "curthread", DT_IDENT_SCALAR, 0, DIF_VAR_CURTHREAD, 219263320Sdim { DTRACE_STABILITY_STABLE, DTRACE_STABILITY_PRIVATE, 220263320Sdim DTRACE_CLASS_COMMON }, DT_VERS_1_0, 221263320Sdim#if defined(sun) 222263320Sdim &dt_idops_type, "genunix`kthread_t *" }, 223263320Sdim#else 224263320Sdim &dt_idops_type, curthread_str }, 225263320Sdim#endif 226263320Sdim{ "ddi_pathname", DT_IDENT_FUNC, 0, DIF_SUBR_DDI_PATHNAME, 227263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 228263320Sdim &dt_idops_func, "string(void *, int64_t)" }, 229263320Sdim{ "denormalize", DT_IDENT_ACTFUNC, 0, DT_ACT_DENORMALIZE, DT_ATTR_STABCMN, 230263320Sdim DT_VERS_1_0, &dt_idops_func, "void(...)" }, 231263320Sdim{ "dirname", DT_IDENT_FUNC, 0, DIF_SUBR_DIRNAME, DT_ATTR_STABCMN, DT_VERS_1_0, 232263320Sdim &dt_idops_func, "string(const char *)" }, 233263320Sdim{ "discard", DT_IDENT_ACTFUNC, 0, DT_ACT_DISCARD, DT_ATTR_STABCMN, DT_VERS_1_0, 234263320Sdim &dt_idops_func, "void(int)" }, 235263320Sdim{ "epid", DT_IDENT_SCALAR, 0, DIF_VAR_EPID, DT_ATTR_STABCMN, DT_VERS_1_0, 236263320Sdim &dt_idops_type, "uint_t" }, 237263320Sdim{ "errno", DT_IDENT_SCALAR, 0, DIF_VAR_ERRNO, DT_ATTR_STABCMN, DT_VERS_1_0, 238263320Sdim &dt_idops_type, "int" }, 239263320Sdim{ "execargs", DT_IDENT_SCALAR, 0, DIF_VAR_EXECARGS, 240263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 241263320Sdim{ "execname", DT_IDENT_SCALAR, 0, DIF_VAR_EXECNAME, 242263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 243263320Sdim{ "exit", DT_IDENT_ACTFUNC, 0, DT_ACT_EXIT, DT_ATTR_STABCMN, DT_VERS_1_0, 244263320Sdim &dt_idops_func, "void(int)" }, 245263320Sdim{ "freopen", DT_IDENT_ACTFUNC, 0, DT_ACT_FREOPEN, DT_ATTR_STABCMN, 246263320Sdim DT_VERS_1_1, &dt_idops_func, "void(@, ...)" }, 247263320Sdim{ "ftruncate", DT_IDENT_ACTFUNC, 0, DT_ACT_FTRUNCATE, DT_ATTR_STABCMN, 248263320Sdim DT_VERS_1_0, &dt_idops_func, "void()" }, 249263320Sdim{ "func", DT_IDENT_ACTFUNC, 0, DT_ACT_SYM, DT_ATTR_STABCMN, 250263320Sdim DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" }, 251263320Sdim{ "getmajor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMAJOR, 252263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 253263320Sdim &dt_idops_func, "genunix`major_t(genunix`dev_t)" }, 254263320Sdim{ "getminor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMINOR, 255263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 256263320Sdim &dt_idops_func, "genunix`minor_t(genunix`dev_t)" }, 257263320Sdim{ "htonl", DT_IDENT_FUNC, 0, DIF_SUBR_HTONL, DT_ATTR_EVOLCMN, DT_VERS_1_3, 258263320Sdim &dt_idops_func, "uint32_t(uint32_t)" }, 259263320Sdim{ "htonll", DT_IDENT_FUNC, 0, DIF_SUBR_HTONLL, DT_ATTR_EVOLCMN, DT_VERS_1_3, 260263320Sdim &dt_idops_func, "uint64_t(uint64_t)" }, 261263320Sdim{ "htons", DT_IDENT_FUNC, 0, DIF_SUBR_HTONS, DT_ATTR_EVOLCMN, DT_VERS_1_3, 262263320Sdim &dt_idops_func, "uint16_t(uint16_t)" }, 263263320Sdim{ "gid", DT_IDENT_SCALAR, 0, DIF_VAR_GID, DT_ATTR_STABCMN, DT_VERS_1_0, 264263320Sdim &dt_idops_type, "gid_t" }, 265263320Sdim{ "id", DT_IDENT_SCALAR, 0, DIF_VAR_ID, DT_ATTR_STABCMN, DT_VERS_1_0, 266263320Sdim &dt_idops_type, "uint_t" }, 267263320Sdim{ "index", DT_IDENT_FUNC, 0, DIF_SUBR_INDEX, DT_ATTR_STABCMN, DT_VERS_1_1, 268263320Sdim &dt_idops_func, "int(const char *, const char *, [int])" }, 269263320Sdim{ "inet_ntoa", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOA, DT_ATTR_STABCMN, 270263320Sdim#if defined(sun) 271263320Sdim DT_VERS_1_5, &dt_idops_func, "string(ipaddr_t *)" }, 272263320Sdim#else 273263320Sdim DT_VERS_1_5, &dt_idops_func, "string(in_addr_t *)" }, 274263320Sdim#endif 275263320Sdim{ "inet_ntoa6", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOA6, DT_ATTR_STABCMN, 276263320Sdim#if defined(sun) 277263320Sdim DT_VERS_1_5, &dt_idops_func, "string(in6_addr_t *)" }, 278263320Sdim#else 279263320Sdim DT_VERS_1_5, &dt_idops_func, "string(struct in6_addr *)" }, 280263320Sdim#endif 281263320Sdim{ "inet_ntop", DT_IDENT_FUNC, 0, DIF_SUBR_INET_NTOP, DT_ATTR_STABCMN, 282263320Sdim DT_VERS_1_5, &dt_idops_func, "string(int, void *)" }, 283263320Sdim{ "ipl", DT_IDENT_SCALAR, 0, DIF_VAR_IPL, DT_ATTR_STABCMN, DT_VERS_1_0, 284263320Sdim &dt_idops_type, "uint_t" }, 285263320Sdim#if defined(sun) 286263320Sdim{ "jstack", DT_IDENT_ACTFUNC, 0, DT_ACT_JSTACK, DT_ATTR_STABCMN, DT_VERS_1_0, 287263320Sdim &dt_idops_func, "stack(...)" }, 288263320Sdim#endif 289263320Sdim{ "lltostr", DT_IDENT_FUNC, 0, DIF_SUBR_LLTOSTR, DT_ATTR_STABCMN, DT_VERS_1_0, 290263320Sdim &dt_idops_func, "string(int64_t)" }, 291263320Sdim{ "lquantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_LQUANTIZE, 292263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, 293263320Sdim &dt_idops_func, "void(@, int32_t, int32_t, ...)" }, 294263320Sdim{ "max", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MAX, DT_ATTR_STABCMN, DT_VERS_1_0, 295263320Sdim &dt_idops_func, "void(@)" }, 296263320Sdim{ "memref", DT_IDENT_FUNC, 0, DIF_SUBR_MEMREF, DT_ATTR_STABCMN, DT_VERS_1_1, 297263320Sdim &dt_idops_func, "uintptr_t *(void *, size_t)" }, 298263320Sdim{ "min", DT_IDENT_AGGFUNC, 0, DTRACEAGG_MIN, DT_ATTR_STABCMN, DT_VERS_1_0, 299263320Sdim &dt_idops_func, "void(@)" }, 300263320Sdim{ "mod", DT_IDENT_ACTFUNC, 0, DT_ACT_MOD, DT_ATTR_STABCMN, 301263320Sdim DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" }, 302263320Sdim{ "msgdsize", DT_IDENT_FUNC, 0, DIF_SUBR_MSGDSIZE, 303263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, 304263320Sdim &dt_idops_func, "size_t(mblk_t *)" }, 305263320Sdim{ "msgsize", DT_IDENT_FUNC, 0, DIF_SUBR_MSGSIZE, 306263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, 307263320Sdim &dt_idops_func, "size_t(mblk_t *)" }, 308263320Sdim#if defined(sun) 309263320Sdim{ "mutex_owned", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNED, 310263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 311263320Sdim &dt_idops_func, "int(genunix`kmutex_t *)" }, 312263320Sdim{ "mutex_owner", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNER, 313263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 314263320Sdim &dt_idops_func, "genunix`kthread_t *(genunix`kmutex_t *)" }, 315263320Sdim{ "mutex_type_adaptive", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_ADAPTIVE, 316263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 317263320Sdim &dt_idops_func, "int(genunix`kmutex_t *)" }, 318263320Sdim{ "mutex_type_spin", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_SPIN, 319263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 320263320Sdim &dt_idops_func, "int(genunix`kmutex_t *)" }, 321263320Sdim#else 322263320Sdim{ "mutex_owned", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNED, 323263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 324263320Sdim &dt_idops_func, intmtx_str }, 325263320Sdim{ "mutex_owner", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_OWNER, 326263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 327263320Sdim &dt_idops_func, threadmtx_str }, 328263320Sdim{ "mutex_type_adaptive", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_ADAPTIVE, 329263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 330263320Sdim &dt_idops_func, intmtx_str }, 331263320Sdim{ "mutex_type_spin", DT_IDENT_FUNC, 0, DIF_SUBR_MUTEX_TYPE_SPIN, 332263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 333263320Sdim &dt_idops_func, intmtx_str }, 334263320Sdim#endif 335263320Sdim{ "ntohl", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHL, DT_ATTR_EVOLCMN, DT_VERS_1_3, 336263320Sdim &dt_idops_func, "uint32_t(uint32_t)" }, 337263320Sdim{ "ntohll", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHLL, DT_ATTR_EVOLCMN, DT_VERS_1_3, 338263320Sdim &dt_idops_func, "uint64_t(uint64_t)" }, 339263320Sdim{ "ntohs", DT_IDENT_FUNC, 0, DIF_SUBR_NTOHS, DT_ATTR_EVOLCMN, DT_VERS_1_3, 340263320Sdim &dt_idops_func, "uint16_t(uint16_t)" }, 341263320Sdim{ "normalize", DT_IDENT_ACTFUNC, 0, DT_ACT_NORMALIZE, DT_ATTR_STABCMN, 342263320Sdim DT_VERS_1_0, &dt_idops_func, "void(...)" }, 343263320Sdim{ "panic", DT_IDENT_ACTFUNC, 0, DT_ACT_PANIC, DT_ATTR_STABCMN, DT_VERS_1_0, 344263320Sdim &dt_idops_func, "void()" }, 345263320Sdim{ "pid", DT_IDENT_SCALAR, 0, DIF_VAR_PID, DT_ATTR_STABCMN, DT_VERS_1_0, 346263320Sdim &dt_idops_type, "pid_t" }, 347263320Sdim{ "ppid", DT_IDENT_SCALAR, 0, DIF_VAR_PPID, DT_ATTR_STABCMN, DT_VERS_1_0, 348263320Sdim &dt_idops_type, "pid_t" }, 349263320Sdim{ "printa", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTA, DT_ATTR_STABCMN, DT_VERS_1_0, 350263320Sdim &dt_idops_func, "void(@, ...)" }, 351263320Sdim{ "printf", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTF, DT_ATTR_STABCMN, DT_VERS_1_0, 352263320Sdim &dt_idops_func, "void(@, ...)" }, 353263320Sdim{ "printm", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTM, DT_ATTR_STABCMN, DT_VERS_1_0, 354263320Sdim &dt_idops_func, "void(size_t, uintptr_t *)" }, 355263320Sdim{ "printt", DT_IDENT_ACTFUNC, 0, DT_ACT_PRINTT, DT_ATTR_STABCMN, DT_VERS_1_0, 356263320Sdim &dt_idops_func, "void(size_t, uintptr_t *)" }, 357263320Sdim{ "probefunc", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEFUNC, 358263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 359263320Sdim{ "probemod", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEMOD, 360263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 361263320Sdim{ "probename", DT_IDENT_SCALAR, 0, DIF_VAR_PROBENAME, 362263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 363263320Sdim{ "probeprov", DT_IDENT_SCALAR, 0, DIF_VAR_PROBEPROV, 364263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 365263320Sdim{ "progenyof", DT_IDENT_FUNC, 0, DIF_SUBR_PROGENYOF, 366263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, 367263320Sdim &dt_idops_func, "int(pid_t)" }, 368263320Sdim{ "quantize", DT_IDENT_AGGFUNC, 0, DTRACEAGG_QUANTIZE, 369263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, 370263320Sdim &dt_idops_func, "void(@, ...)" }, 371263320Sdim{ "raise", DT_IDENT_ACTFUNC, 0, DT_ACT_RAISE, DT_ATTR_STABCMN, DT_VERS_1_0, 372263320Sdim &dt_idops_func, "void(int)" }, 373263320Sdim{ "rand", DT_IDENT_FUNC, 0, DIF_SUBR_RAND, DT_ATTR_STABCMN, DT_VERS_1_0, 374263320Sdim &dt_idops_func, "int()" }, 375263320Sdim{ "rindex", DT_IDENT_FUNC, 0, DIF_SUBR_RINDEX, DT_ATTR_STABCMN, DT_VERS_1_1, 376263320Sdim &dt_idops_func, "int(const char *, const char *, [int])" }, 377263320Sdim#if defined(sun) 378263320Sdim{ "rw_iswriter", DT_IDENT_FUNC, 0, DIF_SUBR_RW_ISWRITER, 379263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 380263320Sdim &dt_idops_func, "int(genunix`krwlock_t *)" }, 381263320Sdim{ "rw_read_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_READ_HELD, 382263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 383263320Sdim &dt_idops_func, "int(genunix`krwlock_t *)" }, 384263320Sdim{ "rw_write_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_WRITE_HELD, 385263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 386263320Sdim &dt_idops_func, "int(genunix`krwlock_t *)" }, 387263320Sdim#else 388263320Sdim{ "rw_iswriter", DT_IDENT_FUNC, 0, DIF_SUBR_RW_ISWRITER, 389263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 390263320Sdim &dt_idops_func, rwlock_str }, 391263320Sdim{ "rw_read_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_READ_HELD, 392263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 393263320Sdim &dt_idops_func, rwlock_str }, 394263320Sdim{ "rw_write_held", DT_IDENT_FUNC, 0, DIF_SUBR_RW_WRITE_HELD, 395263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 396263320Sdim &dt_idops_func, rwlock_str }, 397263320Sdim#endif 398263320Sdim{ "self", DT_IDENT_PTR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0, 399263320Sdim &dt_idops_type, "void" }, 400263320Sdim{ "setopt", DT_IDENT_ACTFUNC, 0, DT_ACT_SETOPT, DT_ATTR_STABCMN, 401263320Sdim DT_VERS_1_2, &dt_idops_func, "void(const char *, [const char *])" }, 402263320Sdim{ "speculate", DT_IDENT_ACTFUNC, 0, DT_ACT_SPECULATE, 403263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, 404263320Sdim &dt_idops_func, "void(int)" }, 405263320Sdim{ "speculation", DT_IDENT_FUNC, 0, DIF_SUBR_SPECULATION, 406263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, 407263320Sdim &dt_idops_func, "int()" }, 408263320Sdim{ "stack", DT_IDENT_ACTFUNC, 0, DT_ACT_STACK, DT_ATTR_STABCMN, DT_VERS_1_0, 409263320Sdim &dt_idops_func, "stack(...)" }, 410263320Sdim{ "stackdepth", DT_IDENT_SCALAR, 0, DIF_VAR_STACKDEPTH, 411263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, 412263320Sdim &dt_idops_type, "uint32_t" }, 413263320Sdim{ "stddev", DT_IDENT_AGGFUNC, 0, DTRACEAGG_STDDEV, DT_ATTR_STABCMN, 414263320Sdim DT_VERS_1_6, &dt_idops_func, "void(@)" }, 415263320Sdim{ "stop", DT_IDENT_ACTFUNC, 0, DT_ACT_STOP, DT_ATTR_STABCMN, DT_VERS_1_0, 416263320Sdim &dt_idops_func, "void()" }, 417263320Sdim{ "strchr", DT_IDENT_FUNC, 0, DIF_SUBR_STRCHR, DT_ATTR_STABCMN, DT_VERS_1_1, 418263320Sdim &dt_idops_func, "string(const char *, char)" }, 419263320Sdim{ "strlen", DT_IDENT_FUNC, 0, DIF_SUBR_STRLEN, DT_ATTR_STABCMN, DT_VERS_1_0, 420263320Sdim &dt_idops_func, "size_t(const char *)" }, 421263320Sdim{ "strjoin", DT_IDENT_FUNC, 0, DIF_SUBR_STRJOIN, DT_ATTR_STABCMN, DT_VERS_1_0, 422263320Sdim &dt_idops_func, "string(const char *, const char *)" }, 423263320Sdim{ "strrchr", DT_IDENT_FUNC, 0, DIF_SUBR_STRRCHR, DT_ATTR_STABCMN, DT_VERS_1_1, 424263320Sdim &dt_idops_func, "string(const char *, char)" }, 425263320Sdim{ "strstr", DT_IDENT_FUNC, 0, DIF_SUBR_STRSTR, DT_ATTR_STABCMN, DT_VERS_1_1, 426263320Sdim &dt_idops_func, "string(const char *, const char *)" }, 427263320Sdim{ "strtok", DT_IDENT_FUNC, 0, DIF_SUBR_STRTOK, DT_ATTR_STABCMN, DT_VERS_1_1, 428263320Sdim &dt_idops_func, "string(const char *, const char *)" }, 429263320Sdim{ "substr", DT_IDENT_FUNC, 0, DIF_SUBR_SUBSTR, DT_ATTR_STABCMN, DT_VERS_1_1, 430263320Sdim &dt_idops_func, "string(const char *, int, [int])" }, 431263320Sdim{ "sum", DT_IDENT_AGGFUNC, 0, DTRACEAGG_SUM, DT_ATTR_STABCMN, DT_VERS_1_0, 432263320Sdim &dt_idops_func, "void(@)" }, 433263320Sdim#if !defined(sun) 434263320Sdim{ "sx_isexclusive", DT_IDENT_FUNC, 0, DIF_SUBR_SX_ISEXCLUSIVE, 435263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 436263320Sdim &dt_idops_func, sxlock_str }, 437263320Sdim{ "sx_shared_held", DT_IDENT_FUNC, 0, DIF_SUBR_SX_SHARED_HELD, 438263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 439263320Sdim &dt_idops_func, sxlock_str }, 440263320Sdim{ "sx_exclusive_held", DT_IDENT_FUNC, 0, DIF_SUBR_SX_EXCLUSIVE_HELD, 441263320Sdim DT_ATTR_EVOLCMN, DT_VERS_1_0, 442263320Sdim &dt_idops_func, sxlock_str }, 443263320Sdim#endif 444263320Sdim{ "sym", DT_IDENT_ACTFUNC, 0, DT_ACT_SYM, DT_ATTR_STABCMN, 445263320Sdim DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" }, 446263320Sdim{ "system", DT_IDENT_ACTFUNC, 0, DT_ACT_SYSTEM, DT_ATTR_STABCMN, DT_VERS_1_0, 447263320Sdim &dt_idops_func, "void(@, ...)" }, 448263320Sdim{ "this", DT_IDENT_PTR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0, 449263320Sdim &dt_idops_type, "void" }, 450263320Sdim{ "tid", DT_IDENT_SCALAR, 0, DIF_VAR_TID, DT_ATTR_STABCMN, DT_VERS_1_0, 451263320Sdim &dt_idops_type, "id_t" }, 452263320Sdim{ "timestamp", DT_IDENT_SCALAR, 0, DIF_VAR_TIMESTAMP, 453263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, 454263320Sdim &dt_idops_type, "uint64_t" }, 455263320Sdim{ "trace", DT_IDENT_ACTFUNC, 0, DT_ACT_TRACE, DT_ATTR_STABCMN, DT_VERS_1_0, 456263320Sdim &dt_idops_func, "void(@)" }, 457263320Sdim{ "tracemem", DT_IDENT_ACTFUNC, 0, DT_ACT_TRACEMEM, 458263320Sdim DT_ATTR_STABCMN, DT_VERS_1_0, 459263320Sdim &dt_idops_func, "void(@, size_t)" }, 460263320Sdim{ "trunc", DT_IDENT_ACTFUNC, 0, DT_ACT_TRUNC, DT_ATTR_STABCMN, 461263320Sdim DT_VERS_1_0, &dt_idops_func, "void(...)" }, 462263320Sdim{ "typeref", DT_IDENT_FUNC, 0, DIF_SUBR_TYPEREF, DT_ATTR_STABCMN, DT_VERS_1_1, 463263320Sdim &dt_idops_func, "uintptr_t *(void *, size_t, string, size_t)" }, 464#if defined(sun) 465{ "uaddr", DT_IDENT_ACTFUNC, 0, DT_ACT_UADDR, DT_ATTR_STABCMN, 466 DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" }, 467{ "ucaller", DT_IDENT_SCALAR, 0, DIF_VAR_UCALLER, DT_ATTR_STABCMN, 468 DT_VERS_1_2, &dt_idops_type, "uint64_t" }, 469{ "ufunc", DT_IDENT_ACTFUNC, 0, DT_ACT_USYM, DT_ATTR_STABCMN, 470 DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" }, 471#endif 472{ "uid", DT_IDENT_SCALAR, 0, DIF_VAR_UID, DT_ATTR_STABCMN, DT_VERS_1_0, 473 &dt_idops_type, "uid_t" }, 474#if defined(sun) 475{ "umod", DT_IDENT_ACTFUNC, 0, DT_ACT_UMOD, DT_ATTR_STABCMN, 476 DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" }, 477{ "uregs", DT_IDENT_ARRAY, 0, DIF_VAR_UREGS, DT_ATTR_STABCMN, DT_VERS_1_0, 478 &dt_idops_regs, NULL }, 479{ "ustack", DT_IDENT_ACTFUNC, 0, DT_ACT_USTACK, DT_ATTR_STABCMN, DT_VERS_1_0, 480 &dt_idops_func, "stack(...)" }, 481{ "ustackdepth", DT_IDENT_SCALAR, 0, DIF_VAR_USTACKDEPTH, 482 DT_ATTR_STABCMN, DT_VERS_1_2, 483 &dt_idops_type, "uint32_t" }, 484{ "usym", DT_IDENT_ACTFUNC, 0, DT_ACT_USYM, DT_ATTR_STABCMN, 485 DT_VERS_1_2, &dt_idops_func, "_usymaddr(uintptr_t)" }, 486#endif 487{ "vtimestamp", DT_IDENT_SCALAR, 0, DIF_VAR_VTIMESTAMP, 488 DT_ATTR_STABCMN, DT_VERS_1_0, 489 &dt_idops_type, "uint64_t" }, 490{ "walltimestamp", DT_IDENT_SCALAR, 0, DIF_VAR_WALLTIMESTAMP, 491 DT_ATTR_STABCMN, DT_VERS_1_0, 492 &dt_idops_type, "int64_t" }, 493#if defined(sun) 494{ "zonename", DT_IDENT_SCALAR, 0, DIF_VAR_ZONENAME, 495 DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" }, 496#endif 497{ NULL, 0, 0, 0, { 0, 0, 0 }, 0, NULL, NULL } 498}; 499 500/* 501 * Tables of ILP32 intrinsic integer and floating-point type templates to use 502 * to populate the dynamic "C" CTF type container. 503 */ 504static const dt_intrinsic_t _dtrace_intrinsics_32[] = { 505{ "void", { CTF_INT_SIGNED, 0, 0 }, CTF_K_INTEGER }, 506{ "signed", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 507{ "unsigned", { 0, 0, 32 }, CTF_K_INTEGER }, 508{ "char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 509{ "short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, 510{ "int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 511{ "long", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 512{ "long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 513{ "signed char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 514{ "signed short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, 515{ "signed int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 516{ "signed long", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 517{ "signed long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 518{ "unsigned char", { CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 519{ "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER }, 520{ "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER }, 521{ "unsigned long", { 0, 0, 32 }, CTF_K_INTEGER }, 522{ "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER }, 523{ "_Bool", { CTF_INT_BOOL, 0, 8 }, CTF_K_INTEGER }, 524{ "float", { CTF_FP_SINGLE, 0, 32 }, CTF_K_FLOAT }, 525{ "double", { CTF_FP_DOUBLE, 0, 64 }, CTF_K_FLOAT }, 526{ "long double", { CTF_FP_LDOUBLE, 0, 128 }, CTF_K_FLOAT }, 527{ "float imaginary", { CTF_FP_IMAGRY, 0, 32 }, CTF_K_FLOAT }, 528{ "double imaginary", { CTF_FP_DIMAGRY, 0, 64 }, CTF_K_FLOAT }, 529{ "long double imaginary", { CTF_FP_LDIMAGRY, 0, 128 }, CTF_K_FLOAT }, 530{ "float complex", { CTF_FP_CPLX, 0, 64 }, CTF_K_FLOAT }, 531{ "double complex", { CTF_FP_DCPLX, 0, 128 }, CTF_K_FLOAT }, 532{ "long double complex", { CTF_FP_LDCPLX, 0, 256 }, CTF_K_FLOAT }, 533{ NULL, { 0, 0, 0 }, 0 } 534}; 535 536/* 537 * Tables of LP64 intrinsic integer and floating-point type templates to use 538 * to populate the dynamic "C" CTF type container. 539 */ 540static const dt_intrinsic_t _dtrace_intrinsics_64[] = { 541{ "void", { CTF_INT_SIGNED, 0, 0 }, CTF_K_INTEGER }, 542{ "signed", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 543{ "unsigned", { 0, 0, 32 }, CTF_K_INTEGER }, 544{ "char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 545{ "short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, 546{ "int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 547{ "long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 548{ "long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 549{ "signed char", { CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 550{ "signed short", { CTF_INT_SIGNED, 0, 16 }, CTF_K_INTEGER }, 551{ "signed int", { CTF_INT_SIGNED, 0, 32 }, CTF_K_INTEGER }, 552{ "signed long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 553{ "signed long long", { CTF_INT_SIGNED, 0, 64 }, CTF_K_INTEGER }, 554{ "unsigned char", { CTF_INT_CHAR, 0, 8 }, CTF_K_INTEGER }, 555{ "unsigned short", { 0, 0, 16 }, CTF_K_INTEGER }, 556{ "unsigned int", { 0, 0, 32 }, CTF_K_INTEGER }, 557{ "unsigned long", { 0, 0, 64 }, CTF_K_INTEGER }, 558{ "unsigned long long", { 0, 0, 64 }, CTF_K_INTEGER }, 559{ "_Bool", { CTF_INT_BOOL, 0, 8 }, CTF_K_INTEGER }, 560{ "float", { CTF_FP_SINGLE, 0, 32 }, CTF_K_FLOAT }, 561{ "double", { CTF_FP_DOUBLE, 0, 64 }, CTF_K_FLOAT }, 562{ "long double", { CTF_FP_LDOUBLE, 0, 128 }, CTF_K_FLOAT }, 563{ "float imaginary", { CTF_FP_IMAGRY, 0, 32 }, CTF_K_FLOAT }, 564{ "double imaginary", { CTF_FP_DIMAGRY, 0, 64 }, CTF_K_FLOAT }, 565{ "long double imaginary", { CTF_FP_LDIMAGRY, 0, 128 }, CTF_K_FLOAT }, 566{ "float complex", { CTF_FP_CPLX, 0, 64 }, CTF_K_FLOAT }, 567{ "double complex", { CTF_FP_DCPLX, 0, 128 }, CTF_K_FLOAT }, 568{ "long double complex", { CTF_FP_LDCPLX, 0, 256 }, CTF_K_FLOAT }, 569{ NULL, { 0, 0, 0 }, 0 } 570}; 571 572/* 573 * Tables of ILP32 typedefs to use to populate the dynamic "D" CTF container. 574 * These aliases ensure that D definitions can use typical <sys/types.h> names. 575 */ 576static const dt_typedef_t _dtrace_typedefs_32[] = { 577{ "char", "int8_t" }, 578{ "short", "int16_t" }, 579{ "int", "int32_t" }, 580{ "long long", "int64_t" }, 581{ "int", "intptr_t" }, 582{ "int", "ssize_t" }, 583{ "unsigned char", "uint8_t" }, 584{ "unsigned short", "uint16_t" }, 585{ "unsigned", "uint32_t" }, 586{ "unsigned long long", "uint64_t" }, 587{ "unsigned char", "uchar_t" }, 588{ "unsigned short", "ushort_t" }, 589{ "unsigned", "uint_t" }, 590{ "unsigned long", "ulong_t" }, 591{ "unsigned long long", "u_longlong_t" }, 592{ "int", "ptrdiff_t" }, 593{ "unsigned", "uintptr_t" }, 594{ "unsigned", "size_t" }, 595{ "long", "id_t" }, 596{ "long", "pid_t" }, 597{ NULL, NULL } 598}; 599 600/* 601 * Tables of LP64 typedefs to use to populate the dynamic "D" CTF container. 602 * These aliases ensure that D definitions can use typical <sys/types.h> names. 603 */ 604static const dt_typedef_t _dtrace_typedefs_64[] = { 605{ "char", "int8_t" }, 606{ "short", "int16_t" }, 607{ "int", "int32_t" }, 608{ "long", "int64_t" }, 609{ "long", "intptr_t" }, 610{ "long", "ssize_t" }, 611{ "unsigned char", "uint8_t" }, 612{ "unsigned short", "uint16_t" }, 613{ "unsigned", "uint32_t" }, 614{ "unsigned long", "uint64_t" }, 615{ "unsigned char", "uchar_t" }, 616{ "unsigned short", "ushort_t" }, 617{ "unsigned", "uint_t" }, 618{ "unsigned long", "ulong_t" }, 619{ "unsigned long long", "u_longlong_t" }, 620{ "long", "ptrdiff_t" }, 621{ "unsigned long", "uintptr_t" }, 622{ "unsigned long", "size_t" }, 623{ "int", "id_t" }, 624{ "int", "pid_t" }, 625{ NULL, NULL } 626}; 627 628/* 629 * Tables of ILP32 integer type templates used to populate the dtp->dt_ints[] 630 * cache when a new dtrace client open occurs. Values are set by dtrace_open(). 631 */ 632static const dt_intdesc_t _dtrace_ints_32[] = { 633{ "int", NULL, CTF_ERR, 0x7fffffffULL }, 634{ "unsigned int", NULL, CTF_ERR, 0xffffffffULL }, 635{ "long", NULL, CTF_ERR, 0x7fffffffULL }, 636{ "unsigned long", NULL, CTF_ERR, 0xffffffffULL }, 637{ "long long", NULL, CTF_ERR, 0x7fffffffffffffffULL }, 638{ "unsigned long long", NULL, CTF_ERR, 0xffffffffffffffffULL } 639}; 640 641/* 642 * Tables of LP64 integer type templates used to populate the dtp->dt_ints[] 643 * cache when a new dtrace client open occurs. Values are set by dtrace_open(). 644 */ 645static const dt_intdesc_t _dtrace_ints_64[] = { 646{ "int", NULL, CTF_ERR, 0x7fffffffULL }, 647{ "unsigned int", NULL, CTF_ERR, 0xffffffffULL }, 648{ "long", NULL, CTF_ERR, 0x7fffffffffffffffULL }, 649{ "unsigned long", NULL, CTF_ERR, 0xffffffffffffffffULL }, 650{ "long long", NULL, CTF_ERR, 0x7fffffffffffffffULL }, 651{ "unsigned long long", NULL, CTF_ERR, 0xffffffffffffffffULL } 652}; 653 654/* 655 * Table of macro variable templates used to populate the macro identifier hash 656 * when a new dtrace client open occurs. Values are set by dtrace_update(). 657 */ 658static const dt_ident_t _dtrace_macros[] = { 659{ "egid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 660{ "euid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 661{ "gid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 662{ "pid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 663{ "pgid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 664{ "ppid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 665{ "projid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 666{ "sid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 667{ "taskid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 668{ "target", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 669{ "uid", DT_IDENT_SCALAR, 0, 0, DT_ATTR_STABCMN, DT_VERS_1_0 }, 670{ NULL, 0, 0, 0, { 0, 0, 0 }, 0 } 671}; 672 673/* 674 * Hard-wired definition string to be compiled and cached every time a new 675 * DTrace library handle is initialized. This string should only be used to 676 * contain definitions that should be present regardless of DTRACE_O_NOLIBS. 677 */ 678static const char _dtrace_hardwire[] = "\ 679inline long NULL = 0; \n\ 680#pragma D binding \"1.0\" NULL\n\ 681"; 682 683/* 684 * Default DTrace configuration to use when opening libdtrace DTRACE_O_NODEV. 685 * If DTRACE_O_NODEV is not set, we load the configuration from the kernel. 686 * The use of CTF_MODEL_NATIVE is more subtle than it might appear: we are 687 * relying on the fact that when running dtrace(1M), isaexec will invoke the 688 * binary with the same bitness as the kernel, which is what we want by default 689 * when generating our DIF. The user can override the choice using oflags. 690 */ 691static const dtrace_conf_t _dtrace_conf = { 692 DIF_VERSION, /* dtc_difversion */ 693 DIF_DIR_NREGS, /* dtc_difintregs */ 694 DIF_DTR_NREGS, /* dtc_diftupregs */ 695 CTF_MODEL_NATIVE /* dtc_ctfmodel */ 696}; 697 698const dtrace_attribute_t _dtrace_maxattr = { 699 DTRACE_STABILITY_MAX, 700 DTRACE_STABILITY_MAX, 701 DTRACE_CLASS_MAX 702}; 703 704const dtrace_attribute_t _dtrace_defattr = { 705 DTRACE_STABILITY_STABLE, 706 DTRACE_STABILITY_STABLE, 707 DTRACE_CLASS_COMMON 708}; 709 710const dtrace_attribute_t _dtrace_symattr = { 711 DTRACE_STABILITY_PRIVATE, 712 DTRACE_STABILITY_PRIVATE, 713 DTRACE_CLASS_UNKNOWN 714}; 715 716const dtrace_attribute_t _dtrace_typattr = { 717 DTRACE_STABILITY_PRIVATE, 718 DTRACE_STABILITY_PRIVATE, 719 DTRACE_CLASS_UNKNOWN 720}; 721 722const dtrace_attribute_t _dtrace_prvattr = { 723 DTRACE_STABILITY_PRIVATE, 724 DTRACE_STABILITY_PRIVATE, 725 DTRACE_CLASS_UNKNOWN 726}; 727 728const dtrace_pattr_t _dtrace_prvdesc = { 729{ DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, 730{ DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, 731{ DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, 732{ DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, 733{ DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, 734}; 735 736#if defined(sun) 737const char *_dtrace_defcpp = "/usr/ccs/lib/cpp"; /* default cpp(1) to invoke */ 738const char *_dtrace_defld = "/usr/ccs/bin/ld"; /* default ld(1) to invoke */ 739#else 740const char *_dtrace_defcpp = "cpp"; /* default cpp(1) to invoke */ 741const char *_dtrace_defld = "ld"; /* default ld(1) to invoke */ 742#endif 743 744const char *_dtrace_libdir = "/usr/lib/dtrace"; /* default library directory */ 745#if defined(sun) 746const char *_dtrace_provdir = "/dev/dtrace/provider"; /* provider directory */ 747#else 748const char *_dtrace_provdir = "/dev/dtrace"; /* provider directory */ 749#endif 750 751int _dtrace_strbuckets = 211; /* default number of hash buckets (prime) */ 752int _dtrace_intbuckets = 256; /* default number of integer buckets (Pof2) */ 753uint_t _dtrace_strsize = 256; /* default size of string intrinsic type */ 754uint_t _dtrace_stkindent = 14; /* default whitespace indent for stack/ustack */ 755uint_t _dtrace_pidbuckets = 64; /* default number of pid hash buckets */ 756uint_t _dtrace_pidlrulim = 8; /* default number of pid handles to cache */ 757size_t _dtrace_bufsize = 512; /* default dt_buf_create() size */ 758int _dtrace_argmax = 32; /* default maximum number of probe arguments */ 759 760int _dtrace_debug = 0; /* debug messages enabled (off) */ 761const char *const _dtrace_version = DT_VERS_STRING; /* API version string */ 762#if defined(sun) 763int _dtrace_rdvers = RD_VERSION; /* rtld_db feature version */ 764#endif 765 766typedef struct dt_fdlist { 767 int *df_fds; /* array of provider driver file descriptors */ 768 uint_t df_ents; /* number of valid elements in df_fds[] */ 769 uint_t df_size; /* size of df_fds[] */ 770} dt_fdlist_t; 771 772#if defined(sun) 773#pragma init(_dtrace_init) 774#else 775void _dtrace_init(void) __attribute__ ((constructor)); 776#endif 777void 778_dtrace_init(void) 779{ 780 _dtrace_debug = getenv("DTRACE_DEBUG") != NULL; 781 782#if defined(sun) 783 for (; _dtrace_rdvers > 0; _dtrace_rdvers--) { 784 if (rd_init(_dtrace_rdvers) == RD_OK) 785 break; 786 } 787#endif 788#if defined(__i386__) 789 /* make long doubles 64 bits -sson */ 790 (void) fpsetprec(FP_PE); 791#endif 792} 793 794static dtrace_hdl_t * 795set_open_errno(dtrace_hdl_t *dtp, int *errp, int err) 796{ 797 if (dtp != NULL) 798 dtrace_close(dtp); 799 if (errp != NULL) 800 *errp = err; 801 return (NULL); 802} 803 804static void 805dt_provmod_open(dt_provmod_t **provmod, dt_fdlist_t *dfp) 806{ 807 dt_provmod_t *prov; 808 char path[PATH_MAX]; 809 int fd; 810#if defined(sun) 811 struct dirent *dp, *ep; 812 DIR *dirp; 813 814 if ((dirp = opendir(_dtrace_provdir)) == NULL) 815 return; /* failed to open directory; just skip it */ 816 817 ep = alloca(sizeof (struct dirent) + PATH_MAX + 1); 818 bzero(ep, sizeof (struct dirent) + PATH_MAX + 1); 819 820 while (readdir_r(dirp, ep, &dp) == 0 && dp != NULL) { 821 if (dp->d_name[0] == '.') 822 continue; /* skip "." and ".." */ 823 824 if (dfp->df_ents == dfp->df_size) { 825 uint_t size = dfp->df_size ? dfp->df_size * 2 : 16; 826 int *fds = realloc(dfp->df_fds, size * sizeof (int)); 827 828 if (fds == NULL) 829 break; /* skip the rest of this directory */ 830 831 dfp->df_fds = fds; 832 dfp->df_size = size; 833 } 834 835 (void) snprintf(path, sizeof (path), "%s/%s", 836 _dtrace_provdir, dp->d_name); 837 838 if ((fd = open(path, O_RDONLY)) == -1) 839 continue; /* failed to open driver; just skip it */ 840 841 if (((prov = malloc(sizeof (dt_provmod_t))) == NULL) || 842 (prov->dp_name = malloc(strlen(dp->d_name) + 1)) == NULL) { 843 free(prov); 844 (void) close(fd); 845 break; 846 } 847 848 (void) strcpy(prov->dp_name, dp->d_name); 849 prov->dp_next = *provmod; 850 *provmod = prov; 851 852 dt_dprintf("opened provider %s\n", dp->d_name); 853 dfp->df_fds[dfp->df_ents++] = fd; 854 } 855 856 (void) closedir(dirp); 857#else 858 char *p; 859 char *p1; 860 char *p_providers = NULL; 861 int error; 862 size_t len = 0; 863 864 /* 865 * Loop to allocate/reallocate memory for the string of provider 866 * names and retry: 867 */ 868 while(1) { 869 /* 870 * The first time around, get the string length. The next time, 871 * hopefully we've allocated enough memory. 872 */ 873 error = sysctlbyname("debug.dtrace.providers",p_providers,&len,NULL,0); 874 if (len == 0) 875 /* No providers? That's strange. Where's dtrace? */ 876 break; 877 else if (error == 0 && p_providers == NULL) { 878 /* 879 * Allocate the initial memory which should be enough 880 * unless another provider loads before we have 881 * time to go back and get the string. 882 */ 883 if ((p_providers = malloc(len)) == NULL) 884 /* How do we report errors here? */ 885 return; 886 } else if (error == -1 && errno == ENOMEM) { 887 /* 888 * The current buffer isn't large enough, so 889 * reallocate it. We normally won't need to do this 890 * because providers aren't being loaded all the time. 891 */ 892 if ((p = realloc(p_providers,len)) == NULL) 893 /* How do we report errors here? */ 894 return; 895 p_providers = p; 896 } else 897 break; 898 } 899 900 /* Check if we got a string of provider names: */ 901 if (error == 0 && len > 0 && p_providers != NULL) { 902 p = p_providers; 903 904 /* 905 * Parse the string containing the space separated 906 * provider names. 907 */ 908 while ((p1 = strsep(&p," ")) != NULL) { 909 if (dfp->df_ents == dfp->df_size) { 910 uint_t size = dfp->df_size ? dfp->df_size * 2 : 16; 911 int *fds = realloc(dfp->df_fds, size * sizeof (int)); 912 913 if (fds == NULL) 914 break; 915 916 dfp->df_fds = fds; 917 dfp->df_size = size; 918 } 919 920 (void) snprintf(path, sizeof (path), "/dev/dtrace/%s", p1); 921 922 if ((fd = open(path, O_RDONLY)) == -1) 923 continue; /* failed to open driver; just skip it */ 924 925 if (((prov = malloc(sizeof (dt_provmod_t))) == NULL) || 926 (prov->dp_name = malloc(strlen(p1) + 1)) == NULL) { 927 free(prov); 928 (void) close(fd); 929 break; 930 } 931 932 (void) strcpy(prov->dp_name, p1); 933 prov->dp_next = *provmod; 934 *provmod = prov; 935 936 dt_dprintf("opened provider %s\n", p1); 937 dfp->df_fds[dfp->df_ents++] = fd; 938 } 939 } 940 if (p_providers != NULL) 941 free(p_providers); 942#endif 943} 944 945static void 946dt_provmod_destroy(dt_provmod_t **provmod) 947{ 948 dt_provmod_t *next, *current; 949 950 for (current = *provmod; current != NULL; current = next) { 951 next = current->dp_next; 952 free(current->dp_name); 953 free(current); 954 } 955 956 *provmod = NULL; 957} 958 959#if defined(sun) 960static const char * 961dt_get_sysinfo(int cmd, char *buf, size_t len) 962{ 963 ssize_t rv = sysinfo(cmd, buf, len); 964 char *p = buf; 965 966 if (rv < 0 || rv > len) 967 (void) snprintf(buf, len, "%s", "Unknown"); 968 969 while ((p = strchr(p, '.')) != NULL) 970 *p++ = '_'; 971 972 return (buf); 973} 974#endif 975 976static dtrace_hdl_t * 977dt_vopen(int version, int flags, int *errp, 978 const dtrace_vector_t *vector, void *arg) 979{ 980 dtrace_hdl_t *dtp = NULL; 981 int dtfd = -1, ftfd = -1, fterr = 0; 982 dtrace_prog_t *pgp; 983 dt_module_t *dmp; 984 dt_provmod_t *provmod = NULL; 985 int i, err; 986 struct rlimit rl; 987 988 const dt_intrinsic_t *dinp; 989 const dt_typedef_t *dtyp; 990 const dt_ident_t *idp; 991 992 dtrace_typeinfo_t dtt; 993 ctf_funcinfo_t ctc; 994 ctf_arinfo_t ctr; 995 996 dt_fdlist_t df = { NULL, 0, 0 }; 997 998 char isadef[32], utsdef[32]; 999 char s1[64], s2[64]; 1000 1001 if (version <= 0) 1002 return (set_open_errno(dtp, errp, EINVAL)); 1003 1004 if (version > DTRACE_VERSION) 1005 return (set_open_errno(dtp, errp, EDT_VERSION)); 1006 1007 if (version < DTRACE_VERSION) { 1008 /* 1009 * Currently, increasing the library version number is used to 1010 * denote a binary incompatible change. That is, a consumer 1011 * of the library cannot run on a version of the library with 1012 * a higher DTRACE_VERSION number than the consumer compiled 1013 * against. Once the library API has been committed to, 1014 * backwards binary compatibility will be required; at that 1015 * time, this check should change to return EDT_OVERSION only 1016 * if the specified version number is less than the version 1017 * number at the time of interface commitment. 1018 */ 1019 return (set_open_errno(dtp, errp, EDT_OVERSION)); 1020 } 1021 1022 if (flags & ~DTRACE_O_MASK) 1023 return (set_open_errno(dtp, errp, EINVAL)); 1024 1025 if ((flags & DTRACE_O_LP64) && (flags & DTRACE_O_ILP32)) 1026 return (set_open_errno(dtp, errp, EINVAL)); 1027 1028 if (vector == NULL && arg != NULL) 1029 return (set_open_errno(dtp, errp, EINVAL)); 1030 1031 if (elf_version(EV_CURRENT) == EV_NONE) 1032 return (set_open_errno(dtp, errp, EDT_ELFVERSION)); 1033 1034 if (vector != NULL || (flags & DTRACE_O_NODEV)) 1035 goto alloc; /* do not attempt to open dtrace device */ 1036 1037 /* 1038 * Before we get going, crank our limit on file descriptors up to the 1039 * hard limit. This is to allow for the fact that libproc keeps file 1040 * descriptors to objects open for the lifetime of the proc handle; 1041 * without raising our hard limit, we would have an acceptably small 1042 * bound on the number of processes that we could concurrently 1043 * instrument with the pid provider. 1044 */ 1045 if (getrlimit(RLIMIT_NOFILE, &rl) == 0) { 1046 rl.rlim_cur = rl.rlim_max; 1047 (void) setrlimit(RLIMIT_NOFILE, &rl); 1048 } 1049 1050 /* 1051 * Get the device path of each of the providers. We hold them open 1052 * in the df.df_fds list until we open the DTrace driver itself, 1053 * allowing us to see all of the probes provided on this system. Once 1054 * we have the DTrace driver open, we can safely close all the providers 1055 * now that they have registered with the framework. 1056 */ 1057 dt_provmod_open(&provmod, &df); 1058 1059 dtfd = open("/dev/dtrace/dtrace", O_RDWR); 1060 err = errno; /* save errno from opening dtfd */ 1061 1062#if defined(sun) 1063 ftfd = open("/dev/dtrace/provider/fasttrap", O_RDWR); 1064#else 1065 ftfd = open("/dev/dtrace/fasttrap", O_RDWR); 1066#endif 1067 fterr = ftfd == -1 ? errno : 0; /* save errno from open ftfd */ 1068 1069 while (df.df_ents-- != 0) 1070 (void) close(df.df_fds[df.df_ents]); 1071 1072 free(df.df_fds); 1073 1074 /* 1075 * If we failed to open the dtrace device, fail dtrace_open(). 1076 * We convert some kernel errnos to custom libdtrace errnos to 1077 * improve the resulting message from the usual strerror(). 1078 */ 1079 if (dtfd == -1) { 1080 dt_provmod_destroy(&provmod); 1081 switch (err) { 1082 case ENOENT: 1083 err = EDT_NOENT; 1084 break; 1085 case EBUSY: 1086 err = EDT_BUSY; 1087 break; 1088 case EACCES: 1089 err = EDT_ACCESS; 1090 break; 1091 } 1092 return (set_open_errno(dtp, errp, err)); 1093 } 1094 1095 (void) fcntl(dtfd, F_SETFD, FD_CLOEXEC); 1096 (void) fcntl(ftfd, F_SETFD, FD_CLOEXEC); 1097 1098alloc: 1099 if ((dtp = malloc(sizeof (dtrace_hdl_t))) == NULL) 1100 return (set_open_errno(dtp, errp, EDT_NOMEM)); 1101 1102 bzero(dtp, sizeof (dtrace_hdl_t)); 1103 dtp->dt_oflags = flags; 1104 dtp->dt_prcmode = DT_PROC_STOP_PREINIT; 1105 dtp->dt_linkmode = DT_LINK_KERNEL; 1106 dtp->dt_linktype = DT_LTYP_ELF; 1107 dtp->dt_xlatemode = DT_XL_STATIC; 1108 dtp->dt_stdcmode = DT_STDC_XA; 1109 dtp->dt_version = version; 1110 dtp->dt_fd = dtfd; 1111 dtp->dt_ftfd = ftfd; 1112 dtp->dt_fterr = fterr; 1113 dtp->dt_cdefs_fd = -1; 1114 dtp->dt_ddefs_fd = -1; 1115#if defined(sun) 1116 dtp->dt_stdout_fd = -1; 1117#else 1118 dtp->dt_freopen_fp = NULL; 1119#endif 1120 dtp->dt_modbuckets = _dtrace_strbuckets; 1121 dtp->dt_mods = calloc(dtp->dt_modbuckets, sizeof (dt_module_t *)); 1122 dtp->dt_provbuckets = _dtrace_strbuckets; 1123 dtp->dt_provs = calloc(dtp->dt_provbuckets, sizeof (dt_provider_t *)); 1124 dt_proc_hash_create(dtp); 1125 dtp->dt_vmax = DT_VERS_LATEST; 1126 dtp->dt_cpp_path = strdup(_dtrace_defcpp); 1127 dtp->dt_cpp_argv = malloc(sizeof (char *)); 1128 dtp->dt_cpp_argc = 1; 1129 dtp->dt_cpp_args = 1; 1130 dtp->dt_ld_path = strdup(_dtrace_defld); 1131 dtp->dt_provmod = provmod; 1132 dtp->dt_vector = vector; 1133 dtp->dt_varg = arg; 1134 dt_dof_init(dtp); 1135 (void) uname(&dtp->dt_uts); 1136 1137 if (dtp->dt_mods == NULL || dtp->dt_provs == NULL || 1138 dtp->dt_procs == NULL || dtp->dt_ld_path == NULL || 1139 dtp->dt_cpp_path == NULL || dtp->dt_cpp_argv == NULL) 1140 return (set_open_errno(dtp, errp, EDT_NOMEM)); 1141 1142 for (i = 0; i < DTRACEOPT_MAX; i++) 1143 dtp->dt_options[i] = DTRACEOPT_UNSET; 1144 1145 dtp->dt_cpp_argv[0] = (char *)strbasename(dtp->dt_cpp_path); 1146 1147#if defined(sun) 1148 (void) snprintf(isadef, sizeof (isadef), "-D__SUNW_D_%u", 1149 (uint_t)(sizeof (void *) * NBBY)); 1150 1151 (void) snprintf(utsdef, sizeof (utsdef), "-D__%s_%s", 1152 dt_get_sysinfo(SI_SYSNAME, s1, sizeof (s1)), 1153 dt_get_sysinfo(SI_RELEASE, s2, sizeof (s2))); 1154 1155 if (dt_cpp_add_arg(dtp, "-D__sun") == NULL || 1156 dt_cpp_add_arg(dtp, "-D__unix") == NULL || 1157 dt_cpp_add_arg(dtp, "-D__SVR4") == NULL || 1158 dt_cpp_add_arg(dtp, "-D__SUNW_D=1") == NULL || 1159 dt_cpp_add_arg(dtp, isadef) == NULL || 1160 dt_cpp_add_arg(dtp, utsdef) == NULL) 1161 return (set_open_errno(dtp, errp, EDT_NOMEM)); 1162#endif 1163 1164 if (flags & DTRACE_O_NODEV) 1165 bcopy(&_dtrace_conf, &dtp->dt_conf, sizeof (_dtrace_conf)); 1166 else if (dt_ioctl(dtp, DTRACEIOC_CONF, &dtp->dt_conf) != 0) 1167 return (set_open_errno(dtp, errp, errno)); 1168 1169 if (flags & DTRACE_O_LP64) 1170 dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_LP64; 1171 else if (flags & DTRACE_O_ILP32) 1172 dtp->dt_conf.dtc_ctfmodel = CTF_MODEL_ILP32; 1173 1174#ifdef __sparc 1175 /* 1176 * On SPARC systems, __sparc is always defined for <sys/isa_defs.h> 1177 * and __sparcv9 is defined if we are doing a 64-bit compile. 1178 */ 1179 if (dt_cpp_add_arg(dtp, "-D__sparc") == NULL) 1180 return (set_open_errno(dtp, errp, EDT_NOMEM)); 1181 1182 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64 && 1183 dt_cpp_add_arg(dtp, "-D__sparcv9") == NULL) 1184 return (set_open_errno(dtp, errp, EDT_NOMEM)); 1185#endif 1186 1187#if defined(sun) 1188#ifdef __x86 1189 /* 1190 * On x86 systems, __i386 is defined for <sys/isa_defs.h> for 32-bit 1191 * compiles and __amd64 is defined for 64-bit compiles. Unlike SPARC, 1192 * they are defined exclusive of one another (see PSARC 2004/619). 1193 */ 1194 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) { 1195 if (dt_cpp_add_arg(dtp, "-D__amd64") == NULL) 1196 return (set_open_errno(dtp, errp, EDT_NOMEM)); 1197 } else { 1198 if (dt_cpp_add_arg(dtp, "-D__i386") == NULL) 1199 return (set_open_errno(dtp, errp, EDT_NOMEM)); 1200 } 1201#endif 1202#else 1203#if defined(__amd64__) || defined(__i386__) 1204 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) { 1205 if (dt_cpp_add_arg(dtp, "-m64") == NULL) 1206 return (set_open_errno(dtp, errp, EDT_NOMEM)); 1207 } else { 1208 if (dt_cpp_add_arg(dtp, "-m32") == NULL) 1209 return (set_open_errno(dtp, errp, EDT_NOMEM)); 1210 } 1211#endif 1212#endif 1213 1214 if (dtp->dt_conf.dtc_difversion < DIF_VERSION) 1215 return (set_open_errno(dtp, errp, EDT_DIFVERS)); 1216 1217 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32) 1218 bcopy(_dtrace_ints_32, dtp->dt_ints, sizeof (_dtrace_ints_32)); 1219 else 1220 bcopy(_dtrace_ints_64, dtp->dt_ints, sizeof (_dtrace_ints_64)); 1221 1222 /* 1223 * On FreeBSD the kernel module name can't be hard-coded. The 1224 * 'kern.bootfile' sysctl value tells us exactly which file is being 1225 * used as the kernel. 1226 */ 1227#if !defined(sun) 1228 { 1229 char bootfile[MAXPATHLEN]; 1230 char *p; 1231 int i; 1232 size_t len = sizeof(bootfile); 1233 1234 /* This call shouldn't fail, but use a default just in case. */ 1235 if (sysctlbyname("kern.bootfile", bootfile, &len, NULL, 0) != 0) 1236 strlcpy(bootfile, "kernel", sizeof(bootfile)); 1237 1238 if ((p = strrchr(bootfile, '/')) != NULL) 1239 p++; 1240 else 1241 p = bootfile; 1242 1243 /* 1244 * Format the global variables based on the kernel module name. 1245 */ 1246 snprintf(curthread_str, sizeof(curthread_str), "%s`struct thread *",p); 1247 snprintf(intmtx_str, sizeof(intmtx_str), "int(%s`struct mtx *)",p); 1248 snprintf(threadmtx_str, sizeof(threadmtx_str), "struct thread *(%s`struct mtx *)",p); 1249 snprintf(rwlock_str, sizeof(rwlock_str), "int(%s`struct rwlock *)",p); 1250 snprintf(sxlock_str, sizeof(sxlock_str), "int(%s`struct sxlock *)",p); 1251 } 1252#endif 1253 1254 dtp->dt_macros = dt_idhash_create("macro", NULL, 0, UINT_MAX); 1255 dtp->dt_aggs = dt_idhash_create("aggregation", NULL, 1256 DTRACE_AGGVARIDNONE + 1, UINT_MAX); 1257 1258 dtp->dt_globals = dt_idhash_create("global", _dtrace_globals, 1259 DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX); 1260 1261 dtp->dt_tls = dt_idhash_create("thread local", NULL, 1262 DIF_VAR_OTHER_UBASE, DIF_VAR_OTHER_MAX); 1263 1264 if (dtp->dt_macros == NULL || dtp->dt_aggs == NULL || 1265 dtp->dt_globals == NULL || dtp->dt_tls == NULL) 1266 return (set_open_errno(dtp, errp, EDT_NOMEM)); 1267 1268 /* 1269 * Populate the dt_macros identifier hash table by hand: we can't use 1270 * the dt_idhash_populate() mechanism because we're not yet compiling 1271 * and dtrace_update() needs to immediately reference these idents. 1272 */ 1273 for (idp = _dtrace_macros; idp->di_name != NULL; idp++) { 1274 if (dt_idhash_insert(dtp->dt_macros, idp->di_name, 1275 idp->di_kind, idp->di_flags, idp->di_id, idp->di_attr, 1276 idp->di_vers, idp->di_ops ? idp->di_ops : &dt_idops_thaw, 1277 idp->di_iarg, 0) == NULL) 1278 return (set_open_errno(dtp, errp, EDT_NOMEM)); 1279 } 1280 1281 /* 1282 * Update the module list using /system/object and load the values for 1283 * the macro variable definitions according to the current process. 1284 */ 1285 dtrace_update(dtp); 1286 1287 /* 1288 * Select the intrinsics and typedefs we want based on the data model. 1289 * The intrinsics are under "C". The typedefs are added under "D". 1290 */ 1291 if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_ILP32) { 1292 dinp = _dtrace_intrinsics_32; 1293 dtyp = _dtrace_typedefs_32; 1294 } else { 1295 dinp = _dtrace_intrinsics_64; 1296 dtyp = _dtrace_typedefs_64; 1297 } 1298 1299 /* 1300 * Create a dynamic CTF container under the "C" scope for intrinsic 1301 * types and types defined in ANSI-C header files that are included. 1302 */ 1303 if ((dmp = dtp->dt_cdefs = dt_module_create(dtp, "C")) == NULL) 1304 return (set_open_errno(dtp, errp, EDT_NOMEM)); 1305 1306 if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL) 1307 return (set_open_errno(dtp, errp, EDT_CTF)); 1308 1309 dt_dprintf("created CTF container for %s (%p)\n", 1310 dmp->dm_name, (void *)dmp->dm_ctfp); 1311 1312 (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel); 1313 ctf_setspecific(dmp->dm_ctfp, dmp); 1314 1315 dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */ 1316 dmp->dm_modid = -1; /* no module ID */ 1317 1318 /* 1319 * Fill the dynamic "C" CTF container with all of the intrinsic 1320 * integer and floating-point types appropriate for this data model. 1321 */ 1322 for (; dinp->din_name != NULL; dinp++) { 1323 if (dinp->din_kind == CTF_K_INTEGER) { 1324 err = ctf_add_integer(dmp->dm_ctfp, CTF_ADD_ROOT, 1325 dinp->din_name, &dinp->din_data); 1326 } else { 1327 err = ctf_add_float(dmp->dm_ctfp, CTF_ADD_ROOT, 1328 dinp->din_name, &dinp->din_data); 1329 } 1330 1331 if (err == CTF_ERR) { 1332 dt_dprintf("failed to add %s to C container: %s\n", 1333 dinp->din_name, ctf_errmsg( 1334 ctf_errno(dmp->dm_ctfp))); 1335 return (set_open_errno(dtp, errp, EDT_CTF)); 1336 } 1337 } 1338 1339 if (ctf_update(dmp->dm_ctfp) != 0) { 1340 dt_dprintf("failed to update C container: %s\n", 1341 ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1342 return (set_open_errno(dtp, errp, EDT_CTF)); 1343 } 1344 1345 /* 1346 * Add intrinsic pointer types that are needed to initialize printf 1347 * format dictionary types (see table in dt_printf.c). 1348 */ 1349 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, 1350 ctf_lookup_by_name(dmp->dm_ctfp, "void")); 1351 1352 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, 1353 ctf_lookup_by_name(dmp->dm_ctfp, "char")); 1354 1355 (void) ctf_add_pointer(dmp->dm_ctfp, CTF_ADD_ROOT, 1356 ctf_lookup_by_name(dmp->dm_ctfp, "int")); 1357 1358 if (ctf_update(dmp->dm_ctfp) != 0) { 1359 dt_dprintf("failed to update C container: %s\n", 1360 ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1361 return (set_open_errno(dtp, errp, EDT_CTF)); 1362 } 1363 1364 /* 1365 * Create a dynamic CTF container under the "D" scope for types that 1366 * are defined by the D program itself or on-the-fly by the D compiler. 1367 * The "D" CTF container is a child of the "C" CTF container. 1368 */ 1369 if ((dmp = dtp->dt_ddefs = dt_module_create(dtp, "D")) == NULL) 1370 return (set_open_errno(dtp, errp, EDT_NOMEM)); 1371 1372 if ((dmp->dm_ctfp = ctf_create(&dtp->dt_ctferr)) == NULL) 1373 return (set_open_errno(dtp, errp, EDT_CTF)); 1374 1375 dt_dprintf("created CTF container for %s (%p)\n", 1376 dmp->dm_name, (void *)dmp->dm_ctfp); 1377 1378 (void) ctf_setmodel(dmp->dm_ctfp, dtp->dt_conf.dtc_ctfmodel); 1379 ctf_setspecific(dmp->dm_ctfp, dmp); 1380 1381 dmp->dm_flags = DT_DM_LOADED; /* fake up loaded bit */ 1382 dmp->dm_modid = -1; /* no module ID */ 1383 1384 if (ctf_import(dmp->dm_ctfp, dtp->dt_cdefs->dm_ctfp) == CTF_ERR) { 1385 dt_dprintf("failed to import D parent container: %s\n", 1386 ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1387 return (set_open_errno(dtp, errp, EDT_CTF)); 1388 } 1389 1390 /* 1391 * Fill the dynamic "D" CTF container with all of the built-in typedefs 1392 * that we need to use for our D variable and function definitions. 1393 * This ensures that basic inttypes.h names are always available to us. 1394 */ 1395 for (; dtyp->dty_src != NULL; dtyp++) { 1396 if (ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 1397 dtyp->dty_dst, ctf_lookup_by_name(dmp->dm_ctfp, 1398 dtyp->dty_src)) == CTF_ERR) { 1399 dt_dprintf("failed to add typedef %s %s to D " 1400 "container: %s", dtyp->dty_src, dtyp->dty_dst, 1401 ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1402 return (set_open_errno(dtp, errp, EDT_CTF)); 1403 } 1404 } 1405 1406 /* 1407 * Insert a CTF ID corresponding to a pointer to a type of kind 1408 * CTF_K_FUNCTION we can use in the compiler for function pointers. 1409 * CTF treats all function pointers as "int (*)()" so we only need one. 1410 */ 1411 ctc.ctc_return = ctf_lookup_by_name(dmp->dm_ctfp, "int"); 1412 ctc.ctc_argc = 0; 1413 ctc.ctc_flags = 0; 1414 1415 dtp->dt_type_func = ctf_add_function(dmp->dm_ctfp, 1416 CTF_ADD_ROOT, &ctc, NULL); 1417 1418 dtp->dt_type_fptr = ctf_add_pointer(dmp->dm_ctfp, 1419 CTF_ADD_ROOT, dtp->dt_type_func); 1420 1421 /* 1422 * We also insert CTF definitions for the special D intrinsic types 1423 * string and <DYN> into the D container. The string type is added 1424 * as a typedef of char[n]. The <DYN> type is an alias for void. 1425 * We compare types to these special CTF ids throughout the compiler. 1426 */ 1427 ctr.ctr_contents = ctf_lookup_by_name(dmp->dm_ctfp, "char"); 1428 ctr.ctr_index = ctf_lookup_by_name(dmp->dm_ctfp, "long"); 1429 ctr.ctr_nelems = _dtrace_strsize; 1430 1431 dtp->dt_type_str = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 1432 "string", ctf_add_array(dmp->dm_ctfp, CTF_ADD_ROOT, &ctr)); 1433 1434 dtp->dt_type_dyn = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 1435 "<DYN>", ctf_lookup_by_name(dmp->dm_ctfp, "void")); 1436 1437 dtp->dt_type_stack = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 1438 "stack", ctf_lookup_by_name(dmp->dm_ctfp, "void")); 1439 1440 dtp->dt_type_symaddr = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 1441 "_symaddr", ctf_lookup_by_name(dmp->dm_ctfp, "void")); 1442 1443 dtp->dt_type_usymaddr = ctf_add_typedef(dmp->dm_ctfp, CTF_ADD_ROOT, 1444 "_usymaddr", ctf_lookup_by_name(dmp->dm_ctfp, "void")); 1445 1446 if (dtp->dt_type_func == CTF_ERR || dtp->dt_type_fptr == CTF_ERR || 1447 dtp->dt_type_str == CTF_ERR || dtp->dt_type_dyn == CTF_ERR || 1448 dtp->dt_type_stack == CTF_ERR || dtp->dt_type_symaddr == CTF_ERR || 1449 dtp->dt_type_usymaddr == CTF_ERR) { 1450 dt_dprintf("failed to add intrinsic to D container: %s\n", 1451 ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1452 return (set_open_errno(dtp, errp, EDT_CTF)); 1453 } 1454 1455 if (ctf_update(dmp->dm_ctfp) != 0) { 1456 dt_dprintf("failed update D container: %s\n", 1457 ctf_errmsg(ctf_errno(dmp->dm_ctfp))); 1458 return (set_open_errno(dtp, errp, EDT_CTF)); 1459 } 1460 1461 /* 1462 * Initialize the integer description table used to convert integer 1463 * constants to the appropriate types. Refer to the comments above 1464 * dt_node_int() for a complete description of how this table is used. 1465 */ 1466 for (i = 0; i < sizeof (dtp->dt_ints) / sizeof (dtp->dt_ints[0]); i++) { 1467 if (dtrace_lookup_by_type(dtp, DTRACE_OBJ_EVERY, 1468 dtp->dt_ints[i].did_name, &dtt) != 0) { 1469 dt_dprintf("failed to lookup integer type %s: %s\n", 1470 dtp->dt_ints[i].did_name, 1471 dtrace_errmsg(dtp, dtrace_errno(dtp))); 1472 return (set_open_errno(dtp, errp, dtp->dt_errno)); 1473 } 1474 dtp->dt_ints[i].did_ctfp = dtt.dtt_ctfp; 1475 dtp->dt_ints[i].did_type = dtt.dtt_type; 1476 } 1477 1478 /* 1479 * Now that we've created the "C" and "D" containers, move them to the 1480 * start of the module list so that these types and symbols are found 1481 * first (for stability) when iterating through the module list. 1482 */ 1483 dt_list_delete(&dtp->dt_modlist, dtp->dt_ddefs); 1484 dt_list_prepend(&dtp->dt_modlist, dtp->dt_ddefs); 1485 1486 dt_list_delete(&dtp->dt_modlist, dtp->dt_cdefs); 1487 dt_list_prepend(&dtp->dt_modlist, dtp->dt_cdefs); 1488 1489 if (dt_pfdict_create(dtp) == -1) 1490 return (set_open_errno(dtp, errp, dtp->dt_errno)); 1491 1492 /* 1493 * If we are opening libdtrace DTRACE_O_NODEV enable C_ZDEFS by default 1494 * because without /dev/dtrace open, we will not be able to load the 1495 * names and attributes of any providers or probes from the kernel. 1496 */ 1497 if (flags & DTRACE_O_NODEV) 1498 dtp->dt_cflags |= DTRACE_C_ZDEFS; 1499 1500 /* 1501 * Load hard-wired inlines into the definition cache by calling the 1502 * compiler on the raw definition string defined above. 1503 */ 1504 if ((pgp = dtrace_program_strcompile(dtp, _dtrace_hardwire, 1505 DTRACE_PROBESPEC_NONE, DTRACE_C_EMPTY, 0, NULL)) == NULL) { 1506 dt_dprintf("failed to load hard-wired definitions: %s\n", 1507 dtrace_errmsg(dtp, dtrace_errno(dtp))); 1508 return (set_open_errno(dtp, errp, EDT_HARDWIRE)); 1509 } 1510 1511 dt_program_destroy(dtp, pgp); 1512 1513 /* 1514 * Set up the default DTrace library path. Once set, the next call to 1515 * dt_compile() will compile all the libraries. We intentionally defer 1516 * library processing to improve overhead for clients that don't ever 1517 * compile, and to provide better error reporting (because the full 1518 * reporting of compiler errors requires dtrace_open() to succeed). 1519 */ 1520 if (dtrace_setopt(dtp, "libdir", _dtrace_libdir) != 0) 1521 return (set_open_errno(dtp, errp, dtp->dt_errno)); 1522 1523 return (dtp); 1524} 1525 1526dtrace_hdl_t * 1527dtrace_open(int version, int flags, int *errp) 1528{ 1529 return (dt_vopen(version, flags, errp, NULL, NULL)); 1530} 1531 1532dtrace_hdl_t * 1533dtrace_vopen(int version, int flags, int *errp, 1534 const dtrace_vector_t *vector, void *arg) 1535{ 1536 return (dt_vopen(version, flags, errp, vector, arg)); 1537} 1538 1539void 1540dtrace_close(dtrace_hdl_t *dtp) 1541{ 1542 dt_ident_t *idp, *ndp; 1543 dt_module_t *dmp; 1544 dt_provider_t *pvp; 1545 dtrace_prog_t *pgp; 1546 dt_xlator_t *dxp; 1547 dt_dirpath_t *dirp; 1548 int i; 1549 1550 if (dtp->dt_procs != NULL) 1551 dt_proc_hash_destroy(dtp); 1552 1553 while ((pgp = dt_list_next(&dtp->dt_programs)) != NULL) 1554 dt_program_destroy(dtp, pgp); 1555 1556 while ((dxp = dt_list_next(&dtp->dt_xlators)) != NULL) 1557 dt_xlator_destroy(dtp, dxp); 1558 1559 dt_free(dtp, dtp->dt_xlatormap); 1560 1561 for (idp = dtp->dt_externs; idp != NULL; idp = ndp) { 1562 ndp = idp->di_next; 1563 dt_ident_destroy(idp); 1564 } 1565 1566 if (dtp->dt_macros != NULL) 1567 dt_idhash_destroy(dtp->dt_macros); 1568 if (dtp->dt_aggs != NULL) 1569 dt_idhash_destroy(dtp->dt_aggs); 1570 if (dtp->dt_globals != NULL) 1571 dt_idhash_destroy(dtp->dt_globals); 1572 if (dtp->dt_tls != NULL) 1573 dt_idhash_destroy(dtp->dt_tls); 1574 1575 while ((dmp = dt_list_next(&dtp->dt_modlist)) != NULL) 1576 dt_module_destroy(dtp, dmp); 1577 1578 while ((pvp = dt_list_next(&dtp->dt_provlist)) != NULL) 1579 dt_provider_destroy(dtp, pvp); 1580 1581 if (dtp->dt_fd != -1) 1582 (void) close(dtp->dt_fd); 1583 if (dtp->dt_ftfd != -1) 1584 (void) close(dtp->dt_ftfd); 1585 if (dtp->dt_cdefs_fd != -1) 1586 (void) close(dtp->dt_cdefs_fd); 1587 if (dtp->dt_ddefs_fd != -1) 1588 (void) close(dtp->dt_ddefs_fd); 1589#if defined(sun) 1590 if (dtp->dt_stdout_fd != -1) 1591 (void) close(dtp->dt_stdout_fd); 1592#else 1593 if (dtp->dt_freopen_fp != NULL) 1594 (void) fclose(dtp->dt_freopen_fp); 1595#endif 1596 1597 dt_epid_destroy(dtp); 1598 dt_aggid_destroy(dtp); 1599 dt_format_destroy(dtp); 1600 dt_buffered_destroy(dtp); 1601 dt_aggregate_destroy(dtp); 1602 free(dtp->dt_buf.dtbd_data); 1603 dt_pfdict_destroy(dtp); 1604 dt_provmod_destroy(&dtp->dt_provmod); 1605 dt_dof_fini(dtp); 1606 1607 for (i = 1; i < dtp->dt_cpp_argc; i++) 1608 free(dtp->dt_cpp_argv[i]); 1609 1610 while ((dirp = dt_list_next(&dtp->dt_lib_path)) != NULL) { 1611 dt_list_delete(&dtp->dt_lib_path, dirp); 1612 free(dirp->dir_path); 1613 free(dirp); 1614 } 1615 1616 free(dtp->dt_cpp_argv); 1617 free(dtp->dt_cpp_path); 1618 free(dtp->dt_ld_path); 1619 1620 free(dtp->dt_mods); 1621 free(dtp->dt_provs); 1622 free(dtp); 1623} 1624 1625int 1626dtrace_provider_modules(dtrace_hdl_t *dtp, const char **mods, int nmods) 1627{ 1628 dt_provmod_t *prov; 1629 int i = 0; 1630 1631 for (prov = dtp->dt_provmod; prov != NULL; prov = prov->dp_next, i++) { 1632 if (i < nmods) 1633 mods[i] = prov->dp_name; 1634 } 1635 1636 return (i); 1637} 1638 1639int 1640dtrace_ctlfd(dtrace_hdl_t *dtp) 1641{ 1642 return (dtp->dt_fd); 1643} 1644