Back to index

php5  5.3.10
readelf.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) Christos Zoulas 2003.
00003  * All Rights Reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice immediately at the beginning of the file, without modification,
00010  *    this list of conditions, and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  *  
00015  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00016  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00018  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
00019  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00020  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00021  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00022  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00023  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00024  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00025  * SUCH DAMAGE.
00026  */
00027 /*
00028  * @(#)Id: readelf.h,v 1.9 2002/05/16 18:45:56 christos Exp
00029  *
00030  * Provide elf data structures for non-elf machines, allowing file
00031  * non-elf hosts to determine if an elf binary is stripped.
00032  * Note: cobbled from the linux header file, with modifications
00033  */
00034 #ifndef __fake_elf_h__
00035 #define __fake_elf_h__
00036 
00037 #if HAVE_STDINT_H
00038 #include <stdint.h>
00039 #endif
00040 
00041 typedef uint32_t     Elf32_Addr;
00042 typedef uint32_t     Elf32_Off;
00043 typedef uint16_t     Elf32_Half;
00044 typedef uint32_t     Elf32_Word;
00045 typedef uint8_t             Elf32_Char;
00046 
00047 #if SIZEOF_LONG_LONG != 8
00048 #define USE_ARRAY_FOR_64BIT_TYPES
00049 typedef       uint32_t      Elf64_Addr[2];
00050 typedef       uint32_t      Elf64_Off[2];
00051 typedef uint32_t     Elf64_Xword[2];
00052 #else
00053 #undef USE_ARRAY_FOR_64BIT_TYPES
00054 typedef       uint64_t      Elf64_Addr;
00055 typedef       uint64_t      Elf64_Off;
00056 typedef uint64_t     Elf64_Xword;
00057 #endif
00058 typedef uint16_t     Elf64_Half;
00059 typedef uint32_t     Elf64_Word;
00060 typedef uint8_t             Elf64_Char;
00061 
00062 #define EI_NIDENT    16
00063 
00064 typedef struct {
00065     Elf32_Char       e_ident[EI_NIDENT];
00066     Elf32_Half       e_type;
00067     Elf32_Half       e_machine;
00068     Elf32_Word       e_version;
00069     Elf32_Addr       e_entry;  /* Entry point */
00070     Elf32_Off e_phoff;
00071     Elf32_Off e_shoff;
00072     Elf32_Word       e_flags;
00073     Elf32_Half       e_ehsize;
00074     Elf32_Half       e_phentsize;
00075     Elf32_Half       e_phnum;
00076     Elf32_Half       e_shentsize;
00077     Elf32_Half       e_shnum;
00078     Elf32_Half       e_shstrndx;
00079 } Elf32_Ehdr;
00080 
00081 typedef struct {
00082     Elf64_Char       e_ident[EI_NIDENT];
00083     Elf64_Half       e_type;
00084     Elf64_Half       e_machine;
00085     Elf64_Word       e_version;
00086     Elf64_Addr       e_entry;  /* Entry point */
00087     Elf64_Off e_phoff;
00088     Elf64_Off e_shoff;
00089     Elf64_Word       e_flags;
00090     Elf64_Half       e_ehsize;
00091     Elf64_Half       e_phentsize;
00092     Elf64_Half       e_phnum;
00093     Elf64_Half       e_shentsize;
00094     Elf64_Half       e_shnum;
00095     Elf64_Half       e_shstrndx;
00096 } Elf64_Ehdr;
00097 
00098 /* e_type */
00099 #define ET_REL              1
00100 #define ET_EXEC             2
00101 #define ET_DYN              3
00102 #define ET_CORE             4
00103 
00104 /* e_machine (used only for SunOS 5.x hardware capabilities) */
00105 #define       EM_SPARC      2
00106 #define       EM_386        3
00107 #define       EM_SPARC32PLUS       18
00108 #define       EM_SPARCV9    43
00109 #define       EM_IA_64      50
00110 #define       EM_AMD64      62
00111 
00112 /* sh_type */
00113 #define SHT_SYMTAB   2
00114 #define SHT_NOTE     7
00115 #define SHT_DYNSYM   11
00116 #define SHT_SUNW_cap 0x6ffffff5    /* SunOS 5.x hw/sw capabilites */
00117 
00118 /* elf type */
00119 #define ELFDATANONE  0             /* e_ident[EI_DATA] */
00120 #define ELFDATA2LSB  1
00121 #define ELFDATA2MSB  2
00122 
00123 /* elf class */
00124 #define ELFCLASSNONE 0
00125 #define ELFCLASS32   1
00126 #define ELFCLASS64   2
00127 
00128 /* magic number */
00129 #define       EI_MAG0              0             /* e_ident[] indexes */
00130 #define       EI_MAG1              1
00131 #define       EI_MAG2              2
00132 #define       EI_MAG3              3
00133 #define       EI_CLASS      4
00134 #define       EI_DATA              5
00135 #define       EI_VERSION    6
00136 #define       EI_PAD        7
00137 
00138 #define       ELFMAG0              0x7f          /* EI_MAG */
00139 #define       ELFMAG1              'E'
00140 #define       ELFMAG2              'L'
00141 #define       ELFMAG3              'F'
00142 #define       ELFMAG        "\177ELF"
00143 
00144 #define       OLFMAG1              'O'
00145 #define       OLFMAG        "\177OLF"
00146 
00147 typedef struct {
00148     Elf32_Word       p_type;
00149     Elf32_Off p_offset;
00150     Elf32_Addr       p_vaddr;
00151     Elf32_Addr       p_paddr;
00152     Elf32_Word       p_filesz;
00153     Elf32_Word       p_memsz;
00154     Elf32_Word       p_flags;
00155     Elf32_Word       p_align;
00156 } Elf32_Phdr;
00157 
00158 typedef struct {
00159     Elf64_Word       p_type;
00160     Elf64_Word       p_flags;
00161     Elf64_Off p_offset;
00162     Elf64_Addr       p_vaddr;
00163     Elf64_Addr       p_paddr;
00164     Elf64_Xword      p_filesz;
00165     Elf64_Xword      p_memsz;
00166     Elf64_Xword      p_align;
00167 } Elf64_Phdr;
00168 
00169 #define       PT_NULL              0             /* p_type */
00170 #define       PT_LOAD              1
00171 #define       PT_DYNAMIC    2
00172 #define       PT_INTERP     3
00173 #define       PT_NOTE              4
00174 #define       PT_SHLIB      5
00175 #define       PT_PHDR              6
00176 #define       PT_NUM        7
00177 
00178 typedef struct {
00179     Elf32_Word       sh_name;
00180     Elf32_Word       sh_type;
00181     Elf32_Word       sh_flags;
00182     Elf32_Addr       sh_addr;
00183     Elf32_Off sh_offset;
00184     Elf32_Word       sh_size;
00185     Elf32_Word       sh_link;
00186     Elf32_Word       sh_info;
00187     Elf32_Word       sh_addralign;
00188     Elf32_Word       sh_entsize;
00189 } Elf32_Shdr;
00190 
00191 typedef struct {
00192     Elf64_Word       sh_name;
00193     Elf64_Word       sh_type;
00194     Elf64_Off sh_flags;
00195     Elf64_Addr       sh_addr;
00196     Elf64_Off sh_offset;
00197     Elf64_Off sh_size;
00198     Elf64_Word       sh_link;
00199     Elf64_Word       sh_info;
00200     Elf64_Off sh_addralign;
00201     Elf64_Off sh_entsize;
00202 } Elf64_Shdr;
00203 
00204 #define       NT_NETBSD_CORE_PROCINFO            1
00205 
00206 /* Note header in a PT_NOTE section */
00207 typedef struct elf_note {
00208     Elf32_Word       n_namesz;     /* Name size */
00209     Elf32_Word       n_descsz;     /* Content size */
00210     Elf32_Word       n_type;              /* Content type */
00211 } Elf32_Nhdr;
00212 
00213 typedef struct {
00214     Elf64_Word       n_namesz;
00215     Elf64_Word       n_descsz;
00216     Elf64_Word       n_type;
00217 } Elf64_Nhdr;
00218 
00219 /* Notes used in ET_CORE */
00220 #define       NT_PRSTATUS   1
00221 #define       NT_PRFPREG    2
00222 #define       NT_PRPSINFO   3
00223 #define       NT_PRXREG     4
00224 #define NT_TASKSTRUCT       4
00225 #define       NT_PLATFORM   5
00226 #define       NT_AUXV              6
00227 
00228 /* Note types used in executables */
00229 /* NetBSD executables (name = "NetBSD") */
00230 #define NT_NETBSD_VERSION   1
00231 #define NT_NETBSD_EMULATION 2
00232 #define NT_FREEBSD_VERSION  1
00233 #define NT_OPENBSD_VERSION  1
00234 #define NT_DRAGONFLY_VERSION       1
00235 /* GNU executables (name = "GNU") */
00236 #define NT_GNU_VERSION             1
00237 
00238 /* GNU OS tags */
00239 #define GNU_OS_LINUX 0
00240 #define GNU_OS_HURD  1
00241 #define GNU_OS_SOLARIS      2
00242 #define GNU_OS_KFREEBSD     3
00243 #define GNU_OS_KNETBSD      4
00244 
00245 /* SunOS 5.x hardware/software capabilities */
00246 typedef struct {
00247        Elf32_Word    c_tag;
00248        union {
00249               Elf32_Word    c_val;
00250               Elf32_Addr    c_ptr;
00251        } c_un;
00252 } Elf32_Cap;
00253 
00254 typedef struct {
00255        Elf64_Xword   c_tag;
00256        union {
00257               Elf64_Xword   c_val;
00258               Elf64_Addr    c_ptr;
00259        } c_un;
00260 } Elf64_Cap;
00261 
00262 /* SunOS 5.x hardware/software capability tags */
00263 #define       CA_SUNW_NULL  0
00264 #define       CA_SUNW_HW_1  1
00265 #define       CA_SUNW_SF_1  2
00266 
00267 /* SunOS 5.x software capabilities */
00268 #define       SF1_SUNW_FPKNWN      0x01
00269 #define       SF1_SUNW_FPUSED      0x02
00270 #define       SF1_SUNW_MASK 0x03
00271 
00272 /* SunOS 5.x hardware capabilities: sparc */
00273 #define       AV_SPARC_MUL32              0x0001
00274 #define       AV_SPARC_DIV32              0x0002
00275 #define       AV_SPARC_FSMULD             0x0004
00276 #define       AV_SPARC_V8PLUS             0x0008
00277 #define       AV_SPARC_POPC        0x0010
00278 #define       AV_SPARC_VIS         0x0020
00279 #define       AV_SPARC_VIS2        0x0040
00280 #define       AV_SPARC_ASI_BLK_INIT       0x0080
00281 #define       AV_SPARC_FMAF        0x0100
00282 #define       AV_SPARC_FJFMAU             0x4000
00283 #define       AV_SPARC_IMA         0x8000
00284 
00285 /* SunOS 5.x hardware capabilities: 386 */
00286 #define       AV_386_FPU           0x00000001
00287 #define       AV_386_TSC           0x00000002
00288 #define       AV_386_CX8           0x00000004
00289 #define       AV_386_SEP           0x00000008
00290 #define       AV_386_AMD_SYSC             0x00000010
00291 #define       AV_386_CMOV          0x00000020
00292 #define       AV_386_MMX           0x00000040
00293 #define       AV_386_AMD_MMX              0x00000080
00294 #define       AV_386_AMD_3DNow     0x00000100
00295 #define       AV_386_AMD_3DNowx    0x00000200
00296 #define       AV_386_FXSR          0x00000400
00297 #define       AV_386_SSE           0x00000800
00298 #define       AV_386_SSE2          0x00001000
00299 #define       AV_386_PAUSE         0x00002000
00300 #define       AV_386_SSE3          0x00004000
00301 #define       AV_386_MON           0x00008000
00302 #define       AV_386_CX16          0x00010000
00303 #define       AV_386_AHF           0x00020000
00304 #define       AV_386_TSCP          0x00040000
00305 #define       AV_386_AMD_SSE4A     0x00080000
00306 #define       AV_386_POPCNT        0x00100000
00307 #define       AV_386_AMD_LZCNT     0x00200000
00308 #define       AV_386_SSSE3         0x00400000
00309 #define       AV_386_SSE4_1        0x00800000
00310 #define       AV_386_SSE4_2        0x01000000
00311 
00312 #endif