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