dt_proc.h revision 178529
117987Speter/* 217987Speter * CDDL HEADER START 31556Srgrimes * 41556Srgrimes * The contents of this file are subject to the terms of the 517987Speter * Common Development and Distribution License (the "License"). 61556Srgrimes * You may not use this file except in compliance with the License. 717987Speter * 817987Speter * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 917987Speter * or http://www.opensolaris.org/os/licensing. 1017987Speter * See the License for the specific language governing permissions 1117987Speter * and limitations under the License. 1217987Speter * 1317987Speter * When distributing Covered Code, include this CDDL HEADER in each 1417987Speter * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1517987Speter * If applicable, add the following below this CDDL HEADER, with the 1617987Speter * fields enclosed by brackets "[]" replaced with your own identifying 171556Srgrimes * information: Portions Copyright [yyyy] [name of copyright owner] 181556Srgrimes * 1917987Speter * CDDL HEADER END 201556Srgrimes */ 211556Srgrimes 2217987Speter/* 2317987Speter * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 2417987Speter * Use is subject to license terms. 251556Srgrimes */ 2617987Speter 2713882Sjoerg#ifndef _DT_PROC_H 2817987Speter#define _DT_PROC_H 2917987Speter 301556Srgrimes#pragma ident "%Z%%M% %I% %E% SMI" 3117987Speter 3217987Speter#include <libproc.h> 331556Srgrimes#include <dtrace.h> 3417987Speter#include <pthread.h> 3517987Speter#include <dt_list.h> 361556Srgrimes 3717987Speter#ifdef __cplusplus 381556Srgrimesextern "C" { 391556Srgrimes#endif 401556Srgrimes 411556Srgrimestypedef struct dt_proc { 421556Srgrimes dt_list_t dpr_list; /* prev/next pointers for lru chain */ 4317987Speter struct dt_proc *dpr_hash; /* next pointer for pid hash chain */ 441556Srgrimes dtrace_hdl_t *dpr_hdl; /* back pointer to libdtrace handle */ 451556Srgrimes struct ps_prochandle *dpr_proc; /* proc handle for libproc calls */ 46 char dpr_errmsg[BUFSIZ]; /* error message */ 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 63typedef struct dt_proc_notify { 64 dt_proc_t *dprn_dpr; /* process associated with the event */ 65 char dprn_errmsg[BUFSIZ]; /* error message */ 66 struct dt_proc_notify *dprn_next; /* next pointer */ 67} dt_proc_notify_t; 68 69#define DT_PROC_STOP_IDLE 0x01 /* idle on owner's stop request */ 70#define DT_PROC_STOP_CREATE 0x02 /* wait on dpr_cv at process exec */ 71#define DT_PROC_STOP_GRAB 0x04 /* wait on dpr_cv at process grab */ 72#define DT_PROC_STOP_PREINIT 0x08 /* wait on dpr_cv at rtld preinit */ 73#define DT_PROC_STOP_POSTINIT 0x10 /* wait on dpr_cv at rtld postinit */ 74#define DT_PROC_STOP_MAIN 0x20 /* wait on dpr_cv at a.out`main() */ 75 76typedef void dt_bkpt_f(dtrace_hdl_t *, dt_proc_t *, void *); 77 78typedef struct dt_bkpt { 79 dt_list_t dbp_list; /* prev/next pointers for bkpt list */ 80 dt_bkpt_f *dbp_func; /* callback function to execute */ 81 void *dbp_data; /* callback function private data */ 82 uintptr_t dbp_addr; /* virtual address of breakpoint */ 83 ulong_t dbp_instr; /* saved instruction from breakpoint */ 84 ulong_t dbp_hits; /* count of breakpoint hits for debug */ 85 int dbp_active; /* flag indicating breakpoint is on */ 86} dt_bkpt_t; 87 88typedef struct dt_proc_hash { 89 pthread_mutex_t dph_lock; /* lock protecting dph_notify list */ 90 pthread_cond_t dph_cv; /* cond for waiting for dph_notify */ 91 dt_proc_notify_t *dph_notify; /* list of pending proc notifications */ 92 dt_list_t dph_lrulist; /* list of dt_proc_t's in lru order */ 93 uint_t dph_lrulim; /* limit on number of procs to hold */ 94 uint_t dph_lrucnt; /* count of cached process handles */ 95 uint_t dph_hashlen; /* size of hash chains array */ 96 dt_proc_t *dph_hash[1]; /* hash chains array */ 97} dt_proc_hash_t; 98 99extern struct ps_prochandle *dt_proc_create(dtrace_hdl_t *, 100 const char *, char *const *); 101 102extern struct ps_prochandle *dt_proc_grab(dtrace_hdl_t *, pid_t, int, int); 103extern void dt_proc_release(dtrace_hdl_t *, struct ps_prochandle *); 104extern void dt_proc_continue(dtrace_hdl_t *, struct ps_prochandle *); 105extern void dt_proc_lock(dtrace_hdl_t *, struct ps_prochandle *); 106extern void dt_proc_unlock(dtrace_hdl_t *, struct ps_prochandle *); 107extern dt_proc_t *dt_proc_lookup(dtrace_hdl_t *, struct ps_prochandle *, int); 108 109extern void dt_proc_hash_create(dtrace_hdl_t *); 110extern void dt_proc_hash_destroy(dtrace_hdl_t *); 111 112#ifdef __cplusplus 113} 114#endif 115 116#endif /* _DT_PROC_H */ 117