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