xref: /titanic_52/usr/src/head/link.h (revision 7eea693d6b672899726e75993fddc4e95b52647f)
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 2008 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_NUM		2
118 
119 #define	LM_ID_BRAND		0xfd	/* brand emulation linkmap objs */
120 #define	LM_ID_NONE		0xfe	/* no link map specified */
121 #define	LM_ID_NEWLM		0xff	/* create a new link-map */
122 
123 /*
124  * Runtime Link-Edit Auditing.
125  */
126 #define	LAV_NONE		0
127 #define	LAV_VERSION1		1
128 #define	LAV_VERSION2		2
129 #define	LAV_VERSION3		3
130 #define	LAV_VERSION4		4
131 #define	LAV_CURRENT		LAV_VERSION4
132 #define	LAV_NUM			5
133 
134 /*
135  * Flags that can be or'd into the la_objopen() return code
136  */
137 #define	LA_FLG_BINDTO		0x0001	/* audit symbinds TO this object */
138 #define	LA_FLG_BINDFROM		0x0002	/* audit symbinding FROM this object */
139 
140 /*
141  * Flags that can be or'd into the 'flags' argument of la_symbind()
142  */
143 #define	LA_SYMB_NOPLTENTER	0x0001	/* disable pltenter for this symbol */
144 #define	LA_SYMB_NOPLTEXIT	0x0002	/* disable pltexit for this symbol */
145 #define	LA_SYMB_STRUCTCALL	0x0004	/* this function call passes a */
146 					/*	structure as it's return code */
147 #define	LA_SYMB_DLSYM		0x0008	/* this symbol bindings is due to */
148 					/*	a call to dlsym() */
149 #define	LA_SYMB_ALTVALUE	0x0010	/* alternate symbol binding returned */
150 					/*	by la_symbind() */
151 
152 /*
153  * Flags that describe the object passed to la_objsearch()
154  */
155 #define	LA_SER_ORIG		0x001	/* original (needed) name */
156 #define	LA_SER_LIBPATH		0x002	/* LD_LIBRARY_PATH entry prepended */
157 #define	LA_SER_RUNPATH		0x004	/* runpath entry prepended */
158 #define	LA_SER_CONFIG		0x008	/* configuration entry prepended */
159 #define	LA_SER_DEFAULT		0x040	/* default path prepended */
160 #define	LA_SER_SECURE		0x080	/* default (secure) path prepended */
161 
162 #define	LA_SER_MASK		0xfff	/* mask of known flags */
163 
164 /*
165  * Flags that describe the la_activity()
166  */
167 #define	LA_ACT_CONSISTENT	0x00	/* add/deletion of objects complete */
168 #define	LA_ACT_ADD		0x01	/* objects being added */
169 #define	LA_ACT_DELETE		0x02	/* objects being deleted */
170 
171 
172 #ifndef	_KERNEL
173 #ifndef	_ASM
174 
175 #if defined(_LP64)
176 typedef long	lagreg_t;
177 #else
178 typedef int	lagreg_t;
179 #endif
180 
181 struct _la_sparc_regs {
182 	lagreg_t	lr_rego0;
183 	lagreg_t	lr_rego1;
184 	lagreg_t	lr_rego2;
185 	lagreg_t	lr_rego3;
186 	lagreg_t	lr_rego4;
187 	lagreg_t	lr_rego5;
188 	lagreg_t	lr_rego6;
189 	lagreg_t	lr_rego7;
190 };
191 
192 #if defined(_LP64)
193 typedef struct _la_sparc_regs	La_sparcv9_regs;
194 typedef struct {
195 	lagreg_t	lr_rsp;
196 	lagreg_t	lr_rbp;
197 	lagreg_t	lr_rdi;	    /* arg1 */
198 	lagreg_t	lr_rsi;	    /* arg2 */
199 	lagreg_t	lr_rdx;	    /* arg3 */
200 	lagreg_t	lr_rcx;	    /* arg4 */
201 	lagreg_t	lr_r8;	    /* arg5 */
202 	lagreg_t	lr_r9;	    /* arg6 */
203 } La_amd64_regs;
204 #else
205 typedef struct _la_sparc_regs	La_sparcv8_regs;
206 typedef struct {
207 	lagreg_t	lr_esp;
208 	lagreg_t	lr_ebp;
209 } La_i86_regs;
210 #endif
211 
212 #if	!defined(_SYS_INT_TYPES_H)
213 #if	defined(_LP64) || defined(_I32LPx)
214 typedef unsigned long		uintptr_t;
215 #else
216 typedef	unsigned int		uintptr_t;
217 #endif
218 #endif
219 
220 
221 #ifdef	__STDC__
222 extern uint_t		la_version(uint_t);
223 extern void		la_activity(uintptr_t *, uint_t);
224 extern void		la_preinit(uintptr_t *);
225 extern char		*la_objsearch(const char *, uintptr_t *, uint_t);
226 extern uint_t		la_objopen(Link_map *, Lmid_t, uintptr_t *);
227 extern uint_t		la_objclose(uintptr_t *);
228 extern int		la_objfilter(uintptr_t *, const char *, uintptr_t *,
229 				uint_t);
230 #if	defined(_LP64)
231 extern uintptr_t	la_amd64_pltenter(Elf64_Sym *, uint_t, uintptr_t *,
232 				uintptr_t *, La_amd64_regs *,	uint_t *,
233 				const char *);
234 extern uintptr_t	la_symbind64(Elf64_Sym *, uint_t, uintptr_t *,
235 				uintptr_t *, uint_t *, const char *);
236 extern uintptr_t	la_sparcv9_pltenter(Elf64_Sym *, uint_t, uintptr_t *,
237 				uintptr_t *, La_sparcv9_regs *,	uint_t *,
238 				const char *);
239 extern uintptr_t	la_pltexit64(Elf64_Sym *, uint_t, uintptr_t *,
240 				uintptr_t *, uintptr_t, const char *);
241 #else  /* !defined(_LP64) */
242 extern uintptr_t	la_symbind32(Elf32_Sym *, uint_t, uintptr_t *,
243 				uintptr_t *, uint_t *);
244 extern uintptr_t	la_sparcv8_pltenter(Elf32_Sym *, uint_t, uintptr_t *,
245 				uintptr_t *, La_sparcv8_regs *, uint_t *);
246 extern uintptr_t	la_i86_pltenter(Elf32_Sym *, uint_t, uintptr_t *,
247 				uintptr_t *, La_i86_regs *, uint_t *);
248 extern uintptr_t	la_pltexit(Elf32_Sym *, uint_t, uintptr_t *,
249 				uintptr_t *, uintptr_t);
250 #endif /* _LP64 */
251 #else  /* __STDC__ */
252 extern uint_t		la_version();
253 extern void		la_preinit();
254 extern uint_t		la_objopen();
255 extern uint_t		la_objclose();
256 extern int		la_objfilter();
257 #if	defined(_LP64)
258 extern uintptr_t	la_sparcv9_pltenter();
259 extern uintptr_t	la_pltexit64();
260 extern uintptr_t	la_symbind64();
261 #else  /* _ILP32 */
262 extern uintptr_t	la_sparcv8_pltenter();
263 extern uintptr_t	la_i86_pltenter();
264 extern uintptr_t	la_pltexit();
265 extern uintptr_t	la_symbind32();
266 #endif /* _LP64 */
267 #endif /* __STDC__ */
268 
269 
270 #endif /* _ASM */
271 #endif /* _KERNEL */
272 
273 #ifdef __cplusplus
274 }
275 #endif
276 
277 #endif	/* _LINK_H */
278