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