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