ReactOS 0.4.15-dev-7953-g1f49173
image_private.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  elf_header
 
struct  elf_section_header
 
struct  macho_load_command
 
struct  macho_uuid_command
 
struct  macho_section
 
struct  macho_section32
 
struct  image_file_map
 
struct  image_section_map
 
struct  stab_nlist
 
struct  macho64_nlist
 
struct  image_file_map_ops
 

Macros

#define IMAGE_NO_MAP   ((void*)-1)
 

Functions

BOOL image_check_alternate (struct image_file_map *fmap, const struct module *module) DECLSPEC_HIDDEN
 
BOOL elf_map_handle (HANDLE handle, struct image_file_map *fmap) DECLSPEC_HIDDEN
 
BOOL pe_map_file (HANDLE file, struct image_file_map *fmap, enum module_type mt) DECLSPEC_HIDDEN
 
static BOOL image_find_section (struct image_file_map *fmap, const char *name, struct image_section_map *ism)
 
static void image_unmap_file (struct image_file_map *fmap)
 
static const charimage_map_section (struct image_section_map *ism)
 
static void image_unmap_section (struct image_section_map *ism)
 
static DWORD_PTR image_get_map_rva (const struct image_section_map *ism)
 
static unsigned image_get_map_size (const struct image_section_map *ism)
 

Macro Definition Documentation

◆ IMAGE_NO_MAP

#define IMAGE_NO_MAP   ((void*)-1)

Definition at line 24 of file image_private.h.

Function Documentation

◆ elf_map_handle()

BOOL elf_map_handle ( HANDLE  handle,
struct image_file_map fmap 
)

Definition at line 582 of file elf_module.c.

583{
584 struct elf_map_file_data emfd;
585 emfd.kind = from_handle;
586 emfd.u.handle = handle;
587 return elf_map_file(&emfd, fmap);
588}
static BOOL elf_map_file(struct elf_map_file_data *emfd, struct image_file_map *fmap)
Definition: elf_module.c:406
enum elf_map_file_data::@381 kind

Referenced by image_check_debug_link().

◆ image_check_alternate()

BOOL image_check_alternate ( struct image_file_map fmap,
const struct module module 
)

Definition at line 701 of file module.c.

702{
703 BOOL ret = FALSE;
704 BOOL found = FALSE;
705 struct image_section_map buildid_sect, debuglink_sect;
706
707 /* if present, add the .gnu_debuglink file as an alternate to current one */
708 if (image_find_section(fmap, ".note.gnu.build-id", &buildid_sect))
709 {
710 const UINT32* note;
711
712 found = TRUE;
713 note = (const UINT32*)image_map_section(&buildid_sect);
714 if (note != IMAGE_NO_MAP)
715 {
716 /* the usual ELF note structure: name-size desc-size type <name> <desc> */
717 if (note[2] == NOTE_GNU_BUILD_ID)
718 {
719 ret = image_locate_build_id_target(fmap, (const BYTE*)(note + 3 + ((note[0] + 3) >> 2)), note[1]);
720 }
721 }
722 image_unmap_section(&buildid_sect);
723 }
724 /* if present, add the .gnu_debuglink file as an alternate to current one */
725 if (!ret && image_find_section(fmap, ".gnu_debuglink", &debuglink_sect))
726 {
727 const char* dbg_link;
728
729 found = TRUE;
730 dbg_link = (const char*)image_map_section(&debuglink_sect);
731 if (dbg_link != IMAGE_NO_MAP)
732 {
733 /* The content of a debug link section is:
734 * 1/ a NULL terminated string, containing the file name for the
735 * debug info
736 * 2/ padding on 4 byte boundary
737 * 3/ CRC of the linked file
738 */
739 DWORD crc = *(const DWORD*)(dbg_link + ((DWORD_PTR)(strlen(dbg_link) + 4) & ~3));
740 ret = image_locate_debug_link(module, fmap, dbg_link, crc);
741 if (!ret)
742 WARN("Couldn't load linked debug file for %s\n",
744 }
745 image_unmap_section(&debuglink_sect);
746 }
747 return found ? ret : TRUE;
748}
unsigned int UINT32
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
int note(char *format,...)
Definition: util.c:12
#define WARN(fmt,...)
Definition: debug.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static BOOL image_locate_debug_link(const struct module *module, struct image_file_map *fmap, const char *filename, DWORD crc)
Definition: module.c:543
static BOOL image_locate_build_id_target(struct image_file_map *fmap, const BYTE *id, unsigned idlen)
Definition: module.c:621
#define NOTE_GNU_BUILD_ID
Definition: module.c:38
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IMAGE_NO_MAP
Definition: image_private.h:24
static void image_unmap_section(struct image_section_map *ism)
static BOOL image_find_section(struct image_file_map *fmap, const char *name, struct image_section_map *ism)
static const char * image_map_section(struct image_section_map *ism)
#define debugstr_w
Definition: kernel32.h:32
WCHAR ModuleName[32]
Definition: compat.h:1076
struct image_file_map * fmap
IMAGEHLP_MODULEW64 module
uint32_t DWORD_PTR
Definition: typedefs.h:65
int ret
unsigned char BYTE
Definition: xxhash.c:193

Referenced by elf_load_debug_info_from_map(), and pe_load_debug_info().

◆ image_find_section()

static BOOL image_find_section ( struct image_file_map fmap,
const char name,
struct image_section_map ism 
)
inlinestatic

Definition at line 208 of file image_private.h.

210{
211 while (fmap)
212 {
213 if (fmap->ops->find_section(fmap, name, ism)) return TRUE;
214 fmap = fmap->alternate;
215 }
216 ism->fmap = NULL;
217 ism->sidx = -1;
218 return FALSE;
219}
#define NULL
Definition: types.h:112
struct image_file_map * alternate
const struct image_file_map_ops * ops
Definition: name.c:39

Referenced by dwarf2_init_section(), elf_load_debug_info_from_map(), image_check_alternate(), and image_locate_build_id_target().

◆ image_get_map_rva()

static DWORD_PTR image_get_map_rva ( const struct image_section_map ism)
inlinestatic

Definition at line 240 of file image_private.h.

241{
242 return ism->fmap ? ism->fmap->ops->get_map_rva(ism) : 0;
243}

Referenced by dwarf2_init_section(), and dwarf2_init_zsection().

◆ image_get_map_size()

static unsigned image_get_map_size ( const struct image_section_map ism)
inlinestatic

Definition at line 245 of file image_private.h.

246{
247 return ism->fmap ? ism->fmap->ops->get_map_size(ism) : 0;
248}

Referenced by dwarf2_init_section(), dwarf2_init_zsection(), elf_hash_symtab(), elf_load_debug_info_from_map(), pe_load_rsym(), and pe_load_stabs().

◆ image_map_section()

static const char * image_map_section ( struct image_section_map ism)
inlinestatic

◆ image_unmap_file()

static void image_unmap_file ( struct image_file_map fmap)
inlinestatic

Definition at line 221 of file image_private.h.

222{
223 while (fmap)
224 {
225 fmap->ops->unmap_file(fmap);
226 fmap = fmap->alternate;
227 }
228}

Referenced by elf_fetch_file_info(), elf_load_file(), elf_module_remove(), image_locate_build_id_target(), pe_load_native_module(), and pe_module_remove().

◆ image_unmap_section()

static void image_unmap_section ( struct image_section_map ism)
inlinestatic

◆ pe_map_file()

BOOL pe_map_file ( HANDLE  file,
struct image_file_map fmap,
enum module_type  mt 
)

Definition at line 245 of file pe_module.c.

246{
247 void* mapping;
248
249 fmap->modtype = mt;
250 fmap->ops = &pe_file_map_ops;
251 fmap->alternate = NULL;
252 fmap->u.pe.hMap = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
253 if (fmap->u.pe.hMap == 0) return FALSE;
254 fmap->u.pe.full_count = 0;
255 fmap->u.pe.full_map = NULL;
256 if (!(mapping = pe_map_full(fmap, NULL))) goto error;
257
258 switch (mt)
259 {
260 case DMT_PE:
261 {
262 IMAGE_NT_HEADERS* nthdr;
264 unsigned i;
265
266 if (!(nthdr = RtlImageNtHeader(mapping))) goto error;
267 memcpy(&fmap->u.pe.ntheader, nthdr, sizeof(fmap->u.pe.ntheader));
268 switch (nthdr->OptionalHeader.Magic)
269 {
270 case 0x10b: fmap->addr_size = 32; break;
271 case 0x20b: fmap->addr_size = 64; break;
272 default: return FALSE;
273 }
274
275 fmap->u.pe.builtin = !memcmp((const IMAGE_DOS_HEADER*)mapping + 1, builtin_signature, sizeof(builtin_signature));
277 ((char*)&nthdr->OptionalHeader + nthdr->FileHeader.SizeOfOptionalHeader);
278 fmap->u.pe.sect = HeapAlloc(GetProcessHeap(), 0,
279 nthdr->FileHeader.NumberOfSections * sizeof(fmap->u.pe.sect[0]));
280 if (!fmap->u.pe.sect) goto error;
281 for (i = 0; i < nthdr->FileHeader.NumberOfSections; i++)
282 {
283 memcpy(&fmap->u.pe.sect[i].shdr, section + i, sizeof(IMAGE_SECTION_HEADER));
284 fmap->u.pe.sect[i].mapped = IMAGE_NO_MAP;
285 }
287 {
289
291 {
292 /* FIXME ugly: should rather map the relevant content instead of copying it */
293 const char* src = (const char*)mapping +
295 nthdr->FileHeader.NumberOfSymbols * sizeof(IMAGE_SYMBOL);
296 char* dst;
297 DWORD sz = *(DWORD*)src;
298
299 if ((dst = HeapAlloc(GetProcessHeap(), 0, sz)))
300 memcpy(dst, src, sz);
301 fmap->u.pe.strtable = dst;
302 }
303 else
304 {
305 WARN("Bad coff table... wipping out\n");
306 /* we have bad information here, wipe it out */
307 fmap->u.pe.ntheader.FileHeader.PointerToSymbolTable = 0;
308 fmap->u.pe.ntheader.FileHeader.NumberOfSymbols = 0;
309 fmap->u.pe.strtable = NULL;
310 }
311 }
312 else fmap->u.pe.strtable = NULL;
313 }
314 break;
315 default: assert(0); goto error;
316 }
317 pe_unmap_full(fmap);
318
319 return TRUE;
320error:
321 pe_unmap_full(fmap);
322 CloseHandle(fmap->u.pe.hMap);
323 return FALSE;
324}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
@ DMT_PE
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define PAGE_READONLY
Definition: compat.h:138
#define HeapAlloc
Definition: compat.h:733
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:744
#define RtlImageNtHeader
Definition: compat.h:806
#define GetFileSizeEx
Definition: compat.h:757
#define assert(x)
Definition: debug.h:53
LARGE_INTEGER li
Definition: fxtimerapi.cpp:235
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
GLenum GLenum GLenum GLenum mapping
Definition: glext.h:9031
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define error(str)
Definition: mkdosfs.c:1605
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static const struct image_file_map_ops pe_file_map_ops
Definition: pe_module.c:211
static void * pe_map_full(struct image_file_map *fmap, IMAGE_NT_HEADERS **nth)
Definition: pe_module.c:50
static void pe_unmap_full(struct image_file_map *fmap)
Definition: pe_module.c:65
static const char builtin_signature[]
Definition: pe_module.c:48
static BOOL pe_is_valid_pointer_table(const IMAGE_NT_HEADERS *nthdr, const void *mapping, DWORD64 sz)
Definition: pe_module.c:227
DWORD NumberOfSymbols
Definition: ntddk_ex.h:126
DWORD PointerToSymbolTable
Definition: ntddk_ex.h:125
WORD SizeOfOptionalHeader
Definition: ntddk_ex.h:127
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
Definition: fci.c:127
enum module_type modtype
union image_file_map::@385 u
struct image_file_map::@385::pe_file_map pe
unsigned addr_size
Definition: parser.c:56
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by image_check_debug_link(), pe_load_native_module(), and search_builtin_pe().