xref: /titanic_44/usr/src/head/link.h (revision 4a634bb80136cc001d14ab96addd9915105e5223)
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 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _LINK_H
27 #define	_LINK_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/link.h>
32 
33 #ifndef _ASM
34 #include <libelf.h>
35 #include <sys/types.h>
36 #include <dlfcn.h>
37 #endif
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 #ifndef _ASM
44 /*
45  * ld support library calls
46  */
47 #ifdef __STDC__
48 extern uint_t	ld_version(uint_t);
49 extern void	ld_input_done(uint_t *);
50 
51 extern void	ld_start(const char *, const Elf32_Half, const char *);
52 extern void	ld_atexit(int);
53 extern void	ld_open(const char **, const char **, int *, int, Elf **,
54 			Elf *, size_t, const Elf_Kind);
55 extern void	ld_file(const char *, const Elf_Kind, int, Elf *);
56 extern void	ld_input_section(const char *, Elf32_Shdr **, Elf32_Word,
57 			Elf_Data *, Elf *, uint_t *);
58 extern void	ld_section(const char *, Elf32_Shdr *, Elf32_Word,
59 			Elf_Data *, Elf *);
60 
61 #if defined(_LP64) || defined(_LONGLONG_TYPE)
62 extern void	ld_start64(const char *, const Elf64_Half, const char *);
63 extern void	ld_atexit64(int);
64 extern void	ld_open64(const char **, const char **, int *, int, Elf **,
65 			Elf *, size_t, const Elf_Kind);
66 extern void	ld_file64(const char *, const Elf_Kind, int, Elf *);
67 extern void	ld_input_section64(const char *, Elf64_Shdr **, Elf64_Word,
68 			Elf_Data *, Elf *, uint_t *);
69 extern void	ld_section64(const char *, Elf64_Shdr *, Elf64_Word,
70 			Elf_Data *, Elf *);
71 
72 #endif /* (defined(_LP64) || defined(_LONGLONG_TYPE) */
73 #else
74 extern void	ld_version();
75 extern void	ld_input_done();
76 
77 extern void	ld_start();
78 extern void	ld_atexit();
79 extern void	ld_open();
80 extern void	ld_file();
81 extern void	ld_input_section();
82 extern void	ld_section();
83 
84 #if defined(_LP64) || defined(_LONGLONG_TYPE)
85 extern void	ld_start64();
86 extern void	ld_atexit64();
87 extern void	ld_open64();
88 extern void	ld_file64();
89 extern void	ld_input_section64();
90 extern void	ld_section64();
91 
92 #endif /* (defined(_LP64) || defined(_LONGLONG_TYPE) */
93 #endif /* __STDC__ */
94 
95 /*
96  * ld_version() version values.
97  */
98 #define	LD_SUP_VNONE	0
99 #define	LD_SUP_VERSION1	1
100 #define	LD_SUP_VERSION2	2
101 #define	LD_SUP_VERSION3	3
102 #define	LD_SUP_VCURRENT	LD_SUP_VERSION3
103 
104 /*
105  * Flags passed to ld support calls.
106  */
107 #define	LD_SUP_DERIVED		0x1	/* derived filename */
108 #define	LD_SUP_INHERITED	0x2	/* file inherited from .so DT_NEEDED */
109 #define	LD_SUP_EXTRACTED	0x4	/* file extracted from archive */
110 #endif
111 
112 /*
113  * Runtime link-map identifiers.
114  */
115 #define	LM_ID_BASE		0x00
116 #define	LM_ID_LDSO		0x01
117 #define	LM_ID_BRAND		0x02	/* marks branded objs in rd_loadobj_t */
118 
119 #define	LM_ID_NUM		3
120 
121 
122 #define	LM_ID_NEWLM		0xff	/* create a new link-map */
123 
124 /*
125  * Runtime Link-Edit Auditing.
126  */
127 #define	LAV_NONE		0
128 #define	LAV_VERSION1		1
129 #define	LAV_VERSION2		2
130 #define	LAV_VERSION3		3
131 #define	LAV_VERSION4		4
132 #define	LAV_CURRENT		LAV_VERSION4
133 #define	LAV_NUM			5
134 
135 /*
136  * Flags that can be or'd into the la_objopen() return code
137  */
138 #define	LA_FLG_BINDTO		0x0001	/* audit symbinds TO this object */
139 #define	LA_FLG_BINDFROM		0x0002	/* audit symbinding FROM this object */
140 
141 /*
142  * Flags that can be or'd into the 'flags' argument of la_symbind()
143  */
144 #define	LA_SYMB_NOPLTENTER	0x0001	/* disable pltenter for this symbol */
145 #define	LA_SYMB_NOPLTEXIT	0x0002	/* disable pltexit for this symbol */
146 #define	LA_SYMB_STRUCTCALL	0x0004	/* this function call passes a */
147 					/*	structure as it's return code */
148 #define	LA_SYMB_DLSYM		0x0008	/* this symbol bindings is due to */
149 					/*	a call to dlsym() */
150 #define	LA_SYMB_ALTVALUE	0x0010	/* alternate symbol binding returned */
151 					/*	by la_symbind() */
152 
153 /*
154  * Flags that describe the object passed to la_objsearch()
155  */
156 #define	LA_SER_ORIG		0x001	/* original (needed) name */
157 #define	LA_SER_LIBPATH		0x002	/* LD_LIBRARY_PATH entry prepended */
158 #define	LA_SER_RUNPATH		0x004	/* runpath entry prepended */
159 #define	LA_SER_CONFIG		0x008	/* configuration entry prepended */
160 #define	LA_SER_DEFAULT		0x040	/* default path prepended */
161 #define	LA_SER_SECURE		0x080	/* default (secure) path prepended */
162 
163 #define	LA_SER_MASK		0xfff	/* mask of known flags */
164 
165 /*
166  * Flags that describe the la_activity()
167  */
168 #define	LA_ACT_CONSISTENT	0x00	/* add/deletion of objects complete */
169 #define	LA_ACT_ADD		0x01	/* objects being added */
170 #define	LA_ACT_DELETE		0x02	/* objects being deleted */
171 
172 
173 #ifndef	_KERNEL
174 #ifndef	_ASM
175 
176 #if defined(_LP64)
177 typedef long	lagreg_t;
178 #else
179 typedef int	lagreg_t;
180 #endif
181 
182 struct _la_sparc_regs {
183 	lagreg_t	lr_rego0;
184 	lagreg_t	lr_rego1;
185 	lagreg_t	lr_rego2;
186 	lagreg_t	lr_rego3;
187 	lagreg_t	lr_rego4;
188 	lagreg_t	lr_rego5;
189 	lagreg_t	lr_rego6;
190 	lagreg_t	lr_rego7;
191 };
192 
193 #if defined(_LP64)
194 typedef struct _la_sparc_regs	La_sparcv9_regs;
195 typedef struct {
196 	lagreg_t	lr_rsp;
197 	lagreg_t	lr_rbp;
198 	lagreg_t	lr_rdi;	    /* arg1 */
199 	lagreg_t	lr_rsi;	    /* arg2 */
200 	lagreg_t	lr_rdx;	    /* arg3 */
201 	lagreg_t	lr_rcx;	    /* arg4 */
202 	lagreg_t	lr_r8;	    /* arg5 */
203 	lagreg_t	lr_r9;	    /* arg6 */
204 } La_amd64_regs;
205 #else
206 typedef struct _la_sparc_regs	La_sparcv8_regs;
207 typedef struct {
208 	lagreg_t	lr_esp;
209 	lagreg_t	lr_ebp;
210 } La_i86_regs;
211 #endif
212 
213 #if	!defined(_SYS_INT_TYPES_H)
214 #if	defined(_LP64) || defined(_I32LPx)
215 typedef unsigned long		uintptr_t;
216 #else
217 typedef	unsigned int		uintptr_t;
218 #endif
219 #endif
220 
221 
222 #ifdef	__STDC__
223 extern uint_t		la_version(uint_t);
224 extern void		la_activity(uintptr_t *, uint_t);
225 extern void		la_preinit(uintptr_t *);
226 extern char		*la_objsearch(const char *, uintptr_t *, uint_t);
227 extern uint_t		la_objopen(Link_map *, Lmid_t, uintptr_t *);
228 extern uint_t		la_objclose(uintptr_t *);
229 extern int		la_objfilter(uintptr_t *, const char *, uintptr_t *,
230 				uint_t);
231 #if	defined(_LP64)
232 extern uintptr_t	la_amd64_pltenter(Elf64_Sym *, uint_t, uintptr_t *,
233 				uintptr_t *, La_amd64_regs *,	uint_t *,
234 				const char *);
235 extern uintptr_t	la_symbind64(Elf64_Sym *, uint_t, uintptr_t *,
236 				uintptr_t *, uint_t *, const char *);
237 extern uintptr_t	la_sparcv9_pltenter(Elf64_Sym *, uint_t, uintptr_t *,
238 				uintptr_t *, La_sparcv9_regs *,	uint_t *,
239 				const char *);
240 extern uintptr_t	la_pltexit64(Elf64_Sym *, uint_t, uintptr_t *,
241 				uintptr_t *, uintptr_t, const char *);
242 #else  /* !defined(_LP64) */
243 extern uintptr_t	la_symbind32(Elf32_Sym *, uint_t, uintptr_t *,
244 				uintptr_t *, uint_t *);
245 extern uintptr_t	la_sparcv8_pltenter(Elf32_Sym *, uint_t, uintptr_t *,
246 				uintptr_t *, La_sparcv8_regs *, uint_t *);
247 extern uintptr_t	la_i86_pltenter(Elf32_Sym *, uint_t, uintptr_t *,
248 				uintptr_t *, La_i86_regs *, uint_t *);
249 extern uintptr_t	la_pltexit(Elf32_Sym *, uint_t, uintptr_t *,
250 				uintptr_t *, uintptr_t);
251 #endif /* _LP64 */
252 #else  /* __STDC__ */
253 extern uint_t		la_version();
254 extern void		la_preinit();
255 extern uint_t		la_objopen();
256 extern uint_t		la_objclose();
257 extern int		la_objfilter();
258 #if	defined(_LP64)
259 extern uintptr_t	la_sparcv9_pltenter();
260 extern uintptr_t	la_pltexit64();
261 extern uintptr_t	la_symbind64();
262 #else  /* _ILP32 */
263 extern uintptr_t	la_sparcv8_pltenter();
264 extern uintptr_t	la_i86_pltenter();
265 extern uintptr_t	la_pltexit();
266 extern uintptr_t	la_symbind32();
267 #endif /* _LP64 */
268 #endif /* __STDC__ */
269 
270 
271 #endif /* _ASM */
272 #endif /* _KERNEL */
273 
274 #ifdef __cplusplus
275 }
276 #endif
277 
278 #endif	/* _LINK_H */
279