17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*b885580bSAlexander Kolbasov * Common Development and Distribution License (the "License"). 6*b885580bSAlexander Kolbasov * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*b885580bSAlexander Kolbasov * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _LIBPCTX_H 277c478bd9Sstevel@tonic-gate #define _LIBPCTX_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> 307c478bd9Sstevel@tonic-gate #include <fcntl.h> 317c478bd9Sstevel@tonic-gate #include <stdarg.h> 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate /* 347c478bd9Sstevel@tonic-gate * The process context library allows callers to use the facilities 357c478bd9Sstevel@tonic-gate * of /proc to control processes in a simplified way by managing 367c478bd9Sstevel@tonic-gate * the process via an event loop. The controlling process expresses 377c478bd9Sstevel@tonic-gate * interest in various events which are handled as callbacks by the 387c478bd9Sstevel@tonic-gate * library. 397c478bd9Sstevel@tonic-gate */ 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #ifdef __cplusplus 427c478bd9Sstevel@tonic-gate extern "C" { 437c478bd9Sstevel@tonic-gate #endif 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate typedef struct __pctx pctx_t; 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* 487c478bd9Sstevel@tonic-gate * A vprintf-like error handling routine can be passed in for use 497c478bd9Sstevel@tonic-gate * by more sophisticated callers. If specified as NULL, errors 507c478bd9Sstevel@tonic-gate * are written to stderr. 517c478bd9Sstevel@tonic-gate */ 527c478bd9Sstevel@tonic-gate typedef void (pctx_errfn_t)(const char *fn, const char *fmt, va_list ap); 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate extern pctx_t *pctx_create(const char *filename, char *const *argv, 557c478bd9Sstevel@tonic-gate void *arg, int verbose, pctx_errfn_t *errfn); 567c478bd9Sstevel@tonic-gate extern pctx_t *pctx_capture(pid_t pid, 577c478bd9Sstevel@tonic-gate void *arg, int verbose, pctx_errfn_t *errfn); 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate typedef int pctx_sysc_execfn_t(pctx_t *, pid_t, id_t, char *, void *); 607c478bd9Sstevel@tonic-gate typedef void pctx_sysc_forkfn_t(pctx_t *, pid_t, id_t, pid_t, void *); 617c478bd9Sstevel@tonic-gate typedef void pctx_sysc_exitfn_t(pctx_t *, pid_t, id_t, int, void *); 627c478bd9Sstevel@tonic-gate typedef int pctx_sysc_lwp_createfn_t(pctx_t *, pid_t, id_t, void *); 637c478bd9Sstevel@tonic-gate typedef int pctx_init_lwpfn_t(pctx_t *, pid_t, id_t, void *); 647c478bd9Sstevel@tonic-gate typedef int pctx_fini_lwpfn_t(pctx_t *, pid_t, id_t, void *); 657c478bd9Sstevel@tonic-gate typedef int pctx_sysc_lwp_exitfn_t(pctx_t *, pid_t, id_t, void *); 667c478bd9Sstevel@tonic-gate 67*b885580bSAlexander Kolbasov extern void pctx_terminate(pctx_t *); 68*b885580bSAlexander Kolbasov 697c478bd9Sstevel@tonic-gate typedef enum { 707c478bd9Sstevel@tonic-gate PCTX_NULL_EVENT = 0, 717c478bd9Sstevel@tonic-gate PCTX_SYSC_EXEC_EVENT, 727c478bd9Sstevel@tonic-gate PCTX_SYSC_FORK_EVENT, 737c478bd9Sstevel@tonic-gate PCTX_SYSC_EXIT_EVENT, 747c478bd9Sstevel@tonic-gate PCTX_SYSC_LWP_CREATE_EVENT, 757c478bd9Sstevel@tonic-gate PCTX_INIT_LWP_EVENT, 767c478bd9Sstevel@tonic-gate PCTX_FINI_LWP_EVENT, 777c478bd9Sstevel@tonic-gate PCTX_SYSC_LWP_EXIT_EVENT 787c478bd9Sstevel@tonic-gate } pctx_event_t; 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate extern int pctx_set_events(pctx_t *pctx, ...); 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate extern int pctx_run(pctx_t *pctx, uint_t msec, uint_t nsamples, 837c478bd9Sstevel@tonic-gate int (*tick)(pctx_t *, pid_t, id_t, void *)); 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate extern void pctx_release(pctx_t *pctx); 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate /* 887c478bd9Sstevel@tonic-gate * Implementation-private interfaces used by libcpc. 897c478bd9Sstevel@tonic-gate */ 907c478bd9Sstevel@tonic-gate struct __cpc; 917c478bd9Sstevel@tonic-gate extern int __pctx_cpc(pctx_t *, struct __cpc *, int, id_t, 927c478bd9Sstevel@tonic-gate void *, void *, void *, int); 937c478bd9Sstevel@tonic-gate extern void __pctx_cpc_register_callback(void (*)(struct __cpc *, 947c478bd9Sstevel@tonic-gate struct __pctx *)); 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate #ifdef __cplusplus 977c478bd9Sstevel@tonic-gate } 987c478bd9Sstevel@tonic-gate #endif 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate #endif /* _LIBPCTX_H */ 101