Path: blob/main/cddl/contrib/opensolaris/lib/libdtrace/common/dt_impl.h
39562 views
/*1* CDDL HEADER START2*3* The contents of this file are subject to the terms of the4* Common Development and Distribution License (the "License").5* You may not use this file except in compliance with the License.6*7* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE8* or http://www.opensolaris.org/os/licensing.9* See the License for the specific language governing permissions10* and limitations under the License.11*12* When distributing Covered Code, include this CDDL HEADER in each13* file and include the License file at usr/src/OPENSOLARIS.LICENSE.14* If applicable, add the following below this CDDL HEADER, with the15* fields enclosed by brackets "[]" replaced with your own identifying16* information: Portions Copyright [yyyy] [name of copyright owner]17*18* CDDL HEADER END19*/2021/*22* Copyright 2010 Sun Microsystems, Inc. All rights reserved.23* Use is subject to license terms.24*/2526/*27* Copyright (c) 2013, Joyent, Inc. All rights reserved.28* Copyright (c) 2011, 2016 by Delphix. All rights reserved.29*/3031#ifndef _DT_IMPL_H32#define _DT_IMPL_H3334#include <sys/param.h>35#include <sys/objfs.h>36#ifndef illumos37#include <sys/bitmap.h>38#include <sys/utsname.h>39#include <sys/ioccom.h>40#include <sys/time.h>41#include <string.h>42#endif43#include <setjmp.h>44#include <libctf.h>45#include <dtrace.h>46#include <gelf.h>47#ifdef illumos48#include <synch.h>49#endif5051#ifdef __cplusplus52extern "C" {53#endif5455#include <dt_parser.h>56#include <dt_regset.h>57#include <dt_inttab.h>58#include <dt_strtab.h>59#include <dt_ident.h>60#include <dt_list.h>61#include <dt_decl.h>62#include <dt_as.h>63#include <dt_proc.h>64#include <dt_dof.h>65#include <dt_pcb.h>66#include <dt_pq.h>6768struct dt_module; /* see below */69struct dt_pfdict; /* see <dt_printf.h> */70struct dt_arg; /* see below */71struct dt_provider; /* see <dt_provider.h> */72struct dt_xlator; /* see <dt_xlator.h> */7374typedef struct dt_intrinsic {75const char *din_name; /* string name of the intrinsic type */76ctf_encoding_t din_data; /* integer or floating-point CTF encoding */77uint_t din_kind; /* CTF type kind to instantiate */78} dt_intrinsic_t;7980typedef struct dt_typedef {81const char *dty_src; /* string name of typedef source type */82const char *dty_dst; /* string name of typedef destination type */83} dt_typedef_t;8485typedef struct dt_intdesc {86const char *did_name; /* string name of the integer type */87ctf_file_t *did_ctfp; /* CTF container for this type reference */88ctf_id_t did_type; /* CTF type reference for this type */89uintmax_t did_limit; /* maximum positive value held by type */90} dt_intdesc_t;9192typedef struct dt_modops {93uint_t (*do_syminit)(struct dt_module *);94void (*do_symsort)(struct dt_module *);95GElf_Sym *(*do_symname)(struct dt_module *,96const char *, GElf_Sym *, uint_t *);97GElf_Sym *(*do_symaddr)(struct dt_module *,98GElf_Addr, GElf_Sym *, uint_t *);99} dt_modops_t;100101typedef struct dt_arg {102int da_ndx; /* index of this argument */103int da_mapping; /* mapping of argument indices to arguments */104ctf_id_t da_type; /* type of argument */105ctf_file_t *da_ctfp; /* CTF container for type */106dt_ident_t *da_xlator; /* translator, if any */107struct dt_arg *da_next; /* next argument */108} dt_arg_t;109110typedef struct dt_sym {111uint_t ds_symid; /* id of corresponding symbol */112uint_t ds_next; /* index of next element in hash chain */113} dt_sym_t;114115typedef struct dt_module {116dt_list_t dm_list; /* list forward/back pointers */117char dm_name[DTRACE_MODNAMELEN]; /* string name of module */118char dm_file[MAXPATHLEN]; /* file path of module (if any) */119struct dt_module *dm_next; /* pointer to next module in hash chain */120const dt_modops_t *dm_ops; /* pointer to data model's ops vector */121Elf *dm_elf; /* libelf handle for module object */122objfs_info_t dm_info; /* object filesystem private info */123ctf_sect_t dm_symtab; /* symbol table for module */124ctf_sect_t dm_strtab; /* string table for module */125ctf_sect_t dm_ctdata; /* CTF data for module */126ctf_file_t *dm_ctfp; /* CTF container handle */127uint_t *dm_symbuckets; /* symbol table hash buckets (chain indices) */128dt_sym_t *dm_symchains; /* symbol table hash chains buffer */129void *dm_asmap; /* symbol pointers sorted by value */130uint_t dm_symfree; /* index of next free hash element */131uint_t dm_nsymbuckets; /* number of elements in bucket array */132uint_t dm_nsymelems; /* number of elements in hash table */133uint_t dm_asrsv; /* actual reserved size of dm_asmap */134uint_t dm_aslen; /* number of entries in dm_asmap */135uint_t dm_flags; /* module flags (see below) */136int dm_modid; /* modinfo(1M) module identifier */137GElf_Addr dm_text_va; /* virtual address of text section */138GElf_Xword dm_text_size; /* size in bytes of text section */139GElf_Addr dm_data_va; /* virtual address of data section */140GElf_Xword dm_data_size; /* size in bytes of data section */141GElf_Addr dm_bss_va; /* virtual address of BSS */142GElf_Xword dm_bss_size; /* size in bytes of BSS */143dt_idhash_t *dm_extern; /* external symbol definitions */144#ifndef illumos145caddr_t dm_reloc_offset; /* Symbol relocation offset. */146uintptr_t *dm_sec_offsets;147#endif148pid_t dm_pid; /* pid for this module */149uint_t dm_nctflibs; /* number of ctf children libraries */150ctf_file_t **dm_libctfp; /* process library ctf pointers */151char **dm_libctfn; /* names of process ctf containers */152} dt_module_t;153154#define DT_DM_LOADED 0x1 /* module symbol and type data is loaded */155#define DT_DM_KERNEL 0x2 /* module is associated with a kernel object */156#define DT_DM_PRIMARY 0x4 /* module is a krtld primary kernel object */157158#ifdef __FreeBSD__159/*160* A representation of a FreeBSD kernel module, used when checking module161* dependencies. This differs from dt_module_t, which refers to a KLD in the162* case of kernel probes. Since modules can be identified regardless of whether163* they've been compiled into the kernel, we use them to identify DTrace164* modules.165*/166typedef struct dt_kmodule {167struct dt_kmodule *dkm_next; /* hash table entry */168char *dkm_name; /* string name of module */169dt_module_t *dkm_module; /* corresponding KLD module */170} dt_kmodule_t;171#endif172173typedef struct dt_provmod {174char *dp_name; /* name of provider module */175struct dt_provmod *dp_next; /* next module */176} dt_provmod_t;177178typedef struct dt_ahashent {179struct dt_ahashent *dtahe_prev; /* prev on hash chain */180struct dt_ahashent *dtahe_next; /* next on hash chain */181struct dt_ahashent *dtahe_prevall; /* prev on list of all */182struct dt_ahashent *dtahe_nextall; /* next on list of all */183uint64_t dtahe_hashval; /* hash value */184size_t dtahe_size; /* size of data */185dtrace_aggdata_t dtahe_data; /* data */186void (*dtahe_aggregate)(int64_t *, int64_t *, size_t); /* function */187} dt_ahashent_t;188189typedef struct dt_ahash {190dt_ahashent_t **dtah_hash; /* hash table */191dt_ahashent_t *dtah_all; /* list of all elements */192size_t dtah_size; /* size of hash table */193} dt_ahash_t;194195typedef struct dt_aggregate {196dtrace_bufdesc_t dtat_buf; /* buf aggregation snapshot */197int dtat_flags; /* aggregate flags */198processorid_t dtat_ncpus; /* number of CPUs in aggregate */199processorid_t *dtat_cpus; /* CPUs in aggregate */200processorid_t dtat_ncpu; /* size of dtat_cpus array */201processorid_t dtat_maxcpu; /* maximum number of CPUs */202dt_ahash_t dtat_hash; /* aggregate hash table */203} dt_aggregate_t;204205typedef struct dt_print_aggdata {206dtrace_hdl_t *dtpa_dtp; /* pointer to libdtrace handle */207dtrace_aggvarid_t dtpa_id; /* aggregation variable of interest */208FILE *dtpa_fp; /* file pointer */209int dtpa_allunprint; /* print only unprinted aggregations */210int dtpa_agghist; /* print aggregation as histogram */211int dtpa_agghisthdr; /* aggregation histogram hdr printed */212int dtpa_aggpack; /* pack quantized aggregations */213char dtpa_keyname[256]; /* key name for oformat */214char *dtpa_aggname; /* aggregate name for oformat */215} dt_print_aggdata_t;216217typedef struct dt_dirpath {218dt_list_t dir_list; /* linked-list forward/back pointers */219char *dir_path; /* directory pathname */220} dt_dirpath_t;221222typedef struct dt_lib_depend {223dt_list_t dtld_deplist; /* linked-list forward/back pointers */224char *dtld_library; /* library name */225char *dtld_libpath; /* library pathname */226uint_t dtld_finish; /* completion time in tsort for lib */227uint_t dtld_start; /* starting time in tsort for lib */228uint_t dtld_loaded; /* boolean: is this library loaded */229dt_list_t dtld_dependencies; /* linked-list of lib dependencies */230dt_list_t dtld_dependents; /* linked-list of lib dependents */231} dt_lib_depend_t;232233typedef uint32_t dt_version_t; /* encoded version (see below) */234235struct dtrace_hdl {236const dtrace_vector_t *dt_vector; /* library vector, if vectored open */237void *dt_varg; /* vector argument, if vectored open */238dtrace_conf_t dt_conf; /* DTrace driver configuration profile */239char dt_errmsg[BUFSIZ]; /* buffer for formatted syntax error msgs */240const char *dt_errtag; /* tag used with last call to dt_set_errmsg() */241dt_pcb_t *dt_pcb; /* pointer to current parsing control block */242ulong_t dt_gen; /* compiler generation number */243dt_list_t dt_programs; /* linked list of dtrace_prog_t's */244dt_list_t dt_xlators; /* linked list of dt_xlator_t's */245struct dt_xlator **dt_xlatormap; /* dt_xlator_t's indexed by dx_id */246id_t dt_xlatorid; /* next dt_xlator_t id to assign */247dt_ident_t *dt_externs; /* linked list of external symbol identifiers */248dt_idhash_t *dt_macros; /* hash table of macro variable identifiers */249dt_idhash_t *dt_aggs; /* hash table of aggregation identifiers */250dt_idhash_t *dt_globals; /* hash table of global identifiers */251dt_idhash_t *dt_tls; /* hash table of thread-local identifiers */252dt_list_t dt_modlist; /* linked list of dt_module_t's */253dt_module_t **dt_mods; /* hash table of dt_module_t's */254#ifdef __FreeBSD__255dt_kmodule_t **dt_kmods; /* hash table of dt_kmodule_t's */256#endif257uint_t dt_modbuckets; /* number of module hash buckets */258uint_t dt_nmods; /* number of modules in hash and list */259dt_provmod_t *dt_provmod; /* linked list of provider modules */260dt_module_t *dt_exec; /* pointer to executable module */261dt_module_t *dt_rtld; /* pointer to run-time linker module */262dt_module_t *dt_cdefs; /* pointer to C dynamic type module */263dt_module_t *dt_ddefs; /* pointer to D dynamic type module */264dt_list_t dt_provlist; /* linked list of dt_provider_t's */265struct dt_provider **dt_provs; /* hash table of dt_provider_t's */266uint_t dt_provbuckets; /* number of provider hash buckets */267uint_t dt_nprovs; /* number of providers in hash and list */268dt_proc_hash_t *dt_procs; /* hash table of grabbed process handles */269char **dt_proc_env; /* additional environment variables */270dt_intdesc_t dt_ints[6]; /* cached integer type descriptions */271ctf_id_t dt_type_func; /* cached CTF identifier for function type */272ctf_id_t dt_type_fptr; /* cached CTF identifier for function pointer */273ctf_id_t dt_type_str; /* cached CTF identifier for string type */274ctf_id_t dt_type_dyn; /* cached CTF identifier for <DYN> type */275ctf_id_t dt_type_stack; /* cached CTF identifier for stack type */276ctf_id_t dt_type_symaddr; /* cached CTF identifier for _symaddr type */277ctf_id_t dt_type_usymaddr; /* cached CTF ident. for _usymaddr type */278size_t dt_maxprobe; /* max enabled probe ID */279dtrace_eprobedesc_t **dt_edesc; /* enabled probe descriptions */280dtrace_probedesc_t **dt_pdesc; /* probe descriptions for enabled prbs */281size_t dt_maxagg; /* max aggregation ID */282dtrace_aggdesc_t **dt_aggdesc; /* aggregation descriptions */283int dt_maxformat; /* max format ID */284void **dt_formats; /* pointer to format array */285int dt_maxstrdata; /* max strdata ID */286char **dt_strdata; /* pointer to strdata array */287dt_aggregate_t dt_aggregate; /* aggregate */288dt_pq_t *dt_bufq; /* CPU-specific data queue */289struct dt_pfdict *dt_pfdict; /* dictionary of printf conversions */290dt_version_t dt_vmax; /* optional ceiling on program API binding */291dtrace_attribute_t dt_amin; /* optional floor on program attributes */292char *dt_cpp_path; /* pathname of cpp(1) to invoke if needed */293char **dt_cpp_argv; /* argument vector for exec'ing cpp(1) */294int dt_cpp_argc; /* count of initialized cpp(1) arguments */295int dt_cpp_args; /* size of dt_cpp_argv[] array */296char *dt_ld_path; /* pathname of ld(1) to invoke if needed */297#ifdef __FreeBSD__298char *dt_objcopy_path; /* pathname of objcopy(1) to invoke if needed */299#endif300dt_list_t dt_lib_path; /* linked-list forming library search path */301uint_t dt_lazyload; /* boolean: set via -xlazyload */302uint_t dt_droptags; /* boolean: set via -xdroptags */303uint_t dt_active; /* boolean: set once tracing is active */304uint_t dt_stopped; /* boolean: set once tracing is stopped */305processorid_t dt_beganon; /* CPU that executed BEGIN probe (if any) */306processorid_t dt_endedon; /* CPU that executed END probe (if any) */307uint_t dt_oflags; /* dtrace open-time options (see dtrace.h) */308uint_t dt_cflags; /* dtrace compile-time options (see dtrace.h) */309uint_t dt_dflags; /* dtrace link-time options (see dtrace.h) */310uint_t dt_prcmode; /* dtrace process create mode (see dt_proc.h) */311uint_t dt_linkmode; /* dtrace symbol linking mode (see below) */312uint_t dt_linktype; /* dtrace link output file type (see below) */313uint_t dt_xlatemode; /* dtrace translator linking mode (see below) */314uint_t dt_stdcmode; /* dtrace stdc compatibility mode (see below) */315uint_t dt_encoding; /* dtrace output encoding (see below) */316uint_t dt_treedump; /* dtrace tree debug bitmap (see below) */317uint64_t dt_options[DTRACEOPT_MAX]; /* dtrace run-time options */318int dt_version; /* library version requested by client */319int dt_ctferr; /* error resulting from last CTF failure */320int dt_errno; /* error resulting from last failed operation */321#ifndef illumos322const char *dt_errfile;323int dt_errline;324#endif325int dt_fd; /* file descriptor for dtrace pseudo-device */326int dt_ftfd; /* file descriptor for fasttrap pseudo-device */327int dt_kinstfd; /* file descriptor for kinst pseudo-device */328int dt_fterr; /* saved errno from failed open of dt_ftfd */329int dt_cdefs_fd; /* file descriptor for C CTF debugging cache */330int dt_ddefs_fd; /* file descriptor for D CTF debugging cache */331#ifdef illumos332int dt_stdout_fd; /* file descriptor for saved stdout */333#else334FILE *dt_freopen_fp; /* file pointer for freopened stdout */335#endif336dtrace_handle_err_f *dt_errhdlr; /* error handler, if any */337void *dt_errarg; /* error handler argument */338dtrace_prog_t *dt_errprog; /* error handler program, if any */339dtrace_handle_drop_f *dt_drophdlr; /* drop handler, if any */340void *dt_droparg; /* drop handler argument */341dtrace_handle_proc_f *dt_prochdlr; /* proc handler, if any */342void *dt_procarg; /* proc handler argument */343dtrace_handle_setopt_f *dt_setopthdlr; /* setopt handler, if any */344void *dt_setoptarg; /* setopt handler argument */345dtrace_status_t dt_status[2]; /* status cache */346int dt_statusgen; /* current status generation */347hrtime_t dt_laststatus; /* last status */348hrtime_t dt_lastswitch; /* last switch of buffer data */349hrtime_t dt_lastagg; /* last snapshot of aggregation data */350char *dt_sprintf_buf; /* buffer for dtrace_sprintf() */351int dt_sprintf_buflen; /* length of dtrace_sprintf() buffer */352const char *dt_filetag; /* default filetag for dt_set_errmsg() */353char *dt_buffered_buf; /* buffer for buffered output */354size_t dt_buffered_offs; /* current offset into buffered buffer */355size_t dt_buffered_size; /* size of buffered buffer */356dtrace_handle_buffered_f *dt_bufhdlr; /* buffered handler, if any */357void *dt_bufarg; /* buffered handler argument */358dt_dof_t dt_dof; /* DOF generation buffers (see dt_dof.c) */359struct utsname dt_uts; /* uname(2) information for system */360dt_list_t dt_lib_dep; /* scratch linked-list of lib dependencies */361dt_list_t dt_lib_dep_sorted; /* dependency sorted library list */362dtrace_flowkind_t dt_flow; /* flow kind */363const char *dt_prefix; /* recommended flow prefix */364int dt_indent; /* recommended flow indent */365dtrace_epid_t dt_last_epid; /* most recently consumed EPID */366uint64_t dt_last_timestamp; /* most recently consumed timestamp */367boolean_t dt_has_sugar; /* syntactic sugar used? */368int dt_oformat; /* output format (none, json, xml, html) */369};370371/*372* Values for the user arg of the ECB.373*/374#define DT_ECB_DEFAULT 0375#define DT_ECB_ERROR 1376377/*378* Values for the dt_linkmode property, which is used by the assembler when379* processing external symbol references. User can set using -xlink=<mode>.380*/381#define DT_LINK_KERNEL 0 /* kernel syms static, user syms dynamic */382#define DT_LINK_PRIMARY 1 /* primary kernel syms static, others dynamic */383#define DT_LINK_DYNAMIC 2 /* all symbols dynamic */384#define DT_LINK_STATIC 3 /* all symbols static */385386/*387* Values for the dt_linktype property, which is used by dtrace_program_link()388* to determine the type of output file that is desired by the client.389*/390#define DT_LTYP_ELF 0 /* produce ELF containing DOF */391#define DT_LTYP_DOF 1 /* produce stand-alone DOF */392393/*394* Values for the dt_xlatemode property, which is used to determine whether395* references to dynamic translators are permitted. Set using -xlate=<mode>.396*/397#define DT_XL_STATIC 0 /* require xlators to be statically defined */398#define DT_XL_DYNAMIC 1 /* produce references to dynamic translators */399400/*401* Values for the dt_stdcmode property, which is used by the compiler when402* running cpp to determine the presence and setting of the __STDC__ macro.403*/404#define DT_STDC_XA 0 /* ISO C + K&R C compat w/o ISO: __STDC__=0 */405#define DT_STDC_XC 1 /* Strict ISO C: __STDC__=1 */406#define DT_STDC_XS 2 /* K&R C: __STDC__ not defined */407#define DT_STDC_XT 3 /* ISO C + K&R C compat with ISO: __STDC__=0 */408409/*410* Values for the dt_encoding property, which is used to force a particular411* character encoding (overriding default behavior and/or automatic detection).412*/413#define DT_ENCODING_UNSET 0414#define DT_ENCODING_ASCII 1415#define DT_ENCODING_UTF8 2416417/*418* Macro to test whether a given pass bit is set in the dt_treedump bit-vector.419* If the bit for pass 'p' is set, the D compiler displays the parse tree for420* the program by printing it to stderr at the end of compiler pass 'p'.421*/422#define DT_TREEDUMP_PASS(dtp, p) ((dtp)->dt_treedump & (1 << ((p) - 1)))423424/*425* Macros for accessing the cached CTF container and type ID for the common426* types "int", "string", and <DYN>, which we need to use frequently in the D427* compiler. The DT_INT_* macro relies upon "int" being at index 0 in the428* _dtrace_ints_* tables in dt_open.c; the others are also set up there.429*/430#define DT_INT_CTFP(dtp) ((dtp)->dt_ints[0].did_ctfp)431#define DT_INT_TYPE(dtp) ((dtp)->dt_ints[0].did_type)432433#define DT_FUNC_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp)434#define DT_FUNC_TYPE(dtp) ((dtp)->dt_type_func)435436#define DT_FPTR_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp)437#define DT_FPTR_TYPE(dtp) ((dtp)->dt_type_fptr)438439#define DT_STR_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp)440#define DT_STR_TYPE(dtp) ((dtp)->dt_type_str)441442#define DT_DYN_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp)443#define DT_DYN_TYPE(dtp) ((dtp)->dt_type_dyn)444445#define DT_STACK_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp)446#define DT_STACK_TYPE(dtp) ((dtp)->dt_type_stack)447448#define DT_SYMADDR_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp)449#define DT_SYMADDR_TYPE(dtp) ((dtp)->dt_type_symaddr)450451#define DT_USYMADDR_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp)452#define DT_USYMADDR_TYPE(dtp) ((dtp)->dt_type_usymaddr)453454/*455* Actions and subroutines are both DT_NODE_FUNC nodes; to avoid confusing456* an action for a subroutine (or vice versa), we assure that the DT_ACT_*457* constants and the DIF_SUBR_* constants occupy non-overlapping ranges by458* starting the DT_ACT_* constants at DIF_SUBR_MAX + 1.459*/460#define DT_ACT_BASE DIF_SUBR_MAX + 1461#define DT_ACT(n) (DT_ACT_BASE + (n))462463#define DT_ACT_PRINTF DT_ACT(0) /* printf() action */464#define DT_ACT_TRACE DT_ACT(1) /* trace() action */465#define DT_ACT_TRACEMEM DT_ACT(2) /* tracemem() action */466#define DT_ACT_STACK DT_ACT(3) /* stack() action */467#define DT_ACT_STOP DT_ACT(4) /* stop() action */468#define DT_ACT_BREAKPOINT DT_ACT(5) /* breakpoint() action */469#define DT_ACT_PANIC DT_ACT(6) /* panic() action */470#define DT_ACT_SPECULATE DT_ACT(7) /* speculate() action */471#define DT_ACT_COMMIT DT_ACT(8) /* commit() action */472#define DT_ACT_DISCARD DT_ACT(9) /* discard() action */473#define DT_ACT_CHILL DT_ACT(10) /* chill() action */474#define DT_ACT_EXIT DT_ACT(11) /* exit() action */475#define DT_ACT_USTACK DT_ACT(12) /* ustack() action */476#define DT_ACT_PRINTA DT_ACT(13) /* printa() action */477#define DT_ACT_RAISE DT_ACT(14) /* raise() action */478#define DT_ACT_CLEAR DT_ACT(15) /* clear() action */479#define DT_ACT_NORMALIZE DT_ACT(16) /* normalize() action */480#define DT_ACT_DENORMALIZE DT_ACT(17) /* denormalize() action */481#define DT_ACT_TRUNC DT_ACT(18) /* trunc() action */482#define DT_ACT_SYSTEM DT_ACT(19) /* system() action */483#define DT_ACT_JSTACK DT_ACT(20) /* jstack() action */484#define DT_ACT_FTRUNCATE DT_ACT(21) /* ftruncate() action */485#define DT_ACT_FREOPEN DT_ACT(22) /* freopen() action */486#define DT_ACT_SYM DT_ACT(23) /* sym()/func() actions */487#define DT_ACT_MOD DT_ACT(24) /* mod() action */488#define DT_ACT_USYM DT_ACT(25) /* usym()/ufunc() actions */489#define DT_ACT_UMOD DT_ACT(26) /* umod() action */490#define DT_ACT_UADDR DT_ACT(27) /* uaddr() action */491#define DT_ACT_SETOPT DT_ACT(28) /* setopt() action */492#define DT_ACT_PRINT DT_ACT(29) /* print() action */493#define DT_ACT_PRINTM DT_ACT(30) /* printm() action */494495/*496* Sentinel to tell freopen() to restore the saved stdout. This must not497* be ever valid for opening for write access via freopen(3C), which of498* course, "." never is.499*/500#define DT_FREOPEN_RESTORE "."501502#define EDT_BASE 1000 /* base value for libdtrace errnos */503504enum {505EDT_VERSION = EDT_BASE, /* client is requesting unsupported version */506EDT_VERSINVAL, /* version string is invalid or overflows */507EDT_VERSUNDEF, /* requested API version is not defined */508EDT_VERSREDUCED, /* requested API version has been reduced */509EDT_CTF, /* libctf called failed (dt_ctferr has more) */510EDT_COMPILER, /* error in D program compilation */511EDT_NOTUPREG, /* tuple register allocation failure */512EDT_NOMEM, /* memory allocation failure */513EDT_INT2BIG, /* integer limit exceeded */514EDT_STR2BIG, /* string limit exceeded */515EDT_NOMOD, /* unknown module name */516EDT_NOPROV, /* unknown provider name */517EDT_NOPROBE, /* unknown probe name */518EDT_NOSYM, /* unknown symbol name */519EDT_NOSYMADDR, /* no symbol corresponds to address */520EDT_NOTYPE, /* unknown type name */521EDT_NOVAR, /* unknown variable name */522EDT_NOAGG, /* unknown aggregation name */523EDT_BADSCOPE, /* improper use of type name scoping operator */524EDT_BADSPEC, /* overspecified probe description */525EDT_BADSPCV, /* bad macro variable in probe description */526EDT_BADID, /* invalid probe identifier */527EDT_NOTLOADED, /* module is not currently loaded */528EDT_NOCTF, /* module does not contain any CTF data */529EDT_DATAMODEL, /* module and program data models don't match */530EDT_DIFVERS, /* library has newer DIF version than driver */531EDT_BADAGG, /* unrecognized aggregating action */532EDT_FIO, /* file i/o error */533EDT_DIFINVAL, /* invalid DIF program */534EDT_DIFSIZE, /* invalid DIF size */535EDT_DIFFAULT, /* failed to copyin DIF program */536EDT_BADPROBE, /* bad probe description */537EDT_BADPGLOB, /* bad probe description globbing pattern */538EDT_NOSCOPE, /* declaration scope stack underflow */539EDT_NODECL, /* declaration stack underflow */540EDT_DMISMATCH, /* record list does not match statement */541EDT_DOFFSET, /* record data offset error */542EDT_DALIGN, /* record data alignment error */543EDT_BADOPTNAME, /* invalid dtrace_setopt option name */544EDT_BADOPTVAL, /* invalid dtrace_setopt option value */545EDT_BADOPTCTX, /* invalid dtrace_setopt option context */546EDT_CPPFORK, /* failed to fork preprocessor */547EDT_CPPEXEC, /* failed to exec preprocessor */548EDT_CPPENT, /* preprocessor not found */549EDT_CPPERR, /* unknown preprocessor error */550EDT_SYMOFLOW, /* external symbol table overflow */551EDT_ACTIVE, /* operation illegal when tracing is active */552EDT_DESTRUCTIVE, /* destructive actions not allowed */553EDT_NOANON, /* no anonymous tracing state */554EDT_ISANON, /* can't claim anon state and enable probes */555EDT_ENDTOOBIG, /* END enablings exceed size of prncpl buffer */556EDT_NOCONV, /* failed to load type for printf conversion */557EDT_BADCONV, /* incomplete printf conversion */558EDT_BADERROR, /* invalid library ERROR action */559EDT_ERRABORT, /* abort due to error */560EDT_DROPABORT, /* abort due to drop */561EDT_DIRABORT, /* abort explicitly directed */562EDT_BADRVAL, /* invalid return value from callback */563EDT_BADNORMAL, /* invalid normalization */564EDT_BUFTOOSMALL, /* enabling exceeds size of buffer */565EDT_BADTRUNC, /* invalid truncation */566EDT_BUSY, /* device busy (active kernel debugger) */567EDT_ACCESS, /* insufficient privileges to use DTrace */568EDT_NOENT, /* dtrace device not available */569EDT_BRICKED, /* abort due to systemic unresponsiveness */570EDT_HARDWIRE, /* failed to load hard-wired definitions */571EDT_ELFVERSION, /* libelf is out-of-date w.r.t libdtrace */572EDT_NOBUFFERED, /* attempt to buffer output without handler */573EDT_UNSTABLE, /* description matched unstable set of probes */574EDT_BADSETOPT, /* invalid setopt library action */575EDT_BADSTACKPC, /* invalid stack program counter size */576EDT_BADAGGVAR, /* invalid aggregation variable identifier */577EDT_OVERSION, /* client is requesting deprecated version */578EDT_ENABLING_ERR, /* failed to enable probe */579EDT_NOPROBES, /* no probes sites for declared provider */580EDT_CANTLOAD /* failed to load a module */581};582583/*584* Interfaces for parsing and comparing DTrace attribute tuples, which describe585* stability and architectural binding information. The dtrace_attribute_t586* structure and associated constant definitions are found in <sys/dtrace.h>.587*/588extern dtrace_attribute_t dt_attr_min(dtrace_attribute_t, dtrace_attribute_t);589extern dtrace_attribute_t dt_attr_max(dtrace_attribute_t, dtrace_attribute_t);590extern char *dt_attr_str(dtrace_attribute_t, char *, size_t);591extern int dt_attr_cmp(dtrace_attribute_t, dtrace_attribute_t);592593/*594* Interfaces for parsing and handling DTrace version strings. Version binding595* is a feature of the D compiler that is handled completely independently of596* the DTrace kernel infrastructure, so the definitions are here in libdtrace.597* Version strings are compiled into an encoded uint32_t which can be compared598* using C comparison operators. Version definitions are found in dt_open.c.599*/600#define DT_VERSION_STRMAX 16 /* enough for "255.4095.4095\0" */601#define DT_VERSION_MAJMAX 0xFF /* maximum major version number */602#define DT_VERSION_MINMAX 0xFFF /* maximum minor version number */603#define DT_VERSION_MICMAX 0xFFF /* maximum micro version number */604605#define DT_VERSION_NUMBER(M, m, u) \606((((M) & 0xFF) << 24) | (((m) & 0xFFF) << 12) | ((u) & 0xFFF))607608#define DT_VERSION_MAJOR(v) (((v) & 0xFF000000) >> 24)609#define DT_VERSION_MINOR(v) (((v) & 0x00FFF000) >> 12)610#define DT_VERSION_MICRO(v) ((v) & 0x00000FFF)611612extern char *dt_version_num2str(dt_version_t, char *, size_t);613extern int dt_version_str2num(const char *, dt_version_t *);614extern int dt_version_defined(dt_version_t);615616/*617* Miscellaneous internal libdtrace interfaces. The definitions below are for618* libdtrace routines that do not yet merit their own separate header file.619*/620extern char *dt_cpp_add_arg(dtrace_hdl_t *, const char *);621extern char *dt_cpp_pop_arg(dtrace_hdl_t *);622extern int dt_cpu_maxid(dtrace_hdl_t *);623624#ifdef illumos625extern int dt_set_errno(dtrace_hdl_t *, int);626#else627int _dt_set_errno(dtrace_hdl_t *, int, const char *, int);628void dt_get_errloc(dtrace_hdl_t *, const char **, int *);629#define dt_set_errno(_a,_b) _dt_set_errno(_a,_b,__FILE__,__LINE__)630#endif631extern void dt_set_errmsg(dtrace_hdl_t *, const char *, const char *,632const char *, int, const char *, va_list);633634#ifdef illumos635extern int dt_ioctl(dtrace_hdl_t *, int, void *);636#else637extern int dt_ioctl(dtrace_hdl_t *, u_long, void *);638#endif639extern int dt_status(dtrace_hdl_t *, processorid_t);640extern long dt_sysconf(dtrace_hdl_t *, int);641extern ssize_t dt_write(dtrace_hdl_t *, int, const void *, size_t);642extern int dt_printf(dtrace_hdl_t *, FILE *, const char *, ...);643644extern void *dt_zalloc(dtrace_hdl_t *, size_t);645extern void *dt_alloc(dtrace_hdl_t *, size_t);646extern void dt_free(dtrace_hdl_t *, void *);647extern void dt_difo_free(dtrace_hdl_t *, dtrace_difo_t *);648649extern int dt_gmatch(const char *, const char *);650extern char *dt_basename(char *);651652extern ulong_t dt_popc(ulong_t);653extern ulong_t dt_popcb(const ulong_t *, ulong_t);654655extern int dt_buffered_enable(dtrace_hdl_t *);656extern int dt_buffered_flush(dtrace_hdl_t *, dtrace_probedata_t *,657const dtrace_recdesc_t *, const dtrace_aggdata_t *, uint32_t flags);658extern void dt_buffered_disable(dtrace_hdl_t *);659extern void dt_buffered_destroy(dtrace_hdl_t *);660661extern uint64_t dt_stddev(uint64_t *, uint64_t);662663extern int dt_rw_read_held(pthread_rwlock_t *);664extern int dt_rw_write_held(pthread_rwlock_t *);665extern int dt_mutex_held(pthread_mutex_t *);666extern int dt_options_load(dtrace_hdl_t *);667668#define DT_RW_READ_HELD(x) dt_rw_read_held(x)669#define DT_RW_WRITE_HELD(x) dt_rw_write_held(x)670#define DT_RW_LOCK_HELD(x) (DT_RW_READ_HELD(x) || DT_RW_WRITE_HELD(x))671#define DT_MUTEX_HELD(x) dt_mutex_held(x)672673extern void dt_dprintf(const char *, ...);674675extern void dt_setcontext(dtrace_hdl_t *, dtrace_probedesc_t *);676extern void dt_endcontext(dtrace_hdl_t *);677678extern void dt_pragma(dt_node_t *);679extern int dt_reduce(dtrace_hdl_t *, dt_version_t);680extern void dt_cg(dt_pcb_t *, dt_node_t *);681extern dtrace_difo_t *dt_as(dt_pcb_t *);682extern void dt_dis(const dtrace_difo_t *, FILE *);683684extern int dt_aggregate_go(dtrace_hdl_t *);685extern int dt_aggregate_init(dtrace_hdl_t *);686extern void dt_aggregate_destroy(dtrace_hdl_t *);687688extern int dt_epid_lookup(dtrace_hdl_t *, dtrace_epid_t,689dtrace_eprobedesc_t **, dtrace_probedesc_t **);690extern void dt_epid_destroy(dtrace_hdl_t *);691extern int dt_aggid_lookup(dtrace_hdl_t *, dtrace_aggid_t, dtrace_aggdesc_t **);692extern void dt_aggid_destroy(dtrace_hdl_t *);693694extern void *dt_format_lookup(dtrace_hdl_t *, int);695extern void dt_format_destroy(dtrace_hdl_t *);696697extern const char *dt_strdata_lookup(dtrace_hdl_t *, int);698extern void dt_strdata_destroy(dtrace_hdl_t *);699700extern int dt_print_quantize(dtrace_hdl_t *, FILE *,701const void *, size_t, uint64_t);702extern int dt_print_lquantize(dtrace_hdl_t *, FILE *,703const void *, size_t, uint64_t);704extern int dt_print_llquantize(dtrace_hdl_t *, FILE *,705const void *, size_t, uint64_t);706extern int dt_print_agg(const dtrace_aggdata_t *, void *);707708extern int dt_format_agg(const dtrace_aggdata_t *, void *);709710extern int dt_handle(dtrace_hdl_t *, dtrace_probedata_t *);711extern int dt_handle_liberr(dtrace_hdl_t *,712const dtrace_probedata_t *, const char *);713extern int dt_handle_cpudrop(dtrace_hdl_t *, processorid_t,714dtrace_dropkind_t, uint64_t);715extern int dt_handle_status(dtrace_hdl_t *,716dtrace_status_t *, dtrace_status_t *);717extern int dt_handle_setopt(dtrace_hdl_t *, dtrace_setoptdata_t *);718719extern void dt_oformat_drop(dtrace_hdl_t *, processorid_t);720721extern int dt_lib_depend_add(dtrace_hdl_t *, dt_list_t *, const char *);722extern dt_lib_depend_t *dt_lib_depend_lookup(dt_list_t *, const char *);723724extern dt_pcb_t *yypcb; /* pointer to current parser control block */725extern char yyintprefix; /* int token prefix for macros (+/-) */726extern char yyintsuffix[4]; /* int token suffix ([uUlL]*) */727extern int yyintdecimal; /* int token is decimal (1) or octal/hex (0) */728extern char *yytext; /* lex input buffer */729extern int yylineno; /* lex line number */730extern int yydebug; /* lex debugging */731extern dt_node_t *yypragma; /* lex token list for control lines */732733extern const dtrace_attribute_t _dtrace_maxattr; /* maximum attributes */734extern const dtrace_attribute_t _dtrace_defattr; /* default attributes */735extern const dtrace_attribute_t _dtrace_symattr; /* symbol ref attributes */736extern const dtrace_attribute_t _dtrace_typattr; /* type ref attributes */737extern const dtrace_attribute_t _dtrace_prvattr; /* provider attributes */738extern const dtrace_pattr_t _dtrace_prvdesc; /* provider attribute bundle */739740extern const dt_version_t _dtrace_versions[]; /* array of valid versions */741extern const char *const _dtrace_version; /* current version string */742743extern int _dtrace_strbuckets; /* number of hash buckets for strings */744extern int _dtrace_intbuckets; /* number of hash buckets for ints */745extern uint_t _dtrace_stkindent; /* default indent for stack/ustack */746extern uint_t _dtrace_pidbuckets; /* number of hash buckets for pids */747extern uint_t _dtrace_pidlrulim; /* number of proc handles to cache */748extern int _dtrace_debug; /* debugging messages enabled */749extern size_t _dtrace_bufsize; /* default dt_buf_create() size */750extern int _dtrace_argmax; /* default maximum probe arguments */751752extern const char *_dtrace_libdir; /* default library directory */753extern const char *_dtrace_moddir; /* default kernel module directory */754755#ifdef __FreeBSD__756extern int gmatch(const char *, const char *);757extern int yylex(void);758#endif759760#ifdef __cplusplus761}762#endif763764#endif /* _DT_IMPL_H */765766767