xref: /titanic_51/usr/src/head/libelf.h (revision 62b628a68db596a2d75a316dc7ffef658079231f)
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 /*
25*62b628a6SAli Bahrami  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef _LIBELF_H
307c478bd9Sstevel@tonic-gate #define	_LIBELF_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/elf.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #if defined(_ILP32) && (_FILE_OFFSET_BITS != 32)
427c478bd9Sstevel@tonic-gate #error "large files are not supported by libelf"
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #undef _
477c478bd9Sstevel@tonic-gate #ifdef __STDC__
487c478bd9Sstevel@tonic-gate typedef void		Elf_Void;
497c478bd9Sstevel@tonic-gate #define	_(a)		a
507c478bd9Sstevel@tonic-gate #else
517c478bd9Sstevel@tonic-gate typedef char		Elf_Void;
527c478bd9Sstevel@tonic-gate #define	_(a)		()
537c478bd9Sstevel@tonic-gate #undef const
547c478bd9Sstevel@tonic-gate #define	const
557c478bd9Sstevel@tonic-gate #endif
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate  * Commands
607c478bd9Sstevel@tonic-gate  */
617c478bd9Sstevel@tonic-gate typedef enum {
627c478bd9Sstevel@tonic-gate 	ELF_C_NULL = 0,	/* must be first, 0 */
637c478bd9Sstevel@tonic-gate 	ELF_C_READ,
647c478bd9Sstevel@tonic-gate 	ELF_C_WRITE,
657c478bd9Sstevel@tonic-gate 	ELF_C_CLR,
667c478bd9Sstevel@tonic-gate 	ELF_C_SET,
677c478bd9Sstevel@tonic-gate 	ELF_C_FDDONE,
687c478bd9Sstevel@tonic-gate 	ELF_C_FDREAD,
697c478bd9Sstevel@tonic-gate 	ELF_C_RDWR,
707c478bd9Sstevel@tonic-gate 	ELF_C_WRIMAGE,
717c478bd9Sstevel@tonic-gate 	ELF_C_IMAGE,
727c478bd9Sstevel@tonic-gate 	ELF_C_NUM	/* must be last */
737c478bd9Sstevel@tonic-gate } Elf_Cmd;
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate /*
777c478bd9Sstevel@tonic-gate  * Flags
787c478bd9Sstevel@tonic-gate  */
797c478bd9Sstevel@tonic-gate #define	ELF_F_DIRTY	0x1
807c478bd9Sstevel@tonic-gate #define	ELF_F_LAYOUT	0x4
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate  * File types
857c478bd9Sstevel@tonic-gate  */
867c478bd9Sstevel@tonic-gate typedef enum {
877c478bd9Sstevel@tonic-gate 	ELF_K_NONE = 0,	/* must be first, 0 */
887c478bd9Sstevel@tonic-gate 	ELF_K_AR,
897c478bd9Sstevel@tonic-gate 	ELF_K_COFF,
907c478bd9Sstevel@tonic-gate 	ELF_K_ELF,
917c478bd9Sstevel@tonic-gate 	ELF_K_NUM	/* must be last */
927c478bd9Sstevel@tonic-gate } Elf_Kind;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /*
967c478bd9Sstevel@tonic-gate  * Translation types
977c478bd9Sstevel@tonic-gate  */
987c478bd9Sstevel@tonic-gate typedef enum {
997c478bd9Sstevel@tonic-gate 	ELF_T_BYTE = 0,	/* must be first, 0 */
1007c478bd9Sstevel@tonic-gate 	ELF_T_ADDR,
1017c478bd9Sstevel@tonic-gate 	ELF_T_DYN,
1027c478bd9Sstevel@tonic-gate 	ELF_T_EHDR,
1037c478bd9Sstevel@tonic-gate 	ELF_T_HALF,
1047c478bd9Sstevel@tonic-gate 	ELF_T_OFF,
1057c478bd9Sstevel@tonic-gate 	ELF_T_PHDR,
1067c478bd9Sstevel@tonic-gate 	ELF_T_RELA,
1077c478bd9Sstevel@tonic-gate 	ELF_T_REL,
1087c478bd9Sstevel@tonic-gate 	ELF_T_SHDR,
1097c478bd9Sstevel@tonic-gate 	ELF_T_SWORD,
1107c478bd9Sstevel@tonic-gate 	ELF_T_SYM,
1117c478bd9Sstevel@tonic-gate 	ELF_T_WORD,
1127c478bd9Sstevel@tonic-gate 	ELF_T_VDEF,
1137c478bd9Sstevel@tonic-gate 	ELF_T_VNEED,
1147c478bd9Sstevel@tonic-gate 	ELF_T_SXWORD,
1157c478bd9Sstevel@tonic-gate 	ELF_T_XWORD,
1167c478bd9Sstevel@tonic-gate 	ELF_T_SYMINFO,
1177c478bd9Sstevel@tonic-gate 	ELF_T_NOTE,
1187c478bd9Sstevel@tonic-gate 	ELF_T_MOVE,
1197c478bd9Sstevel@tonic-gate 	ELF_T_MOVEP,
1207c478bd9Sstevel@tonic-gate 	ELF_T_CAP,
1217c478bd9Sstevel@tonic-gate 	ELF_T_NUM	/* must be last */
1227c478bd9Sstevel@tonic-gate } Elf_Type;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate typedef struct Elf	Elf;
1267c478bd9Sstevel@tonic-gate typedef struct Elf_Scn	Elf_Scn;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate  * Archive member header
1317c478bd9Sstevel@tonic-gate  */
1327c478bd9Sstevel@tonic-gate typedef struct {
1337c478bd9Sstevel@tonic-gate 	char		*ar_name;
1347c478bd9Sstevel@tonic-gate 	time_t		ar_date;
1357c478bd9Sstevel@tonic-gate 	uid_t		ar_uid;
1367c478bd9Sstevel@tonic-gate 	gid_t 		ar_gid;
1377c478bd9Sstevel@tonic-gate 	mode_t		ar_mode;
1387c478bd9Sstevel@tonic-gate 	off_t		ar_size;
1397c478bd9Sstevel@tonic-gate 	char 		*ar_rawname;
1407c478bd9Sstevel@tonic-gate } Elf_Arhdr;
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate /*
1447c478bd9Sstevel@tonic-gate  * Archive symbol table
1457c478bd9Sstevel@tonic-gate  */
1467c478bd9Sstevel@tonic-gate typedef struct {
1477c478bd9Sstevel@tonic-gate 	char		*as_name;
1487c478bd9Sstevel@tonic-gate 	size_t		as_off;
1497c478bd9Sstevel@tonic-gate 	unsigned long	as_hash;
1507c478bd9Sstevel@tonic-gate } Elf_Arsym;
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate  * Data descriptor
1557c478bd9Sstevel@tonic-gate  */
1567c478bd9Sstevel@tonic-gate typedef struct {
1577c478bd9Sstevel@tonic-gate 	Elf_Void	*d_buf;
1587c478bd9Sstevel@tonic-gate 	Elf_Type	d_type;
1597c478bd9Sstevel@tonic-gate 	size_t		d_size;
1607c478bd9Sstevel@tonic-gate 	off_t		d_off;		/* offset into section */
1617c478bd9Sstevel@tonic-gate 	size_t		d_align;	/* alignment in section */
1627c478bd9Sstevel@tonic-gate 	unsigned	d_version;	/* elf version */
1637c478bd9Sstevel@tonic-gate } Elf_Data;
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate /*
1677c478bd9Sstevel@tonic-gate  * Function declarations
1687c478bd9Sstevel@tonic-gate  */
1697c478bd9Sstevel@tonic-gate Elf		*elf_begin	_((int, Elf_Cmd, Elf *));
1707c478bd9Sstevel@tonic-gate int		elf_cntl	_((Elf *, Elf_Cmd));
1717c478bd9Sstevel@tonic-gate int		elf_end		_((Elf *));
1727c478bd9Sstevel@tonic-gate const char	*elf_errmsg	_((int));
1737c478bd9Sstevel@tonic-gate int		elf_errno	_((void));
1747c478bd9Sstevel@tonic-gate void		elf_fill	_((int));
1757c478bd9Sstevel@tonic-gate unsigned	elf_flagdata	_((Elf_Data *, Elf_Cmd, unsigned));
1767c478bd9Sstevel@tonic-gate unsigned	elf_flagehdr	_((Elf *, Elf_Cmd,  unsigned));
1777c478bd9Sstevel@tonic-gate unsigned	elf_flagelf	_((Elf *, Elf_Cmd, unsigned));
1787c478bd9Sstevel@tonic-gate unsigned	elf_flagphdr	_((Elf *, Elf_Cmd, unsigned));
1797c478bd9Sstevel@tonic-gate unsigned	elf_flagscn	_((Elf_Scn *, Elf_Cmd, unsigned));
1807c478bd9Sstevel@tonic-gate unsigned	elf_flagshdr	_((Elf_Scn *, Elf_Cmd, unsigned));
1817c478bd9Sstevel@tonic-gate size_t		elf32_fsize	_((Elf_Type, size_t, unsigned));
1827c478bd9Sstevel@tonic-gate Elf_Arhdr	*elf_getarhdr	_((Elf *));
1837c478bd9Sstevel@tonic-gate Elf_Arsym	*elf_getarsym	_((Elf *, size_t *));
1847c478bd9Sstevel@tonic-gate off_t		elf_getbase	_((Elf *));
1857c478bd9Sstevel@tonic-gate Elf_Data	*elf_getdata	_((Elf_Scn *, Elf_Data *));
1867c478bd9Sstevel@tonic-gate Elf32_Ehdr	*elf32_getehdr	_((Elf *));
1877c478bd9Sstevel@tonic-gate char		*elf_getident	_((Elf *, size_t *));
1887c478bd9Sstevel@tonic-gate Elf32_Phdr	*elf32_getphdr	_((Elf *));
1897c478bd9Sstevel@tonic-gate Elf_Scn		*elf_getscn	_((Elf *elf, size_t));
1907c478bd9Sstevel@tonic-gate Elf32_Shdr	*elf32_getshdr	_((Elf_Scn *));
19130da1432Sahl int		elf_getphnum	_((Elf *, size_t *));
192*62b628a6SAli Bahrami int		elf_getphdrnum	_((Elf *, size_t *));
1937c478bd9Sstevel@tonic-gate int		elf_getshnum	_((Elf *, size_t *));
194*62b628a6SAli Bahrami int		elf_getshdrnum	_((Elf *, size_t *));
1957c478bd9Sstevel@tonic-gate int		elf_getshstrndx	_((Elf *, size_t *));
196*62b628a6SAli Bahrami int		elf_getshdrstrndx _((Elf *, size_t *));
1977c478bd9Sstevel@tonic-gate unsigned long	elf_hash	_((const char *));
198f3324781Sab196087 uint_t		elf_sys_encoding _((void));
1997c478bd9Sstevel@tonic-gate long		elf32_checksum	_((Elf *));
2007c478bd9Sstevel@tonic-gate Elf_Kind	elf_kind	_((Elf *));
2017c478bd9Sstevel@tonic-gate Elf		*elf_memory	_((char *, size_t));
2027c478bd9Sstevel@tonic-gate size_t		elf_ndxscn	_((Elf_Scn *));
2037c478bd9Sstevel@tonic-gate Elf_Data	*elf_newdata	_((Elf_Scn *));
2047c478bd9Sstevel@tonic-gate Elf32_Ehdr	*elf32_newehdr	_((Elf *));
2057c478bd9Sstevel@tonic-gate Elf32_Phdr	*elf32_newphdr	_((Elf *, size_t));
2067c478bd9Sstevel@tonic-gate Elf_Scn		*elf_newscn	_((Elf *));
2077c478bd9Sstevel@tonic-gate Elf_Scn		*elf_nextscn	_((Elf *, Elf_Scn *));
2087c478bd9Sstevel@tonic-gate Elf_Cmd		elf_next	_((Elf *));
2097c478bd9Sstevel@tonic-gate size_t		elf_rand	_((Elf *, size_t));
2107c478bd9Sstevel@tonic-gate Elf_Data	*elf_rawdata	_((Elf_Scn *, Elf_Data *));
2117c478bd9Sstevel@tonic-gate char		*elf_rawfile	_((Elf *, size_t *));
2127c478bd9Sstevel@tonic-gate char		*elf_strptr	_((Elf *, size_t, size_t));
2137c478bd9Sstevel@tonic-gate off_t		elf_update	_((Elf *, Elf_Cmd));
2147c478bd9Sstevel@tonic-gate unsigned	elf_version	_((unsigned));
2157c478bd9Sstevel@tonic-gate Elf_Data	*elf32_xlatetof	_((Elf_Data *, const Elf_Data *, unsigned));
2167c478bd9Sstevel@tonic-gate Elf_Data	*elf32_xlatetom	_((Elf_Data *, const Elf_Data *, unsigned));
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_LONGLONG_TYPE)
2197c478bd9Sstevel@tonic-gate size_t		elf64_fsize	_((Elf_Type, size_t, unsigned));
2207c478bd9Sstevel@tonic-gate Elf64_Ehdr	*elf64_getehdr	_((Elf *));
2217c478bd9Sstevel@tonic-gate Elf64_Phdr	*elf64_getphdr	_((Elf *));
2227c478bd9Sstevel@tonic-gate Elf64_Shdr	*elf64_getshdr	_((Elf_Scn *));
2237c478bd9Sstevel@tonic-gate long		elf64_checksum	_((Elf *));
2247c478bd9Sstevel@tonic-gate Elf64_Ehdr	*elf64_newehdr	_((Elf *));
2257c478bd9Sstevel@tonic-gate Elf64_Phdr	*elf64_newphdr	_((Elf *, size_t));
2267c478bd9Sstevel@tonic-gate Elf_Data	*elf64_xlatetof	_((Elf_Data *, const Elf_Data *, unsigned));
2277c478bd9Sstevel@tonic-gate Elf_Data	*elf64_xlatetom	_((Elf_Data *, const Elf_Data *, unsigned));
2287c478bd9Sstevel@tonic-gate #endif /* (defined(_LP64) || defined(_LONGLONG_TYPE) */
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate #undef	_
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate #endif
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate #endif	/* _LIBELF_H */
237