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