xref: /titanic_44/usr/src/head/rtld_db.h (revision 160abee025ef30c34521b981edd40ffcaab560aa)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_RTLD_DB_H
27 #define	_RTLD_DB_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 #include <sys/lwp.h>
38 #include <sys/elf.h>
39 #include <link.h>
40 #include <proc_service.h>
41 
42 
43 /*
44  * librtld_db interface versions
45  */
46 #define	RD_VERSION1	1
47 #define	RD_VERSION2	2
48 #define	RD_VERSION3	3
49 #define	RD_VERSION4	4
50 #define	RD_VERSION	RD_VERSION4
51 
52 typedef enum {
53 	RD_ERR,		/* generic */
54 	RD_OK,		/* generic "call" succeeded */
55 	RD_NOCAPAB,	/* capability not available */
56 	RD_DBERR,	/* import service failed */
57 	RD_NOBASE,	/* 5.x: aux tag AT_BASE not found */
58 	RD_NODYNAM,	/* symbol 'DYNAMIC' not found */
59 	RD_NOMAPS	/* link-maps are not yet available */
60 } rd_err_e;
61 
62 
63 /*
64  * ways that the event notification can take place:
65  */
66 typedef enum {
67 	RD_NOTIFY_BPT,		/* set break-point at address */
68 	RD_NOTIFY_AUTOBPT,	/* 4.x compat. not used in 5.x */
69 	RD_NOTIFY_SYSCALL	/* watch for syscall */
70 } rd_notify_e;
71 
72 /*
73  * information on ways that the event notification can take place:
74  */
75 typedef struct rd_notify {
76 	rd_notify_e	type;
77 	union {
78 		psaddr_t	bptaddr;	/* break point address */
79 		long		syscallno;	/* system call id */
80 	} u;
81 } rd_notify_t;
82 
83 /*
84  * information about event instance:
85  */
86 typedef enum {
87 	RD_NOSTATE = 0,		/* no state information */
88 	RD_CONSISTENT,		/* link-maps are stable */
89 	RD_ADD,			/* currently adding object to link-maps */
90 	RD_DELETE		/* currently deleteing object from link-maps */
91 } rd_state_e;
92 
93 typedef struct rd_event_msg {
94 	rd_event_e	type;
95 	union {
96 		rd_state_e	state;	/* for DLACTIVITY */
97 	} u;
98 } rd_event_msg_t;
99 
100 
101 /*
102  * iteration over load objects
103  */
104 typedef struct rd_loadobj {
105 	psaddr_t	rl_nameaddr;	/* address of the name in user space */
106 	unsigned	rl_flags;
107 	psaddr_t	rl_base;	/* base of address of code */
108 	psaddr_t	rl_data_base;	/* base of address of data */
109 	Lmid_t		rl_lmident;	/* ident of link map */
110 	psaddr_t	rl_refnameaddr;	/* reference name of filter in user */
111 					/* space.  If non null object is a */
112 					/* filter. */
113 	psaddr_t	rl_plt_base;	/* These fields are present for 4.x */
114 	unsigned	rl_plt_size;	/* compatibility and are not */
115 					/* currently used  in SunOS5.x */
116 	psaddr_t	rl_bend;	/* end of image (text+data+bss) */
117 	psaddr_t	rl_padstart;	/* start of padding */
118 	psaddr_t	rl_padend;	/* end of image after padding */
119 	psaddr_t	rl_dynamic;	/* points to the DYNAMIC section */
120 					/* in the target process */
121 	unsigned long	rl_tlsmodid;	/* module ID for TLS references */
122 } rd_loadobj_t;
123 
124 /*
125  * Values for rl_flags
126  */
127 #define	RD_FLG_MEM_OBJECT	0x0001	/* Identifies this object as */
128 					/* originating from a relocatable */
129 					/* module which was dynamically */
130 					/* loaded */
131 
132 /*
133  * Commands for rd_ctl()
134  */
135 #define	RD_CTL_SET_HELPPATH	0x01	/* Set the path used to find helpers */
136 
137 typedef struct rd_agent rd_agent_t;
138 #ifdef __STDC__
139 typedef int rl_iter_f(const rd_loadobj_t *, void *);
140 #else
141 typedef int rl_iter_f();
142 #endif
143 
144 
145 /*
146  * PLT skipping
147  */
148 typedef enum {
149     RD_RESOLVE_NONE,		/* don't do anything special */
150     RD_RESOLVE_STEP,		/* step 'pi_nstep' instructions */
151     RD_RESOLVE_TARGET,		/* resolved target is in 'pi_target' */
152     RD_RESOLVE_TARGET_STEP	/* put a bpt on target, then step nstep times */
153 } rd_skip_e;
154 
155 
156 typedef struct rd_plt_info {
157 	rd_skip_e	pi_skip_method;
158 	long		pi_nstep;
159 	psaddr_t	pi_target;
160 	psaddr_t	pi_baddr;
161 	unsigned int	pi_flags;
162 } rd_plt_info_t;
163 
164 /*
165  * State kept for brand helper libraries
166  */
167 typedef struct rd_helper_ops {
168 	void	*(*rho_init)(struct ps_prochandle *);
169 	int	(*rho_loadobj_iter)(struct ps_prochandle *, rl_iter_f *cb,
170 	    void *client_data, void *helper_data);
171 	void	(*rho_fix_phdrs)(struct rd_agent *, Elf32_Dyn *, size_t,
172 	    psaddr_t addr);
173 } rd_helper_ops_t;
174 
175 typedef struct rd_helper {
176 	rd_helper_ops_t	*rh_ops;
177 	void		*rh_data;
178 	void		*rh_dlhandle;
179 } rd_helper_t;
180 
181 /*
182  * Brand helper libraries must name their ops vector using this macro.
183  */
184 #define	RTLD_DB_BRAND_OPS rtld_db_brand_ops
185 
186 /*
187  * Values for pi_flags
188  */
189 #define	RD_FLG_PI_PLTBOUND	0x0001	/* Indicates that the PLT */
190 					/* has been bound - and that */
191 					/* pi_baddr will contain its */
192 					/* destination address */
193 
194 struct	ps_prochandle;
195 
196 /*
197  * librtld_db.so entry points
198  */
199 #ifdef __STDC__
200 extern void		rd_delete(rd_agent_t *);
201 extern char		*rd_errstr(rd_err_e rderr);
202 extern rd_err_e		rd_event_addr(rd_agent_t *, rd_event_e, rd_notify_t *);
203 extern rd_err_e		rd_event_enable(rd_agent_t *, int);
204 extern rd_err_e		rd_event_getmsg(rd_agent_t *, rd_event_msg_t *);
205 extern rd_err_e		rd_init(int);
206 extern rd_err_e		rd_ctl(int, void *);
207 extern rd_err_e		rd_loadobj_iter(rd_agent_t *, rl_iter_f *,
208 				void *);
209 extern void		rd_log(const int);
210 extern rd_agent_t	*rd_new(struct ps_prochandle *);
211 extern rd_err_e		rd_objpad_enable(struct rd_agent *, size_t);
212 extern rd_err_e		rd_plt_resolution(rd_agent_t *, psaddr_t, lwpid_t,
213 				psaddr_t, rd_plt_info_t *);
214 extern void		rd_fix_phdrs(struct rd_agent *, Elf32_Dyn *,
215     size_t, uintptr_t);
216 extern rd_err_e		rd_reset(struct rd_agent *);
217 #else
218 extern void		rd_delete();
219 extern char		*rd_errstr();
220 extern rd_err_e		rd_event_addr();
221 extern rd_err_e		rd_event_enable();
222 extern rd_err_e		rd_event_getmsg();
223 extern rd_err_e		rd_init();
224 extern rd_err_e		rd_ctl();
225 extern rd_err_e		rd_loadobj_iter();
226 extern void		rd_log();
227 extern rd_agent_t	*rd_new();
228 extern rd_err_e		rd_objpad_enable();
229 extern rd_err_e		rd_plt_resolution();
230 extern void		rd_fix_phdrs();
231 extern rd_err_e		rd_reset();
232 #endif
233 
234 #ifdef	__cplusplus
235 }
236 #endif
237 
238 #endif	/* _RTLD_DB_H */
239