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