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