164562Sgshapiro/* 264562Sgshapiro * CDDL HEADER START 364562Sgshapiro * 464562Sgshapiro * The contents of this file are subject to the terms of the 564562Sgshapiro * Common Development and Distribution License (the "License"). 664562Sgshapiro * You may not use this file except in compliance with the License. 764562Sgshapiro * 864562Sgshapiro * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 964562Sgshapiro * or http://www.opensolaris.org/os/licensing. 1064562Sgshapiro * See the License for the specific language governing permissions 1164562Sgshapiro * and limitations under the License. 12132943Sgshapiro * 13132943Sgshapiro * When distributing Covered Code, include this CDDL HEADER in each 1464562Sgshapiro * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1590792Sgshapiro * If applicable, add the following below this CDDL HEADER, with the 1690792Sgshapiro * fields enclosed by brackets "[]" replaced with your own identifying 1790792Sgshapiro * information: Portions Copyright [yyyy] [name of copyright owner] 1864562Sgshapiro * 1990792Sgshapiro * CDDL HEADER END 2090792Sgshapiro */ 2190792Sgshapiro 2290792Sgshapiro/* 23132943Sgshapiro * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24132943Sgshapiro * Use is subject to license terms. 2590792Sgshapiro */ 26132943Sgshapiro 27132943Sgshapiro#ifndef _DT_PROC_H 28132943Sgshapiro#define _DT_PROC_H 2990792Sgshapiro 30132943Sgshapiro#pragma ident "%Z%%M% %I% %E% SMI" 31132943Sgshapiro 3290792Sgshapiro#include <libproc.h> 33132943Sgshapiro#include <dtrace.h> 34132943Sgshapiro#include <pthread.h> 35132943Sgshapiro#include <dt_list.h> 3664562Sgshapiro 3764562Sgshapiro#ifdef __cplusplus 3864562Sgshapiroextern "C" { 3964562Sgshapiro#endif 4064562Sgshapiro 4164562Sgshapirotypedef struct dt_proc { 4264562Sgshapiro dt_list_t dpr_list; /* prev/next pointers for lru chain */ 4364562Sgshapiro struct dt_proc *dpr_hash; /* next pointer for pid hash chain */ 44110560Sgshapiro dtrace_hdl_t *dpr_hdl; /* back pointer to libdtrace handle */ 4564562Sgshapiro struct ps_prochandle *dpr_proc; /* proc handle for libproc calls */ 4664562Sgshapiro char dpr_errmsg[BUFSIZ]; /* error message */ 4764562Sgshapiro rd_agent_t *dpr_rtld; /* rtld handle for librtld_db calls */ 4864562Sgshapiro pthread_mutex_t dpr_lock; /* lock for manipulating dpr_hdl */ 4964562Sgshapiro pthread_cond_t dpr_cv; /* cond for dpr_stop/quit/done */ 5090792Sgshapiro pid_t dpr_pid; /* pid of process */ 5190792Sgshapiro uint_t dpr_refs; /* reference count */ 5264562Sgshapiro uint8_t dpr_cacheable; /* cache handle using lru list */ 5364562Sgshapiro uint8_t dpr_stop; /* stop mask: see flag bits below */ 5464562Sgshapiro uint8_t dpr_quit; /* quit flag: ctl thread should quit */ 5564562Sgshapiro uint8_t dpr_done; /* done flag: ctl thread has exited */ 5664562Sgshapiro uint8_t dpr_usdt; /* usdt flag: usdt initialized */ 5764562Sgshapiro uint8_t dpr_stale; /* proc flag: been deprecated */ 5864562Sgshapiro uint8_t dpr_rdonly; /* proc flag: opened read-only */ 5973188Sgshapiro pthread_t dpr_tid; /* control thread (or zero if none) */ 6073188Sgshapiro dt_list_t dpr_bps; /* list of dt_bkpt_t structures */ 6173188Sgshapiro} dt_proc_t; 6273188Sgshapiro 6364562Sgshapirotypedef struct dt_proc_notify { 6473188Sgshapiro dt_proc_t *dprn_dpr; /* process associated with the event */ 6564562Sgshapiro char dprn_errmsg[BUFSIZ]; /* error message */ 6664562Sgshapiro struct dt_proc_notify *dprn_next; /* next pointer */ 6764562Sgshapiro} dt_proc_notify_t; 6864562Sgshapiro 6964562Sgshapiro#define DT_PROC_STOP_IDLE 0x01 /* idle on owner's stop request */ 7064562Sgshapiro#define DT_PROC_STOP_CREATE 0x02 /* wait on dpr_cv at process exec */ 7164562Sgshapiro#define DT_PROC_STOP_GRAB 0x04 /* wait on dpr_cv at process grab */ 7264562Sgshapiro#define DT_PROC_STOP_PREINIT 0x08 /* wait on dpr_cv at rtld preinit */ 7364562Sgshapiro#define DT_PROC_STOP_POSTINIT 0x10 /* wait on dpr_cv at rtld postinit */ 7480785Sgshapiro#define DT_PROC_STOP_MAIN 0x20 /* wait on dpr_cv at a.out`main() */ 7564562Sgshapiro 7664562Sgshapirotypedef void dt_bkpt_f(dtrace_hdl_t *, dt_proc_t *, void *); 7764562Sgshapiro 7864562Sgshapirotypedef struct dt_bkpt { 7964562Sgshapiro dt_list_t dbp_list; /* prev/next pointers for bkpt list */ 8064562Sgshapiro dt_bkpt_f *dbp_func; /* callback function to execute */ 8180785Sgshapiro void *dbp_data; /* callback function private data */ 8264562Sgshapiro uintptr_t dbp_addr; /* virtual address of breakpoint */ 8364562Sgshapiro ulong_t dbp_instr; /* saved instruction from breakpoint */ 8464562Sgshapiro ulong_t dbp_hits; /* count of breakpoint hits for debug */ 8564562Sgshapiro int dbp_active; /* flag indicating breakpoint is on */ 8664562Sgshapiro} dt_bkpt_t; 8764562Sgshapiro 8864562Sgshapirotypedef struct dt_proc_hash { 8964562Sgshapiro pthread_mutex_t dph_lock; /* lock protecting dph_notify list */ 9064562Sgshapiro pthread_cond_t dph_cv; /* cond for waiting for dph_notify */ 9166494Sgshapiro dt_proc_notify_t *dph_notify; /* list of pending proc notifications */ 9290792Sgshapiro dt_list_t dph_lrulist; /* list of dt_proc_t's in lru order */ 9366494Sgshapiro uint_t dph_lrulim; /* limit on number of procs to hold */ 9464562Sgshapiro uint_t dph_lrucnt; /* count of cached process handles */ 9580785Sgshapiro uint_t dph_hashlen; /* size of hash chains array */ 9664562Sgshapiro dt_proc_t *dph_hash[1]; /* hash chains array */ 9764562Sgshapiro} dt_proc_hash_t; 9890792Sgshapiro 9980785Sgshapiroextern struct ps_prochandle *dt_proc_create(dtrace_hdl_t *, 10080785Sgshapiro const char *, char *const *, proc_child_func *, void *); 10180785Sgshapiro 10280785Sgshapiroextern struct ps_prochandle *dt_proc_grab(dtrace_hdl_t *, pid_t, int, int); 10380785Sgshapiroextern void dt_proc_release(dtrace_hdl_t *, struct ps_prochandle *); 10464562Sgshapiroextern void dt_proc_continue(dtrace_hdl_t *, struct ps_prochandle *); 10564562Sgshapiroextern void dt_proc_lock(dtrace_hdl_t *, struct ps_prochandle *); 10680785Sgshapiroextern void dt_proc_unlock(dtrace_hdl_t *, struct ps_prochandle *); 10780785Sgshapiroextern dt_proc_t *dt_proc_lookup(dtrace_hdl_t *, struct ps_prochandle *, int); 10864562Sgshapiro 10990792Sgshapiroextern void dt_proc_hash_create(dtrace_hdl_t *); 11064562Sgshapiroextern void dt_proc_hash_destroy(dtrace_hdl_t *); 11164562Sgshapiro 11264562Sgshapiro#ifdef __cplusplus 11366494Sgshapiro} 11477349Sgshapiro#endif 11577349Sgshapiro 11664562Sgshapiro#endif /* _DT_PROC_H */ 11766494Sgshapiro