xref: /titanic_44/usr/src/lib/libtnfctl/tnfctl_int.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  *      Copyright (c) 1994, by Sun Microsytems, Inc.
24*7c478bd9Sstevel@tonic-gate  */
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate #ifndef _TNFCTL_INT_H
27*7c478bd9Sstevel@tonic-gate #define	_TNFCTL_INT_H
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate /*
32*7c478bd9Sstevel@tonic-gate  * Interfaces private to libtnfctl
33*7c478bd9Sstevel@tonic-gate  *	layout of tnfctl handle structure
34*7c478bd9Sstevel@tonic-gate  *	layout of probe handle structure
35*7c478bd9Sstevel@tonic-gate  *	other misc. interfaces used across source files
36*7c478bd9Sstevel@tonic-gate  */
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
39*7c478bd9Sstevel@tonic-gate extern "C" {
40*7c478bd9Sstevel@tonic-gate #endif
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #include "tnfctl.h"
43*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
44*7c478bd9Sstevel@tonic-gate #include <gelf.h>
45*7c478bd9Sstevel@tonic-gate #include <libelf.h>
46*7c478bd9Sstevel@tonic-gate #include "prb_proc.h"
47*7c478bd9Sstevel@tonic-gate /* for warlock (lock_lint) static lock checking */
48*7c478bd9Sstevel@tonic-gate #include <note.h>
49*7c478bd9Sstevel@tonic-gate #include <thread.h>
50*7c478bd9Sstevel@tonic-gate #include <synch.h>
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate /*
53*7c478bd9Sstevel@tonic-gate  * This bogus structure is our way of getting around the fact that
54*7c478bd9Sstevel@tonic-gate  * warlock does not handle recursive locks (warlock does not complain
55*7c478bd9Sstevel@tonic-gate  * when anonymous locks, such as warlock_kludge->lmap_lock, are
56*7c478bd9Sstevel@tonic-gate  * multiply locked).
57*7c478bd9Sstevel@tonic-gate  */
58*7c478bd9Sstevel@tonic-gate #if defined(__lock_lint)
59*7c478bd9Sstevel@tonic-gate struct warlock {
60*7c478bd9Sstevel@tonic-gate 	mutex_t lmap_lock;
61*7c478bd9Sstevel@tonic-gate } *warlock_kludge;
62*7c478bd9Sstevel@tonic-gate #endif
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate /*
65*7c478bd9Sstevel@tonic-gate  * global variables used for INTERNAL_MODE synchronization with
66*7c478bd9Sstevel@tonic-gate  * dlopen's and dlclose's on another thread.
67*7c478bd9Sstevel@tonic-gate  */
68*7c478bd9Sstevel@tonic-gate extern mutex_t		_tnfctl_lmap_lock;
69*7c478bd9Sstevel@tonic-gate extern boolean_t	_tnfctl_libs_changed;
70*7c478bd9Sstevel@tonic-gate NOTE(MUTEX_PROTECTS_DATA(warlock::lmap_lock, _tnfctl_libs_changed))
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate /* Project private interface - function name in target */
73*7c478bd9Sstevel@tonic-gate #define	TRACE_END_FUNC		"tnf_trace_end"
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate /* All tnfctl handles are in one of the following 4 modes */
76*7c478bd9Sstevel@tonic-gate enum proc_mode {
77*7c478bd9Sstevel@tonic-gate 	KERNEL_MODE,		/* kernel tracing */
78*7c478bd9Sstevel@tonic-gate 	DIRECT_MODE,		/* tracing another process (exec or attach) */
79*7c478bd9Sstevel@tonic-gate 	INDIRECT_MODE,		/* client provides /proc functions */
80*7c478bd9Sstevel@tonic-gate 	INTERNAL_MODE		/* tracing probes in the same process */
81*7c478bd9Sstevel@tonic-gate };
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate typedef struct prbctlref prbctlref_t;
84*7c478bd9Sstevel@tonic-gate typedef struct objlist objlist_t;
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate /* per probe state - transient - freed on dlclose() */
87*7c478bd9Sstevel@tonic-gate struct prbctlref {
88*7c478bd9Sstevel@tonic-gate 	uintptr_t		addr;		/* probe address in target */
89*7c478bd9Sstevel@tonic-gate 	objlist_t		*obj;		/* obj that this probe is in */
90*7c478bd9Sstevel@tonic-gate 	ulong_t			probe_id;	/* assigned id */
91*7c478bd9Sstevel@tonic-gate 	char			*attr_string;
92*7c478bd9Sstevel@tonic-gate 	tnf_probe_control_t 	wrkprbctl;	/* probe struct from target */
93*7c478bd9Sstevel@tonic-gate 	tnfctl_probe_t		*probe_handle;	/* handle visible to client */
94*7c478bd9Sstevel@tonic-gate };
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate NOTE(SCHEME_PROTECTS_DATA("one thread per handle", prbctlref))
97*7c478bd9Sstevel@tonic-gate NOTE(MUTEX_PROTECTS_DATA(warlock::lmap_lock, prbctlref::{addr obj}))
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate /* per object state */
100*7c478bd9Sstevel@tonic-gate struct objlist {
101*7c478bd9Sstevel@tonic-gate 	boolean_t	new_probe;	/* relative to last library change */
102*7c478bd9Sstevel@tonic-gate 	boolean_t	new;		/* relative to last sync with linker */
103*7c478bd9Sstevel@tonic-gate 	boolean_t	old;		/* relative to last sync with linker */
104*7c478bd9Sstevel@tonic-gate 	char *		objname;
105*7c478bd9Sstevel@tonic-gate 	uintptr_t	baseaddr;
106*7c478bd9Sstevel@tonic-gate 	int		objfd;
107*7c478bd9Sstevel@tonic-gate 	uint_t		min_probe_num;	/* first probe id in object */
108*7c478bd9Sstevel@tonic-gate 	uint_t		probecnt;	/* number of probes in object */
109*7c478bd9Sstevel@tonic-gate 	prbctlref_t	*probes;	/* pointer to an array of probes */
110*7c478bd9Sstevel@tonic-gate 	objlist_t	*next;
111*7c478bd9Sstevel@tonic-gate };
112*7c478bd9Sstevel@tonic-gate NOTE(SCHEME_PROTECTS_DATA("one thread per handle", objlist))
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate /* per probe state that is freed only on tnfctl_close() */
115*7c478bd9Sstevel@tonic-gate struct tnfctl_probe_handle {
116*7c478bd9Sstevel@tonic-gate 	boolean_t	valid;
117*7c478bd9Sstevel@tonic-gate 	prbctlref_t	*probe_p;
118*7c478bd9Sstevel@tonic-gate 	void		*client_registered_data;
119*7c478bd9Sstevel@tonic-gate 	struct tnfctl_probe_handle *next;
120*7c478bd9Sstevel@tonic-gate };
121*7c478bd9Sstevel@tonic-gate NOTE(SCHEME_PROTECTS_DATA("one thread per handle", tnfctl_probe_handle))
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate /*
124*7c478bd9Sstevel@tonic-gate  * state saved per tnfctl handle
125*7c478bd9Sstevel@tonic-gate  */
126*7c478bd9Sstevel@tonic-gate struct tnfctl_handle {
127*7c478bd9Sstevel@tonic-gate 	void		*proc_p;	/* proc handle */
128*7c478bd9Sstevel@tonic-gate 	int		kfd;		/* kernel handle */
129*7c478bd9Sstevel@tonic-gate 	pid_t		targ_pid;	/* pid of target */
130*7c478bd9Sstevel@tonic-gate 	enum proc_mode	mode;		/* mode of handle */
131*7c478bd9Sstevel@tonic-gate 	/* tracing info */
132*7c478bd9Sstevel@tonic-gate 	const char 	*trace_file_name;
133*7c478bd9Sstevel@tonic-gate 	int		trace_buf_size;
134*7c478bd9Sstevel@tonic-gate 	int		trace_min_size;
135*7c478bd9Sstevel@tonic-gate 	tnfctl_bufstate_t	trace_buf_state;
136*7c478bd9Sstevel@tonic-gate 	boolean_t	trace_state;
137*7c478bd9Sstevel@tonic-gate 	boolean_t	kpidfilter_state;
138*7c478bd9Sstevel@tonic-gate 	boolean_t	called_exit;
139*7c478bd9Sstevel@tonic-gate 	/* addresses of functions in target */
140*7c478bd9Sstevel@tonic-gate 	uintptr_t	testfunc;
141*7c478bd9Sstevel@tonic-gate 	uintptr_t	allocfunc;
142*7c478bd9Sstevel@tonic-gate 	uintptr_t	commitfunc;
143*7c478bd9Sstevel@tonic-gate 	uintptr_t	endfunc;
144*7c478bd9Sstevel@tonic-gate 	uintptr_t	rollbackfunc;
145*7c478bd9Sstevel@tonic-gate 	uintptr_t	probelist_head;
146*7c478bd9Sstevel@tonic-gate 	uintptr_t	probelist_valid;
147*7c478bd9Sstevel@tonic-gate 	uintptr_t	trace_error;
148*7c478bd9Sstevel@tonic-gate 	uintptr_t	memseg_p;
149*7c478bd9Sstevel@tonic-gate 	uintptr_t	nonthread_test;
150*7c478bd9Sstevel@tonic-gate 	uintptr_t	thread_test;
151*7c478bd9Sstevel@tonic-gate 	uintptr_t	thread_sync;
152*7c478bd9Sstevel@tonic-gate 	boolean_t	mt_target;
153*7c478bd9Sstevel@tonic-gate 	uint_t		num_probes;	/* number of probes in target */
154*7c478bd9Sstevel@tonic-gate 	tnfctl_probe_t	*probe_handle_list_head;
155*7c478bd9Sstevel@tonic-gate 	/* object info */
156*7c478bd9Sstevel@tonic-gate 	boolean_t	in_objlist;	/* _tnfctl_lmap_lock reentrancy check */
157*7c478bd9Sstevel@tonic-gate 	objlist_t	*objlist;
158*7c478bd9Sstevel@tonic-gate 	/* combination info */
159*7c478bd9Sstevel@tonic-gate 	void		*buildroot;	/* root of built combinations */
160*7c478bd9Sstevel@tonic-gate 	void		*decoderoot;	/* root of decoded combinations */
161*7c478bd9Sstevel@tonic-gate 	/* per probe create/destroy functions */
162*7c478bd9Sstevel@tonic-gate 	void *(*create_func)(tnfctl_handle_t *, tnfctl_probe_t *);
163*7c478bd9Sstevel@tonic-gate 	void (*destroy_func)(void *);
164*7c478bd9Sstevel@tonic-gate 	/* functions to inspect target process */
165*7c478bd9Sstevel@tonic-gate 	int (*p_read)(void *prochandle, uintptr_t addr, void *buf, size_t size);
166*7c478bd9Sstevel@tonic-gate 	int (*p_write)(void *prochandle, uintptr_t addr,
167*7c478bd9Sstevel@tonic-gate 			void *buf, size_t size);
168*7c478bd9Sstevel@tonic-gate 	int (*p_obj_iter)(void *prochandle, tnfctl_ind_obj_f *func,
169*7c478bd9Sstevel@tonic-gate 						void *client_data);
170*7c478bd9Sstevel@tonic-gate 	pid_t (*p_getpid)(void *prochandle);
171*7c478bd9Sstevel@tonic-gate };
172*7c478bd9Sstevel@tonic-gate 
173*7c478bd9Sstevel@tonic-gate NOTE(SCHEME_PROTECTS_DATA("one thread per handle", tnfctl_handle))
174*7c478bd9Sstevel@tonic-gate NOTE(MUTEX_PROTECTS_DATA(warlock::lmap_lock, tnfctl_handle::objlist))
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate typedef enum comb_op {
177*7c478bd9Sstevel@tonic-gate 	PRB_COMB_CHAIN = 0,	/* call the down, then the next */
178*7c478bd9Sstevel@tonic-gate 	PRB_COMB_COUNT = 1	/* how many? */
179*7c478bd9Sstevel@tonic-gate } comb_op_t;
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate enum event_op_t {
182*7c478bd9Sstevel@tonic-gate 	EVT_NONE,
183*7c478bd9Sstevel@tonic-gate 	EVT_OPEN,
184*7c478bd9Sstevel@tonic-gate 	EVT_CLOSE
185*7c478bd9Sstevel@tonic-gate };
186*7c478bd9Sstevel@tonic-gate 
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate /*
189*7c478bd9Sstevel@tonic-gate  * interfaces to search for symbols or to search for relocations
190*7c478bd9Sstevel@tonic-gate  * in an elf file
191*7c478bd9Sstevel@tonic-gate  */
192*7c478bd9Sstevel@tonic-gate typedef struct tnfctl_elf_search tnfctl_elf_search_t;
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate /* prototype for callback for traversing an elf section */
195*7c478bd9Sstevel@tonic-gate typedef tnfctl_errcode_t
196*7c478bd9Sstevel@tonic-gate (*tnfctl_traverse_section_func_t) (Elf * elf, char *strs, Elf_Scn * scn,
197*7c478bd9Sstevel@tonic-gate 	GElf_Shdr * shdr, Elf_Data * data, uintptr_t baseaddr,
198*7c478bd9Sstevel@tonic-gate 	tnfctl_elf_search_t * search_info);
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate /* prototype for callback for traversing records in an elf section */
201*7c478bd9Sstevel@tonic-gate typedef tnfctl_errcode_t
202*7c478bd9Sstevel@tonic-gate (*tnfctl_record_func_t) (char *name, uintptr_t addr, void *entry,
203*7c478bd9Sstevel@tonic-gate 	tnfctl_elf_search_t * search_info);
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate struct tnfctl_elf_search {
206*7c478bd9Sstevel@tonic-gate 	tnfctl_traverse_section_func_t	section_func;
207*7c478bd9Sstevel@tonic-gate 	void				*section_data;
208*7c478bd9Sstevel@tonic-gate 	tnfctl_record_func_t		record_func;
209*7c478bd9Sstevel@tonic-gate 	void				*record_data;
210*7c478bd9Sstevel@tonic-gate };
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate /* traverse all the sections in an object */
213*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_traverse_object(int objfd, uintptr_t addr,
214*7c478bd9Sstevel@tonic-gate 			tnfctl_elf_search_t *search_info_p);
215*7c478bd9Sstevel@tonic-gate /* search a .rela section */
216*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_traverse_rela(Elf * elf, char *strs, Elf_Scn * rel_scn,
217*7c478bd9Sstevel@tonic-gate 	GElf_Shdr * rel_shdr, Elf_Data * rel_data, uintptr_t baseaddr,
218*7c478bd9Sstevel@tonic-gate 	tnfctl_elf_search_t * search_info_p);
219*7c478bd9Sstevel@tonic-gate /* search a .dynsym section */
220*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_traverse_dynsym(Elf * elf, char *elfstrs,
221*7c478bd9Sstevel@tonic-gate 	Elf_Scn * scn, GElf_Shdr * shdr, Elf_Data * data, uintptr_t baseaddr,
222*7c478bd9Sstevel@tonic-gate 	tnfctl_elf_search_t * search_info_p);
223*7c478bd9Sstevel@tonic-gate 
224*7c478bd9Sstevel@tonic-gate /* prototype of callback for internal probe traversal function */
225*7c478bd9Sstevel@tonic-gate typedef tnfctl_errcode_t
226*7c478bd9Sstevel@tonic-gate (*_tnfctl_traverse_probe_func_t)(tnfctl_handle_t *, prbctlref_t *, void *);
227*7c478bd9Sstevel@tonic-gate 
228*7c478bd9Sstevel@tonic-gate /* sync up list of objects with that of the linker */
229*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_lmap_update(tnfctl_handle_t *hndl, boolean_t *lmap_ok,
230*7c478bd9Sstevel@tonic-gate 					enum event_op_t *evt);
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate /* sync up list of objects and probes */
233*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_refresh_process(tnfctl_handle_t *, boolean_t *,
234*7c478bd9Sstevel@tonic-gate 				enum event_op_t *);
235*7c478bd9Sstevel@tonic-gate 
236*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_set_state(tnfctl_handle_t *hndl);
237*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_create_tracefile(tnfctl_handle_t *hndl,
238*7c478bd9Sstevel@tonic-gate 		const char *trace_file_name, uint_t trace_file_size);
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate /* probe interfaces */
241*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_find_all_probes(tnfctl_handle_t *hndl);
242*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_probes_traverse(tnfctl_handle_t *hndl,
243*7c478bd9Sstevel@tonic-gate 	_tnfctl_traverse_probe_func_t func_p, void *calldata_p);
244*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_flush_a_probe(tnfctl_handle_t *hndl,
245*7c478bd9Sstevel@tonic-gate 	prbctlref_t *ref_p, size_t offset, size_t size);
246*7c478bd9Sstevel@tonic-gate 
247*7c478bd9Sstevel@tonic-gate /* combination interfaces */
248*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_comb_build(tnfctl_handle_t *hndl, comb_op_t op,
249*7c478bd9Sstevel@tonic-gate 	uintptr_t down, uintptr_t next, uintptr_t *comb_p);
250*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_comb_decode(tnfctl_handle_t *hndl, uintptr_t addr,
251*7c478bd9Sstevel@tonic-gate 	char ***func_names, uintptr_t **func_addrs);
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate /* allocate memory in target process */
254*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_targmem_alloc(tnfctl_handle_t *hndl, size_t size,
255*7c478bd9Sstevel@tonic-gate 			uintptr_t *addr_p);
256*7c478bd9Sstevel@tonic-gate 
257*7c478bd9Sstevel@tonic-gate /* inprocess "plug ins" for functions in tnfctl_handle_t structure */
258*7c478bd9Sstevel@tonic-gate int _tnfctl_read_targ(void *proc_p, uintptr_t addr, void *buf, size_t size);
259*7c478bd9Sstevel@tonic-gate int _tnfctl_write_targ(void *proc_p, uintptr_t addr, void *buf, size_t size);
260*7c478bd9Sstevel@tonic-gate int _tnfctl_loadobj_iter(void *proc_p, tnfctl_ind_obj_f *func,
261*7c478bd9Sstevel@tonic-gate 			void *client_data);
262*7c478bd9Sstevel@tonic-gate pid_t _tnfctl_pid_get(void *proc_p);
263*7c478bd9Sstevel@tonic-gate 
264*7c478bd9Sstevel@tonic-gate /* read a string from the target process */
265*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_readstr_targ(tnfctl_handle_t *hndl, uintptr_t addr,
266*7c478bd9Sstevel@tonic-gate 				char **outstr_pp);
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate /* symbol searching interfaces */
269*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_sym_find_in_obj(int objfd, uintptr_t baseaddr,
270*7c478bd9Sstevel@tonic-gate 		const char *symname, uintptr_t *symaddr);
271*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_sym_obj_find(tnfctl_handle_t *hndl,
272*7c478bd9Sstevel@tonic-gate 	const char *lib_base_name, const char *symname, uintptr_t *symaddr);
273*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_sym_find(tnfctl_handle_t *hndl, const char *symname,
274*7c478bd9Sstevel@tonic-gate 			uintptr_t *symaddr);
275*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_sym_findname(tnfctl_handle_t *hndl, uintptr_t symaddr,
276*7c478bd9Sstevel@tonic-gate 	char **symname);
277*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_elf_dbgent(tnfctl_handle_t *hndl,
278*7c478bd9Sstevel@tonic-gate 				uintptr_t * entaddr_p);
279*7c478bd9Sstevel@tonic-gate 
280*7c478bd9Sstevel@tonic-gate /* free objs and probes */
281*7c478bd9Sstevel@tonic-gate void _tnfctl_free_objs_and_probes(tnfctl_handle_t *);
282*7c478bd9Sstevel@tonic-gate 
283*7c478bd9Sstevel@tonic-gate /* locking interfaces */
284*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_lock_libs(tnfctl_handle_t *hndl,
285*7c478bd9Sstevel@tonic-gate 	boolean_t *release_lock);
286*7c478bd9Sstevel@tonic-gate void _tnfctl_unlock_libs(tnfctl_handle_t *hndl, boolean_t release_lock);
287*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_sync_lib_list(tnfctl_handle_t *hndl);
288*7c478bd9Sstevel@tonic-gate 
289*7c478bd9Sstevel@tonic-gate /*
290*7c478bd9Sstevel@tonic-gate  * BugID 1253419
291*7c478bd9Sstevel@tonic-gate  * The flags that indicate if in/external trace control is active.
292*7c478bd9Sstevel@tonic-gate  * Used to prevent simultaneous internal and external probe control.
293*7c478bd9Sstevel@tonic-gate  * For external control keep pid of traced process to handle case
294*7c478bd9Sstevel@tonic-gate  * where process forks. (child is not under external control)
295*7c478bd9Sstevel@tonic-gate  */
296*7c478bd9Sstevel@tonic-gate #define	TNFCTL_INTERNAL_TRACEFLAG	"_tnfctl_internal_tracing_flag"
297*7c478bd9Sstevel@tonic-gate #define	TNFCTL_EXTERNAL_TRACEDPID	"_tnfctl_externally_traced_pid"
298*7c478bd9Sstevel@tonic-gate extern boolean_t _tnfctl_internal_tracing_flag;
299*7c478bd9Sstevel@tonic-gate extern pid_t _tnfctl_externally_traced_pid;
300*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_internal_getlock(void);
301*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_external_getlock(tnfctl_handle_t *hndl);
302*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_internal_releaselock(void);
303*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_external_releaselock(tnfctl_handle_t *hndl);
304*7c478bd9Sstevel@tonic-gate 
305*7c478bd9Sstevel@tonic-gate /* error mapping functions */
306*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_map_to_errcode(prb_status_t prbstat);
307*7c478bd9Sstevel@tonic-gate tnfctl_errcode_t tnfctl_status_map(int);
308*7c478bd9Sstevel@tonic-gate 
309*7c478bd9Sstevel@tonic-gate 
310*7c478bd9Sstevel@tonic-gate /*
311*7c478bd9Sstevel@tonic-gate  * LOCK is the macro to lock down the library list so that a dlopen or
312*7c478bd9Sstevel@tonic-gate  * dlclose by another thread will block waiting for the lock to be released.
313*7c478bd9Sstevel@tonic-gate  *
314*7c478bd9Sstevel@tonic-gate  * LOCK_SYNC does the same as LOCK + it syncs up libtnfctl's cache of
315*7c478bd9Sstevel@tonic-gate  * libraries in target process with that of what the run time linker maintains.
316*7c478bd9Sstevel@tonic-gate  *
317*7c478bd9Sstevel@tonic-gate  * These macros do conditional locking because they are needed only by
318*7c478bd9Sstevel@tonic-gate  * INTERNAL_MODE clients.  There are 2 versions of these macros so that
319*7c478bd9Sstevel@tonic-gate  * lock_lint won't have to see the conditional locking.
320*7c478bd9Sstevel@tonic-gate  * CAUTION: Be aware that these macros have a return() embedded in them.
321*7c478bd9Sstevel@tonic-gate  */
322*7c478bd9Sstevel@tonic-gate #ifdef __lock_lint
323*7c478bd9Sstevel@tonic-gate 
324*7c478bd9Sstevel@tonic-gate #define	LOCK(hndl, stat, release) (void) _tnfctl_lock_libs(hndl, &release)
325*7c478bd9Sstevel@tonic-gate 
326*7c478bd9Sstevel@tonic-gate #define	LOCK_SYNC(hndl, stat, release)					\
327*7c478bd9Sstevel@tonic-gate 	(void) _tnfctl_lock_libs(hndl, &release); 			\
328*7c478bd9Sstevel@tonic-gate 	(void) _tnfctl_sync_lib_list(hndl)
329*7c478bd9Sstevel@tonic-gate 
330*7c478bd9Sstevel@tonic-gate #define	UNLOCK(hndl, release)	_tnfctl_unlock_libs(hndl, release)
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate #else
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate #define	LOCK(hndl, stat, release)					\
335*7c478bd9Sstevel@tonic-gate 	if (hndl->mode == INTERNAL_MODE) {				\
336*7c478bd9Sstevel@tonic-gate 		stat = _tnfctl_lock_libs(hndl, &release);		\
337*7c478bd9Sstevel@tonic-gate 		if (stat)						\
338*7c478bd9Sstevel@tonic-gate 			return (stat);					\
339*7c478bd9Sstevel@tonic-gate 	}								\
340*7c478bd9Sstevel@tonic-gate 	else
341*7c478bd9Sstevel@tonic-gate 
342*7c478bd9Sstevel@tonic-gate #define	LOCK_SYNC(hndl, stat, release)					\
343*7c478bd9Sstevel@tonic-gate 	if (hndl->mode == INTERNAL_MODE) {				\
344*7c478bd9Sstevel@tonic-gate 		stat = _tnfctl_lock_libs(hndl, &release);		\
345*7c478bd9Sstevel@tonic-gate 		if (stat)						\
346*7c478bd9Sstevel@tonic-gate 			return (stat);					\
347*7c478bd9Sstevel@tonic-gate 		stat = _tnfctl_sync_lib_list(hndl);			\
348*7c478bd9Sstevel@tonic-gate 		if (stat) {						\
349*7c478bd9Sstevel@tonic-gate 			_tnfctl_unlock_libs(hndl, release);		\
350*7c478bd9Sstevel@tonic-gate 			return (stat);					\
351*7c478bd9Sstevel@tonic-gate 		}							\
352*7c478bd9Sstevel@tonic-gate 	}								\
353*7c478bd9Sstevel@tonic-gate 	else
354*7c478bd9Sstevel@tonic-gate 
355*7c478bd9Sstevel@tonic-gate #define	UNLOCK(hndl, release)						\
356*7c478bd9Sstevel@tonic-gate 	if (hndl->mode == INTERNAL_MODE)				\
357*7c478bd9Sstevel@tonic-gate 		_tnfctl_unlock_libs(hndl, release_lock);		\
358*7c478bd9Sstevel@tonic-gate 	else
359*7c478bd9Sstevel@tonic-gate 
360*7c478bd9Sstevel@tonic-gate #endif
361*7c478bd9Sstevel@tonic-gate 
362*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
363*7c478bd9Sstevel@tonic-gate }
364*7c478bd9Sstevel@tonic-gate #endif
365*7c478bd9Sstevel@tonic-gate 
366*7c478bd9Sstevel@tonic-gate #endif /* _TNFCTL_INT_H */
367