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