1 // Copyright (c) 2012, Google Inc. 2 // All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions are 6 // met: 7 // 8 // * Redistributions of source code must retain the above copyright 9 // notice, this list of conditions and the following disclaimer. 10 // * Redistributions in binary form must reproduce the above 11 // copyright notice, this list of conditions and the following disclaimer 12 // in the documentation and/or other materials provided with the 13 // distribution. 14 // * Neither the name of Google Inc. nor the names of its 15 // contributors may be used to endorse or promote products derived from 16 // this software without specific prior written permission. 17 // 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 30 #ifndef GOOGLE_BREAKPAD_COMMON_ANDROID_INCLUDE_ELF_H 31 #define GOOGLE_BREAKPAD_COMMON_ANDROID_INCLUDE_ELF_H 32 33 #include <stdint.h> 34 #include <libgen.h> 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif // __cplusplus 39 40 // The Android <elf.h> provides BSD-based definitions for the ElfXX_Nhdr 41 // types 42 // always source-compatible with the GLibc/kernel ones. To overcome this 43 // issue without modifying a lot of code in Breakpad, use an ugly macro 44 // renaming trick with #include_next 45 46 // Avoid conflict with BSD-based definition of ElfXX_Nhdr. 47 // Unfortunately, their field member names do not use a 'n_' prefix. 48 #define Elf32_Nhdr __bsd_Elf32_Nhdr 49 #define Elf64_Nhdr __bsd_Elf64_Nhdr 50 51 // In case they are defined by the NDK version 52 #define Elf32_auxv_t __bionic_Elf32_auxv_t 53 #define Elf64_auxv_t __bionic_Elf64_auxv_t 54 55 #define Elf32_Dyn __bionic_Elf32_Dyn 56 #define Elf64_Dyn __bionic_Elf64_Dyn 57 58 #include_next <elf.h> 59 60 #undef Elf32_Nhdr 61 #undef Elf64_Nhdr 62 63 typedef struct { 64 Elf32_Word n_namesz; 65 Elf32_Word n_descsz; 66 Elf32_Word n_type; 67 } Elf32_Nhdr; 68 69 typedef struct { 70 Elf64_Word n_namesz; 71 Elf64_Word n_descsz; 72 Elf64_Word n_type; 73 } Elf64_Nhdr; 74 75 #undef Elf32_auxv_t 76 #undef Elf64_auxv_t 77 78 typedef struct { 79 uint32_t a_type; 80 union { 81 uint32_t a_val; 82 } a_un; 83 } Elf32_auxv_t; 84 85 typedef struct { 86 uint64_t a_type; 87 union { 88 uint64_t a_val; 89 } a_un; 90 } Elf64_auxv_t; 91 92 #undef Elf32_Dyn 93 #undef Elf64_Dyn 94 95 typedef struct { 96 Elf32_Sword d_tag; 97 union { 98 Elf32_Word d_val; 99 Elf32_Addr d_ptr; 100 } d_un; 101 } Elf32_Dyn; 102 103 typedef struct { 104 Elf64_Sxword d_tag; 105 union { 106 Elf64_Xword d_val; 107 Elf64_Addr d_ptr; 108 } d_un; 109 } Elf64_Dyn; 110 111 112 // __WORDSIZE is GLibc-specific and used by Google Breakpad on Linux. 113 #ifndef __WORDSIZE 114 #if defined(__i386__) || defined(__ARM_EABI__) || defined(__mips__) 115 #define __WORDSIZE 32 116 #elif defined(__x86_64__) || defined(__aarch64__) 117 #define __WORDSIZE 64 118 #else 119 #error "Unsupported Android CPU ABI" 120 #endif 121 #endif 122 123 // The Android headers don't always define this constant. 124 #ifndef EM_X86_64 125 #define EM_X86_64 62 126 #endif 127 128 #ifndef EM_PPC64 129 #define EM_PPC64 21 130 #endif 131 132 #ifndef EM_S390 133 #define EM_S390 22 134 #endif 135 136 #if !defined(AT_SYSINFO_EHDR) 137 #define AT_SYSINFO_EHDR 33 138 #endif 139 140 #if !defined(NT_PRSTATUS) 141 #define NT_PRSTATUS 1 142 #endif 143 144 #if !defined(NT_PRPSINFO) 145 #define NT_PRPSINFO 3 146 #endif 147 148 #if !defined(NT_AUXV) 149 #define NT_AUXV 6 150 #endif 151 152 #if !defined(NT_PRXFPREG) 153 #define NT_PRXFPREG 0x46e62b7f 154 #endif 155 156 #if !defined(NT_FPREGSET) 157 #define NT_FPREGSET 2 158 #endif 159 160 #if !defined(SHT_MIPS_DWARF) 161 #define SHT_MIPS_DWARF 0x7000001e 162 #endif 163 164 #ifdef __cplusplus 165 } // extern "C" 166 #endif // __cplusplus 167 168 #endif // GOOGLE_BREAKPAD_COMMON_ANDROID_INCLUDE_ELF_H 169