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
27 #ifdef HAVE_SYS_ELF32_H
28 # include <sys/elf32.h>
30 #ifdef HAVE_SYS_EXEC_ELF_H
31 # include <sys/exec_elf.h>
34 # if defined(DT_COUNT)
35 # define DT_NUM DT_COUNT
37 /* this seems to be a satisfactory value on Solaris, which doesn't support this AFAICT */
44 #ifdef HAVE_SYS_LINK_H
45 # include <sys/link.h>
48 #define IMAGE_NO_MAP ((void*)-1)
50 #if defined(__ELF__) && !defined(DBGHELP_STATIC_LIB)
53 #define Elf_Ehdr Elf64_Ehdr
54 #define Elf_Shdr Elf64_Shdr
55 #define Elf_Phdr Elf64_Phdr
56 #define Elf_Dyn Elf64_Dyn
57 #define Elf_Sym Elf64_Sym
58 #define Elf_auxv_t Elf64_auxv_t
60 #define Elf_Ehdr Elf32_Ehdr
61 #define Elf_Shdr Elf32_Shdr
62 #define Elf_Phdr Elf32_Phdr
63 #define Elf_Dyn Elf32_Dyn
64 #define Elf_Sym Elf32_Sym
65 #define Elf_auxv_t Elf32_auxv_t
73 /* structure holding information while handling an ELF image
74 * allows one by one section mapping for memory savings
78 enum module_type modtype
;
79 unsigned addr_size
; /* either 16 (not used), 32 or 64 */
88 struct image_file_map
* alternate
; /* another ELF file (linked to this one) */
90 #if defined(__ELF__) && !defined(DBGHELP_STATIC_LIB)
102 IMAGE_NT_HEADERS ntheader
;
107 IMAGE_SECTION_HEADER shdr
;
110 const char* strtable
;
115 struct image_section_map
117 struct image_file_map
* fmap
;
121 extern BOOL
elf_find_section(struct image_file_map
* fmap
, const char* name
,
122 unsigned sht
, struct image_section_map
* ism
) DECLSPEC_HIDDEN
;
123 extern const char* elf_map_section(struct image_section_map
* ism
) DECLSPEC_HIDDEN
;
124 extern void elf_unmap_section(struct image_section_map
* ism
) DECLSPEC_HIDDEN
;
125 extern DWORD_PTR
elf_get_map_rva(const struct image_section_map
* ism
) DECLSPEC_HIDDEN
;
126 extern unsigned elf_get_map_size(const struct image_section_map
* ism
) DECLSPEC_HIDDEN
;
128 extern BOOL
pe_find_section(struct image_file_map
* fmap
, const char* name
,
129 struct image_section_map
* ism
) DECLSPEC_HIDDEN
;
130 extern const char* pe_map_section(struct image_section_map
* psm
) DECLSPEC_HIDDEN
;
131 extern void pe_unmap_section(struct image_section_map
* psm
) DECLSPEC_HIDDEN
;
132 extern DWORD_PTR
pe_get_map_rva(const struct image_section_map
* psm
) DECLSPEC_HIDDEN
;
133 extern unsigned pe_get_map_size(const struct image_section_map
* psm
) DECLSPEC_HIDDEN
;
135 static inline BOOL
image_find_section(struct image_file_map
* fmap
, const char* name
,
136 struct image_section_map
* ism
)
138 switch (fmap
->modtype
)
140 #ifndef DBGHELP_STATIC_LIB
141 case DMT_ELF
: return elf_find_section(fmap
, name
, SHT_NULL
, ism
);
143 case DMT_PE
: return pe_find_section(fmap
, name
, ism
);
144 default: assert(0); return FALSE
;
148 static inline const char* image_map_section(struct image_section_map
* ism
)
150 if (!ism
->fmap
) return NULL
;
151 switch (ism
->fmap
->modtype
)
153 #ifndef DBGHELP_STATIC_LIB
154 case DMT_ELF
: return elf_map_section(ism
);
156 case DMT_PE
: return pe_map_section(ism
);
157 default: assert(0); return NULL
;
161 static inline void image_unmap_section(struct image_section_map
* ism
)
163 if (!ism
->fmap
) return;
164 switch (ism
->fmap
->modtype
)
166 #ifndef DBGHELP_STATIC_LIB
167 case DMT_ELF
: elf_unmap_section(ism
); break;
169 case DMT_PE
: pe_unmap_section(ism
); break;
170 default: assert(0); return;
174 static inline DWORD_PTR
image_get_map_rva(const struct image_section_map
* ism
)
176 if (!ism
->fmap
) return 0;
177 switch (ism
->fmap
->modtype
)
179 #ifndef DBGHELP_STATIC_LIB
180 case DMT_ELF
: return elf_get_map_rva(ism
);
182 case DMT_PE
: return pe_get_map_rva(ism
);
183 default: assert(0); return 0;
187 static inline unsigned image_get_map_size(const struct image_section_map
* ism
)
189 if (!ism
->fmap
) return 0;
190 switch (ism
->fmap
->modtype
)
192 #ifndef DBGHELP_STATIC_LIB
193 case DMT_ELF
: return elf_get_map_size(ism
);
195 case DMT_PE
: return pe_get_map_size(ism
);
196 default: assert(0); return 0;