xref: /titanic_50/usr/src/lib/libdtrace/common/dt_proc.h (revision e5803b76927480e8f9b67b22201c484ccf4c2bcf)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5dcafa303Sahl  * Common Development and Distribution License (the "License").
6dcafa303Sahl  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21900524f3Sahl 
227c478bd9Sstevel@tonic-gate /*
23dcafa303Sahl  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
27*e5803b76SAdam H. Leventhal /*
28*e5803b76SAdam H. Leventhal  * Copyright (c) 2012 by Delphix. All rights reserved.
29*e5803b76SAdam H. Leventhal  */
30*e5803b76SAdam H. Leventhal 
317c478bd9Sstevel@tonic-gate #ifndef	_DT_PROC_H
327c478bd9Sstevel@tonic-gate #define	_DT_PROC_H
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <libproc.h>
357c478bd9Sstevel@tonic-gate #include <dtrace.h>
367c478bd9Sstevel@tonic-gate #include <pthread.h>
377c478bd9Sstevel@tonic-gate #include <dt_list.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
407c478bd9Sstevel@tonic-gate extern "C" {
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate typedef struct dt_proc {
447c478bd9Sstevel@tonic-gate 	dt_list_t dpr_list;		/* prev/next pointers for lru chain */
457c478bd9Sstevel@tonic-gate 	struct dt_proc *dpr_hash;	/* next pointer for pid hash chain */
467c478bd9Sstevel@tonic-gate 	dtrace_hdl_t *dpr_hdl;		/* back pointer to libdtrace handle */
477c478bd9Sstevel@tonic-gate 	struct ps_prochandle *dpr_proc;	/* proc handle for libproc calls */
48900524f3Sahl 	char dpr_errmsg[BUFSIZ];	/* error message */
497c478bd9Sstevel@tonic-gate 	rd_agent_t *dpr_rtld;		/* rtld handle for librtld_db calls */
507c478bd9Sstevel@tonic-gate 	pthread_mutex_t dpr_lock;	/* lock for manipulating dpr_hdl */
517c478bd9Sstevel@tonic-gate 	pthread_cond_t dpr_cv;		/* cond for dpr_stop/quit/done */
527c478bd9Sstevel@tonic-gate 	pid_t dpr_pid;			/* pid of process */
537c478bd9Sstevel@tonic-gate 	uint_t dpr_refs;		/* reference count */
547c478bd9Sstevel@tonic-gate 	uint8_t dpr_cacheable;		/* cache handle using lru list */
557c478bd9Sstevel@tonic-gate 	uint8_t dpr_stop;		/* stop mask: see flag bits below */
567c478bd9Sstevel@tonic-gate 	uint8_t dpr_quit;		/* quit flag: ctl thread should quit */
577c478bd9Sstevel@tonic-gate 	uint8_t dpr_done;		/* done flag: ctl thread has exited */
587c478bd9Sstevel@tonic-gate 	uint8_t dpr_usdt;		/* usdt flag: usdt initialized */
597c478bd9Sstevel@tonic-gate 	uint8_t dpr_stale;		/* proc flag: been deprecated */
607c478bd9Sstevel@tonic-gate 	uint8_t dpr_rdonly;		/* proc flag: opened read-only */
617c478bd9Sstevel@tonic-gate 	pthread_t dpr_tid;		/* control thread (or zero if none) */
627c478bd9Sstevel@tonic-gate 	dt_list_t dpr_bps;		/* list of dt_bkpt_t structures */
637c478bd9Sstevel@tonic-gate } dt_proc_t;
647c478bd9Sstevel@tonic-gate 
65900524f3Sahl typedef struct dt_proc_notify {
66900524f3Sahl 	dt_proc_t *dprn_dpr;		/* process associated with the event */
67900524f3Sahl 	char dprn_errmsg[BUFSIZ];	/* error message */
68900524f3Sahl 	struct dt_proc_notify *dprn_next; /* next pointer */
69900524f3Sahl } dt_proc_notify_t;
70900524f3Sahl 
717c478bd9Sstevel@tonic-gate #define	DT_PROC_STOP_IDLE	0x01	/* idle on owner's stop request */
727c478bd9Sstevel@tonic-gate #define	DT_PROC_STOP_CREATE	0x02	/* wait on dpr_cv at process exec */
737c478bd9Sstevel@tonic-gate #define	DT_PROC_STOP_GRAB	0x04	/* wait on dpr_cv at process grab */
747c478bd9Sstevel@tonic-gate #define	DT_PROC_STOP_PREINIT	0x08	/* wait on dpr_cv at rtld preinit */
757c478bd9Sstevel@tonic-gate #define	DT_PROC_STOP_POSTINIT	0x10	/* wait on dpr_cv at rtld postinit */
767c478bd9Sstevel@tonic-gate #define	DT_PROC_STOP_MAIN	0x20	/* wait on dpr_cv at a.out`main() */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate typedef void dt_bkpt_f(dtrace_hdl_t *, dt_proc_t *, void *);
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate typedef struct dt_bkpt {
817c478bd9Sstevel@tonic-gate 	dt_list_t dbp_list;		/* prev/next pointers for bkpt list */
827c478bd9Sstevel@tonic-gate 	dt_bkpt_f *dbp_func;		/* callback function to execute */
837c478bd9Sstevel@tonic-gate 	void *dbp_data;			/* callback function private data */
847c478bd9Sstevel@tonic-gate 	uintptr_t dbp_addr;		/* virtual address of breakpoint */
857c478bd9Sstevel@tonic-gate 	ulong_t dbp_instr;		/* saved instruction from breakpoint */
867c478bd9Sstevel@tonic-gate 	ulong_t dbp_hits;		/* count of breakpoint hits for debug */
877c478bd9Sstevel@tonic-gate 	int dbp_active;			/* flag indicating breakpoint is on */
887c478bd9Sstevel@tonic-gate } dt_bkpt_t;
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate typedef struct dt_proc_hash {
917c478bd9Sstevel@tonic-gate 	pthread_mutex_t dph_lock;	/* lock protecting dph_notify list */
927c478bd9Sstevel@tonic-gate 	pthread_cond_t dph_cv;		/* cond for waiting for dph_notify */
93900524f3Sahl 	dt_proc_notify_t *dph_notify;	/* list of pending proc notifications */
947c478bd9Sstevel@tonic-gate 	dt_list_t dph_lrulist;		/* list of dt_proc_t's in lru order */
957c478bd9Sstevel@tonic-gate 	uint_t dph_lrulim;		/* limit on number of procs to hold */
967c478bd9Sstevel@tonic-gate 	uint_t dph_lrucnt;		/* count of cached process handles */
977c478bd9Sstevel@tonic-gate 	uint_t dph_hashlen;		/* size of hash chains array */
987c478bd9Sstevel@tonic-gate 	dt_proc_t *dph_hash[1];		/* hash chains array */
997c478bd9Sstevel@tonic-gate } dt_proc_hash_t;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate extern struct ps_prochandle *dt_proc_create(dtrace_hdl_t *,
1027c478bd9Sstevel@tonic-gate     const char *, char *const *);
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate extern struct ps_prochandle *dt_proc_grab(dtrace_hdl_t *, pid_t, int, int);
1057c478bd9Sstevel@tonic-gate extern void dt_proc_release(dtrace_hdl_t *, struct ps_prochandle *);
1067c478bd9Sstevel@tonic-gate extern void dt_proc_continue(dtrace_hdl_t *, struct ps_prochandle *);
1077c478bd9Sstevel@tonic-gate extern void dt_proc_lock(dtrace_hdl_t *, struct ps_prochandle *);
1087c478bd9Sstevel@tonic-gate extern void dt_proc_unlock(dtrace_hdl_t *, struct ps_prochandle *);
1097c478bd9Sstevel@tonic-gate extern dt_proc_t *dt_proc_lookup(dtrace_hdl_t *, struct ps_prochandle *, int);
1107c478bd9Sstevel@tonic-gate 
111*e5803b76SAdam H. Leventhal extern void dt_proc_init(dtrace_hdl_t *);
112*e5803b76SAdam H. Leventhal extern void dt_proc_fini(dtrace_hdl_t *);
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate #endif
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate #endif	/* _DT_PROC_H */
119