10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*11389SAlexander.Kolbasov@Sun.COM * Common Development and Distribution License (the "License"). 6*11389SAlexander.Kolbasov@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*11389SAlexander.Kolbasov@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _LIBPCTX_H 270Sstevel@tonic-gate #define _LIBPCTX_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/types.h> 300Sstevel@tonic-gate #include <fcntl.h> 310Sstevel@tonic-gate #include <stdarg.h> 320Sstevel@tonic-gate 330Sstevel@tonic-gate /* 340Sstevel@tonic-gate * The process context library allows callers to use the facilities 350Sstevel@tonic-gate * of /proc to control processes in a simplified way by managing 360Sstevel@tonic-gate * the process via an event loop. The controlling process expresses 370Sstevel@tonic-gate * interest in various events which are handled as callbacks by the 380Sstevel@tonic-gate * library. 390Sstevel@tonic-gate */ 400Sstevel@tonic-gate 410Sstevel@tonic-gate #ifdef __cplusplus 420Sstevel@tonic-gate extern "C" { 430Sstevel@tonic-gate #endif 440Sstevel@tonic-gate 450Sstevel@tonic-gate typedef struct __pctx pctx_t; 460Sstevel@tonic-gate 470Sstevel@tonic-gate /* 480Sstevel@tonic-gate * A vprintf-like error handling routine can be passed in for use 490Sstevel@tonic-gate * by more sophisticated callers. If specified as NULL, errors 500Sstevel@tonic-gate * are written to stderr. 510Sstevel@tonic-gate */ 520Sstevel@tonic-gate typedef void (pctx_errfn_t)(const char *fn, const char *fmt, va_list ap); 530Sstevel@tonic-gate 540Sstevel@tonic-gate extern pctx_t *pctx_create(const char *filename, char *const *argv, 550Sstevel@tonic-gate void *arg, int verbose, pctx_errfn_t *errfn); 560Sstevel@tonic-gate extern pctx_t *pctx_capture(pid_t pid, 570Sstevel@tonic-gate void *arg, int verbose, pctx_errfn_t *errfn); 580Sstevel@tonic-gate 590Sstevel@tonic-gate typedef int pctx_sysc_execfn_t(pctx_t *, pid_t, id_t, char *, void *); 600Sstevel@tonic-gate typedef void pctx_sysc_forkfn_t(pctx_t *, pid_t, id_t, pid_t, void *); 610Sstevel@tonic-gate typedef void pctx_sysc_exitfn_t(pctx_t *, pid_t, id_t, int, void *); 620Sstevel@tonic-gate typedef int pctx_sysc_lwp_createfn_t(pctx_t *, pid_t, id_t, void *); 630Sstevel@tonic-gate typedef int pctx_init_lwpfn_t(pctx_t *, pid_t, id_t, void *); 640Sstevel@tonic-gate typedef int pctx_fini_lwpfn_t(pctx_t *, pid_t, id_t, void *); 650Sstevel@tonic-gate typedef int pctx_sysc_lwp_exitfn_t(pctx_t *, pid_t, id_t, void *); 660Sstevel@tonic-gate 67*11389SAlexander.Kolbasov@Sun.COM extern void pctx_terminate(pctx_t *); 68*11389SAlexander.Kolbasov@Sun.COM 690Sstevel@tonic-gate typedef enum { 700Sstevel@tonic-gate PCTX_NULL_EVENT = 0, 710Sstevel@tonic-gate PCTX_SYSC_EXEC_EVENT, 720Sstevel@tonic-gate PCTX_SYSC_FORK_EVENT, 730Sstevel@tonic-gate PCTX_SYSC_EXIT_EVENT, 740Sstevel@tonic-gate PCTX_SYSC_LWP_CREATE_EVENT, 750Sstevel@tonic-gate PCTX_INIT_LWP_EVENT, 760Sstevel@tonic-gate PCTX_FINI_LWP_EVENT, 770Sstevel@tonic-gate PCTX_SYSC_LWP_EXIT_EVENT 780Sstevel@tonic-gate } pctx_event_t; 790Sstevel@tonic-gate 800Sstevel@tonic-gate extern int pctx_set_events(pctx_t *pctx, ...); 810Sstevel@tonic-gate 820Sstevel@tonic-gate extern int pctx_run(pctx_t *pctx, uint_t msec, uint_t nsamples, 830Sstevel@tonic-gate int (*tick)(pctx_t *, pid_t, id_t, void *)); 840Sstevel@tonic-gate 850Sstevel@tonic-gate extern void pctx_release(pctx_t *pctx); 860Sstevel@tonic-gate 870Sstevel@tonic-gate /* 880Sstevel@tonic-gate * Implementation-private interfaces used by libcpc. 890Sstevel@tonic-gate */ 900Sstevel@tonic-gate struct __cpc; 910Sstevel@tonic-gate extern int __pctx_cpc(pctx_t *, struct __cpc *, int, id_t, 920Sstevel@tonic-gate void *, void *, void *, int); 930Sstevel@tonic-gate extern void __pctx_cpc_register_callback(void (*)(struct __cpc *, 940Sstevel@tonic-gate struct __pctx *)); 950Sstevel@tonic-gate 960Sstevel@tonic-gate #ifdef __cplusplus 970Sstevel@tonic-gate } 980Sstevel@tonic-gate #endif 990Sstevel@tonic-gate 1000Sstevel@tonic-gate #endif /* _LIBPCTX_H */ 101