Path: blob/main/cddl/contrib/opensolaris/lib/libdtrace/common/dt_proc.h
39562 views
/*1* CDDL HEADER START2*3* The contents of this file are subject to the terms of the4* Common Development and Distribution License (the "License").5* You may not use this file except in compliance with the License.6*7* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE8* or http://www.opensolaris.org/os/licensing.9* See the License for the specific language governing permissions10* and limitations under the License.11*12* When distributing Covered Code, include this CDDL HEADER in each13* file and include the License file at usr/src/OPENSOLARIS.LICENSE.14* If applicable, add the following below this CDDL HEADER, with the15* fields enclosed by brackets "[]" replaced with your own identifying16* information: Portions Copyright [yyyy] [name of copyright owner]17*18* CDDL HEADER END19*/2021/*22* Copyright 2007 Sun Microsystems, Inc. All rights reserved.23* Use is subject to license terms.24*/2526/*27* Copyright (c) 2012 by Delphix. All rights reserved.28*/2930#ifndef _DT_PROC_H31#define _DT_PROC_H3233#include <libproc.h>34#include <dtrace.h>35#include <pthread.h>36#include <dt_list.h>3738#ifdef __cplusplus39extern "C" {40#endif4142enum dt_close_action {43DT_CLOSE_RUN,44DT_CLOSE_KILL,45};4647typedef struct dt_proc {48dt_list_t dpr_list; /* prev/next pointers for lru chain */49struct dt_proc *dpr_hash; /* next pointer for pid hash chain */50dtrace_hdl_t *dpr_hdl; /* back pointer to libdtrace handle */51struct ps_prochandle *dpr_proc; /* proc handle for libproc calls */52char dpr_errmsg[BUFSIZ]; /* error message */53rd_agent_t *dpr_rtld; /* rtld handle for librtld_db calls */54pthread_mutex_t dpr_lock; /* lock for manipulating dpr_hdl */55pthread_cond_t dpr_cv; /* cond for dpr_stop/quit/done */56pid_t dpr_pid; /* pid of process */57uint_t dpr_refs; /* reference count */58uint8_t dpr_cacheable; /* cache handle using lru list */59uint8_t dpr_stop; /* stop mask: see flag bits below */60uint8_t dpr_quit; /* quit flag: ctl thread should quit */61uint8_t dpr_done; /* done flag: ctl thread has exited */62uint8_t dpr_usdt; /* usdt flag: usdt initialized */63uint8_t dpr_stale; /* proc flag: been deprecated */64uint8_t dpr_rdonly; /* proc flag: opened read-only */65pthread_t dpr_tid; /* control thread (or zero if none) */66dt_list_t dpr_bps; /* list of dt_bkpt_t structures */67enum dt_close_action dpr_close; /* do this to child when exiting */68} dt_proc_t;6970typedef struct dt_proc_notify {71dt_proc_t *dprn_dpr; /* process associated with the event */72char dprn_errmsg[BUFSIZ]; /* error message */73struct dt_proc_notify *dprn_next; /* next pointer */74} dt_proc_notify_t;7576#define DT_PROC_STOP_IDLE 0x01 /* idle on owner's stop request */77#define DT_PROC_STOP_CREATE 0x02 /* wait on dpr_cv at process exec */78#define DT_PROC_STOP_GRAB 0x04 /* wait on dpr_cv at process grab */79#define DT_PROC_STOP_PREINIT 0x08 /* wait on dpr_cv at rtld preinit */80#define DT_PROC_STOP_POSTINIT 0x10 /* wait on dpr_cv at rtld postinit */81#define DT_PROC_STOP_MAIN 0x20 /* wait on dpr_cv at a.out`main() */8283typedef void dt_bkpt_f(dtrace_hdl_t *, dt_proc_t *, void *);8485typedef struct dt_bkpt {86dt_list_t dbp_list; /* prev/next pointers for bkpt list */87dt_bkpt_f *dbp_func; /* callback function to execute */88void *dbp_data; /* callback function private data */89uintptr_t dbp_addr; /* virtual address of breakpoint */90ulong_t dbp_instr; /* saved instruction from breakpoint */91ulong_t dbp_hits; /* count of breakpoint hits for debug */92int dbp_active; /* flag indicating breakpoint is on */93} dt_bkpt_t;9495typedef struct dt_proc_hash {96pthread_mutex_t dph_lock; /* lock protecting dph_notify list */97pthread_cond_t dph_cv; /* cond for waiting for dph_notify */98dt_proc_notify_t *dph_notify; /* list of pending proc notifications */99dt_list_t dph_lrulist; /* list of dt_proc_t's in lru order */100uint_t dph_lrulim; /* limit on number of procs to hold */101uint_t dph_lrucnt; /* count of cached process handles */102uint_t dph_hashlen; /* size of hash chains array */103dt_proc_t *dph_hash[1]; /* hash chains array */104} dt_proc_hash_t;105106extern struct ps_prochandle *dt_proc_create(dtrace_hdl_t *,107const char *, char *const *, proc_child_func *, void *);108109extern struct ps_prochandle *dt_proc_grab(dtrace_hdl_t *, pid_t, int, int);110extern void dt_proc_release(dtrace_hdl_t *, struct ps_prochandle *);111extern void dt_proc_continue(dtrace_hdl_t *, struct ps_prochandle *);112extern void dt_proc_lock(dtrace_hdl_t *, struct ps_prochandle *);113extern void dt_proc_unlock(dtrace_hdl_t *, struct ps_prochandle *);114extern dt_proc_t *dt_proc_lookup(dtrace_hdl_t *, struct ps_prochandle *, int);115116extern void dt_proc_init(dtrace_hdl_t *);117extern void dt_proc_fini(dtrace_hdl_t *);118119#ifdef __cplusplus120}121#endif122123#endif /* _DT_PROC_H */124125126