libelf.h revision 9900:1b86d65a4f9e
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/* Copyright (c) 1988 AT&T */ 22/* All Rights Reserved */ 23 24/* 25 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 */ 28 29#ifndef _LIBELF_H 30#define _LIBELF_H 31 32#include <sys/types.h> 33#include <sys/elf.h> 34 35 36#ifdef __cplusplus 37extern "C" { 38#endif 39 40 41#if defined(_ILP32) && (_FILE_OFFSET_BITS != 32) 42#error "large files are not supported by libelf" 43#endif 44 45 46#undef _ 47#ifdef __STDC__ 48typedef void Elf_Void; 49#define _(a) a 50#else 51typedef char Elf_Void; 52#define _(a) () 53#undef const 54#define const 55#endif 56 57 58/* 59 * Commands 60 */ 61typedef enum { 62 ELF_C_NULL = 0, /* must be first, 0 */ 63 ELF_C_READ, 64 ELF_C_WRITE, 65 ELF_C_CLR, 66 ELF_C_SET, 67 ELF_C_FDDONE, 68 ELF_C_FDREAD, 69 ELF_C_RDWR, 70 ELF_C_WRIMAGE, 71 ELF_C_IMAGE, 72 ELF_C_NUM /* must be last */ 73} Elf_Cmd; 74 75 76/* 77 * Flags 78 */ 79#define ELF_F_DIRTY 0x1 80#define ELF_F_LAYOUT 0x4 81 82 83/* 84 * File types 85 */ 86typedef enum { 87 ELF_K_NONE = 0, /* must be first, 0 */ 88 ELF_K_AR, 89 ELF_K_COFF, 90 ELF_K_ELF, 91 ELF_K_NUM /* must be last */ 92} Elf_Kind; 93 94 95/* 96 * Translation types 97 */ 98typedef enum { 99 ELF_T_BYTE = 0, /* must be first, 0 */ 100 ELF_T_ADDR, 101 ELF_T_DYN, 102 ELF_T_EHDR, 103 ELF_T_HALF, 104 ELF_T_OFF, 105 ELF_T_PHDR, 106 ELF_T_RELA, 107 ELF_T_REL, 108 ELF_T_SHDR, 109 ELF_T_SWORD, 110 ELF_T_SYM, 111 ELF_T_WORD, 112 ELF_T_VDEF, 113 ELF_T_VNEED, 114 ELF_T_SXWORD, 115 ELF_T_XWORD, 116 ELF_T_SYMINFO, 117 ELF_T_NOTE, 118 ELF_T_MOVE, 119 ELF_T_MOVEP, 120 ELF_T_CAP, 121 ELF_T_NUM /* must be last */ 122} Elf_Type; 123 124 125typedef struct Elf Elf; 126typedef struct Elf_Scn Elf_Scn; 127 128 129/* 130 * Archive member header 131 */ 132typedef struct { 133 char *ar_name; 134 time_t ar_date; 135 uid_t ar_uid; 136 gid_t ar_gid; 137 mode_t ar_mode; 138 off_t ar_size; 139 char *ar_rawname; 140} Elf_Arhdr; 141 142 143/* 144 * Archive symbol table 145 */ 146typedef struct { 147 char *as_name; 148 size_t as_off; 149 unsigned long as_hash; 150} Elf_Arsym; 151 152 153/* 154 * Data descriptor 155 */ 156typedef struct { 157 Elf_Void *d_buf; 158 Elf_Type d_type; 159 size_t d_size; 160 off_t d_off; /* offset into section */ 161 size_t d_align; /* alignment in section */ 162 unsigned d_version; /* elf version */ 163} Elf_Data; 164 165 166/* 167 * Function declarations 168 */ 169Elf *elf_begin _((int, Elf_Cmd, Elf *)); 170int elf_cntl _((Elf *, Elf_Cmd)); 171int elf_end _((Elf *)); 172const char *elf_errmsg _((int)); 173int elf_errno _((void)); 174void elf_fill _((int)); 175unsigned elf_flagdata _((Elf_Data *, Elf_Cmd, unsigned)); 176unsigned elf_flagehdr _((Elf *, Elf_Cmd, unsigned)); 177unsigned elf_flagelf _((Elf *, Elf_Cmd, unsigned)); 178unsigned elf_flagphdr _((Elf *, Elf_Cmd, unsigned)); 179unsigned elf_flagscn _((Elf_Scn *, Elf_Cmd, unsigned)); 180unsigned elf_flagshdr _((Elf_Scn *, Elf_Cmd, unsigned)); 181size_t elf32_fsize _((Elf_Type, size_t, unsigned)); 182Elf_Arhdr *elf_getarhdr _((Elf *)); 183Elf_Arsym *elf_getarsym _((Elf *, size_t *)); 184off_t elf_getbase _((Elf *)); 185Elf_Data *elf_getdata _((Elf_Scn *, Elf_Data *)); 186Elf32_Ehdr *elf32_getehdr _((Elf *)); 187char *elf_getident _((Elf *, size_t *)); 188Elf32_Phdr *elf32_getphdr _((Elf *)); 189Elf_Scn *elf_getscn _((Elf *elf, size_t)); 190Elf32_Shdr *elf32_getshdr _((Elf_Scn *)); 191int elf_getphnum _((Elf *, size_t *)); 192int elf_getphdrnum _((Elf *, size_t *)); 193int elf_getshnum _((Elf *, size_t *)); 194int elf_getshdrnum _((Elf *, size_t *)); 195int elf_getshstrndx _((Elf *, size_t *)); 196int elf_getshdrstrndx _((Elf *, size_t *)); 197unsigned long elf_hash _((const char *)); 198uint_t elf_sys_encoding _((void)); 199long elf32_checksum _((Elf *)); 200Elf_Kind elf_kind _((Elf *)); 201Elf *elf_memory _((char *, size_t)); 202size_t elf_ndxscn _((Elf_Scn *)); 203Elf_Data *elf_newdata _((Elf_Scn *)); 204Elf32_Ehdr *elf32_newehdr _((Elf *)); 205Elf32_Phdr *elf32_newphdr _((Elf *, size_t)); 206Elf_Scn *elf_newscn _((Elf *)); 207Elf_Scn *elf_nextscn _((Elf *, Elf_Scn *)); 208Elf_Cmd elf_next _((Elf *)); 209size_t elf_rand _((Elf *, size_t)); 210Elf_Data *elf_rawdata _((Elf_Scn *, Elf_Data *)); 211char *elf_rawfile _((Elf *, size_t *)); 212char *elf_strptr _((Elf *, size_t, size_t)); 213off_t elf_update _((Elf *, Elf_Cmd)); 214unsigned elf_version _((unsigned)); 215Elf_Data *elf32_xlatetof _((Elf_Data *, const Elf_Data *, unsigned)); 216Elf_Data *elf32_xlatetom _((Elf_Data *, const Elf_Data *, unsigned)); 217 218#if defined(_LP64) || defined(_LONGLONG_TYPE) 219size_t elf64_fsize _((Elf_Type, size_t, unsigned)); 220Elf64_Ehdr *elf64_getehdr _((Elf *)); 221Elf64_Phdr *elf64_getphdr _((Elf *)); 222Elf64_Shdr *elf64_getshdr _((Elf_Scn *)); 223long elf64_checksum _((Elf *)); 224Elf64_Ehdr *elf64_newehdr _((Elf *)); 225Elf64_Phdr *elf64_newphdr _((Elf *, size_t)); 226Elf_Data *elf64_xlatetof _((Elf_Data *, const Elf_Data *, unsigned)); 227Elf_Data *elf64_xlatetom _((Elf_Data *, const Elf_Data *, unsigned)); 228#endif /* (defined(_LP64) || defined(_LONGLONG_TYPE) */ 229 230#undef _ 231 232#ifdef __cplusplus 233} 234#endif 235 236#endif /* _LIBELF_H */ 237