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