xref: /onnv-gate/usr/src/head/libelf.h (revision 9900:1b86d65a4f9e)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55189Sab196087  * Common Development and Distribution License (the "License").
65189Sab196087  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
220Sstevel@tonic-gate /*	  All Rights Reserved  	*/
230Sstevel@tonic-gate 
240Sstevel@tonic-gate /*
25*9900SAli.Bahrami@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
26942Sahl  * Use is subject to license terms.
270Sstevel@tonic-gate  */
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifndef _LIBELF_H
300Sstevel@tonic-gate #define	_LIBELF_H
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <sys/elf.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #ifdef	__cplusplus
370Sstevel@tonic-gate extern "C" {
380Sstevel@tonic-gate #endif
390Sstevel@tonic-gate 
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #if defined(_ILP32) && (_FILE_OFFSET_BITS != 32)
420Sstevel@tonic-gate #error "large files are not supported by libelf"
430Sstevel@tonic-gate #endif
440Sstevel@tonic-gate 
450Sstevel@tonic-gate 
460Sstevel@tonic-gate #undef _
470Sstevel@tonic-gate #ifdef __STDC__
480Sstevel@tonic-gate typedef void		Elf_Void;
490Sstevel@tonic-gate #define	_(a)		a
500Sstevel@tonic-gate #else
510Sstevel@tonic-gate typedef char		Elf_Void;
520Sstevel@tonic-gate #define	_(a)		()
530Sstevel@tonic-gate #undef const
540Sstevel@tonic-gate #define	const
550Sstevel@tonic-gate #endif
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /*
590Sstevel@tonic-gate  * Commands
600Sstevel@tonic-gate  */
610Sstevel@tonic-gate typedef enum {
620Sstevel@tonic-gate 	ELF_C_NULL = 0,	/* must be first, 0 */
630Sstevel@tonic-gate 	ELF_C_READ,
640Sstevel@tonic-gate 	ELF_C_WRITE,
650Sstevel@tonic-gate 	ELF_C_CLR,
660Sstevel@tonic-gate 	ELF_C_SET,
670Sstevel@tonic-gate 	ELF_C_FDDONE,
680Sstevel@tonic-gate 	ELF_C_FDREAD,
690Sstevel@tonic-gate 	ELF_C_RDWR,
700Sstevel@tonic-gate 	ELF_C_WRIMAGE,
710Sstevel@tonic-gate 	ELF_C_IMAGE,
720Sstevel@tonic-gate 	ELF_C_NUM	/* must be last */
730Sstevel@tonic-gate } Elf_Cmd;
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate  * Flags
780Sstevel@tonic-gate  */
790Sstevel@tonic-gate #define	ELF_F_DIRTY	0x1
800Sstevel@tonic-gate #define	ELF_F_LAYOUT	0x4
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 
830Sstevel@tonic-gate /*
840Sstevel@tonic-gate  * File types
850Sstevel@tonic-gate  */
860Sstevel@tonic-gate typedef enum {
870Sstevel@tonic-gate 	ELF_K_NONE = 0,	/* must be first, 0 */
880Sstevel@tonic-gate 	ELF_K_AR,
890Sstevel@tonic-gate 	ELF_K_COFF,
900Sstevel@tonic-gate 	ELF_K_ELF,
910Sstevel@tonic-gate 	ELF_K_NUM	/* must be last */
920Sstevel@tonic-gate } Elf_Kind;
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 
950Sstevel@tonic-gate /*
960Sstevel@tonic-gate  * Translation types
970Sstevel@tonic-gate  */
980Sstevel@tonic-gate typedef enum {
990Sstevel@tonic-gate 	ELF_T_BYTE = 0,	/* must be first, 0 */
1000Sstevel@tonic-gate 	ELF_T_ADDR,
1010Sstevel@tonic-gate 	ELF_T_DYN,
1020Sstevel@tonic-gate 	ELF_T_EHDR,
1030Sstevel@tonic-gate 	ELF_T_HALF,
1040Sstevel@tonic-gate 	ELF_T_OFF,
1050Sstevel@tonic-gate 	ELF_T_PHDR,
1060Sstevel@tonic-gate 	ELF_T_RELA,
1070Sstevel@tonic-gate 	ELF_T_REL,
1080Sstevel@tonic-gate 	ELF_T_SHDR,
1090Sstevel@tonic-gate 	ELF_T_SWORD,
1100Sstevel@tonic-gate 	ELF_T_SYM,
1110Sstevel@tonic-gate 	ELF_T_WORD,
1120Sstevel@tonic-gate 	ELF_T_VDEF,
1130Sstevel@tonic-gate 	ELF_T_VNEED,
1140Sstevel@tonic-gate 	ELF_T_SXWORD,
1150Sstevel@tonic-gate 	ELF_T_XWORD,
1160Sstevel@tonic-gate 	ELF_T_SYMINFO,
1170Sstevel@tonic-gate 	ELF_T_NOTE,
1180Sstevel@tonic-gate 	ELF_T_MOVE,
1190Sstevel@tonic-gate 	ELF_T_MOVEP,
1200Sstevel@tonic-gate 	ELF_T_CAP,
1210Sstevel@tonic-gate 	ELF_T_NUM	/* must be last */
1220Sstevel@tonic-gate } Elf_Type;
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate typedef struct Elf	Elf;
1260Sstevel@tonic-gate typedef struct Elf_Scn	Elf_Scn;
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate /*
1300Sstevel@tonic-gate  * Archive member header
1310Sstevel@tonic-gate  */
1320Sstevel@tonic-gate typedef struct {
1330Sstevel@tonic-gate 	char		*ar_name;
1340Sstevel@tonic-gate 	time_t		ar_date;
1350Sstevel@tonic-gate 	uid_t		ar_uid;
1360Sstevel@tonic-gate 	gid_t 		ar_gid;
1370Sstevel@tonic-gate 	mode_t		ar_mode;
1380Sstevel@tonic-gate 	off_t		ar_size;
1390Sstevel@tonic-gate 	char 		*ar_rawname;
1400Sstevel@tonic-gate } Elf_Arhdr;
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate /*
1440Sstevel@tonic-gate  * Archive symbol table
1450Sstevel@tonic-gate  */
1460Sstevel@tonic-gate typedef struct {
1470Sstevel@tonic-gate 	char		*as_name;
1480Sstevel@tonic-gate 	size_t		as_off;
1490Sstevel@tonic-gate 	unsigned long	as_hash;
1500Sstevel@tonic-gate } Elf_Arsym;
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate /*
1540Sstevel@tonic-gate  * Data descriptor
1550Sstevel@tonic-gate  */
1560Sstevel@tonic-gate typedef struct {
1570Sstevel@tonic-gate 	Elf_Void	*d_buf;
1580Sstevel@tonic-gate 	Elf_Type	d_type;
1590Sstevel@tonic-gate 	size_t		d_size;
1600Sstevel@tonic-gate 	off_t		d_off;		/* offset into section */
1610Sstevel@tonic-gate 	size_t		d_align;	/* alignment in section */
1620Sstevel@tonic-gate 	unsigned	d_version;	/* elf version */
1630Sstevel@tonic-gate } Elf_Data;
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate /*
1670Sstevel@tonic-gate  * Function declarations
1680Sstevel@tonic-gate  */
1690Sstevel@tonic-gate Elf		*elf_begin	_((int, Elf_Cmd, Elf *));
1700Sstevel@tonic-gate int		elf_cntl	_((Elf *, Elf_Cmd));
1710Sstevel@tonic-gate int		elf_end		_((Elf *));
1720Sstevel@tonic-gate const char	*elf_errmsg	_((int));
1730Sstevel@tonic-gate int		elf_errno	_((void));
1740Sstevel@tonic-gate void		elf_fill	_((int));
1750Sstevel@tonic-gate unsigned	elf_flagdata	_((Elf_Data *, Elf_Cmd, unsigned));
1760Sstevel@tonic-gate unsigned	elf_flagehdr	_((Elf *, Elf_Cmd,  unsigned));
1770Sstevel@tonic-gate unsigned	elf_flagelf	_((Elf *, Elf_Cmd, unsigned));
1780Sstevel@tonic-gate unsigned	elf_flagphdr	_((Elf *, Elf_Cmd, unsigned));
1790Sstevel@tonic-gate unsigned	elf_flagscn	_((Elf_Scn *, Elf_Cmd, unsigned));
1800Sstevel@tonic-gate unsigned	elf_flagshdr	_((Elf_Scn *, Elf_Cmd, unsigned));
1810Sstevel@tonic-gate size_t		elf32_fsize	_((Elf_Type, size_t, unsigned));
1820Sstevel@tonic-gate Elf_Arhdr	*elf_getarhdr	_((Elf *));
1830Sstevel@tonic-gate Elf_Arsym	*elf_getarsym	_((Elf *, size_t *));
1840Sstevel@tonic-gate off_t		elf_getbase	_((Elf *));
1850Sstevel@tonic-gate Elf_Data	*elf_getdata	_((Elf_Scn *, Elf_Data *));
1860Sstevel@tonic-gate Elf32_Ehdr	*elf32_getehdr	_((Elf *));
1870Sstevel@tonic-gate char		*elf_getident	_((Elf *, size_t *));
1880Sstevel@tonic-gate Elf32_Phdr	*elf32_getphdr	_((Elf *));
1890Sstevel@tonic-gate Elf_Scn		*elf_getscn	_((Elf *elf, size_t));
1900Sstevel@tonic-gate Elf32_Shdr	*elf32_getshdr	_((Elf_Scn *));
191942Sahl int		elf_getphnum	_((Elf *, size_t *));
192*9900SAli.Bahrami@Sun.COM int		elf_getphdrnum	_((Elf *, size_t *));
1930Sstevel@tonic-gate int		elf_getshnum	_((Elf *, size_t *));
194*9900SAli.Bahrami@Sun.COM int		elf_getshdrnum	_((Elf *, size_t *));
1950Sstevel@tonic-gate int		elf_getshstrndx	_((Elf *, size_t *));
196*9900SAli.Bahrami@Sun.COM int		elf_getshdrstrndx _((Elf *, size_t *));
1970Sstevel@tonic-gate unsigned long	elf_hash	_((const char *));
1985189Sab196087 uint_t		elf_sys_encoding _((void));
1990Sstevel@tonic-gate long		elf32_checksum	_((Elf *));
2000Sstevel@tonic-gate Elf_Kind	elf_kind	_((Elf *));
2010Sstevel@tonic-gate Elf		*elf_memory	_((char *, size_t));
2020Sstevel@tonic-gate size_t		elf_ndxscn	_((Elf_Scn *));
2030Sstevel@tonic-gate Elf_Data	*elf_newdata	_((Elf_Scn *));
2040Sstevel@tonic-gate Elf32_Ehdr	*elf32_newehdr	_((Elf *));
2050Sstevel@tonic-gate Elf32_Phdr	*elf32_newphdr	_((Elf *, size_t));
2060Sstevel@tonic-gate Elf_Scn		*elf_newscn	_((Elf *));
2070Sstevel@tonic-gate Elf_Scn		*elf_nextscn	_((Elf *, Elf_Scn *));
2080Sstevel@tonic-gate Elf_Cmd		elf_next	_((Elf *));
2090Sstevel@tonic-gate size_t		elf_rand	_((Elf *, size_t));
2100Sstevel@tonic-gate Elf_Data	*elf_rawdata	_((Elf_Scn *, Elf_Data *));
2110Sstevel@tonic-gate char		*elf_rawfile	_((Elf *, size_t *));
2120Sstevel@tonic-gate char		*elf_strptr	_((Elf *, size_t, size_t));
2130Sstevel@tonic-gate off_t		elf_update	_((Elf *, Elf_Cmd));
2140Sstevel@tonic-gate unsigned	elf_version	_((unsigned));
2150Sstevel@tonic-gate Elf_Data	*elf32_xlatetof	_((Elf_Data *, const Elf_Data *, unsigned));
2160Sstevel@tonic-gate Elf_Data	*elf32_xlatetom	_((Elf_Data *, const Elf_Data *, unsigned));
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate #if defined(_LP64) || defined(_LONGLONG_TYPE)
2190Sstevel@tonic-gate size_t		elf64_fsize	_((Elf_Type, size_t, unsigned));
2200Sstevel@tonic-gate Elf64_Ehdr	*elf64_getehdr	_((Elf *));
2210Sstevel@tonic-gate Elf64_Phdr	*elf64_getphdr	_((Elf *));
2220Sstevel@tonic-gate Elf64_Shdr	*elf64_getshdr	_((Elf_Scn *));
2230Sstevel@tonic-gate long		elf64_checksum	_((Elf *));
2240Sstevel@tonic-gate Elf64_Ehdr	*elf64_newehdr	_((Elf *));
2250Sstevel@tonic-gate Elf64_Phdr	*elf64_newphdr	_((Elf *, size_t));
2260Sstevel@tonic-gate Elf_Data	*elf64_xlatetof	_((Elf_Data *, const Elf_Data *, unsigned));
2270Sstevel@tonic-gate Elf_Data	*elf64_xlatetom	_((Elf_Data *, const Elf_Data *, unsigned));
2280Sstevel@tonic-gate #endif /* (defined(_LP64) || defined(_LONGLONG_TYPE) */
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate #undef	_
2310Sstevel@tonic-gate 
2320Sstevel@tonic-gate #ifdef	__cplusplus
2330Sstevel@tonic-gate }
2340Sstevel@tonic-gate #endif
2350Sstevel@tonic-gate 
2360Sstevel@tonic-gate #endif	/* _LIBELF_H */
237