makefiles: Output rules for building generated .rc files.
[wine.git] / dlls / dbghelp / image_private.h
bloba29794ef582bc21e576fc22be4fec27de886e984
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>
47 #endif
49 #define IMAGE_NO_MAP ((void*)-1)
51 #ifndef __ELF__
52 #ifndef SHT_NULL
53 #define SHT_NULL 0
54 #endif
55 #endif
57 /* structure holding information while handling an ELF image
58 * allows one by one section mapping for memory savings
60 struct image_file_map
62 enum module_type modtype;
63 unsigned addr_size; /* either 16 (not used), 32 or 64 */
64 union
66 struct elf_file_map
68 size_t elf_size;
69 size_t elf_start;
70 int fd;
71 const char* shstrtab;
72 struct image_file_map* alternate; /* another ELF file (linked to this one) */
73 char* target_copy;
74 #ifdef __ELF__
75 Elf64_Ehdr elfhdr;
76 struct
78 Elf64_Shdr shdr;
79 const char* mapped;
80 }* sect;
81 #endif
82 } elf;
83 struct macho_file_map
85 size_t segs_size;
86 size_t segs_start;
87 int fd;
88 struct image_file_map* dsym; /* the debug symbols file associated with this one */
90 #ifdef HAVE_MACH_O_LOADER_H
91 struct mach_header mach_header;
92 size_t header_size; /* size of real header in file */
93 const struct load_command* load_commands;
94 const struct uuid_command* uuid;
96 /* The offset in the file which is this architecture. mach_header was
97 * read from arch_offset. */
98 unsigned arch_offset;
100 int num_sections;
101 struct
103 struct section_64 section;
104 const char* mapped;
105 unsigned int ignored : 1;
106 }* sect;
107 #endif
108 } macho;
109 struct pe_file_map
111 HANDLE hMap;
112 IMAGE_NT_HEADERS ntheader;
113 unsigned full_count;
114 void* full_map;
115 struct
117 IMAGE_SECTION_HEADER shdr;
118 const char* mapped;
119 }* sect;
120 const char* strtable;
121 } pe;
122 } u;
125 struct image_section_map
127 struct image_file_map* fmap;
128 long sidx;
131 extern BOOL elf_find_section(struct image_file_map* fmap, const char* name,
132 unsigned sht, struct image_section_map* ism) DECLSPEC_HIDDEN;
133 extern const char* elf_map_section(struct image_section_map* ism) DECLSPEC_HIDDEN;
134 extern void elf_unmap_section(struct image_section_map* ism) DECLSPEC_HIDDEN;
135 extern DWORD_PTR elf_get_map_rva(const struct image_section_map* ism) DECLSPEC_HIDDEN;
136 extern unsigned elf_get_map_size(const struct image_section_map* ism) DECLSPEC_HIDDEN;
138 extern BOOL macho_find_section(struct image_file_map* ifm, const char* segname,
139 const char* sectname, struct image_section_map* ism) DECLSPEC_HIDDEN;
140 extern const char* macho_map_section(struct image_section_map* ism) DECLSPEC_HIDDEN;
141 extern void macho_unmap_section(struct image_section_map* ism) DECLSPEC_HIDDEN;
142 extern DWORD_PTR macho_get_map_rva(const struct image_section_map* ism) DECLSPEC_HIDDEN;
143 extern unsigned macho_get_map_size(const struct image_section_map* ism) DECLSPEC_HIDDEN;
145 extern BOOL pe_find_section(struct image_file_map* fmap, const char* name,
146 struct image_section_map* ism) DECLSPEC_HIDDEN;
147 extern const char* pe_map_section(struct image_section_map* psm) DECLSPEC_HIDDEN;
148 extern void pe_unmap_section(struct image_section_map* psm) DECLSPEC_HIDDEN;
149 extern DWORD_PTR pe_get_map_rva(const struct image_section_map* psm) DECLSPEC_HIDDEN;
150 extern unsigned pe_get_map_size(const struct image_section_map* psm) DECLSPEC_HIDDEN;
152 static inline BOOL image_find_section(struct image_file_map* fmap, const char* name,
153 struct image_section_map* ism)
155 switch (fmap->modtype)
157 case DMT_ELF: return elf_find_section(fmap, name, SHT_NULL, ism);
158 case DMT_MACHO: return macho_find_section(fmap, NULL, name, ism);
159 case DMT_PE: return pe_find_section(fmap, name, ism);
160 default: assert(0); return FALSE;
164 static inline const char* image_map_section(struct image_section_map* ism)
166 if (!ism->fmap) return NULL;
167 switch (ism->fmap->modtype)
169 case DMT_ELF: return elf_map_section(ism);
170 case DMT_MACHO: return macho_map_section(ism);
171 case DMT_PE: return pe_map_section(ism);
172 default: assert(0); return NULL;
176 static inline void image_unmap_section(struct image_section_map* ism)
178 if (!ism->fmap) return;
179 switch (ism->fmap->modtype)
181 case DMT_ELF: elf_unmap_section(ism); break;
182 case DMT_MACHO: macho_unmap_section(ism); break;
183 case DMT_PE: pe_unmap_section(ism); break;
184 default: assert(0); return;
188 static inline DWORD_PTR image_get_map_rva(const struct image_section_map* ism)
190 if (!ism->fmap) return 0;
191 switch (ism->fmap->modtype)
193 case DMT_ELF: return elf_get_map_rva(ism);
194 case DMT_MACHO: return macho_get_map_rva(ism);
195 case DMT_PE: return pe_get_map_rva(ism);
196 default: assert(0); return 0;
200 static inline unsigned image_get_map_size(const struct image_section_map* ism)
202 if (!ism->fmap) return 0;
203 switch (ism->fmap->modtype)
205 case DMT_ELF: return elf_get_map_size(ism);
206 case DMT_MACHO: return macho_get_map_size(ism);
207 case DMT_PE: return pe_get_map_size(ism);
208 default: assert(0); return 0;