xref: /freebsd/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h (revision 0bc2abddc8d4abb89a210f2bb113e9e7c2d4ce18)
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 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Copyright (c) 2013 by Delphix. All rights reserved.
29  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
30  */
31 
32 #ifndef	_DTRACE_H
33 #define	_DTRACE_H
34 
35 #include <sys/dtrace.h>
36 #include <stdarg.h>
37 #include <stdio.h>
38 #include <gelf.h>
39 #include <libproc.h>
40 #ifndef illumos
41 #include <rtld_db.h>
42 #endif
43 
44 #ifdef	__cplusplus
45 extern "C" {
46 #endif
47 
48 /*
49  * DTrace Dynamic Tracing Software: Library Interfaces
50  *
51  * Note: The contents of this file are private to the implementation of the
52  * Solaris system and DTrace subsystem and are subject to change at any time
53  * without notice.  Applications and drivers using these interfaces will fail
54  * to run on future releases.  These interfaces should not be used for any
55  * purpose except those expressly outlined in dtrace(7D) and libdtrace(3LIB).
56  * Please refer to the "Solaris Dynamic Tracing Guide" for more information.
57  */
58 
59 #define	DTRACE_VERSION	3		/* library ABI interface version */
60 
61 struct ps_prochandle;
62 typedef struct dtrace_hdl dtrace_hdl_t;
63 typedef struct dtrace_prog dtrace_prog_t;
64 typedef struct dtrace_vector dtrace_vector_t;
65 typedef struct dtrace_aggdata dtrace_aggdata_t;
66 
67 #define	DTRACE_O_NODEV		0x01	/* do not open dtrace(7D) device */
68 #define	DTRACE_O_NOSYS		0x02	/* do not load /system/object modules */
69 #define	DTRACE_O_LP64		0x04	/* force D compiler to be LP64 */
70 #define	DTRACE_O_ILP32		0x08	/* force D compiler to be ILP32 */
71 #define	DTRACE_O_MASK		0x0f	/* mask of valid flags to dtrace_open */
72 
73 extern dtrace_hdl_t *dtrace_open(int, int, int *);
74 extern dtrace_hdl_t *dtrace_vopen(int, int, int *,
75     const dtrace_vector_t *, void *);
76 
77 extern int dtrace_go(dtrace_hdl_t *);
78 extern int dtrace_stop(dtrace_hdl_t *);
79 extern void dtrace_sleep(dtrace_hdl_t *);
80 extern void dtrace_close(dtrace_hdl_t *);
81 
82 extern int dtrace_errno(dtrace_hdl_t *);
83 extern const char *dtrace_errmsg(dtrace_hdl_t *, int);
84 extern const char *dtrace_faultstr(dtrace_hdl_t *, int);
85 extern const char *dtrace_subrstr(dtrace_hdl_t *, int);
86 
87 extern int dtrace_setopt(dtrace_hdl_t *, const char *, const char *);
88 extern int dtrace_getopt(dtrace_hdl_t *, const char *, dtrace_optval_t *);
89 
90 extern void dtrace_update(dtrace_hdl_t *);
91 extern int dtrace_ctlfd(dtrace_hdl_t *);
92 
93 /*
94  * DTrace Program Interface
95  *
96  * DTrace programs can be created by compiling ASCII text files containing
97  * D programs or by compiling in-memory C strings that specify a D program.
98  * Once created, callers can examine the list of program statements and
99  * enable the probes and actions described by these statements.
100  */
101 
102 typedef struct dtrace_proginfo {
103 	dtrace_attribute_t dpi_descattr; /* minimum probedesc attributes */
104 	dtrace_attribute_t dpi_stmtattr; /* minimum statement attributes */
105 	uint_t dpi_aggregates;	/* number of aggregates specified in program */
106 	uint_t dpi_recgens;	/* number of record generating probes in prog */
107 	uint_t dpi_matches;	/* number of probes matched by program */
108 	uint_t dpi_speculations; /* number of speculations specified in prog */
109 } dtrace_proginfo_t;
110 
111 #define	DTRACE_C_DIFV	0x0001	/* DIF verbose mode: show each compiled DIFO */
112 #define	DTRACE_C_EMPTY	0x0002	/* Permit compilation of empty D source files */
113 #define	DTRACE_C_ZDEFS	0x0004	/* Permit probe defs that match zero probes */
114 #define	DTRACE_C_EATTR	0x0008	/* Error if program attributes less than min */
115 #define	DTRACE_C_CPP	0x0010	/* Preprocess input file with cpp(1) utility */
116 #define	DTRACE_C_KNODEF	0x0020	/* Permit unresolved kernel symbols in DIFO */
117 #define	DTRACE_C_UNODEF	0x0040	/* Permit unresolved user symbols in DIFO */
118 #define	DTRACE_C_PSPEC	0x0080	/* Intepret ambiguous specifiers as probes */
119 #define	DTRACE_C_ETAGS	0x0100	/* Prefix error messages with error tags */
120 #define	DTRACE_C_ARGREF	0x0200	/* Do not require all macro args to be used */
121 #define	DTRACE_C_DEFARG	0x0800	/* Use 0/"" as value for unspecified args */
122 #define	DTRACE_C_NOLIBS	0x1000	/* Do not process D system libraries */
123 #define	DTRACE_C_CTL	0x2000	/* Only process control directives */
124 #define	DTRACE_C_MASK	0x3bff	/* mask of all valid flags to dtrace_*compile */
125 
126 extern dtrace_prog_t *dtrace_program_strcompile(dtrace_hdl_t *,
127     const char *, dtrace_probespec_t, uint_t, int, char *const []);
128 
129 extern dtrace_prog_t *dtrace_program_fcompile(dtrace_hdl_t *,
130     FILE *, uint_t, int, char *const []);
131 
132 extern int dtrace_program_exec(dtrace_hdl_t *, dtrace_prog_t *,
133     dtrace_proginfo_t *);
134 extern void dtrace_program_info(dtrace_hdl_t *, dtrace_prog_t *,
135     dtrace_proginfo_t *);
136 
137 #define	DTRACE_D_STRIP	0x01	/* strip non-loadable sections from program */
138 #define	DTRACE_D_PROBES	0x02	/* include provider and probe definitions */
139 #define	DTRACE_D_MASK	0x03	/* mask of valid flags to dtrace_dof_create */
140 
141 extern int dtrace_program_link(dtrace_hdl_t *, dtrace_prog_t *,
142     uint_t, const char *, int, char *const []);
143 
144 extern int dtrace_program_header(dtrace_hdl_t *, FILE *, const char *);
145 
146 extern void *dtrace_dof_create(dtrace_hdl_t *, dtrace_prog_t *, uint_t);
147 extern void dtrace_dof_destroy(dtrace_hdl_t *, void *);
148 
149 extern void *dtrace_getopt_dof(dtrace_hdl_t *);
150 extern void *dtrace_geterr_dof(dtrace_hdl_t *);
151 
152 typedef struct dtrace_stmtdesc {
153 	dtrace_ecbdesc_t *dtsd_ecbdesc;		/* ECB description */
154 	dtrace_actdesc_t *dtsd_action;		/* action list */
155 	dtrace_actdesc_t *dtsd_action_last;	/* last action in action list */
156 	void *dtsd_aggdata;			/* aggregation data */
157 	void *dtsd_fmtdata;			/* type-specific output data */
158 	void *dtsd_strdata;			/* type-specific string data */
159 	void (*dtsd_callback)(void);		/* callback function for EPID */
160 	void *dtsd_data;			/* callback data pointer */
161 	dtrace_attribute_t dtsd_descattr;	/* probedesc attributes */
162 	dtrace_attribute_t dtsd_stmtattr;	/* statement attributes */
163 } dtrace_stmtdesc_t;
164 
165 typedef int dtrace_stmt_f(dtrace_hdl_t *, dtrace_prog_t *,
166     dtrace_stmtdesc_t *, void *);
167 
168 extern dtrace_stmtdesc_t *dtrace_stmt_create(dtrace_hdl_t *,
169     dtrace_ecbdesc_t *);
170 extern dtrace_actdesc_t *dtrace_stmt_action(dtrace_hdl_t *,
171     dtrace_stmtdesc_t *);
172 extern int dtrace_stmt_add(dtrace_hdl_t *, dtrace_prog_t *,
173     dtrace_stmtdesc_t *);
174 extern int dtrace_stmt_iter(dtrace_hdl_t *, dtrace_prog_t *,
175     dtrace_stmt_f *, void *);
176 extern void dtrace_stmt_destroy(dtrace_hdl_t *, dtrace_stmtdesc_t *);
177 
178 /*
179  * DTrace Data Consumption Interface
180  */
181 typedef enum {
182 	DTRACEFLOW_ENTRY,
183 	DTRACEFLOW_RETURN,
184 	DTRACEFLOW_NONE
185 } dtrace_flowkind_t;
186 
187 #define	DTRACE_CONSUME_ERROR		-1	/* error while processing */
188 #define	DTRACE_CONSUME_THIS		0	/* consume this probe/record */
189 #define	DTRACE_CONSUME_NEXT		1	/* advance to next probe/rec */
190 #define	DTRACE_CONSUME_ABORT		2	/* abort consumption */
191 
192 typedef struct dtrace_probedata {
193 	dtrace_hdl_t *dtpda_handle;		/* handle to DTrace library */
194 	dtrace_eprobedesc_t *dtpda_edesc;	/* enabled probe description */
195 	dtrace_probedesc_t *dtpda_pdesc;	/* probe description */
196 	processorid_t dtpda_cpu;		/* CPU for data */
197 	caddr_t dtpda_data;			/* pointer to raw data */
198 	dtrace_flowkind_t dtpda_flow;		/* flow kind */
199 	const char *dtpda_prefix;		/* recommended flow prefix */
200 	int dtpda_indent;			/* recommended flow indent */
201 } dtrace_probedata_t;
202 
203 typedef int dtrace_consume_probe_f(const dtrace_probedata_t *, void *);
204 typedef int dtrace_consume_rec_f(const dtrace_probedata_t *,
205     const dtrace_recdesc_t *, void *);
206 
207 extern int dtrace_consume(dtrace_hdl_t *, FILE *,
208     dtrace_consume_probe_f *, dtrace_consume_rec_f *, void *);
209 
210 #define	DTRACE_STATUS_NONE	0	/* no status; not yet time */
211 #define	DTRACE_STATUS_OKAY	1	/* status okay */
212 #define	DTRACE_STATUS_EXITED	2	/* exit() was called; tracing stopped */
213 #define	DTRACE_STATUS_FILLED	3	/* fill buffer filled; tracing stoped */
214 #define	DTRACE_STATUS_STOPPED	4	/* tracing already stopped */
215 
216 extern int dtrace_status(dtrace_hdl_t *);
217 
218 /*
219  * DTrace Formatted Output Interfaces
220  *
221  * To format output associated with a given dtrace_stmtdesc, the caller can
222  * invoke one of the following functions, passing the opaque dtsd_fmtdata and a
223  * list of record descriptions.  These functions return either -1 to indicate
224  * an error, or a positive integer indicating the number of records consumed.
225  * For anonymous enablings, the consumer can use the dtrd_format member of
226  * the record description to obtain a format description.  The dtfd_string
227  * member of the format description may be passed to dtrace_print{fa}_create()
228  * to create the opaque format data.
229  */
230 extern void *dtrace_printf_create(dtrace_hdl_t *, const char *);
231 extern void *dtrace_printa_create(dtrace_hdl_t *, const char *);
232 extern size_t dtrace_printf_format(dtrace_hdl_t *, void *, char *, size_t);
233 
234 extern int dtrace_fprintf(dtrace_hdl_t *, FILE *, void *,
235     const dtrace_probedata_t *, const dtrace_recdesc_t *, uint_t,
236     const void *, size_t);
237 
238 extern int dtrace_fprinta(dtrace_hdl_t *, FILE *, void *,
239     const dtrace_probedata_t *, const dtrace_recdesc_t *, uint_t,
240     const void *, size_t);
241 
242 extern int dtrace_system(dtrace_hdl_t *, FILE *, void *,
243     const dtrace_probedata_t *, const dtrace_recdesc_t *, uint_t,
244     const void *, size_t);
245 
246 extern int dtrace_freopen(dtrace_hdl_t *, FILE *, void *,
247     const dtrace_probedata_t *, const dtrace_recdesc_t *, uint_t,
248     const void *, size_t);
249 
250 /*
251  * Type-specific output printing
252  *
253  * The print() action will associate a string data record that is actually the
254  * fully-qualified type name of the data traced by the DIFEXPR action.  This is
255  * stored in the same 'format' record from the kernel, but we know by virtue of
256  * the fact that the action is still DIFEXPR that it is actually a reference to
257  * plain string data.
258  */
259 extern int dtrace_print(dtrace_hdl_t *, FILE *, const char *,
260     caddr_t, size_t);
261 
262 /*
263  * DTrace Work Interface
264  */
265 typedef enum {
266 	DTRACE_WORKSTATUS_ERROR = -1,
267 	DTRACE_WORKSTATUS_OKAY,
268 	DTRACE_WORKSTATUS_DONE
269 } dtrace_workstatus_t;
270 
271 extern dtrace_workstatus_t dtrace_work(dtrace_hdl_t *, FILE *,
272     dtrace_consume_probe_f *, dtrace_consume_rec_f *, void *);
273 
274 /*
275  * DTrace Handler Interface
276  */
277 #define	DTRACE_HANDLE_ABORT		-1	/* abort current operation */
278 #define	DTRACE_HANDLE_OK		0	/* handled okay; continue */
279 
280 typedef struct dtrace_errdata {
281 	dtrace_hdl_t *dteda_handle;		/* handle to DTrace library */
282 	dtrace_eprobedesc_t *dteda_edesc;	/* enabled probe inducing err */
283 	dtrace_probedesc_t *dteda_pdesc;	/* probe inducing error */
284 	processorid_t dteda_cpu;		/* CPU of error */
285 	int dteda_action;			/* action inducing error */
286 	int dteda_offset;			/* offset in DIFO of error */
287 	int dteda_fault;			/* specific fault */
288 	uint64_t dteda_addr;			/* address of fault, if any */
289 	const char *dteda_msg;			/* preconstructed message */
290 } dtrace_errdata_t;
291 
292 typedef int dtrace_handle_err_f(const dtrace_errdata_t *, void *);
293 extern int dtrace_handle_err(dtrace_hdl_t *, dtrace_handle_err_f *, void *);
294 
295 typedef enum {
296 	DTRACEDROP_PRINCIPAL,			/* drop to principal buffer */
297 	DTRACEDROP_AGGREGATION,			/* drop to aggregation buffer */
298 	DTRACEDROP_DYNAMIC,			/* dynamic drop */
299 	DTRACEDROP_DYNRINSE,			/* dyn drop due to rinsing */
300 	DTRACEDROP_DYNDIRTY,			/* dyn drop due to dirty */
301 	DTRACEDROP_SPEC,			/* speculative drop */
302 	DTRACEDROP_SPECBUSY,			/* spec drop due to busy */
303 	DTRACEDROP_SPECUNAVAIL,			/* spec drop due to unavail */
304 	DTRACEDROP_STKSTROVERFLOW,		/* stack string tab overflow */
305 	DTRACEDROP_DBLERROR			/* error in ERROR probe */
306 } dtrace_dropkind_t;
307 
308 typedef struct dtrace_dropdata {
309 	dtrace_hdl_t *dtdda_handle;		/* handle to DTrace library */
310 	processorid_t dtdda_cpu;		/* CPU, if any */
311 	dtrace_dropkind_t dtdda_kind;		/* kind of drop */
312 	uint64_t dtdda_drops;			/* number of drops */
313 	uint64_t dtdda_total;			/* total drops */
314 	const char *dtdda_msg;			/* preconstructed message */
315 } dtrace_dropdata_t;
316 
317 typedef int dtrace_handle_drop_f(const dtrace_dropdata_t *, void *);
318 extern int dtrace_handle_drop(dtrace_hdl_t *, dtrace_handle_drop_f *, void *);
319 
320 typedef void dtrace_handle_proc_f(struct ps_prochandle *, const char *, void *);
321 extern int dtrace_handle_proc(dtrace_hdl_t *, dtrace_handle_proc_f *, void *);
322 
323 #define	DTRACE_BUFDATA_AGGKEY		0x0001	/* aggregation key */
324 #define	DTRACE_BUFDATA_AGGVAL		0x0002	/* aggregation value */
325 #define	DTRACE_BUFDATA_AGGFORMAT	0x0004	/* aggregation format data */
326 #define	DTRACE_BUFDATA_AGGLAST		0x0008	/* last for this key/val */
327 
328 typedef struct dtrace_bufdata {
329 	dtrace_hdl_t *dtbda_handle;		/* handle to DTrace library */
330 	const char *dtbda_buffered;		/* buffered output */
331 	dtrace_probedata_t *dtbda_probe;	/* probe data */
332 	const dtrace_recdesc_t *dtbda_recdesc;	/* record description */
333 	const dtrace_aggdata_t *dtbda_aggdata;	/* aggregation data, if agg. */
334 	uint32_t dtbda_flags;			/* flags; see above */
335 } dtrace_bufdata_t;
336 
337 typedef int dtrace_handle_buffered_f(const dtrace_bufdata_t *, void *);
338 extern int dtrace_handle_buffered(dtrace_hdl_t *,
339     dtrace_handle_buffered_f *, void *);
340 
341 typedef struct dtrace_setoptdata {
342 	dtrace_hdl_t *dtsda_handle;		/* handle to DTrace library */
343 	const dtrace_probedata_t *dtsda_probe;	/* probe data */
344 	const char *dtsda_option;		/* option that was set */
345 	dtrace_optval_t dtsda_oldval;		/* old value */
346 	dtrace_optval_t dtsda_newval;		/* new value */
347 } dtrace_setoptdata_t;
348 
349 typedef int dtrace_handle_setopt_f(const dtrace_setoptdata_t *, void *);
350 extern int dtrace_handle_setopt(dtrace_hdl_t *,
351     dtrace_handle_setopt_f *, void *);
352 
353 /*
354  * DTrace Aggregate Interface
355  */
356 
357 #define	DTRACE_A_PERCPU		0x0001
358 #define	DTRACE_A_KEEPDELTA	0x0002
359 #define	DTRACE_A_ANONYMOUS	0x0004
360 #define	DTRACE_A_TOTAL		0x0008
361 #define	DTRACE_A_MINMAXBIN	0x0010
362 #define	DTRACE_A_HASNEGATIVES	0x0020
363 #define	DTRACE_A_HASPOSITIVES	0x0040
364 
365 #define	DTRACE_AGGZOOM_MAX		0.95	/* height of max bar */
366 
367 #define	DTRACE_AGGWALK_ERROR		-1	/* error while processing */
368 #define	DTRACE_AGGWALK_NEXT		0	/* proceed to next element */
369 #define	DTRACE_AGGWALK_ABORT		1	/* abort aggregation walk */
370 #define	DTRACE_AGGWALK_CLEAR		2	/* clear this element */
371 #define	DTRACE_AGGWALK_NORMALIZE	3	/* normalize this element */
372 #define	DTRACE_AGGWALK_DENORMALIZE	4	/* denormalize this element */
373 #define	DTRACE_AGGWALK_REMOVE		5	/* remove this element */
374 
375 struct dtrace_aggdata {
376 	dtrace_hdl_t *dtada_handle;		/* handle to DTrace library */
377 	dtrace_aggdesc_t *dtada_desc;		/* aggregation description */
378 	dtrace_eprobedesc_t *dtada_edesc;	/* enabled probe description */
379 	dtrace_probedesc_t *dtada_pdesc;	/* probe description */
380 	caddr_t dtada_data;			/* pointer to raw data */
381 	uint64_t dtada_normal;			/* the normal -- 1 for denorm */
382 	size_t dtada_size;			/* total size of the data */
383 	caddr_t dtada_delta;			/* delta data, if available */
384 	caddr_t *dtada_percpu;			/* per CPU data, if avail */
385 	caddr_t *dtada_percpu_delta;		/* per CPU delta, if avail */
386 	int64_t dtada_total;			/* per agg total, if avail */
387 	uint16_t dtada_minbin;			/* minimum bin, if avail */
388 	uint16_t dtada_maxbin;			/* maximum bin, if avail */
389 	uint32_t dtada_flags;			/* flags */
390 };
391 
392 typedef int dtrace_aggregate_f(const dtrace_aggdata_t *, void *);
393 typedef int dtrace_aggregate_walk_f(dtrace_hdl_t *,
394     dtrace_aggregate_f *, void *);
395 typedef int dtrace_aggregate_walk_joined_f(const dtrace_aggdata_t **,
396     const int, void *);
397 
398 extern void dtrace_aggregate_clear(dtrace_hdl_t *);
399 extern int dtrace_aggregate_snap(dtrace_hdl_t *);
400 extern int dtrace_aggregate_print(dtrace_hdl_t *, FILE *,
401     dtrace_aggregate_walk_f *);
402 
403 extern int dtrace_aggregate_walk(dtrace_hdl_t *, dtrace_aggregate_f *, void *);
404 
405 extern int dtrace_aggregate_walk_joined(dtrace_hdl_t *,
406     dtrace_aggvarid_t *, int, dtrace_aggregate_walk_joined_f *, void *);
407 
408 extern int dtrace_aggregate_walk_sorted(dtrace_hdl_t *,
409     dtrace_aggregate_f *, void *);
410 
411 extern int dtrace_aggregate_walk_keysorted(dtrace_hdl_t *,
412     dtrace_aggregate_f *, void *);
413 
414 extern int dtrace_aggregate_walk_valsorted(dtrace_hdl_t *,
415     dtrace_aggregate_f *, void *);
416 
417 extern int dtrace_aggregate_walk_keyvarsorted(dtrace_hdl_t *,
418     dtrace_aggregate_f *, void *);
419 
420 extern int dtrace_aggregate_walk_valvarsorted(dtrace_hdl_t *,
421     dtrace_aggregate_f *, void *);
422 
423 extern int dtrace_aggregate_walk_keyrevsorted(dtrace_hdl_t *,
424     dtrace_aggregate_f *, void *);
425 
426 extern int dtrace_aggregate_walk_valrevsorted(dtrace_hdl_t *,
427     dtrace_aggregate_f *, void *);
428 
429 extern int dtrace_aggregate_walk_keyvarrevsorted(dtrace_hdl_t *,
430     dtrace_aggregate_f *, void *);
431 
432 extern int dtrace_aggregate_walk_valvarrevsorted(dtrace_hdl_t *,
433     dtrace_aggregate_f *, void *);
434 
435 #define	DTRACE_AGD_PRINTED	0x1	/* aggregation printed in program */
436 
437 /*
438  * DTrace Process Control Interface
439  *
440  * Library clients who wish to have libdtrace create or grab processes for
441  * monitoring of their symbol table changes may use these interfaces to
442  * request that libdtrace obtain control of the process using libproc.
443  */
444 
445 extern struct ps_prochandle *dtrace_proc_create(dtrace_hdl_t *,
446     const char *, char *const *, proc_child_func *, void *);
447 
448 extern struct ps_prochandle *dtrace_proc_grab(dtrace_hdl_t *, pid_t, int);
449 extern void dtrace_proc_release(dtrace_hdl_t *, struct ps_prochandle *);
450 extern void dtrace_proc_continue(dtrace_hdl_t *, struct ps_prochandle *);
451 
452 /*
453  * DTrace Object, Symbol, and Type Interfaces
454  *
455  * Library clients can use libdtrace to perform symbol and C type information
456  * lookups by symbol name, symbol address, or C type name, or to lookup meta-
457  * information cached for each of the program objects in use by DTrace.  The
458  * resulting struct contain pointers to arbitrary-length strings, including
459  * object, symbol, and type names, that are persistent until the next call to
460  * dtrace_update().  Once dtrace_update() is called, any cached values must
461  * be flushed and not used subsequently by the client program.
462  */
463 
464 #define	DTRACE_OBJ_EXEC	 ((const char *)0L)	/* primary executable file */
465 #define	DTRACE_OBJ_RTLD	 ((const char *)1L)	/* run-time link-editor */
466 #define	DTRACE_OBJ_CDEFS ((const char *)2L)	/* C include definitions */
467 #define	DTRACE_OBJ_DDEFS ((const char *)3L)	/* D program definitions */
468 #define	DTRACE_OBJ_EVERY ((const char *)-1L)	/* all known objects */
469 #define	DTRACE_OBJ_KMODS ((const char *)-2L)	/* all kernel objects */
470 #define	DTRACE_OBJ_UMODS ((const char *)-3L)	/* all user objects */
471 
472 typedef struct dtrace_objinfo {
473 	const char *dto_name;			/* object file scope name */
474 	const char *dto_file;			/* object file path (if any) */
475 	int dto_id;				/* object file id (if any) */
476 	uint_t dto_flags;			/* object flags (see below) */
477 	GElf_Addr dto_text_va;			/* address of text section */
478 	GElf_Xword dto_text_size;		/* size of text section */
479 	GElf_Addr dto_data_va;			/* address of data section */
480 	GElf_Xword dto_data_size;		/* size of data section */
481 	GElf_Addr dto_bss_va;			/* address of BSS */
482 	GElf_Xword dto_bss_size;		/* size of BSS */
483 } dtrace_objinfo_t;
484 
485 #define	DTRACE_OBJ_F_KERNEL	0x1		/* object is a kernel module */
486 #define	DTRACE_OBJ_F_PRIMARY	0x2		/* object is a primary module */
487 
488 typedef int dtrace_obj_f(dtrace_hdl_t *, const dtrace_objinfo_t *, void *);
489 
490 extern int dtrace_object_iter(dtrace_hdl_t *, dtrace_obj_f *, void *);
491 extern int dtrace_object_info(dtrace_hdl_t *, const char *, dtrace_objinfo_t *);
492 
493 typedef struct dtrace_syminfo {
494 	const char *dts_object;			/* object name */
495 	const char *dts_name;			/* symbol name */
496 	ulong_t dts_id;				/* symbol id */
497 } dtrace_syminfo_t;
498 
499 extern int dtrace_lookup_by_name(dtrace_hdl_t *, const char *, const char *,
500     GElf_Sym *, dtrace_syminfo_t *);
501 
502 extern int dtrace_lookup_by_addr(dtrace_hdl_t *, GElf_Addr addr,
503     GElf_Sym *, dtrace_syminfo_t *);
504 
505 typedef struct dtrace_typeinfo {
506 	const char *dtt_object;			/* object containing type */
507 	ctf_file_t *dtt_ctfp;			/* CTF container handle */
508 	ctf_id_t dtt_type;			/* CTF type identifier */
509 	uint_t dtt_flags;			/* Misc. flags */
510 } dtrace_typeinfo_t;
511 
512 #define	DTT_FL_USER	0x1			/* user type */
513 
514 extern int dtrace_lookup_by_type(dtrace_hdl_t *, const char *, const char *,
515     dtrace_typeinfo_t *);
516 
517 extern int dtrace_symbol_type(dtrace_hdl_t *, const GElf_Sym *,
518     const dtrace_syminfo_t *, dtrace_typeinfo_t *);
519 
520 extern int dtrace_type_strcompile(dtrace_hdl_t *,
521     const char *, dtrace_typeinfo_t *);
522 
523 extern int dtrace_type_fcompile(dtrace_hdl_t *,
524     FILE *, dtrace_typeinfo_t *);
525 
526 /*
527  * DTrace Probe Interface
528  *
529  * Library clients can use these functions to iterate over the set of available
530  * probe definitions and inquire as to their attributes.  The probe iteration
531  * interfaces report probes that are declared as well as those from dtrace(7D).
532  */
533 typedef struct dtrace_probeinfo {
534 	dtrace_attribute_t dtp_attr;		/* name attributes */
535 	dtrace_attribute_t dtp_arga;		/* arg attributes */
536 	const dtrace_typeinfo_t *dtp_argv;	/* arg types */
537 	int dtp_argc;				/* arg count */
538 } dtrace_probeinfo_t;
539 
540 typedef int dtrace_probe_f(dtrace_hdl_t *, const dtrace_probedesc_t *, void *);
541 
542 extern int dtrace_probe_iter(dtrace_hdl_t *,
543     const dtrace_probedesc_t *pdp, dtrace_probe_f *, void *);
544 
545 extern int dtrace_probe_info(dtrace_hdl_t *,
546     const dtrace_probedesc_t *, dtrace_probeinfo_t *);
547 
548 /*
549  * DTrace Vector Interface
550  *
551  * The DTrace library normally speaks directly to dtrace(7D).  However,
552  * this communication may be vectored elsewhere.  Consumers who wish to
553  * perform a vectored open must fill in the vector, and use the dtrace_vopen()
554  * entry point to obtain a library handle.
555  */
556 struct dtrace_vector {
557 #ifdef illumos
558 	int (*dtv_ioctl)(void *, int, void *);
559 #else
560 	int (*dtv_ioctl)(void *, u_long, void *);
561 #endif
562 	int (*dtv_lookup_by_addr)(void *, GElf_Addr, GElf_Sym *,
563 	    dtrace_syminfo_t *);
564 	int (*dtv_status)(void *, processorid_t);
565 	long (*dtv_sysconf)(void *, int);
566 };
567 
568 /*
569  * DTrace Utility Functions
570  *
571  * Library clients can use these functions to convert addresses strings, to
572  * convert between string and integer probe descriptions and the
573  * dtrace_probedesc_t representation, and to perform similar conversions on
574  * stability attributes.
575  */
576 extern int dtrace_addr2str(dtrace_hdl_t *, uint64_t, char *, int);
577 extern int dtrace_uaddr2str(dtrace_hdl_t *, pid_t, uint64_t, char *, int);
578 
579 extern int dtrace_xstr2desc(dtrace_hdl_t *, dtrace_probespec_t,
580     const char *, int, char *const [], dtrace_probedesc_t *);
581 
582 extern int dtrace_str2desc(dtrace_hdl_t *, dtrace_probespec_t,
583     const char *, dtrace_probedesc_t *);
584 
585 extern int dtrace_id2desc(dtrace_hdl_t *, dtrace_id_t, dtrace_probedesc_t *);
586 
587 #define	DTRACE_DESC2STR_MAX	1024	/* min buf size for dtrace_desc2str() */
588 
589 extern char *dtrace_desc2str(const dtrace_probedesc_t *, char *, size_t);
590 
591 #define	DTRACE_ATTR2STR_MAX	64	/* min buf size for dtrace_attr2str() */
592 
593 extern char *dtrace_attr2str(dtrace_attribute_t, char *, size_t);
594 extern int dtrace_str2attr(const char *, dtrace_attribute_t *);
595 
596 extern const char *dtrace_stability_name(dtrace_stability_t);
597 extern const char *dtrace_class_name(dtrace_class_t);
598 
599 extern int dtrace_provider_modules(dtrace_hdl_t *, const char **, int);
600 
601 extern const char *const _dtrace_version;
602 extern int _dtrace_debug;
603 
604 #ifdef	__cplusplus
605 }
606 #endif
607 
608 #ifndef illumos
609 #define _SC_CPUID_MAX		_SC_NPROCESSORS_CONF
610 #define _SC_NPROCESSORS_MAX	_SC_NPROCESSORS_CONF
611 #endif
612 
613 #endif	/* _DTRACE_H */
614