xref: /titanic_51/usr/src/head/libelf.h (revision 7a3fc0ccaf807a654980fdce2d9187503628b99d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5f3324781Sab196087  * Common Development and Distribution License (the "License").
6f3324781Sab196087  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
227c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate /*
2562b628a6SAli Bahrami  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
27*7a3fc0ccSRichard PALO  * Copyright 2014 PALO, Richard. All rights reserved.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef _LIBELF_H
317c478bd9Sstevel@tonic-gate #define	_LIBELF_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/elf.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #if defined(_ILP32) && (_FILE_OFFSET_BITS != 32)
437c478bd9Sstevel@tonic-gate #error "large files are not supported by libelf"
447c478bd9Sstevel@tonic-gate #endif
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate typedef void	Elf_Void;
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate  * Commands
507c478bd9Sstevel@tonic-gate  */
517c478bd9Sstevel@tonic-gate typedef enum {
527c478bd9Sstevel@tonic-gate 	ELF_C_NULL = 0,	/* must be first, 0 */
537c478bd9Sstevel@tonic-gate 	ELF_C_READ,
547c478bd9Sstevel@tonic-gate 	ELF_C_WRITE,
557c478bd9Sstevel@tonic-gate 	ELF_C_CLR,
567c478bd9Sstevel@tonic-gate 	ELF_C_SET,
577c478bd9Sstevel@tonic-gate 	ELF_C_FDDONE,
587c478bd9Sstevel@tonic-gate 	ELF_C_FDREAD,
597c478bd9Sstevel@tonic-gate 	ELF_C_RDWR,
607c478bd9Sstevel@tonic-gate 	ELF_C_WRIMAGE,
617c478bd9Sstevel@tonic-gate 	ELF_C_IMAGE,
627c478bd9Sstevel@tonic-gate 	ELF_C_NUM	/* must be last */
637c478bd9Sstevel@tonic-gate } Elf_Cmd;
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  * Flags
687c478bd9Sstevel@tonic-gate  */
697c478bd9Sstevel@tonic-gate #define	ELF_F_DIRTY	0x1
707c478bd9Sstevel@tonic-gate #define	ELF_F_LAYOUT	0x4
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate  * File types
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate typedef enum {
777c478bd9Sstevel@tonic-gate 	ELF_K_NONE = 0,	/* must be first, 0 */
787c478bd9Sstevel@tonic-gate 	ELF_K_AR,
797c478bd9Sstevel@tonic-gate 	ELF_K_COFF,
807c478bd9Sstevel@tonic-gate 	ELF_K_ELF,
817c478bd9Sstevel@tonic-gate 	ELF_K_NUM	/* must be last */
827c478bd9Sstevel@tonic-gate } Elf_Kind;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate /*
867c478bd9Sstevel@tonic-gate  * Translation types
877c478bd9Sstevel@tonic-gate  */
887c478bd9Sstevel@tonic-gate typedef enum {
897c478bd9Sstevel@tonic-gate 	ELF_T_BYTE = 0,	/* must be first, 0 */
907c478bd9Sstevel@tonic-gate 	ELF_T_ADDR,
917c478bd9Sstevel@tonic-gate 	ELF_T_DYN,
927c478bd9Sstevel@tonic-gate 	ELF_T_EHDR,
937c478bd9Sstevel@tonic-gate 	ELF_T_HALF,
947c478bd9Sstevel@tonic-gate 	ELF_T_OFF,
957c478bd9Sstevel@tonic-gate 	ELF_T_PHDR,
967c478bd9Sstevel@tonic-gate 	ELF_T_RELA,
977c478bd9Sstevel@tonic-gate 	ELF_T_REL,
987c478bd9Sstevel@tonic-gate 	ELF_T_SHDR,
997c478bd9Sstevel@tonic-gate 	ELF_T_SWORD,
1007c478bd9Sstevel@tonic-gate 	ELF_T_SYM,
1017c478bd9Sstevel@tonic-gate 	ELF_T_WORD,
1027c478bd9Sstevel@tonic-gate 	ELF_T_VDEF,
1037c478bd9Sstevel@tonic-gate 	ELF_T_VNEED,
1047c478bd9Sstevel@tonic-gate 	ELF_T_SXWORD,
1057c478bd9Sstevel@tonic-gate 	ELF_T_XWORD,
1067c478bd9Sstevel@tonic-gate 	ELF_T_SYMINFO,
1077c478bd9Sstevel@tonic-gate 	ELF_T_NOTE,
1087c478bd9Sstevel@tonic-gate 	ELF_T_MOVE,
1097c478bd9Sstevel@tonic-gate 	ELF_T_MOVEP,
1107c478bd9Sstevel@tonic-gate 	ELF_T_CAP,
1117c478bd9Sstevel@tonic-gate 	ELF_T_NUM	/* must be last */
1127c478bd9Sstevel@tonic-gate } Elf_Type;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate typedef struct Elf	Elf;
1167c478bd9Sstevel@tonic-gate typedef struct Elf_Scn	Elf_Scn;
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate /*
1207c478bd9Sstevel@tonic-gate  * Archive member header
1217c478bd9Sstevel@tonic-gate  */
1227c478bd9Sstevel@tonic-gate typedef struct {
1237c478bd9Sstevel@tonic-gate 	char		*ar_name;
1247c478bd9Sstevel@tonic-gate 	time_t		ar_date;
1257c478bd9Sstevel@tonic-gate 	uid_t		ar_uid;
1267c478bd9Sstevel@tonic-gate 	gid_t 		ar_gid;
1277c478bd9Sstevel@tonic-gate 	mode_t		ar_mode;
1287c478bd9Sstevel@tonic-gate 	off_t		ar_size;
1297c478bd9Sstevel@tonic-gate 	char 		*ar_rawname;
1307c478bd9Sstevel@tonic-gate } Elf_Arhdr;
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate  * Archive symbol table
1357c478bd9Sstevel@tonic-gate  */
1367c478bd9Sstevel@tonic-gate typedef struct {
1377c478bd9Sstevel@tonic-gate 	char		*as_name;
1387c478bd9Sstevel@tonic-gate 	size_t		as_off;
1397c478bd9Sstevel@tonic-gate 	unsigned long	as_hash;
1407c478bd9Sstevel@tonic-gate } Elf_Arsym;
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate /*
1447c478bd9Sstevel@tonic-gate  * Data descriptor
1457c478bd9Sstevel@tonic-gate  */
1467c478bd9Sstevel@tonic-gate typedef struct {
1477c478bd9Sstevel@tonic-gate 	Elf_Void	*d_buf;
1487c478bd9Sstevel@tonic-gate 	Elf_Type	d_type;
1497c478bd9Sstevel@tonic-gate 	size_t		d_size;
1507c478bd9Sstevel@tonic-gate 	off_t		d_off;		/* offset into section */
1517c478bd9Sstevel@tonic-gate 	size_t		d_align;	/* alignment in section */
1527c478bd9Sstevel@tonic-gate 	unsigned	d_version;	/* elf version */
1537c478bd9Sstevel@tonic-gate } Elf_Data;
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate /*
1577c478bd9Sstevel@tonic-gate  * Function declarations
1587c478bd9Sstevel@tonic-gate  */
159*7a3fc0ccSRichard PALO Elf		*elf_begin(int, Elf_Cmd, Elf *);
160*7a3fc0ccSRichard PALO int		elf_cntl(Elf *, Elf_Cmd);
161*7a3fc0ccSRichard PALO int		elf_end(Elf *);
162*7a3fc0ccSRichard PALO const char	*elf_errmsg(int);
163*7a3fc0ccSRichard PALO int		elf_errno(void);
164*7a3fc0ccSRichard PALO void		elf_fill(int);
165*7a3fc0ccSRichard PALO unsigned	elf_flagdata(Elf_Data *, Elf_Cmd, unsigned);
166*7a3fc0ccSRichard PALO unsigned	elf_flagehdr(Elf *, Elf_Cmd,  unsigned);
167*7a3fc0ccSRichard PALO unsigned	elf_flagelf(Elf *, Elf_Cmd, unsigned);
168*7a3fc0ccSRichard PALO unsigned	elf_flagphdr(Elf *, Elf_Cmd, unsigned);
169*7a3fc0ccSRichard PALO unsigned	elf_flagscn(Elf_Scn *, Elf_Cmd, unsigned);
170*7a3fc0ccSRichard PALO unsigned	elf_flagshdr(Elf_Scn *, Elf_Cmd, unsigned);
171*7a3fc0ccSRichard PALO size_t		elf32_fsize(Elf_Type, size_t, unsigned);
172*7a3fc0ccSRichard PALO Elf_Arhdr	*elf_getarhdr(Elf *);
173*7a3fc0ccSRichard PALO Elf_Arsym	*elf_getarsym(Elf *, size_t *);
174*7a3fc0ccSRichard PALO off_t		elf_getbase(Elf *);
175*7a3fc0ccSRichard PALO Elf_Data	*elf_getdata(Elf_Scn *, Elf_Data *);
176*7a3fc0ccSRichard PALO Elf32_Ehdr	*elf32_getehdr(Elf *);
177*7a3fc0ccSRichard PALO char		*elf_getident(Elf *, size_t *);
178*7a3fc0ccSRichard PALO Elf32_Phdr	*elf32_getphdr(Elf *);
179*7a3fc0ccSRichard PALO Elf_Scn		*elf_getscn(Elf *elf, size_t);
180*7a3fc0ccSRichard PALO Elf32_Shdr	*elf32_getshdr(Elf_Scn *);
181*7a3fc0ccSRichard PALO int		elf_getphnum(Elf *, size_t *);
182*7a3fc0ccSRichard PALO int		elf_getphdrnum(Elf *, size_t *);
183*7a3fc0ccSRichard PALO int		elf_getshnum(Elf *, size_t *);
184*7a3fc0ccSRichard PALO int		elf_getshdrnum(Elf *, size_t *);
185*7a3fc0ccSRichard PALO int		elf_getshstrndx(Elf *, size_t *);
186*7a3fc0ccSRichard PALO int		elf_getshdrstrndx(Elf *, size_t *);
187*7a3fc0ccSRichard PALO unsigned long	elf_hash(const char *);
188*7a3fc0ccSRichard PALO uint_t		elf_sys_encoding(void);
189*7a3fc0ccSRichard PALO long		elf32_checksum(Elf *);
190*7a3fc0ccSRichard PALO Elf_Kind	elf_kind(Elf *);
191*7a3fc0ccSRichard PALO Elf		*elf_memory(char *, size_t);
192*7a3fc0ccSRichard PALO size_t		elf_ndxscn(Elf_Scn *);
193*7a3fc0ccSRichard PALO Elf_Data	*elf_newdata(Elf_Scn *);
194*7a3fc0ccSRichard PALO Elf32_Ehdr	*elf32_newehdr(Elf *);
195*7a3fc0ccSRichard PALO Elf32_Phdr	*elf32_newphdr(Elf *, size_t);
196*7a3fc0ccSRichard PALO Elf_Scn		*elf_newscn(Elf *);
197*7a3fc0ccSRichard PALO Elf_Scn		*elf_nextscn(Elf *, Elf_Scn *);
198*7a3fc0ccSRichard PALO Elf_Cmd		elf_next(Elf *);
199*7a3fc0ccSRichard PALO size_t		elf_rand(Elf *, size_t);
200*7a3fc0ccSRichard PALO Elf_Data	*elf_rawdata(Elf_Scn *, Elf_Data *);
201*7a3fc0ccSRichard PALO char		*elf_rawfile(Elf *, size_t *);
202*7a3fc0ccSRichard PALO char		*elf_strptr(Elf *, size_t, size_t);
203*7a3fc0ccSRichard PALO off_t		elf_update(Elf *, Elf_Cmd);
204*7a3fc0ccSRichard PALO unsigned	elf_version(unsigned);
205*7a3fc0ccSRichard PALO Elf_Data	*elf32_xlatetof(Elf_Data *, const Elf_Data *, unsigned);
206*7a3fc0ccSRichard PALO Elf_Data	*elf32_xlatetom(Elf_Data *, const Elf_Data *, unsigned);
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_LONGLONG_TYPE)
209*7a3fc0ccSRichard PALO size_t		elf64_fsize(Elf_Type, size_t, unsigned);
210*7a3fc0ccSRichard PALO Elf64_Ehdr	*elf64_getehdr(Elf *);
211*7a3fc0ccSRichard PALO Elf64_Phdr	*elf64_getphdr(Elf *);
212*7a3fc0ccSRichard PALO Elf64_Shdr	*elf64_getshdr(Elf_Scn *);
213*7a3fc0ccSRichard PALO long		elf64_checksum(Elf *);
214*7a3fc0ccSRichard PALO Elf64_Ehdr	*elf64_newehdr(Elf *);
215*7a3fc0ccSRichard PALO Elf64_Phdr	*elf64_newphdr(Elf *, size_t);
216*7a3fc0ccSRichard PALO Elf_Data	*elf64_xlatetof(Elf_Data *, const Elf_Data *, unsigned);
217*7a3fc0ccSRichard PALO Elf_Data	*elf64_xlatetom(Elf_Data *, const Elf_Data *, unsigned);
2187c478bd9Sstevel@tonic-gate #endif /* (defined(_LP64) || defined(_LONGLONG_TYPE) */
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate #endif
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate #endif	/* _LIBELF_H */
225