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 5f3324781Sab * Common Development and Distribution License (the "License"). 6f3324781Sab * 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 */ 22b4203d75SMarcel Telka /* All Rights Reserved */ 237c478bd9Sstevel@tonic-gate 247c478bd9Sstevel@tonic-gate /* 2562b628a6SAli Bahrami * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 2630da1432Sahl * Use is subject to license terms. 277a3fc0ccSRichard 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 467a3fc0ccSRichard PALO 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; 126*6e270ca8SMarcel Telka gid_t ar_gid; 1277c478bd9Sstevel@tonic-gate mode_t ar_mode; 1287c478bd9Sstevel@tonic-gate off_t ar_size; 129*6e270ca8SMarcel Telka 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 */ 1597a3fc0ccSRichard PALO Elf *elf_begin(int, Elf_Cmd, Elf *); 1607a3fc0ccSRichard PALO int elf_cntl(Elf *, Elf_Cmd); 1617a3fc0ccSRichard PALO int elf_end(Elf *); 1627a3fc0ccSRichard PALO const char *elf_errmsg(int); 1637a3fc0ccSRichard PALO int elf_errno(void); 1647a3fc0ccSRichard PALO void elf_fill(int); 1657a3fc0ccSRichard PALO unsigned elf_flagdata(Elf_Data *, Elf_Cmd, unsigned); 1667a3fc0ccSRichard PALO unsigned elf_flagehdr(Elf *, Elf_Cmd, unsigned); 1677a3fc0ccSRichard PALO unsigned elf_flagelf(Elf *, Elf_Cmd, unsigned); 1687a3fc0ccSRichard PALO unsigned elf_flagphdr(Elf *, Elf_Cmd, unsigned); 1697a3fc0ccSRichard PALO unsigned elf_flagscn(Elf_Scn *, Elf_Cmd, unsigned); 1707a3fc0ccSRichard PALO unsigned elf_flagshdr(Elf_Scn *, Elf_Cmd, unsigned); 1717a3fc0ccSRichard PALO size_t elf32_fsize(Elf_Type, size_t, unsigned); 1727a3fc0ccSRichard PALO Elf_Arhdr *elf_getarhdr(Elf *); 1737a3fc0ccSRichard PALO Elf_Arsym *elf_getarsym(Elf *, size_t *); 1747a3fc0ccSRichard PALO off_t elf_getbase(Elf *); 1757a3fc0ccSRichard PALO Elf_Data *elf_getdata(Elf_Scn *, Elf_Data *); 1767a3fc0ccSRichard PALO Elf32_Ehdr *elf32_getehdr(Elf *); 1777a3fc0ccSRichard PALO char *elf_getident(Elf *, size_t *); 1787a3fc0ccSRichard PALO Elf32_Phdr *elf32_getphdr(Elf *); 1797a3fc0ccSRichard PALO Elf_Scn *elf_getscn(Elf *elf, size_t); 1807a3fc0ccSRichard PALO Elf32_Shdr *elf32_getshdr(Elf_Scn *); 1817a3fc0ccSRichard PALO int elf_getphnum(Elf *, size_t *); 1827a3fc0ccSRichard PALO int elf_getphdrnum(Elf *, size_t *); 1837a3fc0ccSRichard PALO int elf_getshnum(Elf *, size_t *); 1847a3fc0ccSRichard PALO int elf_getshdrnum(Elf *, size_t *); 1857a3fc0ccSRichard PALO int elf_getshstrndx(Elf *, size_t *); 1867a3fc0ccSRichard PALO int elf_getshdrstrndx(Elf *, size_t *); 1877a3fc0ccSRichard PALO unsigned long elf_hash(const char *); 1887a3fc0ccSRichard PALO uint_t elf_sys_encoding(void); 1897a3fc0ccSRichard PALO long elf32_checksum(Elf *); 1907a3fc0ccSRichard PALO Elf_Kind elf_kind(Elf *); 1917a3fc0ccSRichard PALO Elf *elf_memory(char *, size_t); 1927a3fc0ccSRichard PALO size_t elf_ndxscn(Elf_Scn *); 1937a3fc0ccSRichard PALO Elf_Data *elf_newdata(Elf_Scn *); 1947a3fc0ccSRichard PALO Elf32_Ehdr *elf32_newehdr(Elf *); 1957a3fc0ccSRichard PALO Elf32_Phdr *elf32_newphdr(Elf *, size_t); 1967a3fc0ccSRichard PALO Elf_Scn *elf_newscn(Elf *); 1977a3fc0ccSRichard PALO Elf_Scn *elf_nextscn(Elf *, Elf_Scn *); 1987a3fc0ccSRichard PALO Elf_Cmd elf_next(Elf *); 1997a3fc0ccSRichard PALO size_t elf_rand(Elf *, size_t); 2007a3fc0ccSRichard PALO Elf_Data *elf_rawdata(Elf_Scn *, Elf_Data *); 2017a3fc0ccSRichard PALO char *elf_rawfile(Elf *, size_t *); 2027a3fc0ccSRichard PALO char *elf_strptr(Elf *, size_t, size_t); 2037a3fc0ccSRichard PALO off_t elf_update(Elf *, Elf_Cmd); 2047a3fc0ccSRichard PALO unsigned elf_version(unsigned); 2057a3fc0ccSRichard PALO Elf_Data *elf32_xlatetof(Elf_Data *, const Elf_Data *, unsigned); 2067a3fc0ccSRichard PALO Elf_Data *elf32_xlatetom(Elf_Data *, const Elf_Data *, unsigned); 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_LONGLONG_TYPE) 2097a3fc0ccSRichard PALO size_t elf64_fsize(Elf_Type, size_t, unsigned); 2107a3fc0ccSRichard PALO Elf64_Ehdr *elf64_getehdr(Elf *); 2117a3fc0ccSRichard PALO Elf64_Phdr *elf64_getphdr(Elf *); 2127a3fc0ccSRichard PALO Elf64_Shdr *elf64_getshdr(Elf_Scn *); 2137a3fc0ccSRichard PALO long elf64_checksum(Elf *); 2147a3fc0ccSRichard PALO Elf64_Ehdr *elf64_newehdr(Elf *); 2157a3fc0ccSRichard PALO Elf64_Phdr *elf64_newphdr(Elf *, size_t); 2167a3fc0ccSRichard PALO Elf_Data *elf64_xlatetof(Elf_Data *, const Elf_Data *, unsigned); 2177a3fc0ccSRichard 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