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