14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL HEADER START
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The contents of this file are subject to the terms of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Common Development and Distribution License (the "License").
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * You may not use this file except in compliance with the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * or http://www.opensolaris.org/os/licensing.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * See the License for the specific language governing permissions
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and limitations under the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * When distributing Covered Code, include this CDDL HEADER in each
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If applicable, add the following below this CDDL HEADER, with the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * fields enclosed by brackets "[]" replaced with your own identifying
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * information: Portions Copyright [yyyy] [name of copyright owner]
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL HEADER END
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Use is subject to license terms.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#ifndef _DT_PROC_H
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define _DT_PROC_H
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#pragma ident "%Z%%M% %I% %E% SMI"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <libproc.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <dtrace.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <pthread.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <dt_list.h>
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#else /* VBOX */
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync# include <dtrace.h>
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync# include <dt_list.h>
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync# include <iprt/critsect.h>
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#endif /* VBOX */
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#ifdef __cplusplus
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncextern "C" {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctypedef struct dt_proc {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_list_t dpr_list; /* prev/next pointers for lru chain */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct dt_proc *dpr_hash; /* next pointer for pid hash chain */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_hdl_t *dpr_hdl; /* back pointer to libdtrace handle */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct ps_prochandle *dpr_proc; /* proc handle for libproc calls */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char dpr_errmsg[BUFSIZ]; /* error message */
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rd_agent_t *dpr_rtld; /* rtld handle for librtld_db calls */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pthread_mutex_t dpr_lock; /* lock for manipulating dpr_hdl */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pthread_cond_t dpr_cv; /* cond for dpr_stop/quit/done */
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#else
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync RTCRITSECT dpr_lock;
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync RTSEMEVENT dpr_cv;
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pid_t dpr_pid; /* pid of process */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t dpr_refs; /* reference count */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint8_t dpr_cacheable; /* cache handle using lru list */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint8_t dpr_stop; /* stop mask: see flag bits below */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint8_t dpr_quit; /* quit flag: ctl thread should quit */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint8_t dpr_done; /* done flag: ctl thread has exited */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint8_t dpr_usdt; /* usdt flag: usdt initialized */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint8_t dpr_stale; /* proc flag: been deprecated */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint8_t dpr_rdonly; /* proc flag: opened read-only */
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pthread_t dpr_tid; /* control thread (or zero if none) */
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#else
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync RTTHREAD dpr_tid;
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_list_t dpr_bps; /* list of dt_bkpt_t structures */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync} dt_proc_t;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctypedef struct dt_proc_notify {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_proc_t *dprn_dpr; /* process associated with the event */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char dprn_errmsg[BUFSIZ]; /* error message */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct dt_proc_notify *dprn_next; /* next pointer */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync} dt_proc_notify_t;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define DT_PROC_STOP_IDLE 0x01 /* idle on owner's stop request */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define DT_PROC_STOP_CREATE 0x02 /* wait on dpr_cv at process exec */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define DT_PROC_STOP_GRAB 0x04 /* wait on dpr_cv at process grab */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define DT_PROC_STOP_PREINIT 0x08 /* wait on dpr_cv at rtld preinit */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define DT_PROC_STOP_POSTINIT 0x10 /* wait on dpr_cv at rtld postinit */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define DT_PROC_STOP_MAIN 0x20 /* wait on dpr_cv at a.out`main() */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctypedef void dt_bkpt_f(dtrace_hdl_t *, dt_proc_t *, void *);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctypedef struct dt_bkpt {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_list_t dbp_list; /* prev/next pointers for bkpt list */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_bkpt_f *dbp_func; /* callback function to execute */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync void *dbp_data; /* callback function private data */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uintptr_t dbp_addr; /* virtual address of breakpoint */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ulong_t dbp_instr; /* saved instruction from breakpoint */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ulong_t dbp_hits; /* count of breakpoint hits for debug */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int dbp_active; /* flag indicating breakpoint is on */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync} dt_bkpt_t;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctypedef struct dt_proc_hash {
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#ifndef VBOX
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pthread_mutex_t dph_lock; /* lock protecting dph_notify list */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync pthread_cond_t dph_cv; /* cond for waiting for dph_notify */
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#else
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync RTSEMEVENT dph_event;
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_proc_notify_t *dph_notify; /* list of pending proc notifications */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_list_t dph_lrulist; /* list of dt_proc_t's in lru order */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t dph_lrulim; /* limit on number of procs to hold */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t dph_lrucnt; /* count of cached process handles */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint_t dph_hashlen; /* size of hash chains array */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_proc_t *dph_hash[1]; /* hash chains array */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync} dt_proc_hash_t;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncextern struct ps_prochandle *dt_proc_create(dtrace_hdl_t *,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const char *, char *const *);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncextern struct ps_prochandle *dt_proc_grab(dtrace_hdl_t *, pid_t, int, int);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncextern void dt_proc_release(dtrace_hdl_t *, struct ps_prochandle *);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncextern void dt_proc_continue(dtrace_hdl_t *, struct ps_prochandle *);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncextern void dt_proc_lock(dtrace_hdl_t *, struct ps_prochandle *);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncextern void dt_proc_unlock(dtrace_hdl_t *, struct ps_prochandle *);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncextern dt_proc_t *dt_proc_lookup(dtrace_hdl_t *, struct ps_prochandle *, int);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncextern void dt_proc_hash_create(dtrace_hdl_t *);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncextern void dt_proc_hash_destroy(dtrace_hdl_t *);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#ifdef __cplusplus
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif /* _DT_PROC_H */