TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / dbghelp / image_private.h
blob429b8fbf6efc8695d8af7b4e59f6ceb21aefa47e
1 /*
2 * File elf_private.h - definitions for processing of ELF files
4 * Copyright (C) 1996, Eric Youngdale.
5 * 1999-2007 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #ifdef HAVE_ELF_H
23 # include <elf.h>
24 #endif
25 #ifdef HAVE_SYS_ELF32_H
26 # include <sys/elf32.h>
27 #endif
28 #ifdef HAVE_SYS_EXEC_ELF_H
29 # include <sys/exec_elf.h>
30 #endif
31 #if !defined(DT_NUM)
32 # if defined(DT_COUNT)
33 # define DT_NUM DT_COUNT
34 # else
35 /* this seems to be a satisfactory value on Solaris, which doesn't support this AFAICT */
36 # define DT_NUM 24
37 # endif
38 #endif
39 #ifdef HAVE_LINK_H
40 # include <link.h>
41 #endif
42 #ifdef HAVE_SYS_LINK_H
43 # include <sys/link.h>
44 #endif
45 #ifdef HAVE_MACH_O_LOADER_H
46 #include <mach-o/loader.h>
48 #ifdef _WIN64
49 typedef struct mach_header_64 macho_mach_header;
50 typedef struct section_64 macho_section;
51 #else
52 typedef struct mach_header macho_mach_header;
53 typedef struct section macho_section;
54 #endif
55 #endif
57 #define IMAGE_NO_MAP ((void*)-1)
59 #ifdef __ELF__
61 #ifdef _WIN64
62 #define Elf_Ehdr Elf64_Ehdr
63 #define Elf_Shdr Elf64_Shdr
64 #define Elf_Phdr Elf64_Phdr
65 #define Elf_Dyn Elf64_Dyn
66 #define Elf_Sym Elf64_Sym
67 #define Elf_auxv_t Elf64_auxv_t
68 #else
69 #define Elf_Ehdr Elf32_Ehdr
70 #define Elf_Shdr Elf32_Shdr
71 #define Elf_Phdr Elf32_Phdr
72 #define Elf_Dyn Elf32_Dyn
73 #define Elf_Sym Elf32_Sym
74 #define Elf_auxv_t Elf32_auxv_t
75 #endif
76 #else
77 #ifndef SHT_NULL
78 #define SHT_NULL 0
79 #endif
80 #endif
82 /* structure holding information while handling an ELF image
83 * allows one by one section mapping for memory savings
85 struct image_file_map
87 enum module_type modtype;
88 unsigned addr_size; /* either 16 (not used), 32 or 64 */
89 union
91 struct elf_file_map
93 size_t elf_size;
94 size_t elf_start;
95 int fd;
96 const char* shstrtab;
97 struct image_file_map* alternate; /* another ELF file (linked to this one) */
98 char* target_copy;
99 #ifdef __ELF__
100 Elf_Ehdr elfhdr;
101 struct
103 Elf_Shdr shdr;
104 const char* mapped;
105 }* sect;
106 #endif
107 } elf;
108 struct macho_file_map
110 size_t segs_size;
111 size_t segs_start;
112 int fd;
113 struct image_file_map* dsym; /* the debug symbols file associated with this one */
115 #ifdef HAVE_MACH_O_LOADER_H
116 macho_mach_header mach_header;
117 const struct load_command* load_commands;
118 const struct uuid_command* uuid;
120 /* The offset in the file which is this architecture. mach_header was
121 * read from arch_offset. */
122 unsigned arch_offset;
124 int num_sections;
125 struct
127 const macho_section* section;
128 const char* mapped;
129 unsigned int ignored : 1;
130 }* sect;
131 #endif
132 } macho;
133 struct pe_file_map
135 HANDLE hMap;
136 IMAGE_NT_HEADERS ntheader;
137 unsigned full_count;
138 void* full_map;
139 struct
141 IMAGE_SECTION_HEADER shdr;
142 const char* mapped;
143 }* sect;
144 const char* strtable;
145 } pe;
146 } u;
149 struct image_section_map
151 struct image_file_map* fmap;
152 long sidx;
155 extern BOOL elf_find_section(struct image_file_map* fmap, const char* name,
156 unsigned sht, struct image_section_map* ism) DECLSPEC_HIDDEN;
157 extern const char* elf_map_section(struct image_section_map* ism) DECLSPEC_HIDDEN;
158 extern void elf_unmap_section(struct image_section_map* ism) DECLSPEC_HIDDEN;
159 extern DWORD_PTR elf_get_map_rva(const struct image_section_map* ism) DECLSPEC_HIDDEN;
160 extern unsigned elf_get_map_size(const struct image_section_map* ism) DECLSPEC_HIDDEN;
162 extern BOOL macho_find_section(struct image_file_map* ifm, const char* segname,
163 const char* sectname, struct image_section_map* ism) DECLSPEC_HIDDEN;
164 extern const char* macho_map_section(struct image_section_map* ism) DECLSPEC_HIDDEN;
165 extern void macho_unmap_section(struct image_section_map* ism) DECLSPEC_HIDDEN;
166 extern DWORD_PTR macho_get_map_rva(const struct image_section_map* ism) DECLSPEC_HIDDEN;
167 extern unsigned macho_get_map_size(const struct image_section_map* ism) DECLSPEC_HIDDEN;
169 extern BOOL pe_find_section(struct image_file_map* fmap, const char* name,
170 struct image_section_map* ism) DECLSPEC_HIDDEN;
171 extern const char* pe_map_section(struct image_section_map* psm) DECLSPEC_HIDDEN;
172 extern void pe_unmap_section(struct image_section_map* psm) DECLSPEC_HIDDEN;
173 extern DWORD_PTR pe_get_map_rva(const struct image_section_map* psm) DECLSPEC_HIDDEN;
174 extern unsigned pe_get_map_size(const struct image_section_map* psm) DECLSPEC_HIDDEN;
176 static inline BOOL image_find_section(struct image_file_map* fmap, const char* name,
177 struct image_section_map* ism)
179 switch (fmap->modtype)
181 case DMT_ELF: return elf_find_section(fmap, name, SHT_NULL, ism);
182 case DMT_MACHO: return macho_find_section(fmap, NULL, name, ism);
183 case DMT_PE: return pe_find_section(fmap, name, ism);
184 default: assert(0); return FALSE;
188 static inline const char* image_map_section(struct image_section_map* ism)
190 if (!ism->fmap) return NULL;
191 switch (ism->fmap->modtype)
193 case DMT_ELF: return elf_map_section(ism);
194 case DMT_MACHO: return macho_map_section(ism);
195 case DMT_PE: return pe_map_section(ism);
196 default: assert(0); return NULL;
200 static inline void image_unmap_section(struct image_section_map* ism)
202 if (!ism->fmap) return;
203 switch (ism->fmap->modtype)
205 case DMT_ELF: elf_unmap_section(ism); break;
206 case DMT_MACHO: macho_unmap_section(ism); break;
207 case DMT_PE: pe_unmap_section(ism); break;
208 default: assert(0); return;
212 static inline DWORD_PTR image_get_map_rva(const struct image_section_map* ism)
214 if (!ism->fmap) return 0;
215 switch (ism->fmap->modtype)
217 case DMT_ELF: return elf_get_map_rva(ism);
218 case DMT_MACHO: return macho_get_map_rva(ism);
219 case DMT_PE: return pe_get_map_rva(ism);
220 default: assert(0); return 0;
224 static inline unsigned image_get_map_size(const struct image_section_map* ism)
226 if (!ism->fmap) return 0;
227 switch (ism->fmap->modtype)
229 case DMT_ELF: return elf_get_map_size(ism);
230 case DMT_MACHO: return macho_get_map_size(ism);
231 case DMT_PE: return pe_get_map_size(ism);
232 default: assert(0); return 0;