xref: /titanic_52/usr/src/head/rtld_db.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) 2001 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_RTLD_DB_H
28*7c478bd9Sstevel@tonic-gate #define	_RTLD_DB_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
34*7c478bd9Sstevel@tonic-gate extern "C" {
35*7c478bd9Sstevel@tonic-gate #endif
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/lwp.h>
39*7c478bd9Sstevel@tonic-gate #include <link.h>
40*7c478bd9Sstevel@tonic-gate #include <proc_service.h>
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate /*
44*7c478bd9Sstevel@tonic-gate  * librtld_db interface versions
45*7c478bd9Sstevel@tonic-gate  */
46*7c478bd9Sstevel@tonic-gate #define	RD_VERSION1	1
47*7c478bd9Sstevel@tonic-gate #define	RD_VERSION2	2
48*7c478bd9Sstevel@tonic-gate #define	RD_VERSION3	3
49*7c478bd9Sstevel@tonic-gate #define	RD_VERSION4	4
50*7c478bd9Sstevel@tonic-gate #define	RD_VERSION	RD_VERSION4
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate typedef enum {
53*7c478bd9Sstevel@tonic-gate 	RD_ERR,		/* generic */
54*7c478bd9Sstevel@tonic-gate 	RD_OK,		/* generic "call" succeeded */
55*7c478bd9Sstevel@tonic-gate 	RD_NOCAPAB,	/* capability not available */
56*7c478bd9Sstevel@tonic-gate 	RD_DBERR,	/* import service failed */
57*7c478bd9Sstevel@tonic-gate 	RD_NOBASE,	/* 5.x: aux tag AT_BASE not found */
58*7c478bd9Sstevel@tonic-gate 	RD_NODYNAM,	/* symbol 'DYNAMIC' not found */
59*7c478bd9Sstevel@tonic-gate 	RD_NOMAPS	/* link-maps are not yet available */
60*7c478bd9Sstevel@tonic-gate } rd_err_e;
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate /*
64*7c478bd9Sstevel@tonic-gate  * ways that the event notification can take place:
65*7c478bd9Sstevel@tonic-gate  */
66*7c478bd9Sstevel@tonic-gate typedef enum {
67*7c478bd9Sstevel@tonic-gate 	RD_NOTIFY_BPT,		/* set break-point at address */
68*7c478bd9Sstevel@tonic-gate 	RD_NOTIFY_AUTOBPT,	/* 4.x compat. not used in 5.x */
69*7c478bd9Sstevel@tonic-gate 	RD_NOTIFY_SYSCALL	/* watch for syscall */
70*7c478bd9Sstevel@tonic-gate } rd_notify_e;
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate /*
73*7c478bd9Sstevel@tonic-gate  * information on ways that the event notification can take place:
74*7c478bd9Sstevel@tonic-gate  */
75*7c478bd9Sstevel@tonic-gate typedef struct rd_notify {
76*7c478bd9Sstevel@tonic-gate 	rd_notify_e	type;
77*7c478bd9Sstevel@tonic-gate 	union {
78*7c478bd9Sstevel@tonic-gate 		psaddr_t	bptaddr;	/* break point address */
79*7c478bd9Sstevel@tonic-gate 		long		syscallno;	/* system call id */
80*7c478bd9Sstevel@tonic-gate 	} u;
81*7c478bd9Sstevel@tonic-gate } rd_notify_t;
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate /*
84*7c478bd9Sstevel@tonic-gate  * information about event instance:
85*7c478bd9Sstevel@tonic-gate  */
86*7c478bd9Sstevel@tonic-gate typedef enum {
87*7c478bd9Sstevel@tonic-gate 	RD_NOSTATE = 0,		/* no state information */
88*7c478bd9Sstevel@tonic-gate 	RD_CONSISTENT,		/* link-maps are stable */
89*7c478bd9Sstevel@tonic-gate 	RD_ADD,			/* currently adding object to link-maps */
90*7c478bd9Sstevel@tonic-gate 	RD_DELETE		/* currently deleteing object from link-maps */
91*7c478bd9Sstevel@tonic-gate } rd_state_e;
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate typedef struct rd_event_msg {
94*7c478bd9Sstevel@tonic-gate 	rd_event_e	type;
95*7c478bd9Sstevel@tonic-gate 	union {
96*7c478bd9Sstevel@tonic-gate 		rd_state_e	state;	/* for DLACTIVITY */
97*7c478bd9Sstevel@tonic-gate 	} u;
98*7c478bd9Sstevel@tonic-gate } rd_event_msg_t;
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate /*
102*7c478bd9Sstevel@tonic-gate  * iteration over load objects
103*7c478bd9Sstevel@tonic-gate  */
104*7c478bd9Sstevel@tonic-gate typedef struct rd_loadobj {
105*7c478bd9Sstevel@tonic-gate 	psaddr_t	rl_nameaddr;	/* address of the name in user space */
106*7c478bd9Sstevel@tonic-gate 	unsigned	rl_flags;
107*7c478bd9Sstevel@tonic-gate 	psaddr_t	rl_base;	/* base of address of code */
108*7c478bd9Sstevel@tonic-gate 	psaddr_t	rl_data_base;	/* base of address of data */
109*7c478bd9Sstevel@tonic-gate 	Lmid_t		rl_lmident;	/* ident of link map */
110*7c478bd9Sstevel@tonic-gate 	psaddr_t	rl_refnameaddr;	/* reference name of filter in user */
111*7c478bd9Sstevel@tonic-gate 					/* space.  If non null object is a */
112*7c478bd9Sstevel@tonic-gate 					/* filter. */
113*7c478bd9Sstevel@tonic-gate 	psaddr_t	rl_plt_base;	/* These fields are present for 4.x */
114*7c478bd9Sstevel@tonic-gate 	unsigned	rl_plt_size;	/* compatibility and are not */
115*7c478bd9Sstevel@tonic-gate 					/* currently used  in SunOS5.x */
116*7c478bd9Sstevel@tonic-gate 	psaddr_t	rl_bend;	/* end of image (text+data+bss) */
117*7c478bd9Sstevel@tonic-gate 	psaddr_t	rl_padstart;	/* start of padding */
118*7c478bd9Sstevel@tonic-gate 	psaddr_t	rl_padend;	/* end of image after padding */
119*7c478bd9Sstevel@tonic-gate 	psaddr_t	rl_dynamic;	/* points to the DYNAMIC section */
120*7c478bd9Sstevel@tonic-gate 					/* in the target process */
121*7c478bd9Sstevel@tonic-gate 	unsigned long	rl_tlsmodid;	/* module ID for TLS references */
122*7c478bd9Sstevel@tonic-gate } rd_loadobj_t;
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate /*
125*7c478bd9Sstevel@tonic-gate  * Values for rl_flags
126*7c478bd9Sstevel@tonic-gate  */
127*7c478bd9Sstevel@tonic-gate #define	RD_FLG_MEM_OBJECT	0x0001	/* Identifies this object as */
128*7c478bd9Sstevel@tonic-gate 					/* originating from a relocatable */
129*7c478bd9Sstevel@tonic-gate 					/* module which was dynamically */
130*7c478bd9Sstevel@tonic-gate 					/* loaded */
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate typedef struct rd_agent rd_agent_t;
134*7c478bd9Sstevel@tonic-gate #ifdef __STDC__
135*7c478bd9Sstevel@tonic-gate typedef int rl_iter_f(const rd_loadobj_t *, void *);
136*7c478bd9Sstevel@tonic-gate #else
137*7c478bd9Sstevel@tonic-gate typedef int rl_iter_f();
138*7c478bd9Sstevel@tonic-gate #endif
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate /*
142*7c478bd9Sstevel@tonic-gate  * PLT skipping
143*7c478bd9Sstevel@tonic-gate  */
144*7c478bd9Sstevel@tonic-gate typedef enum {
145*7c478bd9Sstevel@tonic-gate     RD_RESOLVE_NONE,		/* don't do anything special */
146*7c478bd9Sstevel@tonic-gate     RD_RESOLVE_STEP,		/* step 'pi_nstep' instructions */
147*7c478bd9Sstevel@tonic-gate     RD_RESOLVE_TARGET,		/* resolved target is in 'pi_target' */
148*7c478bd9Sstevel@tonic-gate     RD_RESOLVE_TARGET_STEP	/* put a bpt on target, then step nstep times */
149*7c478bd9Sstevel@tonic-gate } rd_skip_e;
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate typedef struct rd_plt_info {
153*7c478bd9Sstevel@tonic-gate 	rd_skip_e	pi_skip_method;
154*7c478bd9Sstevel@tonic-gate 	long		pi_nstep;
155*7c478bd9Sstevel@tonic-gate 	psaddr_t	pi_target;
156*7c478bd9Sstevel@tonic-gate 	psaddr_t	pi_baddr;
157*7c478bd9Sstevel@tonic-gate 	unsigned int	pi_flags;
158*7c478bd9Sstevel@tonic-gate } rd_plt_info_t;
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate /*
161*7c478bd9Sstevel@tonic-gate  * Values for pi_flags
162*7c478bd9Sstevel@tonic-gate  */
163*7c478bd9Sstevel@tonic-gate #define	RD_FLG_PI_PLTBOUND	0x0001	/* Indicates that the PLT */
164*7c478bd9Sstevel@tonic-gate 					/* has been bound - and that */
165*7c478bd9Sstevel@tonic-gate 					/* pi_baddr will contain it's */
166*7c478bd9Sstevel@tonic-gate 					/* destination address */
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate struct	ps_prochandle;
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate /*
171*7c478bd9Sstevel@tonic-gate  * librtld_db.so entry points
172*7c478bd9Sstevel@tonic-gate  */
173*7c478bd9Sstevel@tonic-gate #ifdef __STDC__
174*7c478bd9Sstevel@tonic-gate extern void		rd_delete(rd_agent_t *);
175*7c478bd9Sstevel@tonic-gate extern char *		rd_errstr(rd_err_e rderr);
176*7c478bd9Sstevel@tonic-gate extern rd_err_e		rd_event_addr(rd_agent_t *, rd_event_e, rd_notify_t *);
177*7c478bd9Sstevel@tonic-gate extern rd_err_e		rd_event_enable(rd_agent_t *, int);
178*7c478bd9Sstevel@tonic-gate extern rd_err_e		rd_event_getmsg(rd_agent_t *, rd_event_msg_t *);
179*7c478bd9Sstevel@tonic-gate extern rd_err_e		rd_init(int);
180*7c478bd9Sstevel@tonic-gate extern rd_err_e		rd_loadobj_iter(rd_agent_t *, rl_iter_f *,
181*7c478bd9Sstevel@tonic-gate 				void *);
182*7c478bd9Sstevel@tonic-gate extern void		rd_log(const int);
183*7c478bd9Sstevel@tonic-gate extern rd_agent_t *	rd_new(struct ps_prochandle *);
184*7c478bd9Sstevel@tonic-gate extern rd_err_e		rd_objpad_enable(struct rd_agent *, size_t);
185*7c478bd9Sstevel@tonic-gate extern rd_err_e		rd_plt_resolution(rd_agent_t *, psaddr_t, lwpid_t,
186*7c478bd9Sstevel@tonic-gate 				psaddr_t, rd_plt_info_t *);
187*7c478bd9Sstevel@tonic-gate extern rd_err_e		rd_reset(struct rd_agent *);
188*7c478bd9Sstevel@tonic-gate #else
189*7c478bd9Sstevel@tonic-gate extern void		rd_delete();
190*7c478bd9Sstevel@tonic-gate extern char *		rd_errstr();
191*7c478bd9Sstevel@tonic-gate extern rd_err_e		rd_event_addr();
192*7c478bd9Sstevel@tonic-gate extern rd_err_e		rd_event_enable();
193*7c478bd9Sstevel@tonic-gate extern rd_err_e		rd_event_getmsg();
194*7c478bd9Sstevel@tonic-gate extern rd_err_e		rd_init();
195*7c478bd9Sstevel@tonic-gate extern rd_err_e		rd_loadobj_iter();
196*7c478bd9Sstevel@tonic-gate extern void		rd_log();
197*7c478bd9Sstevel@tonic-gate extern rd_agent_t *	rd_new();
198*7c478bd9Sstevel@tonic-gate extern rd_err_e		rd_objpad_enable();
199*7c478bd9Sstevel@tonic-gate extern rd_err_e		rd_plt_resolution();
200*7c478bd9Sstevel@tonic-gate extern rd_err_e		rd_reset();
201*7c478bd9Sstevel@tonic-gate #endif
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
204*7c478bd9Sstevel@tonic-gate }
205*7c478bd9Sstevel@tonic-gate #endif
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate #endif	/* _RTLD_DB_H */
208