16ff6d951SJohn Birrell /* 26ff6d951SJohn Birrell * CDDL HEADER START 36ff6d951SJohn Birrell * 46ff6d951SJohn Birrell * The contents of this file are subject to the terms of the 56ff6d951SJohn Birrell * Common Development and Distribution License (the "License"). 66ff6d951SJohn Birrell * You may not use this file except in compliance with the License. 76ff6d951SJohn Birrell * 86ff6d951SJohn Birrell * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 96ff6d951SJohn Birrell * or http://www.opensolaris.org/os/licensing. 106ff6d951SJohn Birrell * See the License for the specific language governing permissions 116ff6d951SJohn Birrell * and limitations under the License. 126ff6d951SJohn Birrell * 136ff6d951SJohn Birrell * When distributing Covered Code, include this CDDL HEADER in each 146ff6d951SJohn Birrell * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 156ff6d951SJohn Birrell * If applicable, add the following below this CDDL HEADER, with the 166ff6d951SJohn Birrell * fields enclosed by brackets "[]" replaced with your own identifying 176ff6d951SJohn Birrell * information: Portions Copyright [yyyy] [name of copyright owner] 186ff6d951SJohn Birrell * 196ff6d951SJohn Birrell * CDDL HEADER END 206ff6d951SJohn Birrell */ 21f5a73645SJohn Birrell 226ff6d951SJohn Birrell /* 231670a1c2SRui Paulo * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 246ff6d951SJohn Birrell * Use is subject to license terms. 256ff6d951SJohn Birrell */ 266ff6d951SJohn Birrell 27675cf915SPedro F. Giffuni /* 2823e4da43SPedro F. Giffuni * Copyright (c) 2013, Joyent, Inc. All rights reserved. 29650f66acSMark Johnston * Copyright (c) 2011, 2016 by Delphix. All rights reserved. 30675cf915SPedro F. Giffuni */ 31675cf915SPedro F. Giffuni 326ff6d951SJohn Birrell #ifndef _DT_IMPL_H 336ff6d951SJohn Birrell #define _DT_IMPL_H 346ff6d951SJohn Birrell 356ff6d951SJohn Birrell #include <sys/param.h> 366ff6d951SJohn Birrell #include <sys/objfs.h> 37bc96366cSSteven Hartland #ifndef illumos 38f5a73645SJohn Birrell #include <sys/bitmap.h> 39f5a73645SJohn Birrell #include <sys/utsname.h> 40f5a73645SJohn Birrell #include <sys/ioccom.h> 41f5a73645SJohn Birrell #include <sys/time.h> 42f5a73645SJohn Birrell #include <string.h> 43f5a73645SJohn Birrell #endif 446ff6d951SJohn Birrell #include <setjmp.h> 456ff6d951SJohn Birrell #include <libctf.h> 466ff6d951SJohn Birrell #include <dtrace.h> 476ff6d951SJohn Birrell #include <gelf.h> 48bc96366cSSteven Hartland #ifdef illumos 491670a1c2SRui Paulo #include <synch.h> 501670a1c2SRui Paulo #endif 516ff6d951SJohn Birrell 526ff6d951SJohn Birrell #ifdef __cplusplus 536ff6d951SJohn Birrell extern "C" { 546ff6d951SJohn Birrell #endif 556ff6d951SJohn Birrell 566ff6d951SJohn Birrell #include <dt_parser.h> 576ff6d951SJohn Birrell #include <dt_regset.h> 586ff6d951SJohn Birrell #include <dt_inttab.h> 596ff6d951SJohn Birrell #include <dt_strtab.h> 606ff6d951SJohn Birrell #include <dt_ident.h> 616ff6d951SJohn Birrell #include <dt_list.h> 626ff6d951SJohn Birrell #include <dt_decl.h> 636ff6d951SJohn Birrell #include <dt_as.h> 646ff6d951SJohn Birrell #include <dt_proc.h> 656ff6d951SJohn Birrell #include <dt_dof.h> 666ff6d951SJohn Birrell #include <dt_pcb.h> 6709e6105fSMark Johnston #include <dt_pq.h> 686ff6d951SJohn Birrell 696ff6d951SJohn Birrell struct dt_module; /* see below */ 706ff6d951SJohn Birrell struct dt_pfdict; /* see <dt_printf.h> */ 716ff6d951SJohn Birrell struct dt_arg; /* see below */ 726ff6d951SJohn Birrell struct dt_provider; /* see <dt_provider.h> */ 736ff6d951SJohn Birrell struct dt_xlator; /* see <dt_xlator.h> */ 746ff6d951SJohn Birrell 756ff6d951SJohn Birrell typedef struct dt_intrinsic { 766ff6d951SJohn Birrell const char *din_name; /* string name of the intrinsic type */ 776ff6d951SJohn Birrell ctf_encoding_t din_data; /* integer or floating-point CTF encoding */ 786ff6d951SJohn Birrell uint_t din_kind; /* CTF type kind to instantiate */ 796ff6d951SJohn Birrell } dt_intrinsic_t; 806ff6d951SJohn Birrell 816ff6d951SJohn Birrell typedef struct dt_typedef { 826ff6d951SJohn Birrell const char *dty_src; /* string name of typedef source type */ 836ff6d951SJohn Birrell const char *dty_dst; /* string name of typedef destination type */ 846ff6d951SJohn Birrell } dt_typedef_t; 856ff6d951SJohn Birrell 866ff6d951SJohn Birrell typedef struct dt_intdesc { 876ff6d951SJohn Birrell const char *did_name; /* string name of the integer type */ 886ff6d951SJohn Birrell ctf_file_t *did_ctfp; /* CTF container for this type reference */ 896ff6d951SJohn Birrell ctf_id_t did_type; /* CTF type reference for this type */ 906ff6d951SJohn Birrell uintmax_t did_limit; /* maximum positive value held by type */ 916ff6d951SJohn Birrell } dt_intdesc_t; 926ff6d951SJohn Birrell 936ff6d951SJohn Birrell typedef struct dt_modops { 946ff6d951SJohn Birrell uint_t (*do_syminit)(struct dt_module *); 956ff6d951SJohn Birrell void (*do_symsort)(struct dt_module *); 966ff6d951SJohn Birrell GElf_Sym *(*do_symname)(struct dt_module *, 976ff6d951SJohn Birrell const char *, GElf_Sym *, uint_t *); 986ff6d951SJohn Birrell GElf_Sym *(*do_symaddr)(struct dt_module *, 996ff6d951SJohn Birrell GElf_Addr, GElf_Sym *, uint_t *); 1006ff6d951SJohn Birrell } dt_modops_t; 1016ff6d951SJohn Birrell 1026ff6d951SJohn Birrell typedef struct dt_arg { 1036ff6d951SJohn Birrell int da_ndx; /* index of this argument */ 1046ff6d951SJohn Birrell int da_mapping; /* mapping of argument indices to arguments */ 1056ff6d951SJohn Birrell ctf_id_t da_type; /* type of argument */ 1066ff6d951SJohn Birrell ctf_file_t *da_ctfp; /* CTF container for type */ 1076ff6d951SJohn Birrell dt_ident_t *da_xlator; /* translator, if any */ 1086ff6d951SJohn Birrell struct dt_arg *da_next; /* next argument */ 1096ff6d951SJohn Birrell } dt_arg_t; 1106ff6d951SJohn Birrell 1116ff6d951SJohn Birrell typedef struct dt_sym { 1126ff6d951SJohn Birrell uint_t ds_symid; /* id of corresponding symbol */ 1136ff6d951SJohn Birrell uint_t ds_next; /* index of next element in hash chain */ 1146ff6d951SJohn Birrell } dt_sym_t; 1156ff6d951SJohn Birrell 1166ff6d951SJohn Birrell typedef struct dt_module { 1176ff6d951SJohn Birrell dt_list_t dm_list; /* list forward/back pointers */ 1186ff6d951SJohn Birrell char dm_name[DTRACE_MODNAMELEN]; /* string name of module */ 1196ff6d951SJohn Birrell char dm_file[MAXPATHLEN]; /* file path of module (if any) */ 1206ff6d951SJohn Birrell struct dt_module *dm_next; /* pointer to next module in hash chain */ 1216ff6d951SJohn Birrell const dt_modops_t *dm_ops; /* pointer to data model's ops vector */ 1226ff6d951SJohn Birrell Elf *dm_elf; /* libelf handle for module object */ 1236ff6d951SJohn Birrell objfs_info_t dm_info; /* object filesystem private info */ 1246ff6d951SJohn Birrell ctf_sect_t dm_symtab; /* symbol table for module */ 1256ff6d951SJohn Birrell ctf_sect_t dm_strtab; /* string table for module */ 1266ff6d951SJohn Birrell ctf_sect_t dm_ctdata; /* CTF data for module */ 1276ff6d951SJohn Birrell ctf_file_t *dm_ctfp; /* CTF container handle */ 1286ff6d951SJohn Birrell uint_t *dm_symbuckets; /* symbol table hash buckets (chain indices) */ 1296ff6d951SJohn Birrell dt_sym_t *dm_symchains; /* symbol table hash chains buffer */ 1306ff6d951SJohn Birrell void *dm_asmap; /* symbol pointers sorted by value */ 1316ff6d951SJohn Birrell uint_t dm_symfree; /* index of next free hash element */ 1326ff6d951SJohn Birrell uint_t dm_nsymbuckets; /* number of elements in bucket array */ 1336ff6d951SJohn Birrell uint_t dm_nsymelems; /* number of elements in hash table */ 1346ff6d951SJohn Birrell uint_t dm_asrsv; /* actual reserved size of dm_asmap */ 1356ff6d951SJohn Birrell uint_t dm_aslen; /* number of entries in dm_asmap */ 1366ff6d951SJohn Birrell uint_t dm_flags; /* module flags (see below) */ 1376ff6d951SJohn Birrell int dm_modid; /* modinfo(1M) module identifier */ 1386ff6d951SJohn Birrell GElf_Addr dm_text_va; /* virtual address of text section */ 1396ff6d951SJohn Birrell GElf_Xword dm_text_size; /* size in bytes of text section */ 1406ff6d951SJohn Birrell GElf_Addr dm_data_va; /* virtual address of data section */ 1416ff6d951SJohn Birrell GElf_Xword dm_data_size; /* size in bytes of data section */ 1426ff6d951SJohn Birrell GElf_Addr dm_bss_va; /* virtual address of BSS */ 1436ff6d951SJohn Birrell GElf_Xword dm_bss_size; /* size in bytes of BSS */ 1446ff6d951SJohn Birrell dt_idhash_t *dm_extern; /* external symbol definitions */ 145bc96366cSSteven Hartland #ifndef illumos 146f5a73645SJohn Birrell caddr_t dm_reloc_offset; /* Symbol relocation offset. */ 147556cb98dSAndriy Gapon uintptr_t *dm_sec_offsets; 148f5a73645SJohn Birrell #endif 1498e648814SRui Paulo pid_t dm_pid; /* pid for this module */ 1508e648814SRui Paulo uint_t dm_nctflibs; /* number of ctf children libraries */ 1518e648814SRui Paulo ctf_file_t **dm_libctfp; /* process library ctf pointers */ 1528e648814SRui Paulo char **dm_libctfn; /* names of process ctf containers */ 1536ff6d951SJohn Birrell } dt_module_t; 1546ff6d951SJohn Birrell 1556ff6d951SJohn Birrell #define DT_DM_LOADED 0x1 /* module symbol and type data is loaded */ 1566ff6d951SJohn Birrell #define DT_DM_KERNEL 0x2 /* module is associated with a kernel object */ 1576ff6d951SJohn Birrell #define DT_DM_PRIMARY 0x4 /* module is a krtld primary kernel object */ 1586ff6d951SJohn Birrell 1598436cb81SMark Johnston #ifdef __FreeBSD__ 1608436cb81SMark Johnston /* 1618436cb81SMark Johnston * A representation of a FreeBSD kernel module, used when checking module 1628436cb81SMark Johnston * dependencies. This differs from dt_module_t, which refers to a KLD in the 1638436cb81SMark Johnston * case of kernel probes. Since modules can be identified regardless of whether 1648436cb81SMark Johnston * they've been compiled into the kernel, we use them to identify DTrace 1658436cb81SMark Johnston * modules. 1668436cb81SMark Johnston */ 1678436cb81SMark Johnston typedef struct dt_kmodule { 1688436cb81SMark Johnston struct dt_kmodule *dkm_next; /* hash table entry */ 1698436cb81SMark Johnston char *dkm_name; /* string name of module */ 1708436cb81SMark Johnston dt_module_t *dkm_module; /* corresponding KLD module */ 1718436cb81SMark Johnston } dt_kmodule_t; 1728436cb81SMark Johnston #endif 1738436cb81SMark Johnston 1746ff6d951SJohn Birrell typedef struct dt_provmod { 1756ff6d951SJohn Birrell char *dp_name; /* name of provider module */ 1766ff6d951SJohn Birrell struct dt_provmod *dp_next; /* next module */ 1776ff6d951SJohn Birrell } dt_provmod_t; 1786ff6d951SJohn Birrell 1796ff6d951SJohn Birrell typedef struct dt_ahashent { 1806ff6d951SJohn Birrell struct dt_ahashent *dtahe_prev; /* prev on hash chain */ 1816ff6d951SJohn Birrell struct dt_ahashent *dtahe_next; /* next on hash chain */ 1826ff6d951SJohn Birrell struct dt_ahashent *dtahe_prevall; /* prev on list of all */ 1836ff6d951SJohn Birrell struct dt_ahashent *dtahe_nextall; /* next on list of all */ 1846ff6d951SJohn Birrell uint64_t dtahe_hashval; /* hash value */ 1856ff6d951SJohn Birrell size_t dtahe_size; /* size of data */ 1866ff6d951SJohn Birrell dtrace_aggdata_t dtahe_data; /* data */ 1876ff6d951SJohn Birrell void (*dtahe_aggregate)(int64_t *, int64_t *, size_t); /* function */ 1886ff6d951SJohn Birrell } dt_ahashent_t; 1896ff6d951SJohn Birrell 1906ff6d951SJohn Birrell typedef struct dt_ahash { 1916ff6d951SJohn Birrell dt_ahashent_t **dtah_hash; /* hash table */ 1926ff6d951SJohn Birrell dt_ahashent_t *dtah_all; /* list of all elements */ 1936ff6d951SJohn Birrell size_t dtah_size; /* size of hash table */ 1946ff6d951SJohn Birrell } dt_ahash_t; 1956ff6d951SJohn Birrell 1966ff6d951SJohn Birrell typedef struct dt_aggregate { 1976ff6d951SJohn Birrell dtrace_bufdesc_t dtat_buf; /* buf aggregation snapshot */ 1986ff6d951SJohn Birrell int dtat_flags; /* aggregate flags */ 1996ff6d951SJohn Birrell processorid_t dtat_ncpus; /* number of CPUs in aggregate */ 2006ff6d951SJohn Birrell processorid_t *dtat_cpus; /* CPUs in aggregate */ 2016ff6d951SJohn Birrell processorid_t dtat_ncpu; /* size of dtat_cpus array */ 2026ff6d951SJohn Birrell processorid_t dtat_maxcpu; /* maximum number of CPUs */ 2036ff6d951SJohn Birrell dt_ahash_t dtat_hash; /* aggregate hash table */ 2046ff6d951SJohn Birrell } dt_aggregate_t; 2056ff6d951SJohn Birrell 2066ff6d951SJohn Birrell typedef struct dt_print_aggdata { 2076ff6d951SJohn Birrell dtrace_hdl_t *dtpa_dtp; /* pointer to libdtrace handle */ 2086ff6d951SJohn Birrell dtrace_aggvarid_t dtpa_id; /* aggregation variable of interest */ 2096ff6d951SJohn Birrell FILE *dtpa_fp; /* file pointer */ 2106ff6d951SJohn Birrell int dtpa_allunprint; /* print only unprinted aggregations */ 211a43f0be9SRui Paulo int dtpa_agghist; /* print aggregation as histogram */ 212a43f0be9SRui Paulo int dtpa_agghisthdr; /* aggregation histogram hdr printed */ 213a43f0be9SRui Paulo int dtpa_aggpack; /* pack quantized aggregations */ 214*93f27766SDomagoj Stolfa char dtpa_keyname[256]; /* key name for oformat */ 215*93f27766SDomagoj Stolfa char *dtpa_aggname; /* aggregate name for oformat */ 2166ff6d951SJohn Birrell } dt_print_aggdata_t; 2176ff6d951SJohn Birrell 2186ff6d951SJohn Birrell typedef struct dt_dirpath { 2196ff6d951SJohn Birrell dt_list_t dir_list; /* linked-list forward/back pointers */ 2206ff6d951SJohn Birrell char *dir_path; /* directory pathname */ 2216ff6d951SJohn Birrell } dt_dirpath_t; 2226ff6d951SJohn Birrell 2236ff6d951SJohn Birrell typedef struct dt_lib_depend { 2246ff6d951SJohn Birrell dt_list_t dtld_deplist; /* linked-list forward/back pointers */ 2256ff6d951SJohn Birrell char *dtld_library; /* library name */ 2266ff6d951SJohn Birrell char *dtld_libpath; /* library pathname */ 2276ff6d951SJohn Birrell uint_t dtld_finish; /* completion time in tsort for lib */ 2286ff6d951SJohn Birrell uint_t dtld_start; /* starting time in tsort for lib */ 229f5a73645SJohn Birrell uint_t dtld_loaded; /* boolean: is this library loaded */ 2306ff6d951SJohn Birrell dt_list_t dtld_dependencies; /* linked-list of lib dependencies */ 2316ff6d951SJohn Birrell dt_list_t dtld_dependents; /* linked-list of lib dependents */ 2326ff6d951SJohn Birrell } dt_lib_depend_t; 2336ff6d951SJohn Birrell 2346ff6d951SJohn Birrell typedef uint32_t dt_version_t; /* encoded version (see below) */ 2356ff6d951SJohn Birrell 2366ff6d951SJohn Birrell struct dtrace_hdl { 2376ff6d951SJohn Birrell const dtrace_vector_t *dt_vector; /* library vector, if vectored open */ 2386ff6d951SJohn Birrell void *dt_varg; /* vector argument, if vectored open */ 2396ff6d951SJohn Birrell dtrace_conf_t dt_conf; /* DTrace driver configuration profile */ 2406ff6d951SJohn Birrell char dt_errmsg[BUFSIZ]; /* buffer for formatted syntax error msgs */ 2416ff6d951SJohn Birrell const char *dt_errtag; /* tag used with last call to dt_set_errmsg() */ 2426ff6d951SJohn Birrell dt_pcb_t *dt_pcb; /* pointer to current parsing control block */ 2436ff6d951SJohn Birrell ulong_t dt_gen; /* compiler generation number */ 2446ff6d951SJohn Birrell dt_list_t dt_programs; /* linked list of dtrace_prog_t's */ 2456ff6d951SJohn Birrell dt_list_t dt_xlators; /* linked list of dt_xlator_t's */ 2466ff6d951SJohn Birrell struct dt_xlator **dt_xlatormap; /* dt_xlator_t's indexed by dx_id */ 2476ff6d951SJohn Birrell id_t dt_xlatorid; /* next dt_xlator_t id to assign */ 2486ff6d951SJohn Birrell dt_ident_t *dt_externs; /* linked list of external symbol identifiers */ 2496ff6d951SJohn Birrell dt_idhash_t *dt_macros; /* hash table of macro variable identifiers */ 2506ff6d951SJohn Birrell dt_idhash_t *dt_aggs; /* hash table of aggregation identifiers */ 2516ff6d951SJohn Birrell dt_idhash_t *dt_globals; /* hash table of global identifiers */ 2526ff6d951SJohn Birrell dt_idhash_t *dt_tls; /* hash table of thread-local identifiers */ 2536ff6d951SJohn Birrell dt_list_t dt_modlist; /* linked list of dt_module_t's */ 2546ff6d951SJohn Birrell dt_module_t **dt_mods; /* hash table of dt_module_t's */ 2558436cb81SMark Johnston #ifdef __FreeBSD__ 2568436cb81SMark Johnston dt_kmodule_t **dt_kmods; /* hash table of dt_kmodule_t's */ 2578436cb81SMark Johnston #endif 2586ff6d951SJohn Birrell uint_t dt_modbuckets; /* number of module hash buckets */ 2596ff6d951SJohn Birrell uint_t dt_nmods; /* number of modules in hash and list */ 2606ff6d951SJohn Birrell dt_provmod_t *dt_provmod; /* linked list of provider modules */ 2616ff6d951SJohn Birrell dt_module_t *dt_exec; /* pointer to executable module */ 2626ff6d951SJohn Birrell dt_module_t *dt_rtld; /* pointer to run-time linker module */ 2636ff6d951SJohn Birrell dt_module_t *dt_cdefs; /* pointer to C dynamic type module */ 2646ff6d951SJohn Birrell dt_module_t *dt_ddefs; /* pointer to D dynamic type module */ 2656ff6d951SJohn Birrell dt_list_t dt_provlist; /* linked list of dt_provider_t's */ 2666ff6d951SJohn Birrell struct dt_provider **dt_provs; /* hash table of dt_provider_t's */ 2676ff6d951SJohn Birrell uint_t dt_provbuckets; /* number of provider hash buckets */ 2686ff6d951SJohn Birrell uint_t dt_nprovs; /* number of providers in hash and list */ 2696ff6d951SJohn Birrell dt_proc_hash_t *dt_procs; /* hash table of grabbed process handles */ 27009e6105fSMark Johnston char **dt_proc_env; /* additional environment variables */ 2716ff6d951SJohn Birrell dt_intdesc_t dt_ints[6]; /* cached integer type descriptions */ 2726ff6d951SJohn Birrell ctf_id_t dt_type_func; /* cached CTF identifier for function type */ 2736ff6d951SJohn Birrell ctf_id_t dt_type_fptr; /* cached CTF identifier for function pointer */ 2746ff6d951SJohn Birrell ctf_id_t dt_type_str; /* cached CTF identifier for string type */ 2756ff6d951SJohn Birrell ctf_id_t dt_type_dyn; /* cached CTF identifier for <DYN> type */ 2766ff6d951SJohn Birrell ctf_id_t dt_type_stack; /* cached CTF identifier for stack type */ 2776ff6d951SJohn Birrell ctf_id_t dt_type_symaddr; /* cached CTF identifier for _symaddr type */ 2786ff6d951SJohn Birrell ctf_id_t dt_type_usymaddr; /* cached CTF ident. for _usymaddr type */ 2796ff6d951SJohn Birrell size_t dt_maxprobe; /* max enabled probe ID */ 2806ff6d951SJohn Birrell dtrace_eprobedesc_t **dt_edesc; /* enabled probe descriptions */ 2816ff6d951SJohn Birrell dtrace_probedesc_t **dt_pdesc; /* probe descriptions for enabled prbs */ 2826ff6d951SJohn Birrell size_t dt_maxagg; /* max aggregation ID */ 2836ff6d951SJohn Birrell dtrace_aggdesc_t **dt_aggdesc; /* aggregation descriptions */ 2846ff6d951SJohn Birrell int dt_maxformat; /* max format ID */ 2856ff6d951SJohn Birrell void **dt_formats; /* pointer to format array */ 28654727873SPedro F. Giffuni int dt_maxstrdata; /* max strdata ID */ 28754727873SPedro F. Giffuni char **dt_strdata; /* pointer to strdata array */ 2886ff6d951SJohn Birrell dt_aggregate_t dt_aggregate; /* aggregate */ 28909e6105fSMark Johnston dt_pq_t *dt_bufq; /* CPU-specific data queue */ 2906ff6d951SJohn Birrell struct dt_pfdict *dt_pfdict; /* dictionary of printf conversions */ 2916ff6d951SJohn Birrell dt_version_t dt_vmax; /* optional ceiling on program API binding */ 2926ff6d951SJohn Birrell dtrace_attribute_t dt_amin; /* optional floor on program attributes */ 2936ff6d951SJohn Birrell char *dt_cpp_path; /* pathname of cpp(1) to invoke if needed */ 2946ff6d951SJohn Birrell char **dt_cpp_argv; /* argument vector for exec'ing cpp(1) */ 2956ff6d951SJohn Birrell int dt_cpp_argc; /* count of initialized cpp(1) arguments */ 2966ff6d951SJohn Birrell int dt_cpp_args; /* size of dt_cpp_argv[] array */ 2976ff6d951SJohn Birrell char *dt_ld_path; /* pathname of ld(1) to invoke if needed */ 29803a5f9f0SMark Johnston #ifdef __FreeBSD__ 29903a5f9f0SMark Johnston char *dt_objcopy_path; /* pathname of objcopy(1) to invoke if needed */ 30003a5f9f0SMark Johnston #endif 3016ff6d951SJohn Birrell dt_list_t dt_lib_path; /* linked-list forming library search path */ 3026ff6d951SJohn Birrell uint_t dt_lazyload; /* boolean: set via -xlazyload */ 3036ff6d951SJohn Birrell uint_t dt_droptags; /* boolean: set via -xdroptags */ 3046ff6d951SJohn Birrell uint_t dt_active; /* boolean: set once tracing is active */ 3056ff6d951SJohn Birrell uint_t dt_stopped; /* boolean: set once tracing is stopped */ 3066ff6d951SJohn Birrell processorid_t dt_beganon; /* CPU that executed BEGIN probe (if any) */ 3076ff6d951SJohn Birrell processorid_t dt_endedon; /* CPU that executed END probe (if any) */ 3086ff6d951SJohn Birrell uint_t dt_oflags; /* dtrace open-time options (see dtrace.h) */ 3096ff6d951SJohn Birrell uint_t dt_cflags; /* dtrace compile-time options (see dtrace.h) */ 3106ff6d951SJohn Birrell uint_t dt_dflags; /* dtrace link-time options (see dtrace.h) */ 3116ff6d951SJohn Birrell uint_t dt_prcmode; /* dtrace process create mode (see dt_proc.h) */ 3126ff6d951SJohn Birrell uint_t dt_linkmode; /* dtrace symbol linking mode (see below) */ 3136ff6d951SJohn Birrell uint_t dt_linktype; /* dtrace link output file type (see below) */ 3146ff6d951SJohn Birrell uint_t dt_xlatemode; /* dtrace translator linking mode (see below) */ 3156ff6d951SJohn Birrell uint_t dt_stdcmode; /* dtrace stdc compatibility mode (see below) */ 316a43f0be9SRui Paulo uint_t dt_encoding; /* dtrace output encoding (see below) */ 3176ff6d951SJohn Birrell uint_t dt_treedump; /* dtrace tree debug bitmap (see below) */ 3186ff6d951SJohn Birrell uint64_t dt_options[DTRACEOPT_MAX]; /* dtrace run-time options */ 3196ff6d951SJohn Birrell int dt_version; /* library version requested by client */ 3206ff6d951SJohn Birrell int dt_ctferr; /* error resulting from last CTF failure */ 3216ff6d951SJohn Birrell int dt_errno; /* error resulting from last failed operation */ 322bc96366cSSteven Hartland #ifndef illumos 323f5a73645SJohn Birrell const char *dt_errfile; 324f5a73645SJohn Birrell int dt_errline; 325f5a73645SJohn Birrell #endif 3266ff6d951SJohn Birrell int dt_fd; /* file descriptor for dtrace pseudo-device */ 3276ff6d951SJohn Birrell int dt_ftfd; /* file descriptor for fasttrap pseudo-device */ 3282179a159SChristos Margiolis int dt_kinstfd; /* file descriptor for kinst pseudo-device */ 3296ff6d951SJohn Birrell int dt_fterr; /* saved errno from failed open of dt_ftfd */ 3306ff6d951SJohn Birrell int dt_cdefs_fd; /* file descriptor for C CTF debugging cache */ 3316ff6d951SJohn Birrell int dt_ddefs_fd; /* file descriptor for D CTF debugging cache */ 332bc96366cSSteven Hartland #ifdef illumos 3336ff6d951SJohn Birrell int dt_stdout_fd; /* file descriptor for saved stdout */ 334f5a73645SJohn Birrell #else 335f5a73645SJohn Birrell FILE *dt_freopen_fp; /* file pointer for freopened stdout */ 336f5a73645SJohn Birrell #endif 3376ff6d951SJohn Birrell dtrace_handle_err_f *dt_errhdlr; /* error handler, if any */ 3386ff6d951SJohn Birrell void *dt_errarg; /* error handler argument */ 3396ff6d951SJohn Birrell dtrace_prog_t *dt_errprog; /* error handler program, if any */ 3406ff6d951SJohn Birrell dtrace_handle_drop_f *dt_drophdlr; /* drop handler, if any */ 3416ff6d951SJohn Birrell void *dt_droparg; /* drop handler argument */ 3426ff6d951SJohn Birrell dtrace_handle_proc_f *dt_prochdlr; /* proc handler, if any */ 3436ff6d951SJohn Birrell void *dt_procarg; /* proc handler argument */ 3446ff6d951SJohn Birrell dtrace_handle_setopt_f *dt_setopthdlr; /* setopt handler, if any */ 3456ff6d951SJohn Birrell void *dt_setoptarg; /* setopt handler argument */ 3466ff6d951SJohn Birrell dtrace_status_t dt_status[2]; /* status cache */ 3476ff6d951SJohn Birrell int dt_statusgen; /* current status generation */ 3486ff6d951SJohn Birrell hrtime_t dt_laststatus; /* last status */ 3496ff6d951SJohn Birrell hrtime_t dt_lastswitch; /* last switch of buffer data */ 3506ff6d951SJohn Birrell hrtime_t dt_lastagg; /* last snapshot of aggregation data */ 3516ff6d951SJohn Birrell char *dt_sprintf_buf; /* buffer for dtrace_sprintf() */ 3526ff6d951SJohn Birrell int dt_sprintf_buflen; /* length of dtrace_sprintf() buffer */ 3536ff6d951SJohn Birrell const char *dt_filetag; /* default filetag for dt_set_errmsg() */ 3546ff6d951SJohn Birrell char *dt_buffered_buf; /* buffer for buffered output */ 3556ff6d951SJohn Birrell size_t dt_buffered_offs; /* current offset into buffered buffer */ 3566ff6d951SJohn Birrell size_t dt_buffered_size; /* size of buffered buffer */ 3576ff6d951SJohn Birrell dtrace_handle_buffered_f *dt_bufhdlr; /* buffered handler, if any */ 3586ff6d951SJohn Birrell void *dt_bufarg; /* buffered handler argument */ 3596ff6d951SJohn Birrell dt_dof_t dt_dof; /* DOF generation buffers (see dt_dof.c) */ 3606ff6d951SJohn Birrell struct utsname dt_uts; /* uname(2) information for system */ 3616ff6d951SJohn Birrell dt_list_t dt_lib_dep; /* scratch linked-list of lib dependencies */ 3626ff6d951SJohn Birrell dt_list_t dt_lib_dep_sorted; /* dependency sorted library list */ 36309e6105fSMark Johnston dtrace_flowkind_t dt_flow; /* flow kind */ 36409e6105fSMark Johnston const char *dt_prefix; /* recommended flow prefix */ 36509e6105fSMark Johnston int dt_indent; /* recommended flow indent */ 36609e6105fSMark Johnston dtrace_epid_t dt_last_epid; /* most recently consumed EPID */ 36709e6105fSMark Johnston uint64_t dt_last_timestamp; /* most recently consumed timestamp */ 368650f66acSMark Johnston boolean_t dt_has_sugar; /* syntactic sugar used? */ 369*93f27766SDomagoj Stolfa int dt_oformat; /* output format (none, json, xml, html) */ 3706ff6d951SJohn Birrell }; 3716ff6d951SJohn Birrell 3726ff6d951SJohn Birrell /* 3736ff6d951SJohn Birrell * Values for the user arg of the ECB. 3746ff6d951SJohn Birrell */ 3756ff6d951SJohn Birrell #define DT_ECB_DEFAULT 0 3766ff6d951SJohn Birrell #define DT_ECB_ERROR 1 3776ff6d951SJohn Birrell 3786ff6d951SJohn Birrell /* 3796ff6d951SJohn Birrell * Values for the dt_linkmode property, which is used by the assembler when 3806ff6d951SJohn Birrell * processing external symbol references. User can set using -xlink=<mode>. 3816ff6d951SJohn Birrell */ 3826ff6d951SJohn Birrell #define DT_LINK_KERNEL 0 /* kernel syms static, user syms dynamic */ 3836ff6d951SJohn Birrell #define DT_LINK_PRIMARY 1 /* primary kernel syms static, others dynamic */ 3846ff6d951SJohn Birrell #define DT_LINK_DYNAMIC 2 /* all symbols dynamic */ 3856ff6d951SJohn Birrell #define DT_LINK_STATIC 3 /* all symbols static */ 3866ff6d951SJohn Birrell 3876ff6d951SJohn Birrell /* 3886ff6d951SJohn Birrell * Values for the dt_linktype property, which is used by dtrace_program_link() 3896ff6d951SJohn Birrell * to determine the type of output file that is desired by the client. 3906ff6d951SJohn Birrell */ 3916ff6d951SJohn Birrell #define DT_LTYP_ELF 0 /* produce ELF containing DOF */ 3926ff6d951SJohn Birrell #define DT_LTYP_DOF 1 /* produce stand-alone DOF */ 3936ff6d951SJohn Birrell 3946ff6d951SJohn Birrell /* 3956ff6d951SJohn Birrell * Values for the dt_xlatemode property, which is used to determine whether 3966ff6d951SJohn Birrell * references to dynamic translators are permitted. Set using -xlate=<mode>. 3976ff6d951SJohn Birrell */ 3986ff6d951SJohn Birrell #define DT_XL_STATIC 0 /* require xlators to be statically defined */ 3996ff6d951SJohn Birrell #define DT_XL_DYNAMIC 1 /* produce references to dynamic translators */ 4006ff6d951SJohn Birrell 4016ff6d951SJohn Birrell /* 4026ff6d951SJohn Birrell * Values for the dt_stdcmode property, which is used by the compiler when 4036ff6d951SJohn Birrell * running cpp to determine the presence and setting of the __STDC__ macro. 4046ff6d951SJohn Birrell */ 4056ff6d951SJohn Birrell #define DT_STDC_XA 0 /* ISO C + K&R C compat w/o ISO: __STDC__=0 */ 4066ff6d951SJohn Birrell #define DT_STDC_XC 1 /* Strict ISO C: __STDC__=1 */ 4076ff6d951SJohn Birrell #define DT_STDC_XS 2 /* K&R C: __STDC__ not defined */ 4086ff6d951SJohn Birrell #define DT_STDC_XT 3 /* ISO C + K&R C compat with ISO: __STDC__=0 */ 4096ff6d951SJohn Birrell 4106ff6d951SJohn Birrell /* 411a43f0be9SRui Paulo * Values for the dt_encoding property, which is used to force a particular 412a43f0be9SRui Paulo * character encoding (overriding default behavior and/or automatic detection). 413a43f0be9SRui Paulo */ 414a43f0be9SRui Paulo #define DT_ENCODING_UNSET 0 415a43f0be9SRui Paulo #define DT_ENCODING_ASCII 1 416a43f0be9SRui Paulo #define DT_ENCODING_UTF8 2 417a43f0be9SRui Paulo 418a43f0be9SRui Paulo /* 4196ff6d951SJohn Birrell * Macro to test whether a given pass bit is set in the dt_treedump bit-vector. 4206ff6d951SJohn Birrell * If the bit for pass 'p' is set, the D compiler displays the parse tree for 4216ff6d951SJohn Birrell * the program by printing it to stderr at the end of compiler pass 'p'. 4226ff6d951SJohn Birrell */ 4236ff6d951SJohn Birrell #define DT_TREEDUMP_PASS(dtp, p) ((dtp)->dt_treedump & (1 << ((p) - 1))) 4246ff6d951SJohn Birrell 4256ff6d951SJohn Birrell /* 4266ff6d951SJohn Birrell * Macros for accessing the cached CTF container and type ID for the common 4276ff6d951SJohn Birrell * types "int", "string", and <DYN>, which we need to use frequently in the D 4286ff6d951SJohn Birrell * compiler. The DT_INT_* macro relies upon "int" being at index 0 in the 4296ff6d951SJohn Birrell * _dtrace_ints_* tables in dt_open.c; the others are also set up there. 4306ff6d951SJohn Birrell */ 4316ff6d951SJohn Birrell #define DT_INT_CTFP(dtp) ((dtp)->dt_ints[0].did_ctfp) 4326ff6d951SJohn Birrell #define DT_INT_TYPE(dtp) ((dtp)->dt_ints[0].did_type) 4336ff6d951SJohn Birrell 4346ff6d951SJohn Birrell #define DT_FUNC_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) 4356ff6d951SJohn Birrell #define DT_FUNC_TYPE(dtp) ((dtp)->dt_type_func) 4366ff6d951SJohn Birrell 4376ff6d951SJohn Birrell #define DT_FPTR_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) 4386ff6d951SJohn Birrell #define DT_FPTR_TYPE(dtp) ((dtp)->dt_type_fptr) 4396ff6d951SJohn Birrell 4406ff6d951SJohn Birrell #define DT_STR_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) 4416ff6d951SJohn Birrell #define DT_STR_TYPE(dtp) ((dtp)->dt_type_str) 4426ff6d951SJohn Birrell 4436ff6d951SJohn Birrell #define DT_DYN_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) 4446ff6d951SJohn Birrell #define DT_DYN_TYPE(dtp) ((dtp)->dt_type_dyn) 4456ff6d951SJohn Birrell 4466ff6d951SJohn Birrell #define DT_STACK_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) 4476ff6d951SJohn Birrell #define DT_STACK_TYPE(dtp) ((dtp)->dt_type_stack) 4486ff6d951SJohn Birrell 4496ff6d951SJohn Birrell #define DT_SYMADDR_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) 4506ff6d951SJohn Birrell #define DT_SYMADDR_TYPE(dtp) ((dtp)->dt_type_symaddr) 4516ff6d951SJohn Birrell 4526ff6d951SJohn Birrell #define DT_USYMADDR_CTFP(dtp) ((dtp)->dt_ddefs->dm_ctfp) 4536ff6d951SJohn Birrell #define DT_USYMADDR_TYPE(dtp) ((dtp)->dt_type_usymaddr) 4546ff6d951SJohn Birrell 4556ff6d951SJohn Birrell /* 4566ff6d951SJohn Birrell * Actions and subroutines are both DT_NODE_FUNC nodes; to avoid confusing 4576ff6d951SJohn Birrell * an action for a subroutine (or vice versa), we assure that the DT_ACT_* 4586ff6d951SJohn Birrell * constants and the DIF_SUBR_* constants occupy non-overlapping ranges by 4596ff6d951SJohn Birrell * starting the DT_ACT_* constants at DIF_SUBR_MAX + 1. 4606ff6d951SJohn Birrell */ 4616ff6d951SJohn Birrell #define DT_ACT_BASE DIF_SUBR_MAX + 1 4626ff6d951SJohn Birrell #define DT_ACT(n) (DT_ACT_BASE + (n)) 4636ff6d951SJohn Birrell 4646ff6d951SJohn Birrell #define DT_ACT_PRINTF DT_ACT(0) /* printf() action */ 4656ff6d951SJohn Birrell #define DT_ACT_TRACE DT_ACT(1) /* trace() action */ 4666ff6d951SJohn Birrell #define DT_ACT_TRACEMEM DT_ACT(2) /* tracemem() action */ 4676ff6d951SJohn Birrell #define DT_ACT_STACK DT_ACT(3) /* stack() action */ 4686ff6d951SJohn Birrell #define DT_ACT_STOP DT_ACT(4) /* stop() action */ 4696ff6d951SJohn Birrell #define DT_ACT_BREAKPOINT DT_ACT(5) /* breakpoint() action */ 4706ff6d951SJohn Birrell #define DT_ACT_PANIC DT_ACT(6) /* panic() action */ 4716ff6d951SJohn Birrell #define DT_ACT_SPECULATE DT_ACT(7) /* speculate() action */ 4726ff6d951SJohn Birrell #define DT_ACT_COMMIT DT_ACT(8) /* commit() action */ 4736ff6d951SJohn Birrell #define DT_ACT_DISCARD DT_ACT(9) /* discard() action */ 4746ff6d951SJohn Birrell #define DT_ACT_CHILL DT_ACT(10) /* chill() action */ 4756ff6d951SJohn Birrell #define DT_ACT_EXIT DT_ACT(11) /* exit() action */ 4766ff6d951SJohn Birrell #define DT_ACT_USTACK DT_ACT(12) /* ustack() action */ 4776ff6d951SJohn Birrell #define DT_ACT_PRINTA DT_ACT(13) /* printa() action */ 4786ff6d951SJohn Birrell #define DT_ACT_RAISE DT_ACT(14) /* raise() action */ 4796ff6d951SJohn Birrell #define DT_ACT_CLEAR DT_ACT(15) /* clear() action */ 4806ff6d951SJohn Birrell #define DT_ACT_NORMALIZE DT_ACT(16) /* normalize() action */ 4816ff6d951SJohn Birrell #define DT_ACT_DENORMALIZE DT_ACT(17) /* denormalize() action */ 4826ff6d951SJohn Birrell #define DT_ACT_TRUNC DT_ACT(18) /* trunc() action */ 4836ff6d951SJohn Birrell #define DT_ACT_SYSTEM DT_ACT(19) /* system() action */ 4846ff6d951SJohn Birrell #define DT_ACT_JSTACK DT_ACT(20) /* jstack() action */ 4856ff6d951SJohn Birrell #define DT_ACT_FTRUNCATE DT_ACT(21) /* ftruncate() action */ 4866ff6d951SJohn Birrell #define DT_ACT_FREOPEN DT_ACT(22) /* freopen() action */ 4876ff6d951SJohn Birrell #define DT_ACT_SYM DT_ACT(23) /* sym()/func() actions */ 4886ff6d951SJohn Birrell #define DT_ACT_MOD DT_ACT(24) /* mod() action */ 4896ff6d951SJohn Birrell #define DT_ACT_USYM DT_ACT(25) /* usym()/ufunc() actions */ 4906ff6d951SJohn Birrell #define DT_ACT_UMOD DT_ACT(26) /* umod() action */ 4916ff6d951SJohn Birrell #define DT_ACT_UADDR DT_ACT(27) /* uaddr() action */ 4926ff6d951SJohn Birrell #define DT_ACT_SETOPT DT_ACT(28) /* setopt() action */ 49354727873SPedro F. Giffuni #define DT_ACT_PRINT DT_ACT(29) /* print() action */ 49454727873SPedro F. Giffuni #define DT_ACT_PRINTM DT_ACT(30) /* printm() action */ 4956ff6d951SJohn Birrell 4966ff6d951SJohn Birrell /* 4976ff6d951SJohn Birrell * Sentinel to tell freopen() to restore the saved stdout. This must not 4986ff6d951SJohn Birrell * be ever valid for opening for write access via freopen(3C), which of 4996ff6d951SJohn Birrell * course, "." never is. 5006ff6d951SJohn Birrell */ 5016ff6d951SJohn Birrell #define DT_FREOPEN_RESTORE "." 5026ff6d951SJohn Birrell 5036ff6d951SJohn Birrell #define EDT_BASE 1000 /* base value for libdtrace errnos */ 5046ff6d951SJohn Birrell 5056ff6d951SJohn Birrell enum { 5066ff6d951SJohn Birrell EDT_VERSION = EDT_BASE, /* client is requesting unsupported version */ 5076ff6d951SJohn Birrell EDT_VERSINVAL, /* version string is invalid or overflows */ 5086ff6d951SJohn Birrell EDT_VERSUNDEF, /* requested API version is not defined */ 5096ff6d951SJohn Birrell EDT_VERSREDUCED, /* requested API version has been reduced */ 5106ff6d951SJohn Birrell EDT_CTF, /* libctf called failed (dt_ctferr has more) */ 5116ff6d951SJohn Birrell EDT_COMPILER, /* error in D program compilation */ 5126ff6d951SJohn Birrell EDT_NOTUPREG, /* tuple register allocation failure */ 5136ff6d951SJohn Birrell EDT_NOMEM, /* memory allocation failure */ 5146ff6d951SJohn Birrell EDT_INT2BIG, /* integer limit exceeded */ 5156ff6d951SJohn Birrell EDT_STR2BIG, /* string limit exceeded */ 5166ff6d951SJohn Birrell EDT_NOMOD, /* unknown module name */ 5176ff6d951SJohn Birrell EDT_NOPROV, /* unknown provider name */ 5186ff6d951SJohn Birrell EDT_NOPROBE, /* unknown probe name */ 5196ff6d951SJohn Birrell EDT_NOSYM, /* unknown symbol name */ 5206ff6d951SJohn Birrell EDT_NOSYMADDR, /* no symbol corresponds to address */ 5216ff6d951SJohn Birrell EDT_NOTYPE, /* unknown type name */ 5226ff6d951SJohn Birrell EDT_NOVAR, /* unknown variable name */ 5236ff6d951SJohn Birrell EDT_NOAGG, /* unknown aggregation name */ 5246ff6d951SJohn Birrell EDT_BADSCOPE, /* improper use of type name scoping operator */ 5256ff6d951SJohn Birrell EDT_BADSPEC, /* overspecified probe description */ 5266ff6d951SJohn Birrell EDT_BADSPCV, /* bad macro variable in probe description */ 5276ff6d951SJohn Birrell EDT_BADID, /* invalid probe identifier */ 5286ff6d951SJohn Birrell EDT_NOTLOADED, /* module is not currently loaded */ 5296ff6d951SJohn Birrell EDT_NOCTF, /* module does not contain any CTF data */ 5306ff6d951SJohn Birrell EDT_DATAMODEL, /* module and program data models don't match */ 5316ff6d951SJohn Birrell EDT_DIFVERS, /* library has newer DIF version than driver */ 5326ff6d951SJohn Birrell EDT_BADAGG, /* unrecognized aggregating action */ 5336ff6d951SJohn Birrell EDT_FIO, /* file i/o error */ 5346ff6d951SJohn Birrell EDT_DIFINVAL, /* invalid DIF program */ 5356ff6d951SJohn Birrell EDT_DIFSIZE, /* invalid DIF size */ 5366ff6d951SJohn Birrell EDT_DIFFAULT, /* failed to copyin DIF program */ 5376ff6d951SJohn Birrell EDT_BADPROBE, /* bad probe description */ 5386ff6d951SJohn Birrell EDT_BADPGLOB, /* bad probe description globbing pattern */ 5396ff6d951SJohn Birrell EDT_NOSCOPE, /* declaration scope stack underflow */ 5406ff6d951SJohn Birrell EDT_NODECL, /* declaration stack underflow */ 5416ff6d951SJohn Birrell EDT_DMISMATCH, /* record list does not match statement */ 5426ff6d951SJohn Birrell EDT_DOFFSET, /* record data offset error */ 5436ff6d951SJohn Birrell EDT_DALIGN, /* record data alignment error */ 5446ff6d951SJohn Birrell EDT_BADOPTNAME, /* invalid dtrace_setopt option name */ 5456ff6d951SJohn Birrell EDT_BADOPTVAL, /* invalid dtrace_setopt option value */ 5466ff6d951SJohn Birrell EDT_BADOPTCTX, /* invalid dtrace_setopt option context */ 5476ff6d951SJohn Birrell EDT_CPPFORK, /* failed to fork preprocessor */ 5486ff6d951SJohn Birrell EDT_CPPEXEC, /* failed to exec preprocessor */ 5496ff6d951SJohn Birrell EDT_CPPENT, /* preprocessor not found */ 5506ff6d951SJohn Birrell EDT_CPPERR, /* unknown preprocessor error */ 5516ff6d951SJohn Birrell EDT_SYMOFLOW, /* external symbol table overflow */ 5526ff6d951SJohn Birrell EDT_ACTIVE, /* operation illegal when tracing is active */ 5536ff6d951SJohn Birrell EDT_DESTRUCTIVE, /* destructive actions not allowed */ 5546ff6d951SJohn Birrell EDT_NOANON, /* no anonymous tracing state */ 5556ff6d951SJohn Birrell EDT_ISANON, /* can't claim anon state and enable probes */ 5566ff6d951SJohn Birrell EDT_ENDTOOBIG, /* END enablings exceed size of prncpl buffer */ 5576ff6d951SJohn Birrell EDT_NOCONV, /* failed to load type for printf conversion */ 5586ff6d951SJohn Birrell EDT_BADCONV, /* incomplete printf conversion */ 5596ff6d951SJohn Birrell EDT_BADERROR, /* invalid library ERROR action */ 5606ff6d951SJohn Birrell EDT_ERRABORT, /* abort due to error */ 5616ff6d951SJohn Birrell EDT_DROPABORT, /* abort due to drop */ 5626ff6d951SJohn Birrell EDT_DIRABORT, /* abort explicitly directed */ 5636ff6d951SJohn Birrell EDT_BADRVAL, /* invalid return value from callback */ 5646ff6d951SJohn Birrell EDT_BADNORMAL, /* invalid normalization */ 5656ff6d951SJohn Birrell EDT_BUFTOOSMALL, /* enabling exceeds size of buffer */ 5666ff6d951SJohn Birrell EDT_BADTRUNC, /* invalid truncation */ 5676ff6d951SJohn Birrell EDT_BUSY, /* device busy (active kernel debugger) */ 5686ff6d951SJohn Birrell EDT_ACCESS, /* insufficient privileges to use DTrace */ 5696ff6d951SJohn Birrell EDT_NOENT, /* dtrace device not available */ 5706ff6d951SJohn Birrell EDT_BRICKED, /* abort due to systemic unresponsiveness */ 5716ff6d951SJohn Birrell EDT_HARDWIRE, /* failed to load hard-wired definitions */ 5726ff6d951SJohn Birrell EDT_ELFVERSION, /* libelf is out-of-date w.r.t libdtrace */ 5736ff6d951SJohn Birrell EDT_NOBUFFERED, /* attempt to buffer output without handler */ 5746ff6d951SJohn Birrell EDT_UNSTABLE, /* description matched unstable set of probes */ 5756ff6d951SJohn Birrell EDT_BADSETOPT, /* invalid setopt library action */ 5766ff6d951SJohn Birrell EDT_BADSTACKPC, /* invalid stack program counter size */ 5776ff6d951SJohn Birrell EDT_BADAGGVAR, /* invalid aggregation variable identifier */ 5781670a1c2SRui Paulo EDT_OVERSION, /* client is requesting deprecated version */ 57923e4da43SPedro F. Giffuni EDT_ENABLING_ERR, /* failed to enable probe */ 5808e648814SRui Paulo EDT_NOPROBES, /* no probes sites for declared provider */ 5818e648814SRui Paulo EDT_CANTLOAD /* failed to load a module */ 5826ff6d951SJohn Birrell }; 5836ff6d951SJohn Birrell 5846ff6d951SJohn Birrell /* 5856ff6d951SJohn Birrell * Interfaces for parsing and comparing DTrace attribute tuples, which describe 5866ff6d951SJohn Birrell * stability and architectural binding information. The dtrace_attribute_t 5876ff6d951SJohn Birrell * structure and associated constant definitions are found in <sys/dtrace.h>. 5886ff6d951SJohn Birrell */ 5896ff6d951SJohn Birrell extern dtrace_attribute_t dt_attr_min(dtrace_attribute_t, dtrace_attribute_t); 5906ff6d951SJohn Birrell extern dtrace_attribute_t dt_attr_max(dtrace_attribute_t, dtrace_attribute_t); 5916ff6d951SJohn Birrell extern char *dt_attr_str(dtrace_attribute_t, char *, size_t); 5926ff6d951SJohn Birrell extern int dt_attr_cmp(dtrace_attribute_t, dtrace_attribute_t); 5936ff6d951SJohn Birrell 5946ff6d951SJohn Birrell /* 5956ff6d951SJohn Birrell * Interfaces for parsing and handling DTrace version strings. Version binding 5966ff6d951SJohn Birrell * is a feature of the D compiler that is handled completely independently of 5976ff6d951SJohn Birrell * the DTrace kernel infrastructure, so the definitions are here in libdtrace. 5986ff6d951SJohn Birrell * Version strings are compiled into an encoded uint32_t which can be compared 5996ff6d951SJohn Birrell * using C comparison operators. Version definitions are found in dt_open.c. 6006ff6d951SJohn Birrell */ 6016ff6d951SJohn Birrell #define DT_VERSION_STRMAX 16 /* enough for "255.4095.4095\0" */ 6026ff6d951SJohn Birrell #define DT_VERSION_MAJMAX 0xFF /* maximum major version number */ 6036ff6d951SJohn Birrell #define DT_VERSION_MINMAX 0xFFF /* maximum minor version number */ 6046ff6d951SJohn Birrell #define DT_VERSION_MICMAX 0xFFF /* maximum micro version number */ 6056ff6d951SJohn Birrell 6066ff6d951SJohn Birrell #define DT_VERSION_NUMBER(M, m, u) \ 6076ff6d951SJohn Birrell ((((M) & 0xFF) << 24) | (((m) & 0xFFF) << 12) | ((u) & 0xFFF)) 6086ff6d951SJohn Birrell 6096ff6d951SJohn Birrell #define DT_VERSION_MAJOR(v) (((v) & 0xFF000000) >> 24) 6106ff6d951SJohn Birrell #define DT_VERSION_MINOR(v) (((v) & 0x00FFF000) >> 12) 6116ff6d951SJohn Birrell #define DT_VERSION_MICRO(v) ((v) & 0x00000FFF) 6126ff6d951SJohn Birrell 6136ff6d951SJohn Birrell extern char *dt_version_num2str(dt_version_t, char *, size_t); 6146ff6d951SJohn Birrell extern int dt_version_str2num(const char *, dt_version_t *); 6156ff6d951SJohn Birrell extern int dt_version_defined(dt_version_t); 6166ff6d951SJohn Birrell 6176ff6d951SJohn Birrell /* 6186ff6d951SJohn Birrell * Miscellaneous internal libdtrace interfaces. The definitions below are for 6196ff6d951SJohn Birrell * libdtrace routines that do not yet merit their own separate header file. 6206ff6d951SJohn Birrell */ 6216ff6d951SJohn Birrell extern char *dt_cpp_add_arg(dtrace_hdl_t *, const char *); 6226ff6d951SJohn Birrell extern char *dt_cpp_pop_arg(dtrace_hdl_t *); 6236ff6d951SJohn Birrell 624bc96366cSSteven Hartland #ifdef illumos 6256ff6d951SJohn Birrell extern int dt_set_errno(dtrace_hdl_t *, int); 626f5a73645SJohn Birrell #else 627f5a73645SJohn Birrell int _dt_set_errno(dtrace_hdl_t *, int, const char *, int); 628f5a73645SJohn Birrell void dt_get_errloc(dtrace_hdl_t *, const char **, int *); 629f5a73645SJohn Birrell #define dt_set_errno(_a,_b) _dt_set_errno(_a,_b,__FILE__,__LINE__) 630f5a73645SJohn Birrell #endif 6316ff6d951SJohn Birrell extern void dt_set_errmsg(dtrace_hdl_t *, const char *, const char *, 6326ff6d951SJohn Birrell const char *, int, const char *, va_list); 6336ff6d951SJohn Birrell 634bc96366cSSteven Hartland #ifdef illumos 6356ff6d951SJohn Birrell extern int dt_ioctl(dtrace_hdl_t *, int, void *); 636f5a73645SJohn Birrell #else 637f5a73645SJohn Birrell extern int dt_ioctl(dtrace_hdl_t *, u_long, void *); 638f5a73645SJohn Birrell #endif 6396ff6d951SJohn Birrell extern int dt_status(dtrace_hdl_t *, processorid_t); 6406ff6d951SJohn Birrell extern long dt_sysconf(dtrace_hdl_t *, int); 6416ff6d951SJohn Birrell extern ssize_t dt_write(dtrace_hdl_t *, int, const void *, size_t); 6426ff6d951SJohn Birrell extern int dt_printf(dtrace_hdl_t *, FILE *, const char *, ...); 6436ff6d951SJohn Birrell 6446ff6d951SJohn Birrell extern void *dt_zalloc(dtrace_hdl_t *, size_t); 6456ff6d951SJohn Birrell extern void *dt_alloc(dtrace_hdl_t *, size_t); 6466ff6d951SJohn Birrell extern void dt_free(dtrace_hdl_t *, void *); 6476ff6d951SJohn Birrell extern void dt_difo_free(dtrace_hdl_t *, dtrace_difo_t *); 6486ff6d951SJohn Birrell 6496ff6d951SJohn Birrell extern int dt_gmatch(const char *, const char *); 6506ff6d951SJohn Birrell extern char *dt_basename(char *); 6516ff6d951SJohn Birrell 6526ff6d951SJohn Birrell extern ulong_t dt_popc(ulong_t); 6536ff6d951SJohn Birrell extern ulong_t dt_popcb(const ulong_t *, ulong_t); 6546ff6d951SJohn Birrell 6556ff6d951SJohn Birrell extern int dt_buffered_enable(dtrace_hdl_t *); 6566ff6d951SJohn Birrell extern int dt_buffered_flush(dtrace_hdl_t *, dtrace_probedata_t *, 6576ff6d951SJohn Birrell const dtrace_recdesc_t *, const dtrace_aggdata_t *, uint32_t flags); 6586ff6d951SJohn Birrell extern void dt_buffered_disable(dtrace_hdl_t *); 6596ff6d951SJohn Birrell extern void dt_buffered_destroy(dtrace_hdl_t *); 6606ff6d951SJohn Birrell 6616ff6d951SJohn Birrell extern uint64_t dt_stddev(uint64_t *, uint64_t); 6626ff6d951SJohn Birrell 663afba0b6eSRui Paulo extern int dt_rw_read_held(pthread_rwlock_t *); 664afba0b6eSRui Paulo extern int dt_rw_write_held(pthread_rwlock_t *); 665afba0b6eSRui Paulo extern int dt_mutex_held(pthread_mutex_t *); 6666ff6d951SJohn Birrell extern int dt_options_load(dtrace_hdl_t *); 6676ff6d951SJohn Birrell 668afba0b6eSRui Paulo #define DT_RW_READ_HELD(x) dt_rw_read_held(x) 669afba0b6eSRui Paulo #define DT_RW_WRITE_HELD(x) dt_rw_write_held(x) 670afba0b6eSRui Paulo #define DT_RW_LOCK_HELD(x) (DT_RW_READ_HELD(x) || DT_RW_WRITE_HELD(x)) 671afba0b6eSRui Paulo #define DT_MUTEX_HELD(x) dt_mutex_held(x) 672afba0b6eSRui Paulo 6736ff6d951SJohn Birrell extern void dt_dprintf(const char *, ...); 6746ff6d951SJohn Birrell 6756ff6d951SJohn Birrell extern void dt_setcontext(dtrace_hdl_t *, dtrace_probedesc_t *); 6766ff6d951SJohn Birrell extern void dt_endcontext(dtrace_hdl_t *); 6776ff6d951SJohn Birrell 6786ff6d951SJohn Birrell extern void dt_pragma(dt_node_t *); 6796ff6d951SJohn Birrell extern int dt_reduce(dtrace_hdl_t *, dt_version_t); 6806ff6d951SJohn Birrell extern void dt_cg(dt_pcb_t *, dt_node_t *); 6816ff6d951SJohn Birrell extern dtrace_difo_t *dt_as(dt_pcb_t *); 6826ff6d951SJohn Birrell extern void dt_dis(const dtrace_difo_t *, FILE *); 6836ff6d951SJohn Birrell 6846ff6d951SJohn Birrell extern int dt_aggregate_go(dtrace_hdl_t *); 6856ff6d951SJohn Birrell extern int dt_aggregate_init(dtrace_hdl_t *); 6866ff6d951SJohn Birrell extern void dt_aggregate_destroy(dtrace_hdl_t *); 6876ff6d951SJohn Birrell 6886ff6d951SJohn Birrell extern int dt_epid_lookup(dtrace_hdl_t *, dtrace_epid_t, 6896ff6d951SJohn Birrell dtrace_eprobedesc_t **, dtrace_probedesc_t **); 6906ff6d951SJohn Birrell extern void dt_epid_destroy(dtrace_hdl_t *); 6916ff6d951SJohn Birrell extern int dt_aggid_lookup(dtrace_hdl_t *, dtrace_aggid_t, dtrace_aggdesc_t **); 6926ff6d951SJohn Birrell extern void dt_aggid_destroy(dtrace_hdl_t *); 6936ff6d951SJohn Birrell 6946ff6d951SJohn Birrell extern void *dt_format_lookup(dtrace_hdl_t *, int); 6956ff6d951SJohn Birrell extern void dt_format_destroy(dtrace_hdl_t *); 6966ff6d951SJohn Birrell 69754727873SPedro F. Giffuni extern const char *dt_strdata_lookup(dtrace_hdl_t *, int); 69854727873SPedro F. Giffuni extern void dt_strdata_destroy(dtrace_hdl_t *); 69954727873SPedro F. Giffuni 7006ff6d951SJohn Birrell extern int dt_print_quantize(dtrace_hdl_t *, FILE *, 7016ff6d951SJohn Birrell const void *, size_t, uint64_t); 7026ff6d951SJohn Birrell extern int dt_print_lquantize(dtrace_hdl_t *, FILE *, 7036ff6d951SJohn Birrell const void *, size_t, uint64_t); 704675cf915SPedro F. Giffuni extern int dt_print_llquantize(dtrace_hdl_t *, FILE *, 705675cf915SPedro F. Giffuni const void *, size_t, uint64_t); 7066ff6d951SJohn Birrell extern int dt_print_agg(const dtrace_aggdata_t *, void *); 7076ff6d951SJohn Birrell 708*93f27766SDomagoj Stolfa extern int dt_format_agg(const dtrace_aggdata_t *, void *); 709*93f27766SDomagoj Stolfa 7106ff6d951SJohn Birrell extern int dt_handle(dtrace_hdl_t *, dtrace_probedata_t *); 7116ff6d951SJohn Birrell extern int dt_handle_liberr(dtrace_hdl_t *, 7126ff6d951SJohn Birrell const dtrace_probedata_t *, const char *); 7136ff6d951SJohn Birrell extern int dt_handle_cpudrop(dtrace_hdl_t *, processorid_t, 7146ff6d951SJohn Birrell dtrace_dropkind_t, uint64_t); 7156ff6d951SJohn Birrell extern int dt_handle_status(dtrace_hdl_t *, 7166ff6d951SJohn Birrell dtrace_status_t *, dtrace_status_t *); 7176ff6d951SJohn Birrell extern int dt_handle_setopt(dtrace_hdl_t *, dtrace_setoptdata_t *); 7186ff6d951SJohn Birrell 719*93f27766SDomagoj Stolfa extern void dt_oformat_drop(dtrace_hdl_t *, processorid_t); 720*93f27766SDomagoj Stolfa 7216ff6d951SJohn Birrell extern int dt_lib_depend_add(dtrace_hdl_t *, dt_list_t *, const char *); 7226ff6d951SJohn Birrell extern dt_lib_depend_t *dt_lib_depend_lookup(dt_list_t *, const char *); 7236ff6d951SJohn Birrell 7246ff6d951SJohn Birrell extern dt_pcb_t *yypcb; /* pointer to current parser control block */ 7256ff6d951SJohn Birrell extern char yyintprefix; /* int token prefix for macros (+/-) */ 7266ff6d951SJohn Birrell extern char yyintsuffix[4]; /* int token suffix ([uUlL]*) */ 7276ff6d951SJohn Birrell extern int yyintdecimal; /* int token is decimal (1) or octal/hex (0) */ 7288ba333e0SMark Johnston extern char *yytext; /* lex input buffer */ 7296ff6d951SJohn Birrell extern int yylineno; /* lex line number */ 7306ff6d951SJohn Birrell extern int yydebug; /* lex debugging */ 7316ff6d951SJohn Birrell extern dt_node_t *yypragma; /* lex token list for control lines */ 7326ff6d951SJohn Birrell 7336ff6d951SJohn Birrell extern const dtrace_attribute_t _dtrace_maxattr; /* maximum attributes */ 7346ff6d951SJohn Birrell extern const dtrace_attribute_t _dtrace_defattr; /* default attributes */ 7356ff6d951SJohn Birrell extern const dtrace_attribute_t _dtrace_symattr; /* symbol ref attributes */ 7366ff6d951SJohn Birrell extern const dtrace_attribute_t _dtrace_typattr; /* type ref attributes */ 7376ff6d951SJohn Birrell extern const dtrace_attribute_t _dtrace_prvattr; /* provider attributes */ 7386ff6d951SJohn Birrell extern const dtrace_pattr_t _dtrace_prvdesc; /* provider attribute bundle */ 7396ff6d951SJohn Birrell 7406ff6d951SJohn Birrell extern const dt_version_t _dtrace_versions[]; /* array of valid versions */ 7416ff6d951SJohn Birrell extern const char *const _dtrace_version; /* current version string */ 7426ff6d951SJohn Birrell 7436ff6d951SJohn Birrell extern int _dtrace_strbuckets; /* number of hash buckets for strings */ 7446ff6d951SJohn Birrell extern int _dtrace_intbuckets; /* number of hash buckets for ints */ 7456ff6d951SJohn Birrell extern uint_t _dtrace_stkindent; /* default indent for stack/ustack */ 7466ff6d951SJohn Birrell extern uint_t _dtrace_pidbuckets; /* number of hash buckets for pids */ 7476ff6d951SJohn Birrell extern uint_t _dtrace_pidlrulim; /* number of proc handles to cache */ 7486ff6d951SJohn Birrell extern int _dtrace_debug; /* debugging messages enabled */ 7496ff6d951SJohn Birrell extern size_t _dtrace_bufsize; /* default dt_buf_create() size */ 7506ff6d951SJohn Birrell extern int _dtrace_argmax; /* default maximum probe arguments */ 7516ff6d951SJohn Birrell 7526ff6d951SJohn Birrell extern const char *_dtrace_libdir; /* default library directory */ 7536ff6d951SJohn Birrell extern const char *_dtrace_moddir; /* default kernel module directory */ 7546ff6d951SJohn Birrell 7554ddb46f6SXin LI #ifdef __FreeBSD__ 7564ddb46f6SXin LI extern int gmatch(const char *, const char *); 7574ddb46f6SXin LI extern int yylex(void); 7584ddb46f6SXin LI #endif 7594ddb46f6SXin LI 7606ff6d951SJohn Birrell #ifdef __cplusplus 7616ff6d951SJohn Birrell } 7626ff6d951SJohn Birrell #endif 7636ff6d951SJohn Birrell 7646ff6d951SJohn Birrell #endif /* _DT_IMPL_H */ 765