1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #ifndef _DT_PROC_H 28*0Sstevel@tonic-gate #define _DT_PROC_H 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #include <libproc.h> 33*0Sstevel@tonic-gate #include <dtrace.h> 34*0Sstevel@tonic-gate #include <pthread.h> 35*0Sstevel@tonic-gate #include <dt_list.h> 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate #ifdef __cplusplus 38*0Sstevel@tonic-gate extern "C" { 39*0Sstevel@tonic-gate #endif 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate typedef struct dt_proc { 42*0Sstevel@tonic-gate dt_list_t dpr_list; /* prev/next pointers for lru chain */ 43*0Sstevel@tonic-gate struct dt_proc *dpr_hash; /* next pointer for pid hash chain */ 44*0Sstevel@tonic-gate struct dt_proc *dpr_notify; /* next pointer for notification list */ 45*0Sstevel@tonic-gate dtrace_hdl_t *dpr_hdl; /* back pointer to libdtrace handle */ 46*0Sstevel@tonic-gate struct ps_prochandle *dpr_proc; /* proc handle for libproc calls */ 47*0Sstevel@tonic-gate rd_agent_t *dpr_rtld; /* rtld handle for librtld_db calls */ 48*0Sstevel@tonic-gate pthread_mutex_t dpr_lock; /* lock for manipulating dpr_hdl */ 49*0Sstevel@tonic-gate pthread_cond_t dpr_cv; /* cond for dpr_stop/quit/done */ 50*0Sstevel@tonic-gate pid_t dpr_pid; /* pid of process */ 51*0Sstevel@tonic-gate uint_t dpr_refs; /* reference count */ 52*0Sstevel@tonic-gate uint8_t dpr_cacheable; /* cache handle using lru list */ 53*0Sstevel@tonic-gate uint8_t dpr_stop; /* stop mask: see flag bits below */ 54*0Sstevel@tonic-gate uint8_t dpr_quit; /* quit flag: ctl thread should quit */ 55*0Sstevel@tonic-gate uint8_t dpr_done; /* done flag: ctl thread has exited */ 56*0Sstevel@tonic-gate uint8_t dpr_usdt; /* usdt flag: usdt initialized */ 57*0Sstevel@tonic-gate uint8_t dpr_stale; /* proc flag: been deprecated */ 58*0Sstevel@tonic-gate uint8_t dpr_rdonly; /* proc flag: opened read-only */ 59*0Sstevel@tonic-gate pthread_t dpr_tid; /* control thread (or zero if none) */ 60*0Sstevel@tonic-gate dt_list_t dpr_bps; /* list of dt_bkpt_t structures */ 61*0Sstevel@tonic-gate } dt_proc_t; 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate #define DT_PROC_STOP_IDLE 0x01 /* idle on owner's stop request */ 64*0Sstevel@tonic-gate #define DT_PROC_STOP_CREATE 0x02 /* wait on dpr_cv at process exec */ 65*0Sstevel@tonic-gate #define DT_PROC_STOP_GRAB 0x04 /* wait on dpr_cv at process grab */ 66*0Sstevel@tonic-gate #define DT_PROC_STOP_PREINIT 0x08 /* wait on dpr_cv at rtld preinit */ 67*0Sstevel@tonic-gate #define DT_PROC_STOP_POSTINIT 0x10 /* wait on dpr_cv at rtld postinit */ 68*0Sstevel@tonic-gate #define DT_PROC_STOP_MAIN 0x20 /* wait on dpr_cv at a.out`main() */ 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate typedef void dt_bkpt_f(dtrace_hdl_t *, dt_proc_t *, void *); 71*0Sstevel@tonic-gate 72*0Sstevel@tonic-gate typedef struct dt_bkpt { 73*0Sstevel@tonic-gate dt_list_t dbp_list; /* prev/next pointers for bkpt list */ 74*0Sstevel@tonic-gate dt_bkpt_f *dbp_func; /* callback function to execute */ 75*0Sstevel@tonic-gate void *dbp_data; /* callback function private data */ 76*0Sstevel@tonic-gate uintptr_t dbp_addr; /* virtual address of breakpoint */ 77*0Sstevel@tonic-gate ulong_t dbp_instr; /* saved instruction from breakpoint */ 78*0Sstevel@tonic-gate ulong_t dbp_hits; /* count of breakpoint hits for debug */ 79*0Sstevel@tonic-gate int dbp_active; /* flag indicating breakpoint is on */ 80*0Sstevel@tonic-gate } dt_bkpt_t; 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate typedef struct dt_proc_hash { 83*0Sstevel@tonic-gate pthread_mutex_t dph_lock; /* lock protecting dph_notify list */ 84*0Sstevel@tonic-gate pthread_cond_t dph_cv; /* cond for waiting for dph_notify */ 85*0Sstevel@tonic-gate dt_proc_t *dph_notify; /* list of pending proc notifications */ 86*0Sstevel@tonic-gate dt_list_t dph_lrulist; /* list of dt_proc_t's in lru order */ 87*0Sstevel@tonic-gate uint_t dph_lrulim; /* limit on number of procs to hold */ 88*0Sstevel@tonic-gate uint_t dph_lrucnt; /* count of cached process handles */ 89*0Sstevel@tonic-gate uint_t dph_hashlen; /* size of hash chains array */ 90*0Sstevel@tonic-gate dt_proc_t *dph_hash[1]; /* hash chains array */ 91*0Sstevel@tonic-gate } dt_proc_hash_t; 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate extern struct ps_prochandle *dt_proc_create(dtrace_hdl_t *, 94*0Sstevel@tonic-gate const char *, char *const *); 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate extern struct ps_prochandle *dt_proc_grab(dtrace_hdl_t *, pid_t, int, int); 97*0Sstevel@tonic-gate extern void dt_proc_release(dtrace_hdl_t *, struct ps_prochandle *); 98*0Sstevel@tonic-gate extern void dt_proc_continue(dtrace_hdl_t *, struct ps_prochandle *); 99*0Sstevel@tonic-gate extern void dt_proc_lock(dtrace_hdl_t *, struct ps_prochandle *); 100*0Sstevel@tonic-gate extern void dt_proc_unlock(dtrace_hdl_t *, struct ps_prochandle *); 101*0Sstevel@tonic-gate extern dt_proc_t *dt_proc_lookup(dtrace_hdl_t *, struct ps_prochandle *, int); 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate extern void dt_proc_hash_create(dtrace_hdl_t *); 104*0Sstevel@tonic-gate extern void dt_proc_hash_destroy(dtrace_hdl_t *); 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate #ifdef __cplusplus 107*0Sstevel@tonic-gate } 108*0Sstevel@tonic-gate #endif 109*0Sstevel@tonic-gate 110*0Sstevel@tonic-gate #endif /* _DT_PROC_H */ 111