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