xref: /titanic_52/usr/src/head/libelf.h (revision 1cb6af97c6f66f456d4f726ef056e1ebc0f73305)
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 /*	Copyright (c) 1988 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  *	Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28  *	Use is subject to license terms.
29  */
30 
31 #ifndef _LIBELF_H
32 #define	_LIBELF_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.9	*/
35 
36 #include <sys/types.h>
37 #include <sys/elf.h>
38 
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 
45 #if defined(_ILP32) && (_FILE_OFFSET_BITS != 32)
46 #error "large files are not supported by libelf"
47 #endif
48 
49 
50 #undef _
51 #ifdef __STDC__
52 typedef void		Elf_Void;
53 #define	_(a)		a
54 #else
55 typedef char		Elf_Void;
56 #define	_(a)		()
57 #undef const
58 #define	const
59 #endif
60 
61 
62 /*
63  * Commands
64  */
65 typedef enum {
66 	ELF_C_NULL = 0,	/* must be first, 0 */
67 	ELF_C_READ,
68 	ELF_C_WRITE,
69 	ELF_C_CLR,
70 	ELF_C_SET,
71 	ELF_C_FDDONE,
72 	ELF_C_FDREAD,
73 	ELF_C_RDWR,
74 	ELF_C_WRIMAGE,
75 	ELF_C_IMAGE,
76 	ELF_C_NUM	/* must be last */
77 } Elf_Cmd;
78 
79 
80 /*
81  * Flags
82  */
83 #define	ELF_F_DIRTY	0x1
84 #define	ELF_F_LAYOUT	0x4
85 
86 
87 /*
88  * File types
89  */
90 typedef enum {
91 	ELF_K_NONE = 0,	/* must be first, 0 */
92 	ELF_K_AR,
93 	ELF_K_COFF,
94 	ELF_K_ELF,
95 	ELF_K_NUM	/* must be last */
96 } Elf_Kind;
97 
98 
99 /*
100  * Translation types
101  */
102 typedef enum {
103 	ELF_T_BYTE = 0,	/* must be first, 0 */
104 	ELF_T_ADDR,
105 	ELF_T_DYN,
106 	ELF_T_EHDR,
107 	ELF_T_HALF,
108 	ELF_T_OFF,
109 	ELF_T_PHDR,
110 	ELF_T_RELA,
111 	ELF_T_REL,
112 	ELF_T_SHDR,
113 	ELF_T_SWORD,
114 	ELF_T_SYM,
115 	ELF_T_WORD,
116 	ELF_T_VDEF,
117 	ELF_T_VNEED,
118 	ELF_T_SXWORD,
119 	ELF_T_XWORD,
120 	ELF_T_SYMINFO,
121 	ELF_T_NOTE,
122 	ELF_T_MOVE,
123 	ELF_T_MOVEP,
124 	ELF_T_CAP,
125 	ELF_T_NUM	/* must be last */
126 } Elf_Type;
127 
128 
129 typedef struct Elf	Elf;
130 typedef struct Elf_Scn	Elf_Scn;
131 
132 
133 /*
134  * Archive member header
135  */
136 typedef struct {
137 	char		*ar_name;
138 	time_t		ar_date;
139 	uid_t		ar_uid;
140 	gid_t 		ar_gid;
141 	mode_t		ar_mode;
142 	off_t		ar_size;
143 	char 		*ar_rawname;
144 } Elf_Arhdr;
145 
146 
147 /*
148  * Archive symbol table
149  */
150 typedef struct {
151 	char		*as_name;
152 	size_t		as_off;
153 	unsigned long	as_hash;
154 } Elf_Arsym;
155 
156 
157 /*
158  * Data descriptor
159  */
160 typedef struct {
161 	Elf_Void	*d_buf;
162 	Elf_Type	d_type;
163 	size_t		d_size;
164 	off_t		d_off;		/* offset into section */
165 	size_t		d_align;	/* alignment in section */
166 	unsigned	d_version;	/* elf version */
167 } Elf_Data;
168 
169 
170 /*
171  * Function declarations
172  */
173 Elf		*elf_begin	_((int, Elf_Cmd, Elf *));
174 int		elf_cntl	_((Elf *, Elf_Cmd));
175 int		elf_end		_((Elf *));
176 const char	*elf_errmsg	_((int));
177 int		elf_errno	_((void));
178 void		elf_fill	_((int));
179 unsigned	elf_flagdata	_((Elf_Data *, Elf_Cmd, unsigned));
180 unsigned	elf_flagehdr	_((Elf *, Elf_Cmd,  unsigned));
181 unsigned	elf_flagelf	_((Elf *, Elf_Cmd, unsigned));
182 unsigned	elf_flagphdr	_((Elf *, Elf_Cmd, unsigned));
183 unsigned	elf_flagscn	_((Elf_Scn *, Elf_Cmd, unsigned));
184 unsigned	elf_flagshdr	_((Elf_Scn *, Elf_Cmd, unsigned));
185 size_t		elf32_fsize	_((Elf_Type, size_t, unsigned));
186 Elf_Arhdr	*elf_getarhdr	_((Elf *));
187 Elf_Arsym	*elf_getarsym	_((Elf *, size_t *));
188 off_t		elf_getbase	_((Elf *));
189 Elf_Data	*elf_getdata	_((Elf_Scn *, Elf_Data *));
190 Elf32_Ehdr	*elf32_getehdr	_((Elf *));
191 char		*elf_getident	_((Elf *, size_t *));
192 Elf32_Phdr	*elf32_getphdr	_((Elf *));
193 Elf_Scn		*elf_getscn	_((Elf *elf, size_t));
194 Elf32_Shdr	*elf32_getshdr	_((Elf_Scn *));
195 int		elf_getshnum	_((Elf *, size_t *));
196 int		elf_getshstrndx	_((Elf *, size_t *));
197 unsigned long	elf_hash	_((const char *));
198 long		elf32_checksum	_((Elf *));
199 Elf_Kind	elf_kind	_((Elf *));
200 Elf		*elf_memory	_((char *, size_t));
201 size_t		elf_ndxscn	_((Elf_Scn *));
202 Elf_Data	*elf_newdata	_((Elf_Scn *));
203 Elf32_Ehdr	*elf32_newehdr	_((Elf *));
204 Elf32_Phdr	*elf32_newphdr	_((Elf *, size_t));
205 Elf_Scn		*elf_newscn	_((Elf *));
206 Elf_Scn		*elf_nextscn	_((Elf *, Elf_Scn *));
207 Elf_Cmd		elf_next	_((Elf *));
208 size_t		elf_rand	_((Elf *, size_t));
209 Elf_Data	*elf_rawdata	_((Elf_Scn *, Elf_Data *));
210 char		*elf_rawfile	_((Elf *, size_t *));
211 char		*elf_strptr	_((Elf *, size_t, size_t));
212 off_t		elf_update	_((Elf *, Elf_Cmd));
213 unsigned	elf_version	_((unsigned));
214 Elf_Data	*elf32_xlatetof	_((Elf_Data *, const Elf_Data *, unsigned));
215 Elf_Data	*elf32_xlatetom	_((Elf_Data *, const Elf_Data *, unsigned));
216 
217 #if defined(_LP64) || defined(_LONGLONG_TYPE)
218 size_t		elf64_fsize	_((Elf_Type, size_t, unsigned));
219 Elf64_Ehdr	*elf64_getehdr	_((Elf *));
220 Elf64_Phdr	*elf64_getphdr	_((Elf *));
221 Elf64_Shdr	*elf64_getshdr	_((Elf_Scn *));
222 long		elf64_checksum	_((Elf *));
223 Elf64_Ehdr	*elf64_newehdr	_((Elf *));
224 Elf64_Phdr	*elf64_newphdr	_((Elf *, size_t));
225 Elf_Data	*elf64_xlatetof	_((Elf_Data *, const Elf_Data *, unsigned));
226 Elf_Data	*elf64_xlatetom	_((Elf_Data *, const Elf_Data *, unsigned));
227 #endif /* (defined(_LP64) || defined(_LONGLONG_TYPE) */
228 
229 #undef	_
230 
231 #ifdef	__cplusplus
232 }
233 #endif
234 
235 #endif	/* _LIBELF_H */
236