Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenimage_private.h
Go to the documentation of this file.
00001 /* 00002 * File elf_private.h - definitions for processing of ELF files 00003 * 00004 * Copyright (C) 1996, Eric Youngdale. 00005 * 1999-2007 Eric Pouech 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00020 */ 00021 00022 #ifdef HAVE_ELF_H 00023 # include <elf.h> 00024 #endif 00025 #ifdef HAVE_SYS_ELF32_H 00026 # include <sys/elf32.h> 00027 #endif 00028 #ifdef HAVE_SYS_EXEC_ELF_H 00029 # include <sys/exec_elf.h> 00030 #endif 00031 #if !defined(DT_NUM) 00032 # if defined(DT_COUNT) 00033 # define DT_NUM DT_COUNT 00034 # else 00035 /* this seems to be a satisfactory value on Solaris, which doesn't support this AFAICT */ 00036 # define DT_NUM 24 00037 # endif 00038 #endif 00039 #ifdef HAVE_LINK_H 00040 # include <link.h> 00041 #endif 00042 #ifdef HAVE_SYS_LINK_H 00043 # include <sys/link.h> 00044 #endif 00045 00046 #define IMAGE_NO_MAP ((void*)-1) 00047 00048 #ifdef __ELF__ 00049 00050 #ifdef _WIN64 00051 #define Elf_Ehdr Elf64_Ehdr 00052 #define Elf_Shdr Elf64_Shdr 00053 #define Elf_Phdr Elf64_Phdr 00054 #define Elf_Dyn Elf64_Dyn 00055 #define Elf_Sym Elf64_Sym 00056 #define Elf_auxv_t Elf64_auxv_t 00057 #else 00058 #define Elf_Ehdr Elf32_Ehdr 00059 #define Elf_Shdr Elf32_Shdr 00060 #define Elf_Phdr Elf32_Phdr 00061 #define Elf_Dyn Elf32_Dyn 00062 #define Elf_Sym Elf32_Sym 00063 #define Elf_auxv_t Elf32_auxv_t 00064 #endif 00065 #else 00066 #ifndef SHT_NULL 00067 #define SHT_NULL 0 00068 #endif 00069 #endif 00070 00071 /* structure holding information while handling an ELF image 00072 * allows one by one section mapping for memory savings 00073 */ 00074 struct image_file_map 00075 { 00076 enum module_type modtype; 00077 union 00078 { 00079 struct elf_file_map 00080 { 00081 size_t elf_size; 00082 size_t elf_start; 00083 int fd; 00084 const char* shstrtab; 00085 struct image_file_map* alternate; /* another ELF file (linked to this one) */ 00086 char* target_copy; 00087 #ifdef __ELF__ 00088 Elf_Ehdr elfhdr; 00089 struct 00090 { 00091 Elf_Shdr shdr; 00092 const char* mapped; 00093 }* sect; 00094 #endif 00095 } elf; 00096 struct pe_file_map 00097 { 00098 HANDLE hMap; 00099 IMAGE_NT_HEADERS ntheader; 00100 unsigned full_count; 00101 void* full_map; 00102 struct 00103 { 00104 IMAGE_SECTION_HEADER shdr; 00105 const char* mapped; 00106 }* sect; 00107 const char* strtable; 00108 } pe; 00109 } u; 00110 }; 00111 00112 struct image_section_map 00113 { 00114 struct image_file_map* fmap; 00115 long sidx; 00116 }; 00117 00118 extern BOOL elf_find_section(struct image_file_map* fmap, const char* name, 00119 unsigned sht, struct image_section_map* ism) DECLSPEC_HIDDEN; 00120 extern const char* elf_map_section(struct image_section_map* ism) DECLSPEC_HIDDEN; 00121 extern void elf_unmap_section(struct image_section_map* ism) DECLSPEC_HIDDEN; 00122 extern DWORD_PTR elf_get_map_rva(const struct image_section_map* ism) DECLSPEC_HIDDEN; 00123 extern unsigned elf_get_map_size(const struct image_section_map* ism) DECLSPEC_HIDDEN; 00124 00125 extern BOOL pe_find_section(struct image_file_map* fmap, const char* name, 00126 struct image_section_map* ism) DECLSPEC_HIDDEN; 00127 extern const char* pe_map_section(struct image_section_map* psm) DECLSPEC_HIDDEN; 00128 extern void pe_unmap_section(struct image_section_map* psm) DECLSPEC_HIDDEN; 00129 extern DWORD_PTR pe_get_map_rva(const struct image_section_map* psm) DECLSPEC_HIDDEN; 00130 extern unsigned pe_get_map_size(const struct image_section_map* psm) DECLSPEC_HIDDEN; 00131 00132 static inline BOOL image_find_section(struct image_file_map* fmap, const char* name, 00133 struct image_section_map* ism) 00134 { 00135 switch (fmap->modtype) 00136 { 00137 case DMT_ELF: return elf_find_section(fmap, name, SHT_NULL, ism); 00138 case DMT_PE: return pe_find_section(fmap, name, ism); 00139 default: assert(0); return FALSE; 00140 } 00141 } 00142 00143 static inline const char* image_map_section(struct image_section_map* ism) 00144 { 00145 if (!ism->fmap) return NULL; 00146 switch (ism->fmap->modtype) 00147 { 00148 case DMT_ELF: return elf_map_section(ism); 00149 case DMT_PE: return pe_map_section(ism); 00150 default: assert(0); return NULL; 00151 } 00152 } 00153 00154 static inline void image_unmap_section(struct image_section_map* ism) 00155 { 00156 if (!ism->fmap) return; 00157 switch (ism->fmap->modtype) 00158 { 00159 case DMT_ELF: elf_unmap_section(ism); break; 00160 case DMT_PE: pe_unmap_section(ism); break; 00161 default: assert(0); return; 00162 } 00163 } 00164 00165 static inline DWORD_PTR image_get_map_rva(const struct image_section_map* ism) 00166 { 00167 if (!ism->fmap) return 0; 00168 switch (ism->fmap->modtype) 00169 { 00170 case DMT_ELF: return elf_get_map_rva(ism); 00171 case DMT_PE: return pe_get_map_rva(ism); 00172 default: assert(0); return 0; 00173 } 00174 } 00175 00176 static inline unsigned image_get_map_size(const struct image_section_map* ism) 00177 { 00178 if (!ism->fmap) return 0; 00179 switch (ism->fmap->modtype) 00180 { 00181 case DMT_ELF: return elf_get_map_size(ism); 00182 case DMT_PE: return pe_get_map_size(ism); 00183 default: assert(0); return 0; 00184 } 00185 } Generated on Fri May 25 2012 04:21:22 for ReactOS by
1.7.6.1
|