gdi32/tests: Mark tests failing randomly on Windows as flaky.
[wine.git] / dlls / dbghelp / image_private.h
blob964e974e49d30864ed4044ce5d58c96ac5e83660
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 #define IMAGE_NO_MAP ((void*)-1)
24 struct elf_header
26 UINT8 e_ident[16]; /* Magic number and other info */
27 UINT16 e_type; /* Object file type */
28 UINT16 e_machine; /* Architecture */
29 UINT32 e_version; /* Object file version */
30 UINT64 e_entry; /* Entry point virtual address */
31 UINT64 e_phoff; /* Program header table file offset */
32 UINT64 e_shoff; /* Section header table file offset */
33 UINT32 e_flags; /* Processor-specific flags */
34 UINT16 e_ehsize; /* ELF header size in bytes */
35 UINT16 e_phentsize; /* Program header table entry size */
36 UINT16 e_phnum; /* Program header table entry count */
37 UINT16 e_shentsize; /* Section header table entry size */
38 UINT16 e_shnum; /* Section header table entry count */
39 UINT16 e_shstrndx; /* Section header string table index */
42 struct elf_section_header
44 UINT32 sh_name; /* Section name (string tbl index) */
45 UINT32 sh_type; /* Section type */
46 UINT64 sh_flags; /* Section flags */
47 UINT64 sh_addr; /* Section virtual addr at execution */
48 UINT64 sh_offset; /* Section file offset */
49 UINT64 sh_size; /* Section size in bytes */
50 UINT32 sh_link; /* Link to another section */
51 UINT32 sh_info; /* Additional section information */
52 UINT64 sh_addralign; /* Section alignment */
53 UINT64 sh_entsize; /* Entry size if section holds table */
56 struct macho_load_command
58 UINT32 cmd; /* type of load command */
59 UINT32 cmdsize; /* total size of command in bytes */
62 struct macho_uuid_command
64 UINT32 cmd; /* LC_UUID */
65 UINT32 cmdsize;
66 UINT8 uuid[16];
69 struct macho_section
71 char sectname[16]; /* name of this section */
72 char segname[16]; /* segment this section goes in */
73 UINT64 addr; /* memory address of this section */
74 UINT64 size; /* size in bytes of this section */
75 UINT32 offset; /* file offset of this section */
76 UINT32 align; /* section alignment (power of 2) */
77 UINT32 reloff; /* file offset of relocation entries */
78 UINT32 nreloc; /* number of relocation entries */
79 UINT32 flags; /* flags (section type and attributes)*/
80 UINT32 reserved1; /* reserved (for offset or index) */
81 UINT32 reserved2; /* reserved (for count or sizeof) */
82 UINT32 reserved3; /* reserved */
85 struct macho_section32
87 char sectname[16]; /* name of this section */
88 char segname[16]; /* segment this section goes in */
89 UINT32 addr; /* memory address of this section */
90 UINT32 size; /* size in bytes of this section */
91 UINT32 offset; /* file offset of this section */
92 UINT32 align; /* section alignment (power of 2) */
93 UINT32 reloff; /* file offset of relocation entries */
94 UINT32 nreloc; /* number of relocation entries */
95 UINT32 flags; /* flags (section type and attributes)*/
96 UINT32 reserved1; /* reserved (for offset or index) */
97 UINT32 reserved2; /* reserved (for count or sizeof) */
100 /* structure holding information while handling an ELF image
101 * allows one by one section mapping for memory savings
103 struct image_file_map
105 enum module_type modtype;
106 const struct image_file_map_ops *ops;
107 unsigned addr_size; /* either 16 (not used), 32 or 64 */
108 struct image_file_map* alternate; /* another file linked to this one */
109 union
111 struct elf_file_map
113 size_t elf_size;
114 size_t elf_start;
115 HANDLE handle;
116 const char* shstrtab;
117 char* target_copy;
118 struct elf_header elfhdr;
119 struct
121 struct elf_section_header shdr;
122 const char* mapped;
123 }* sect;
124 } elf;
125 struct macho_file_map
127 size_t segs_size;
128 size_t segs_start;
129 HANDLE handle;
130 struct image_file_map* dsym; /* the debug symbols file associated with this one */
131 size_t header_size; /* size of real header in file */
132 size_t commands_size;
133 unsigned int commands_count;
135 const struct macho_load_command* load_commands;
136 const struct macho_uuid_command* uuid;
138 /* The offset in the file which is this architecture. mach_header was
139 * read from arch_offset. */
140 unsigned arch_offset;
142 int num_sections;
143 struct
145 struct macho_section section;
146 const char* mapped;
147 unsigned int ignored : 1;
148 }* sect;
149 } macho;
150 struct pe_file_map
152 HANDLE hMap;
153 IMAGE_FILE_HEADER file_header;
154 union
156 IMAGE_OPTIONAL_HEADER32 header32;
157 IMAGE_OPTIONAL_HEADER64 header64;
158 } opt;
159 BOOL builtin;
160 unsigned full_count;
161 void* full_map;
162 struct
164 IMAGE_SECTION_HEADER shdr;
165 const char* mapped;
166 }* sect;
167 const char* strtable;
168 } pe;
169 } u;
172 struct image_section_map
174 struct image_file_map* fmap;
175 LONG_PTR sidx;
178 struct stab_nlist
180 unsigned n_strx;
181 unsigned char n_type;
182 char n_other;
183 short n_desc;
184 unsigned n_value;
187 struct macho64_nlist
189 unsigned n_strx;
190 unsigned char n_type;
191 char n_other;
192 short n_desc;
193 UINT64 n_value;
196 BOOL image_check_alternate(struct image_file_map* fmap, const struct module* module) DECLSPEC_HIDDEN;
197 struct image_file_map* image_load_debugaltlink(struct image_file_map* fmap, struct module* module) DECLSPEC_HIDDEN;
199 BOOL elf_map_handle(HANDLE handle, struct image_file_map* fmap) DECLSPEC_HIDDEN;
200 BOOL pe_map_file(HANDLE file, struct image_file_map* fmap, enum module_type mt) DECLSPEC_HIDDEN;
202 struct image_file_map_ops
204 const char* (*map_section)(struct image_section_map* ism);
205 void (*unmap_section)(struct image_section_map* ism);
206 BOOL (*find_section)(struct image_file_map* fmap, const char* name, struct image_section_map* ism);
207 DWORD_PTR (*get_map_rva)(const struct image_section_map* ism);
208 unsigned (*get_map_size)(const struct image_section_map* ism);
209 void (*unmap_file)(struct image_file_map *fmap);
212 static inline BOOL image_find_section(struct image_file_map* fmap, const char* name,
213 struct image_section_map* ism)
215 while (fmap)
217 if (fmap->ops->find_section(fmap, name, ism)) return TRUE;
218 fmap = fmap->alternate;
220 ism->fmap = NULL;
221 ism->sidx = -1;
222 return FALSE;
225 static inline void image_unmap_file(struct image_file_map* fmap)
227 while (fmap)
229 fmap->ops->unmap_file(fmap);
230 fmap = fmap->alternate;
234 static inline const char* image_map_section(struct image_section_map* ism)
236 return ism->fmap ? ism->fmap->ops->map_section(ism) : NULL;
239 static inline void image_unmap_section(struct image_section_map* ism)
241 if (ism->fmap) ism->fmap->ops->unmap_section(ism);
244 static inline DWORD_PTR image_get_map_rva(const struct image_section_map* ism)
246 return ism->fmap ? ism->fmap->ops->get_map_rva(ism) : 0;
249 static inline unsigned image_get_map_size(const struct image_section_map* ism)
251 return ism->fmap ? ism->fmap->ops->get_map_size(ism) : 0;