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 #ifndef _DT_IMPL_H 28 #define _DT_IMPL_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #include <sys/param.h> 33 #include <sys/objfs.h> 34 #include <setjmp.h> 35 #include <libctf.h> 36 #include <dtrace.h> 37 #include <gelf.h> 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 #include <dt_parser.h> 44 #include <dt_regset.h> 45 #include <dt_inttab.h> 46 #include <dt_strtab.h> 47 #include <dt_ident.h> 48 #include <dt_list.h> 49 #include <dt_decl.h> 50 #include <dt_as.h> 51 #include <dt_proc.h> 52 #include <dt_dof.h> 53 #include <dt_pcb.h> 54 55 struct dt_module; /* see below */ 56 struct dt_pfdict; /* see <dt_printf.h> */ 57 struct dt_arg; /* see below */ 58 struct dt_provider; /* see <dt_provider.h> */ 59 60 typedef struct dt_intrinsic { 61 const char *din_name; /* string name of the intrinsic type */ 62 ctf_encoding_t din_data; /* integer or floating-point CTF encoding */ 63 uint_t din_kind; /* CTF type kind to instantiate */ 64 } dt_intrinsic_t; 65 66 typedef struct dt_typedef { 67 const char *dty_src; /* string name of typedef source type */ 68 const char *dty_dst; /* string name of typedef destination type */ 69 } dt_typedef_t; 70 71 typedef struct dt_intdesc { 72 const char *did_name; /* string name of the integer type */ 73 ctf_file_t *did_ctfp; /* CTF container for this type reference */ 74 ctf_id_t did_type; /* CTF type reference for this type */ 75 uintmax_t did_limit; /* maximum positive value held by type */ 76 } dt_intdesc_t; 77 78 typedef struct dt_modops { 79 uint_t (*do_syminit)(struct dt_module *); 80 void (*do_symsort)(struct dt_module *); 81 GElf_Sym *(*do_symname)(struct dt_module *, 82 const char *, GElf_Sym *, uint_t *); 83 GElf_Sym *(*do_symaddr)(struct dt_module *, 84 GElf_Addr, GElf_Sym *, uint_t *); 85 } dt_modops_t; 86 87 typedef struct dt_arg { 88 int da_ndx; /* index of this argument */ 89 int da_mapping; /* mapping of argument indices to arguments */ 90 ctf_id_t da_type; /* type of argument */ 91 ctf_file_t *da_ctfp; /* CTF container for type */ 92 dt_ident_t *da_xlator; /* translator, if any */ 93 struct dt_arg *da_next; /* next argument */ 94 } dt_arg_t; 95 96 typedef struct dt_sym { 97 uint_t ds_symid; /* id of corresponding symbol */ 98 uint_t ds_next; /* index of next element in hash chain */ 99 } dt_sym_t; 100 101 typedef struct dt_module { 102 dt_list_t dm_list; /* list forward/back pointers */ 103 char dm_name[DTRACE_MODNAMELEN]; /* string name of module */ 104 char dm_file[MAXPATHLEN]; /* file path of module (if any) */ 105 struct dt_module *dm_next; /* pointer to next module in hash chain */ 106 const dt_modops_t *dm_ops; /* pointer to data model's ops vector */ 107 Elf *dm_elf; /* libelf handle for module object */ 108 objfs_info_t dm_info; /* object filesystem private info */ 109 ctf_sect_t dm_symtab; /* symbol table for module */ 110 ctf_sect_t dm_strtab; /* string table for module */ 111 ctf_sect_t dm_ctdata; /* CTF data for module */ 112 ctf_file_t *dm_ctfp; /* CTF container handle */ 113 uint_t *dm_symbuckets; /* symbol table hash buckets (chain indices) */ 114 dt_sym_t *dm_symchains; /* symbol table hash chains buffer */ 115 void *dm_asmap; /* symbol pointers sorted by value */ 116 uint_t dm_symfree; /* index of next free hash element */ 117 uint_t dm_nsymbuckets; /* number of elements in bucket array */ 118 uint_t dm_nsymelems; /* number of elements in hash table */ 119 uint_t dm_asrsv; /* actual reserved size of dm_asmap */ 120 uint_t dm_aslen; /* number of entries in dm_asmap */ 121 uint_t dm_flags; /* module flags (see below) */ 122 int dm_modid; /* modinfo(1M) module identifier */ 123 GElf_Addr dm_text_va; /* virtual address of text section */ 124 GElf_Xword dm_text_size; /* size in bytes of text section */ 125 GElf_Addr dm_data_va; /* virtual address of data section */ 126 GElf_Xword dm_data_size; /* size in bytes of data section */ 127 GElf_Addr dm_bss_va; /* virtual address of BSS */ 128 GElf_Xword dm_bss_size; /* size in bytes of BSS */ 129 dt_idhash_t *dm_extern; /* external symbol definitions */ 130 } dt_module_t; 131 132 #define DT_DM_LOADED 0x1 /* module symbol and type data is loaded */ 133 #define DT_DM_KERNEL 0x2 /* module is associated with a kernel object */ 134 #define DT_DM_PRIMARY 0x4 /* module is a krtld primary kernel object */ 135 136 typedef struct dt_provmod { 137 char *dp_name; /* name of provider module */ 138 struct dt_provmod *dp_next; /* next module */ 139 } dt_provmod_t; 140 141 typedef struct dt_ahashent { 142 struct dt_ahashent *dtahe_prev; /* prev on hash chain */ 143 struct dt_ahashent *dtahe_next; /* next on hash chain */ 144 struct dt_ahashent *dtahe_prevall; /* prev on list of all */ 145 struct dt_ahashent *dtahe_nextall; /* next on list of all */ 146 uint64_t dtahe_hashval; /* hash value */ 147 size_t dtahe_size; /* size of data */ 148 dtrace_aggdata_t dtahe_data; /* data */ 149 void (*dtahe_aggregate)(uint64_t *, uint64_t *, size_t); /* function */ 150 } dt_ahashent_t; 151 152 typedef struct dt_ahash { 153 dt_ahashent_t **dtah_hash; /* hash table */ 154 dt_ahashent_t *dtah_all; /* list of all elements */ 155 size_t dtah_size; /* size of hash table */ 156 } dt_ahash_t; 157 158 typedef struct dt_aggregate { 159 dtrace_bufdesc_t dtat_buf; /* buf aggregation snapshot */ 160 int dtat_flags; /* aggregate flags */ 161 processorid_t dtat_ncpus; /* number of CPUs in aggregate */ 162 processorid_t *dtat_cpus; /* CPUs in aggregate */ 163 processorid_t dtat_ncpu; /* size of dtat_cpus array */ 164 processorid_t dtat_maxcpu; /* maximum number of CPUs */ 165 dt_ahash_t dtat_hash; /* aggregate hash table */ 166 } dt_aggregate_t; 167 168 typedef struct dt_print_aggdata { 169 dtrace_hdl_t *dtpa_dtp; /* pointer to libdtrace handle */ 170 dtrace_aggvarid_t dtpa_id; /* aggregation variable of interest */ 171 FILE *dtpa_fp; /* file pointer */ 172 int dtpa_allunprint; /* print only unprinted aggregations */ 173 } dt_print_aggdata_t; 174 175 typedef struct dt_dirpath { 176 dt_list_t dir_list; /* linked-list forward/back pointers */ 177 char *dir_path; /* directory pathname */ 178 } dt_dirpath_t; 179 180 typedef uint32_t dt_version_t; /* encoded version (see below) */ 181 182 struct dtrace_hdl { 183 const dtrace_vector_t *dt_vector; /* library vector, if vectored open */ 184 void *dt_varg; /* vector argument, if vectored open */ 185 dtrace_conf_t dt_conf; /* DTrace driver configuration profile */ 186 char dt_errmsg[BUFSIZ]; /* buffer for formatted syntax error msgs */ 187 const char *dt_errtag; /* tag used with last call to dt_set_errmsg() */ 188 dt_pcb_t *dt_pcb; /* pointer to current parsing control block */ 189 ulong_t dt_gen; /* compiler generation number */ 190 dt_list_t dt_programs; /* linked list of dtrace_prog_t's */ 191 dt_list_t dt_xlators; /* linked list of dt_xlator_t's */ 192 dt_ident_t *dt_externs; /* linked list of external symbol identifiers */ 193 dt_idhash_t *dt_macros; /* hash table of macro variable identifiers */ 194 dt_idhash_t *dt_aggs; /* hash table of aggregation identifiers */ 195 dt_idhash_t *dt_globals; /* hash table of global identifiers */ 196 dt_idhash_t *dt_tls; /* hash table of thread-local identifiers */ 197 dt_list_t dt_modlist; /* linked list of dt_module_t's */ 198 dt_module_t **dt_mods; /* hash table of dt_module_t's */ 199 uint_t dt_modbuckets; /* number of module hash buckets */ 200 uint_t dt_nmods; /* number of modules in hash and list */ 201 dt_provmod_t *dt_provmod; /* linked list of provider modules */ 202 dt_module_t *dt_exec; /* pointer to executable module */ 203 dt_module_t *dt_rtld; /* pointer to run-time linker module */ 204 dt_module_t *dt_cdefs; /* pointer to C dynamic type module */ 205 dt_module_t *dt_ddefs; /* pointer to D dynamic type module */ 206 dt_list_t dt_provlist; /* linked list of dt_provider_t's */ 207 struct dt_provider **dt_provs; /* hash table of dt_provider_t's */ 208 uint_t dt_provbuckets; /* number of provider hash buckets */ 209 uint_t dt_nprovs; /* number of providers in hash and list */ 210 dt_proc_hash_t *dt_procs; /* hash table of grabbed process handles */ 211 dt_intdesc_t dt_ints[6]; /* cached integer type descriptions */ 212 ctf_id_t dt_type_func; /* cached CTF identifier for function type */ 213 ctf_id_t dt_type_fptr; /* cached CTF identifier for function pointer */ 214 ctf_id_t dt_type_str; /* cached CTF identifier for string type */ 215 ctf_id_t dt_type_dyn; /* cached CTF identifier for <DYN> type */ 216 ctf_id_t dt_type_stack; /* cached CTF identifier for stack type */ 217 size_t dt_maxprobe; /* max enabled probe ID */ 218 dtrace_eprobedesc_t **dt_edesc; /* enabled probe descriptions */ 219 dtrace_probedesc_t **dt_pdesc; /* probe descriptions for enabled prbs */ 220 size_t dt_maxagg; /* max aggregation ID */ 221 dtrace_aggdesc_t **dt_aggdesc; /* aggregation descriptions */ 222 int dt_maxformat; /* max format ID */ 223 void **dt_formats; /* pointer to format array */ 224 dt_aggregate_t dt_aggregate; /* aggregate */ 225 dtrace_bufdesc_t dt_buf; /* staging buffer */ 226 struct dt_pfdict *dt_pfdict; /* dictionary of printf conversions */ 227 dt_version_t dt_vmax; /* optional ceiling on program API binding */ 228 dtrace_attribute_t dt_amin; /* optional floor on program attributes */ 229 char *dt_cpp_path; /* pathname of cpp(1) to invoke if needed */ 230 char **dt_cpp_argv; /* argument vector for exec'ing cpp(1) */ 231 int dt_cpp_argc; /* count of initialized cpp(1) arguments */ 232 int dt_cpp_args; /* size of dt_cpp_argv[] array */ 233 char *dt_ld_path; /* pathname of ld(1) to invoke if needed */ 234 dt_list_t dt_lib_path; /* linked-list forming library search path */ 235 uint_t dt_lazyload; /* boolean: set via -xlazyload */ 236 uint_t dt_active; /* boolean: set once tracing is active */ 237 uint_t dt_stopped; /* boolean: set once tracing is stopped */ 238 processorid_t dt_beganon; /* CPU that executed BEGIN probe (if any) */ 239 processorid_t dt_endedon; /* CPU that executed END probe (if any) */ 240 uint_t dt_oflags; /* dtrace open-time options (see dtrace.h) */ 241 uint_t dt_cflags; /* dtrace compile-time options (see dtrace.h) */ 242 uint_t dt_dflags; /* dtrace link-time options (see dtrace.h) */ 243 uint_t dt_prcmode; /* dtrace process create mode (see dt_proc.h) */ 244 uint_t dt_linkmode; /* dtrace symbol linking mode (see below) */ 245 uint_t dt_linktype; /* dtrace link output file type (see below) */ 246 uint_t dt_stdcmode; /* dtrace stdc compatibility mode (see below) */ 247 uint_t dt_treedump; /* dtrace tree debug bitmap (see below) */ 248 uint64_t dt_options[DTRACEOPT_MAX]; /* dtrace run-time options */ 249 int dt_version; /* library version requested by client */ 250 int dt_ctferr; /* error resulting from last CTF failure */ 251 int dt_errno; /* error resulting from last failed operation */ 252 int dt_fd; /* file descriptor for dtrace pseudo-device */ 253 int dt_ftfd; /* file descriptor for fasttrap pseudo-device */ 254 int dt_fterr; /* saved errno from failed open of dt_ftfd */ 255 int dt_cdefs_fd; /* file descriptor for C CTF debugging cache */ 256 int dt_ddefs_fd; /* file descriptor for D CTF debugging cache */ 257 int dt_stdout_fd; /* file descriptor for saved stdout */ 258 dtrace_handle_err_f *dt_errhdlr; /* error handler, if any */ 259 void *dt_errarg; /* error handler argument */ 260 dtrace_prog_t *dt_errprog; /* error handler program, if any */ 261 dtrace_handle_drop_f *dt_drophdlr; /* drop handler, if any */ 262 void *dt_droparg; /* drop handler argument */ 263 dtrace_handle_proc_f *dt_prochdlr; /* proc handler, if any */ 264 void *dt_procarg; /* proc handler argument */ 265 dtrace_status_t dt_status[2]; /* status cache */ 266 int dt_statusgen; /* current status generation */ 267 hrtime_t dt_laststatus; /* last status */ 268 hrtime_t dt_lastswitch; /* last switch of buffer data */ 269 hrtime_t dt_lastagg; /* last snapshot of aggregation data */ 270 char *dt_sprintf_buf; /* buffer for dtrace_sprintf() */ 271 int dt_sprintf_buflen; /* length of dtrace_sprintf() buffer */ 272 const char *dt_filetag; /* default filetag for dt_set_errmsg() */ 273 char *dt_buffered_buf; /* buffer for buffered output */ 274 size_t dt_buffered_offs; /* current offset into buffered buffer */ 275 size_t dt_buffered_size; /* size of buffered buffer */ 276 dtrace_handle_buffered_f *dt_bufhdlr; /* buffered handler, if any */ 277 void *dt_bufarg; /* buffered handler argument */ 278 dt_dof_t dt_dof; /* DOF generation buffers (see dt_dof.c) */ 279 struct utsname dt_uts; /* uname(2) information for system */ 280 }; 281 282 /* 283 * Values for the user arg of the ECB. 284 */ 285 #define DT_ECB_DEFAULT 0 286 #define DT_ECB_ERROR 1 287 288 /* 289 * Values for the dt_linkmode property, which is used by the assembler when 290 * processing external symbol references. User can set using -xlink=<mode>. 291 */ 292 #define DT_LINK_KERNEL 0 /* kernel syms static, user syms dynamic */ 293 #define DT_LINK_PRIMARY 1 /* primary kernel syms static, others dynamic */ 294 #define DT_LINK_DYNAMIC 2 /* all symbols dynamic */ 295 #define DT_LINK_STATIC 3 /* all symbols static */ 296 297 /* 298 * Values for the dt_linktype property, which is used by dtrace_program_link() 299 * to determine the type of output file that is desired by the client. 300 */ 301 #define DT_LTYP_ELF 0 /* produce ELF containing DOF */ 302 #define DT_LTYP_DOF 1 /* produce stand-alone DOF */ 303 304 /* 305 * Values for the dt_stdcmode property, which is used by the compiler when 306 * running cpp to determine the presence and setting of the __STDC__ macro. 307 */ 308 #define DT_STDC_XA 0 /* ISO C + K&R C compat w/o ISO: __STDC__=0 */ 309 #define DT_STDC_XC 1 /* Strict ISO C: __STDC__=1 */ 310 #define DT_STDC_XS 2 /* K&R C: __STDC__ not defined */ 311 #define DT_STDC_XT 3 /* ISO C + K&R C compat with ISO: __STDC__=0 */ 312 313 /* 314 * Macro to test whether a given pass bit is set in the dt_treedump bit-vector. 315 * If the bit for pass 'p' is set, the D compiler displays the parse tree for 316 * the program by printing it to stderr at the end of compiler pass 'p'. 317 */ 318 #define DT_TREEDUMP_PASS(dtp, p) ((dtp)->dt_treedump & (1 << ((p) - 1))) 319 320 /* 321 * Macros for accessing the cached CTF container and type ID for the common 322 * types "int", "string", and <DYN>, which we need to use frequently in the D 323 * compiler. The DT_INT_* macro relies upon "int" being at index 0 in the 324 * _dtrace_ints_* tables in dt_open.c; the others are also set up there. 325 */ 326 #define DT_INT_CTFP(dtp) ((dtp)->dt_ints[0].did_ctfp) 327 #define DT_INT_TYPE(dtp) ((dtp)->dt_ints[0].did_type) 328 329 #define DT_FUNC_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) 330 #define DT_FUNC_TYPE(dtp) ((dtp)->dt_type_func) 331 332 #define DT_FPTR_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) 333 #define DT_FPTR_TYPE(dtp) ((dtp)->dt_type_fptr) 334 335 #define DT_STR_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) 336 #define DT_STR_TYPE(dtp) ((dtp)->dt_type_str) 337 338 #define DT_DYN_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) 339 #define DT_DYN_TYPE(dtp) ((dtp)->dt_type_dyn) 340 341 #define DT_STACK_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) 342 #define DT_STACK_TYPE(dtp) ((dtp)->dt_type_stack) 343 344 typedef struct dt_stmt { 345 dt_list_t ds_list; /* list forward/back pointers */ 346 dtrace_stmtdesc_t *ds_desc; /* pointer to statement description */ 347 } dt_stmt_t; 348 349 struct dtrace_prog { 350 dt_list_t dp_list; /* list forward/back pointers */ 351 dt_list_t dp_stmts; /* linked list of dt_stmt_t's */ 352 }; 353 354 #define DT_ACT_PRINTF 0 /* printf() action */ 355 #define DT_ACT_TRACE 1 /* trace() action */ 356 #define DT_ACT_TRACEMEM 2 /* tracemem() action */ 357 #define DT_ACT_STACK 3 /* stack() action */ 358 #define DT_ACT_STOP 4 /* stop() action */ 359 #define DT_ACT_BREAKPOINT 5 /* breakpoint() action */ 360 #define DT_ACT_PANIC 6 /* panic() action */ 361 #define DT_ACT_SPECULATE 7 /* speculate() action */ 362 #define DT_ACT_COMMIT 8 /* commit() action */ 363 #define DT_ACT_DISCARD 9 /* discard() action */ 364 #define DT_ACT_CHILL 10 /* chill() action */ 365 #define DT_ACT_EXIT 11 /* exit() action */ 366 #define DT_ACT_USTACK 12 /* ustack() action */ 367 #define DT_ACT_PRINTA 13 /* printa() action */ 368 #define DT_ACT_RAISE 14 /* raise() action */ 369 #define DT_ACT_CLEAR 15 /* clear() action */ 370 #define DT_ACT_NORMALIZE 16 /* normalize() action */ 371 #define DT_ACT_DENORMALIZE 17 /* denormalize() action */ 372 #define DT_ACT_TRUNC 18 /* trunc() action */ 373 #define DT_ACT_SYSTEM 19 /* system() action */ 374 #define DT_ACT_JSTACK 20 /* jstack() action */ 375 #define DT_ACT_FTRUNCATE 21 /* ftruncate() action */ 376 #define DT_ACT_FREOPEN 22 /* freopen() action */ 377 378 /* 379 * Sentinel to tell freopen() to restore the saved stdout. This must not 380 * be ever valid for opening for write access via freopen(3C), which of 381 * course, "." never is. 382 */ 383 #define DT_FREOPEN_RESTORE "." 384 385 #define EDT_BASE 1000 /* base value for libdtrace errnos */ 386 387 enum { 388 EDT_VERSION = EDT_BASE, /* client is requesting unsupported version */ 389 EDT_VERSINVAL, /* version string is invalid or overflows */ 390 EDT_VERSUNDEF, /* requested API version is not defined */ 391 EDT_VERSREDUCED, /* requested API version has been reduced */ 392 EDT_CTF, /* libctf called failed (dt_ctferr has more) */ 393 EDT_COMPILER, /* error in D program compilation */ 394 EDT_NOREG, /* register allocation failure */ 395 EDT_NOTUPREG, /* tuple register allocation failure */ 396 EDT_NOMEM, /* memory allocation failure */ 397 EDT_INT2BIG, /* integer limit exceeded */ 398 EDT_STR2BIG, /* string limit exceeded */ 399 EDT_NOMOD, /* unknown module name */ 400 EDT_NOPROV, /* unknown provider name */ 401 EDT_NOPROBE, /* unknown probe name */ 402 EDT_NOSYM, /* unknown symbol name */ 403 EDT_NOSYMADDR, /* no symbol corresponds to address */ 404 EDT_NOTYPE, /* unknown type name */ 405 EDT_NOVAR, /* unknown variable name */ 406 EDT_NOAGG, /* unknown aggregation name */ 407 EDT_BADSCOPE, /* improper use of type name scoping operator */ 408 EDT_BADSPEC, /* overspecified probe description */ 409 EDT_BADSPCV, /* bad macro variable in probe description */ 410 EDT_BADID, /* invalid probe identifier */ 411 EDT_NOTLOADED, /* module is not currently loaded */ 412 EDT_NOCTF, /* module does not contain any CTF data */ 413 EDT_DATAMODEL, /* module and program data models don't match */ 414 EDT_DIFVERS, /* library has newer DIF version than driver */ 415 EDT_BADAGG, /* unrecognized aggregating action */ 416 EDT_FIO, /* file i/o error */ 417 EDT_DIFINVAL, /* invalid DIF program */ 418 EDT_DIFSIZE, /* invalid DIF size */ 419 EDT_DIFFAULT, /* failed to copyin DIF program */ 420 EDT_BADPROBE, /* bad probe description */ 421 EDT_BADPGLOB, /* bad probe description globbing pattern */ 422 EDT_NOSCOPE, /* declaration scope stack underflow */ 423 EDT_NODECL, /* declaration stack underflow */ 424 EDT_DMISMATCH, /* record list does not match statement */ 425 EDT_DOFFSET, /* record data offset error */ 426 EDT_DALIGN, /* record data alignment error */ 427 EDT_BADOPTNAME, /* invalid dtrace_setopt option name */ 428 EDT_BADOPTVAL, /* invalid dtrace_setopt option value */ 429 EDT_BADOPTCTX, /* invalid dtrace_setopt option context */ 430 EDT_CPPFORK, /* failed to fork preprocessor */ 431 EDT_CPPEXEC, /* failed to exec preprocessor */ 432 EDT_CPPENT, /* preprocessor not found */ 433 EDT_CPPERR, /* unknown preprocessor error */ 434 EDT_SYMOFLOW, /* external symbol table overflow */ 435 EDT_ACTIVE, /* operation illegal when tracing is active */ 436 EDT_DESTRUCTIVE, /* destructive actions not allowed */ 437 EDT_NOANON, /* no anonymous tracing state */ 438 EDT_ISANON, /* can't claim anon state and enable probes */ 439 EDT_ENDTOOBIG, /* END enablings exceed size of prncpl buffer */ 440 EDT_NOCONV, /* failed to load type for printf conversion */ 441 EDT_BADCONV, /* incomplete printf conversion */ 442 EDT_BADERROR, /* invalid library ERROR action */ 443 EDT_ERRABORT, /* abort due to error */ 444 EDT_DROPABORT, /* abort due to drop */ 445 EDT_DIRABORT, /* abort explicitly directed */ 446 EDT_BADRVAL, /* invalid return value from callback */ 447 EDT_BADNORMAL, /* invalid normalization */ 448 EDT_BUFTOOSMALL, /* enabling exceeds size of buffer */ 449 EDT_BADTRUNC, /* invalid truncation */ 450 EDT_BUSY, /* device busy (active kernel debugger) */ 451 EDT_ACCESS, /* insufficient privileges to use DTrace */ 452 EDT_GNOENT, /* dtrace device not available in global zone */ 453 EDT_ZNOENT, /* dtrace device not available in local zone */ 454 EDT_BRICKED, /* abort due to systemic unresponsiveness */ 455 EDT_HARDWIRE, /* failed to load hard-wired definitions */ 456 EDT_ELFVERSION, /* libelf is out-of-date w.r.t libdtrace */ 457 EDT_NOBUFFERED, /* attempt to buffer output without handler */ 458 EDT_UNSTABLE /* description matched unstable set of probes */ 459 }; 460 461 /* 462 * Interfaces for parsing and comparing DTrace attribute tuples, which describe 463 * stability and architectural binding information. The dtrace_attribute_t 464 * structure and associated constant definitions are found in <sys/dtrace.h>. 465 */ 466 extern dtrace_attribute_t dt_attr_min(dtrace_attribute_t, dtrace_attribute_t); 467 extern dtrace_attribute_t dt_attr_max(dtrace_attribute_t, dtrace_attribute_t); 468 extern char *dt_attr_str(dtrace_attribute_t, char *, size_t); 469 extern int dt_attr_cmp(dtrace_attribute_t, dtrace_attribute_t); 470 471 /* 472 * Interfaces for parsing and handling DTrace version strings. Version binding 473 * is a feature of the D compiler that is handled completely independently of 474 * the DTrace kernel infrastructure, so the definitions are here in libdtrace. 475 * Version strings are compiled into an encoded uint32_t which can be compared 476 * using C comparison operators. Version definitions are found in dt_open.c. 477 */ 478 #define DT_VERSION_STRMAX 16 /* enough for "255.4095.4095\0" */ 479 #define DT_VERSION_MAJMAX 0xFF /* maximum major version number */ 480 #define DT_VERSION_MINMAX 0xFFF /* maximum minor version number */ 481 #define DT_VERSION_MICMAX 0xFFF /* maximum micro version number */ 482 483 #define DT_VERSION_NUMBER(M, m, u) \ 484 ((((M) & 0xFF) << 24) | (((m) & 0xFFF) << 12) | ((u) & 0xFFF)) 485 486 #define DT_VERSION_MAJOR(v) (((v) & 0xFF000000) >> 24) 487 #define DT_VERSION_MINOR(v) (((v) & 0x00FFF000) >> 12) 488 #define DT_VERSION_MICRO(v) ((v) & 0x00000FFF) 489 490 extern char *dt_version_num2str(dt_version_t, char *, size_t); 491 extern int dt_version_str2num(const char *, dt_version_t *); 492 extern int dt_version_defined(dt_version_t); 493 494 /* 495 * Miscellaneous internal libdtrace interfaces. The definitions below are for 496 * libdtrace routines that do not yet merit their own separate header file. 497 */ 498 extern char *dt_cpp_add_arg(dtrace_hdl_t *, const char *); 499 extern char *dt_cpp_pop_arg(dtrace_hdl_t *); 500 501 extern int dt_set_errno(dtrace_hdl_t *, int); 502 extern void dt_set_errmsg(dtrace_hdl_t *, const char *, const char *, 503 const char *, int, const char *, va_list); 504 505 extern int dt_ioctl(dtrace_hdl_t *, int, void *); 506 extern int dt_status(dtrace_hdl_t *, processorid_t); 507 extern long dt_sysconf(dtrace_hdl_t *, int); 508 extern ssize_t dt_write(dtrace_hdl_t *, int, const void *, size_t); 509 extern int dt_printf(dtrace_hdl_t *, FILE *, const char *, ...); 510 511 extern void *dt_zalloc(dtrace_hdl_t *, size_t); 512 extern void *dt_alloc(dtrace_hdl_t *, size_t); 513 extern void dt_free(dtrace_hdl_t *, void *); 514 515 extern int dt_gmatch(const char *, const char *); 516 extern char *dt_basename(char *); 517 518 extern int dt_buffered_enable(dtrace_hdl_t *); 519 extern int dt_buffered_flush(dtrace_hdl_t *, dtrace_probedata_t *, 520 dtrace_recdesc_t *, dtrace_aggdata_t *); 521 extern void dt_buffered_disable(dtrace_hdl_t *); 522 extern void dt_buffered_destroy(dtrace_hdl_t *); 523 524 extern int dt_rw_read_held(pthread_rwlock_t *); 525 extern int dt_rw_write_held(pthread_rwlock_t *); 526 extern int dt_mutex_held(pthread_mutex_t *); 527 528 #define DT_RW_READ_HELD(x) dt_rw_read_held(x) 529 #define DT_RW_WRITE_HELD(x) dt_rw_write_held(x) 530 #define DT_RW_LOCK_HELD(x) (DT_RW_READ_HELD(x) || DT_RW_WRITE_HELD(x)) 531 #define DT_MUTEX_HELD(x) dt_mutex_held(x) 532 533 extern int dt_options_load(dtrace_hdl_t *); 534 535 extern void dt_dprintf(const char *, ...); 536 537 extern void dt_setcontext(dtrace_hdl_t *, dtrace_probedesc_t *); 538 extern void dt_endcontext(dtrace_hdl_t *); 539 540 extern void dt_pragma(dt_node_t *); 541 extern int dt_reduce(dtrace_hdl_t *, dt_version_t); 542 extern void dt_cg(dt_pcb_t *, dt_node_t *); 543 extern dtrace_difo_t *dt_as(dt_pcb_t *); 544 545 extern int dt_aggregate_go(dtrace_hdl_t *); 546 extern int dt_aggregate_init(dtrace_hdl_t *); 547 extern void dt_aggregate_destroy(dtrace_hdl_t *); 548 549 extern int dt_epid_lookup(dtrace_hdl_t *, dtrace_epid_t, 550 dtrace_eprobedesc_t **, dtrace_probedesc_t **); 551 extern void dt_epid_destroy(dtrace_hdl_t *); 552 extern int dt_aggid_lookup(dtrace_hdl_t *, dtrace_aggid_t, dtrace_aggdesc_t **); 553 extern void dt_aggid_destroy(dtrace_hdl_t *); 554 555 extern void *dt_format_lookup(dtrace_hdl_t *, int); 556 extern void dt_format_destroy(dtrace_hdl_t *); 557 558 extern int dt_print_quantize(dtrace_hdl_t *, FILE *, 559 const void *, size_t, uint64_t); 560 extern int dt_print_lquantize(dtrace_hdl_t *, FILE *, 561 const void *, size_t, uint64_t); 562 extern int dt_print_agg(dtrace_aggdata_t *, void *); 563 564 extern int dt_handle(dtrace_hdl_t *, dtrace_probedata_t *); 565 extern int dt_handle_liberr(dtrace_hdl_t *, 566 const dtrace_probedata_t *, const char *); 567 extern int dt_handle_cpudrop(dtrace_hdl_t *, processorid_t, 568 dtrace_dropkind_t, uint64_t); 569 extern int dt_handle_status(dtrace_hdl_t *, 570 dtrace_status_t *, dtrace_status_t *); 571 572 extern dt_pcb_t *yypcb; /* pointer to current parser control block */ 573 extern char yyintprefix; /* int token prefix for macros (+/-) */ 574 extern char yyintsuffix[4]; /* int token suffix ([uUlL]*) */ 575 extern int yyintdecimal; /* int token is decimal (1) or octal/hex (0) */ 576 extern char yytext[]; /* lex input buffer */ 577 extern int yylineno; /* lex line number */ 578 extern int yydebug; /* lex debugging */ 579 extern dt_node_t *yypragma; /* lex token list for control lines */ 580 581 extern const dtrace_attribute_t _dtrace_maxattr; /* maximum attributes */ 582 extern const dtrace_attribute_t _dtrace_defattr; /* default attributes */ 583 extern const dtrace_attribute_t _dtrace_symattr; /* symbol ref attributes */ 584 extern const dtrace_attribute_t _dtrace_typattr; /* type ref attributes */ 585 extern const dtrace_attribute_t _dtrace_prvattr; /* provider attributes */ 586 extern const dtrace_pattr_t _dtrace_prvdesc; /* provider attribute bundle */ 587 588 extern const dt_version_t _dtrace_versions[]; /* array of valid versions */ 589 extern const char *const _dtrace_version; /* current version string */ 590 591 extern int _dtrace_strbuckets; /* number of hash buckets for strings */ 592 extern int _dtrace_intbuckets; /* number of hash buckets for ints */ 593 extern uint_t _dtrace_stkindent; /* default indent for stack/ustack */ 594 extern uint_t _dtrace_pidbuckets; /* number of hash buckets for pids */ 595 extern uint_t _dtrace_pidlrulim; /* number of proc handles to cache */ 596 extern int _dtrace_debug; /* debugging messages enabled */ 597 extern size_t _dtrace_bufsize; /* default dt_buf_create() size */ 598 extern int _dtrace_argmax; /* default maximum probe arguments */ 599 600 extern const char *_dtrace_libdir; /* default library directory */ 601 extern const char *_dtrace_moddir; /* default kernel module directory */ 602 603 #ifdef __cplusplus 604 } 605 #endif 606 607 #endif /* _DT_IMPL_H */ 608