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