msxml3: Fix indexed access to schema collection namespace uris.
[wine] / dlls / dbghelp / image_private.h
1 /*
2  * File elf_private.h - definitions for processing of ELF files
3  *
4  * Copyright (C) 1996, Eric Youngdale.
5  *               1999-2007 Eric Pouech
6  *
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.
11  *
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.
16  *
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
20  */
21
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
46 #define IMAGE_NO_MAP  ((void*)-1)
47
48 #ifdef __ELF__
49
50 #ifdef _WIN64
51 #define         Elf_Ehdr        Elf64_Ehdr
52 #define         Elf_Shdr        Elf64_Shdr
53 #define         Elf_Phdr        Elf64_Phdr
54 #define         Elf_Dyn         Elf64_Dyn
55 #define         Elf_Sym         Elf64_Sym
56 #define         Elf_auxv_t      Elf64_auxv_t
57 #else
58 #define         Elf_Ehdr        Elf32_Ehdr
59 #define         Elf_Shdr        Elf32_Shdr
60 #define         Elf_Phdr        Elf32_Phdr
61 #define         Elf_Dyn         Elf32_Dyn
62 #define         Elf_Sym         Elf32_Sym
63 #define         Elf_auxv_t      Elf32_auxv_t
64 #endif
65 #else
66 #ifndef SHT_NULL
67 #define SHT_NULL        0
68 #endif
69 #endif
70
71 /* structure holding information while handling an ELF image
72  * allows one by one section mapping for memory savings
73  */
74 struct image_file_map
75 {
76     enum module_type            modtype;
77     unsigned                    addr_size;      /* either 16 (not used), 32 or 64 */
78     union
79     {
80         struct elf_file_map
81         {
82             size_t                      elf_size;
83             size_t                      elf_start;
84             int                         fd;
85             const char*                 shstrtab;
86             struct image_file_map*      alternate;      /* another ELF file (linked to this one) */
87             char*                       target_copy;
88 #ifdef __ELF__
89             Elf_Ehdr                    elfhdr;
90             struct
91             {
92                 Elf_Shdr                        shdr;
93                 const char*                     mapped;
94             }*                          sect;
95 #endif
96         } elf;
97         struct pe_file_map
98         {
99             HANDLE                      hMap;
100             IMAGE_NT_HEADERS            ntheader;
101             unsigned                    full_count;
102             void*                       full_map;
103             struct
104             {
105                 IMAGE_SECTION_HEADER            shdr;
106                 const char*                     mapped;
107             }*                          sect;
108             const char*                 strtable;
109         } pe;
110     } u;
111 };
112
113 struct image_section_map
114 {
115     struct image_file_map*      fmap;
116     long                        sidx;
117 };
118
119 extern BOOL         elf_find_section(struct image_file_map* fmap, const char* name,
120                                      unsigned sht, struct image_section_map* ism) DECLSPEC_HIDDEN;
121 extern const char*  elf_map_section(struct image_section_map* ism) DECLSPEC_HIDDEN;
122 extern void         elf_unmap_section(struct image_section_map* ism) DECLSPEC_HIDDEN;
123 extern DWORD_PTR    elf_get_map_rva(const struct image_section_map* ism) DECLSPEC_HIDDEN;
124 extern unsigned     elf_get_map_size(const struct image_section_map* ism) DECLSPEC_HIDDEN;
125
126 extern BOOL         pe_find_section(struct image_file_map* fmap, const char* name,
127                                     struct image_section_map* ism) DECLSPEC_HIDDEN;
128 extern const char*  pe_map_section(struct image_section_map* psm) DECLSPEC_HIDDEN;
129 extern void         pe_unmap_section(struct image_section_map* psm) DECLSPEC_HIDDEN;
130 extern DWORD_PTR    pe_get_map_rva(const struct image_section_map* psm) DECLSPEC_HIDDEN;
131 extern unsigned     pe_get_map_size(const struct image_section_map* psm) DECLSPEC_HIDDEN;
132
133 static inline BOOL image_find_section(struct image_file_map* fmap, const char* name,
134                                       struct image_section_map* ism)
135 {
136     switch (fmap->modtype)
137     {
138     case DMT_ELF: return elf_find_section(fmap, name, SHT_NULL, ism);
139     case DMT_PE:  return pe_find_section(fmap, name, ism);
140     default: assert(0); return FALSE;
141     }
142 }
143
144 static inline const char* image_map_section(struct image_section_map* ism)
145 {
146     if (!ism->fmap) return NULL;
147     switch (ism->fmap->modtype)
148     {
149     case DMT_ELF: return elf_map_section(ism);
150     case DMT_PE:  return pe_map_section(ism);
151     default: assert(0); return NULL;
152     }
153 }
154
155 static inline void image_unmap_section(struct image_section_map* ism)
156 {
157     if (!ism->fmap) return;
158     switch (ism->fmap->modtype)
159     {
160     case DMT_ELF: elf_unmap_section(ism); break;
161     case DMT_PE:  pe_unmap_section(ism);   break;
162     default: assert(0); return;
163     }
164 }
165
166 static inline DWORD_PTR image_get_map_rva(const struct image_section_map* ism)
167 {
168     if (!ism->fmap) return 0;
169     switch (ism->fmap->modtype)
170     {
171     case DMT_ELF: return elf_get_map_rva(ism);
172     case DMT_PE:  return pe_get_map_rva(ism);
173     default: assert(0); return 0;
174     }
175 }
176
177 static inline unsigned image_get_map_size(const struct image_section_map* ism)
178 {
179     if (!ism->fmap) return 0;
180     switch (ism->fmap->modtype)
181     {
182     case DMT_ELF: return elf_get_map_size(ism);
183     case DMT_PE:  return pe_get_map_size(ism);
184     default: assert(0); return 0;
185     }
186 }