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