xref: /titanic_51/usr/src/lib/libpctx/common/libpctx.h (revision 37714ae43602c675f9dc59b070bfdf9fa702872c)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_LIBPCTX_H
28 #define	_LIBPCTX_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <fcntl.h>
34 #include <stdarg.h>
35 
36 /*
37  * The process context library allows callers to use the facilities
38  * of /proc to control processes in a simplified way by managing
39  * the process via an event loop.  The controlling process expresses
40  * interest in various events which are handled as callbacks by the
41  * library.
42  */
43 
44 #ifdef	__cplusplus
45 extern "C" {
46 #endif
47 
48 typedef struct __pctx pctx_t;
49 
50 /*
51  * A vprintf-like error handling routine can be passed in for use
52  * by more sophisticated callers.  If specified as NULL, errors
53  * are written to stderr.
54  */
55 typedef void (pctx_errfn_t)(const char *fn, const char *fmt, va_list ap);
56 
57 extern pctx_t *pctx_create(const char *filename, char *const *argv,
58     void *arg, int verbose, pctx_errfn_t *errfn);
59 extern pctx_t *pctx_capture(pid_t pid,
60     void *arg, int verbose, pctx_errfn_t *errfn);
61 
62 typedef int pctx_sysc_execfn_t(pctx_t *, pid_t, id_t, char *, void *);
63 typedef void pctx_sysc_forkfn_t(pctx_t *, pid_t, id_t, pid_t, void *);
64 typedef void pctx_sysc_exitfn_t(pctx_t *, pid_t, id_t, int, void *);
65 typedef int pctx_sysc_lwp_createfn_t(pctx_t *, pid_t, id_t, void *);
66 typedef int pctx_init_lwpfn_t(pctx_t *, pid_t, id_t, void *);
67 typedef int pctx_fini_lwpfn_t(pctx_t *, pid_t, id_t, void *);
68 typedef int pctx_sysc_lwp_exitfn_t(pctx_t *, pid_t, id_t, void *);
69 
70 typedef	enum {
71 	PCTX_NULL_EVENT = 0,
72 	PCTX_SYSC_EXEC_EVENT,
73 	PCTX_SYSC_FORK_EVENT,
74 	PCTX_SYSC_EXIT_EVENT,
75 	PCTX_SYSC_LWP_CREATE_EVENT,
76 	PCTX_INIT_LWP_EVENT,
77 	PCTX_FINI_LWP_EVENT,
78 	PCTX_SYSC_LWP_EXIT_EVENT
79 } pctx_event_t;
80 
81 extern int pctx_set_events(pctx_t *pctx, ...);
82 
83 extern int pctx_run(pctx_t *pctx, uint_t msec, uint_t nsamples,
84     int (*tick)(pctx_t *, pid_t, id_t, void *));
85 
86 extern void pctx_release(pctx_t *pctx);
87 
88 /*
89  * Implementation-private interfaces used by libcpc.
90  */
91 struct __cpc;
92 extern int __pctx_cpc(pctx_t *, struct __cpc *, int, id_t,
93 	void *, void *, void *, int);
94 extern void __pctx_cpc_register_callback(void (*)(struct __cpc *,
95 	struct __pctx *));
96 
97 #ifdef	__cplusplus
98 }
99 #endif
100 
101 #endif	/* _LIBPCTX_H */
102