xref: /onnv-gate/usr/src/lib/libdtrace/common/dt_proc.h (revision 1399:f3a549d00510)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
22*1399Sahl 
230Sstevel@tonic-gate /*
24*1399Sahl  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
250Sstevel@tonic-gate  * Use is subject to license terms.
260Sstevel@tonic-gate  */
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #ifndef	_DT_PROC_H
290Sstevel@tonic-gate #define	_DT_PROC_H
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <libproc.h>
340Sstevel@tonic-gate #include <dtrace.h>
350Sstevel@tonic-gate #include <pthread.h>
360Sstevel@tonic-gate #include <dt_list.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #ifdef	__cplusplus
390Sstevel@tonic-gate extern "C" {
400Sstevel@tonic-gate #endif
410Sstevel@tonic-gate 
420Sstevel@tonic-gate typedef struct dt_proc {
430Sstevel@tonic-gate 	dt_list_t dpr_list;		/* prev/next pointers for lru chain */
440Sstevel@tonic-gate 	struct dt_proc *dpr_hash;	/* next pointer for pid hash chain */
450Sstevel@tonic-gate 	dtrace_hdl_t *dpr_hdl;		/* back pointer to libdtrace handle */
460Sstevel@tonic-gate 	struct ps_prochandle *dpr_proc;	/* proc handle for libproc calls */
47*1399Sahl 	char dpr_errmsg[BUFSIZ];	/* error message */
480Sstevel@tonic-gate 	rd_agent_t *dpr_rtld;		/* rtld handle for librtld_db calls */
490Sstevel@tonic-gate 	pthread_mutex_t dpr_lock;	/* lock for manipulating dpr_hdl */
500Sstevel@tonic-gate 	pthread_cond_t dpr_cv;		/* cond for dpr_stop/quit/done */
510Sstevel@tonic-gate 	pid_t dpr_pid;			/* pid of process */
520Sstevel@tonic-gate 	uint_t dpr_refs;		/* reference count */
530Sstevel@tonic-gate 	uint8_t dpr_cacheable;		/* cache handle using lru list */
540Sstevel@tonic-gate 	uint8_t dpr_stop;		/* stop mask: see flag bits below */
550Sstevel@tonic-gate 	uint8_t dpr_quit;		/* quit flag: ctl thread should quit */
560Sstevel@tonic-gate 	uint8_t dpr_done;		/* done flag: ctl thread has exited */
570Sstevel@tonic-gate 	uint8_t dpr_usdt;		/* usdt flag: usdt initialized */
580Sstevel@tonic-gate 	uint8_t dpr_stale;		/* proc flag: been deprecated */
590Sstevel@tonic-gate 	uint8_t dpr_rdonly;		/* proc flag: opened read-only */
600Sstevel@tonic-gate 	pthread_t dpr_tid;		/* control thread (or zero if none) */
610Sstevel@tonic-gate 	dt_list_t dpr_bps;		/* list of dt_bkpt_t structures */
620Sstevel@tonic-gate } dt_proc_t;
630Sstevel@tonic-gate 
64*1399Sahl typedef struct dt_proc_notify {
65*1399Sahl 	dt_proc_t *dprn_dpr;		/* process associated with the event */
66*1399Sahl 	char dprn_errmsg[BUFSIZ];	/* error message */
67*1399Sahl 	struct dt_proc_notify *dprn_next; /* next pointer */
68*1399Sahl } dt_proc_notify_t;
69*1399Sahl 
700Sstevel@tonic-gate #define	DT_PROC_STOP_IDLE	0x01	/* idle on owner's stop request */
710Sstevel@tonic-gate #define	DT_PROC_STOP_CREATE	0x02	/* wait on dpr_cv at process exec */
720Sstevel@tonic-gate #define	DT_PROC_STOP_GRAB	0x04	/* wait on dpr_cv at process grab */
730Sstevel@tonic-gate #define	DT_PROC_STOP_PREINIT	0x08	/* wait on dpr_cv at rtld preinit */
740Sstevel@tonic-gate #define	DT_PROC_STOP_POSTINIT	0x10	/* wait on dpr_cv at rtld postinit */
750Sstevel@tonic-gate #define	DT_PROC_STOP_MAIN	0x20	/* wait on dpr_cv at a.out`main() */
760Sstevel@tonic-gate 
770Sstevel@tonic-gate typedef void dt_bkpt_f(dtrace_hdl_t *, dt_proc_t *, void *);
780Sstevel@tonic-gate 
790Sstevel@tonic-gate typedef struct dt_bkpt {
800Sstevel@tonic-gate 	dt_list_t dbp_list;		/* prev/next pointers for bkpt list */
810Sstevel@tonic-gate 	dt_bkpt_f *dbp_func;		/* callback function to execute */
820Sstevel@tonic-gate 	void *dbp_data;			/* callback function private data */
830Sstevel@tonic-gate 	uintptr_t dbp_addr;		/* virtual address of breakpoint */
840Sstevel@tonic-gate 	ulong_t dbp_instr;		/* saved instruction from breakpoint */
850Sstevel@tonic-gate 	ulong_t dbp_hits;		/* count of breakpoint hits for debug */
860Sstevel@tonic-gate 	int dbp_active;			/* flag indicating breakpoint is on */
870Sstevel@tonic-gate } dt_bkpt_t;
880Sstevel@tonic-gate 
890Sstevel@tonic-gate typedef struct dt_proc_hash {
900Sstevel@tonic-gate 	pthread_mutex_t dph_lock;	/* lock protecting dph_notify list */
910Sstevel@tonic-gate 	pthread_cond_t dph_cv;		/* cond for waiting for dph_notify */
92*1399Sahl 	dt_proc_notify_t *dph_notify;	/* list of pending proc notifications */
930Sstevel@tonic-gate 	dt_list_t dph_lrulist;		/* list of dt_proc_t's in lru order */
940Sstevel@tonic-gate 	uint_t dph_lrulim;		/* limit on number of procs to hold */
950Sstevel@tonic-gate 	uint_t dph_lrucnt;		/* count of cached process handles */
960Sstevel@tonic-gate 	uint_t dph_hashlen;		/* size of hash chains array */
970Sstevel@tonic-gate 	dt_proc_t *dph_hash[1];		/* hash chains array */
980Sstevel@tonic-gate } dt_proc_hash_t;
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate extern struct ps_prochandle *dt_proc_create(dtrace_hdl_t *,
1010Sstevel@tonic-gate     const char *, char *const *);
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate extern struct ps_prochandle *dt_proc_grab(dtrace_hdl_t *, pid_t, int, int);
1040Sstevel@tonic-gate extern void dt_proc_release(dtrace_hdl_t *, struct ps_prochandle *);
1050Sstevel@tonic-gate extern void dt_proc_continue(dtrace_hdl_t *, struct ps_prochandle *);
1060Sstevel@tonic-gate extern void dt_proc_lock(dtrace_hdl_t *, struct ps_prochandle *);
1070Sstevel@tonic-gate extern void dt_proc_unlock(dtrace_hdl_t *, struct ps_prochandle *);
1080Sstevel@tonic-gate extern dt_proc_t *dt_proc_lookup(dtrace_hdl_t *, struct ps_prochandle *, int);
1090Sstevel@tonic-gate 
110*1399Sahl extern void dt_proc_bpenable(dt_proc_t *);
111*1399Sahl extern void dt_proc_bpdisable(dt_proc_t *);
112*1399Sahl 
1130Sstevel@tonic-gate extern void dt_proc_hash_create(dtrace_hdl_t *);
1140Sstevel@tonic-gate extern void dt_proc_hash_destroy(dtrace_hdl_t *);
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate #ifdef	__cplusplus
1170Sstevel@tonic-gate }
1180Sstevel@tonic-gate #endif
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate #endif	/* _DT_PROC_H */
121