ReactOS 0.4.15-dev-7928-g68a8619
pe_module.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "dbghelp_private.h"
#include "image_private.h"
#include "winternl.h"
#include "wine/debug.h"
#include "wine/heap.h"
Include dependency graph for pe_module.c:

Go to the source code of this file.

Classes

struct  pe_module_info
 
struct  builtin_search
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (dbghelp)
 
static voidpe_map_full (struct image_file_map *fmap, IMAGE_NT_HEADERS **nth)
 
static void pe_unmap_full (struct image_file_map *fmap)
 
static const charpe_map_section (struct image_section_map *ism)
 
static BOOL pe_find_section (struct image_file_map *fmap, const char *name, struct image_section_map *ism)
 
static void pe_unmap_section (struct image_section_map *ism)
 
static DWORD_PTR pe_get_map_rva (const struct image_section_map *ism)
 
static unsigned pe_get_map_size (const struct image_section_map *ism)
 
static void pe_unmap_file (struct image_file_map *fmap)
 
static BOOL pe_is_valid_pointer_table (const IMAGE_NT_HEADERS *nthdr, const void *mapping, DWORD64 sz)
 
BOOL pe_map_file (HANDLE file, struct image_file_map *fmap, enum module_type mt)
 
const charpe_map_directory (struct module *module, int dirno, DWORD *size)
 
static void pe_module_remove (struct process *pcs, struct module_format *modfmt)
 
static BOOL pe_locate_with_coff_symbol_table (struct module *module)
 
static BOOL pe_load_coff_symbol_table (struct module *module)
 
static BOOL pe_load_stabs (const struct process *pcs, struct module *module)
 
static BOOL pe_load_dwarf (struct module *module)
 
static BOOL pe_load_rsym (struct module *module)
 
static BOOL pe_load_dbg_file (const struct process *pcs, struct module *module, const char *dbg_name, DWORD timestamp)
 
static BOOL pe_load_msc_debug_info (const struct process *pcs, struct module *module)
 
static BOOL pe_load_export_debug_info (const struct process *pcs, struct module *module)
 
BOOL pe_load_debug_info (const struct process *pcs, struct module *module)
 
static BOOL search_builtin_pe (void *param, HANDLE handle, const WCHAR *path)
 
struct modulepe_load_native_module (struct process *pcs, const WCHAR *name, HANDLE hFile, DWORD64 base, DWORD size)
 
BOOL pe_load_nt_header (HANDLE hProc, DWORD64 base, IMAGE_NT_HEADERS *nth)
 
struct modulepe_load_builtin_module (struct process *pcs, const WCHAR *name, DWORD64 base, DWORD64 size)
 
PVOID WINAPI ImageDirectoryEntryToDataEx (PVOID base, BOOLEAN image, USHORT dir, PULONG size, PIMAGE_SECTION_HEADER *section)
 
PVOID WINAPI ImageDirectoryEntryToData (PVOID base, BOOLEAN image, USHORT dir, PULONG size)
 

Variables

static const char builtin_signature [] = "Wine builtin DLL"
 
static const struct image_file_map_ops pe_file_map_ops
 

Function Documentation

◆ ImageDirectoryEntryToData()

PVOID WINAPI ImageDirectoryEntryToData ( PVOID  base,
BOOLEAN  image,
USHORT  dir,
PULONG  size 
)

Definition at line 972 of file pe_module.c.

973{
975}
unsigned int dir
Definition: maze.c:112
#define NULL
Definition: types.h:112
GLsizeiptr size
Definition: glext.h:5919
PVOID WINAPI ImageDirectoryEntryToDataEx(PVOID base, BOOLEAN image, USHORT dir, PULONG size, PIMAGE_SECTION_HEADER *section)
Definition: pe_module.c:934

Referenced by GetExportsFromFile().

◆ ImageDirectoryEntryToDataEx()

PVOID WINAPI ImageDirectoryEntryToDataEx ( PVOID  base,
BOOLEAN  image,
USHORT  dir,
PULONG  size,
PIMAGE_SECTION_HEADER section 
)

Definition at line 934 of file pe_module.c.

935{
936 const IMAGE_NT_HEADERS *nt;
937 DWORD addr;
938
939 *size = 0;
940 if (section) *section = NULL;
941
942 if (!(nt = RtlImageNtHeader( base ))) return NULL;
944 {
945 const IMAGE_NT_HEADERS64 *nt64 = (const IMAGE_NT_HEADERS64 *)nt;
946
947 if (dir >= nt64->OptionalHeader.NumberOfRvaAndSizes) return NULL;
948 if (!(addr = nt64->OptionalHeader.DataDirectory[dir].VirtualAddress)) return NULL;
950 if (image || addr < nt64->OptionalHeader.SizeOfHeaders) return (char *)base + addr;
951 }
953 {
954 const IMAGE_NT_HEADERS32 *nt32 = (const IMAGE_NT_HEADERS32 *)nt;
955
956 if (dir >= nt32->OptionalHeader.NumberOfRvaAndSizes) return NULL;
957 if (!(addr = nt32->OptionalHeader.DataDirectory[dir].VirtualAddress)) return NULL;
959 if (image || addr < nt32->OptionalHeader.SizeOfHeaders) return (char *)base + addr;
960 }
961 else return NULL;
962
963 return RtlImageRvaToVa( nt, base, addr, section );
964}
#define RtlImageRvaToVa
Definition: compat.h:807
#define RtlImageNtHeader
Definition: compat.h:806
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum const GLvoid * addr
Definition: glext.h:9621
IMAGE_NT_HEADERS nt
Definition: module.c:50
#define IMAGE_NT_OPTIONAL_HDR32_MAGIC
Definition: ntimage.h:376
#define IMAGE_NT_OPTIONAL_HDR64_MAGIC
Definition: ntimage.h:377
IMAGE_OPTIONAL_HEADER64 OptionalHeader
Definition: ntimage.h:396
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]
Definition: ntimage.h:370
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]
Definition: ntddk_ex.h:178
Definition: parser.c:56

Referenced by ImageDirectoryEntryToData().

◆ pe_find_section()

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

Definition at line 117 of file pe_module.c.

119{
120 const char* sectname;
121 unsigned i;
122 char tmp[IMAGE_SIZEOF_SHORT_NAME + 1];
123
124 for (i = 0; i < fmap->u.pe.ntheader.FileHeader.NumberOfSections; i++)
125 {
126 sectname = (const char*)fmap->u.pe.sect[i].shdr.Name;
127 /* long section names start with a '/' (at least on MinGW32) */
128 if (sectname[0] == '/' && fmap->u.pe.strtable)
129 sectname = fmap->u.pe.strtable + atoi(sectname + 1);
130 else
131 {
132 /* the section name may not be null terminated */
133 sectname = memcpy(tmp, sectname, IMAGE_SIZEOF_SHORT_NAME);
134 tmp[IMAGE_SIZEOF_SHORT_NAME] = '\0';
135 }
136 if (!stricmp(sectname, name))
137 {
138 ism->fmap = fmap;
139 ism->sidx = i;
140 return TRUE;
141 }
142 }
143 ism->fmap = NULL;
144 ism->sidx = -1;
145
146 return FALSE;
147}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define stricmp(_String1, _String2)
Definition: compat.h:24
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
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
if(dx< 0)
Definition: linetemp.h:194
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define IMAGE_SIZEOF_SHORT_NAME
Definition: pedump.c:277
union image_file_map::@385 u
struct image_file_map::@385::pe_file_map pe
struct image_file_map * fmap
Definition: name.c:39

Referenced by pe_load_rsym(), and pe_load_stabs().

◆ pe_get_map_rva()

static DWORD_PTR pe_get_map_rva ( const struct image_section_map ism)
static

Definition at line 169 of file pe_module.c.

170{
171 if (ism->sidx < 0 || ism->sidx >= ism->fmap->u.pe.ntheader.FileHeader.NumberOfSections)
172 return 0;
173 return ism->fmap->u.pe.sect[ism->sidx].shdr.VirtualAddress;
174}

◆ pe_get_map_size()

static unsigned pe_get_map_size ( const struct image_section_map ism)
static

Definition at line 181 of file pe_module.c.

182{
183 if (ism->sidx < 0 || ism->sidx >= ism->fmap->u.pe.ntheader.FileHeader.NumberOfSections)
184 return 0;
185 return ism->fmap->u.pe.sect[ism->sidx].shdr.Misc.VirtualSize;
186}

◆ pe_is_valid_pointer_table()

static BOOL pe_is_valid_pointer_table ( const IMAGE_NT_HEADERS nthdr,
const void mapping,
DWORD64  sz 
)
static

Definition at line 227 of file pe_module.c.

228{
230
231 /* is the iSym table inside file size ? (including first DWORD of string table, which is its size) */
234 if (offset + sizeof(DWORD) > sz) return FALSE;
235 /* is string table (following iSym table) inside file size ? */
236 offset += *(DWORD*)((const char*)mapping + offset);
237 return offset <= sz;
238}
GLenum GLenum GLenum GLenum mapping
Definition: glext.h:9031
GLintptr offset
Definition: glext.h:5920
struct _IMAGE_SYMBOL IMAGE_SYMBOL
DWORD NumberOfSymbols
Definition: ntddk_ex.h:126
DWORD PointerToSymbolTable
Definition: ntddk_ex.h:125
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
uint64_t DWORD64
Definition: typedefs.h:67

Referenced by pe_map_file().

◆ pe_load_builtin_module()

struct module * pe_load_builtin_module ( struct process pcs,
const WCHAR name,
DWORD64  base,
DWORD64  size 
)

Definition at line 896 of file pe_module.c.

898{
899 struct module* module = NULL;
900
901 if (base && pcs->dbg_hdr_addr)
902 {
904
905 if (pe_load_nt_header(pcs->handle, base, &nth))
906 {
911 }
912 }
913 return module;
914}
struct module * module_new(struct process *pcs, const WCHAR *name, enum module_type type, BOOL virtual, DWORD64 addr, DWORD64 size, ULONG_PTR stamp, ULONG_PTR checksum) DECLSPEC_HIDDEN
Definition: module.c:198
@ DMT_PE
BOOL pe_load_nt_header(HANDLE hProc, DWORD64 base, IMAGE_NT_HEADERS *nth)
Definition: pe_module.c:881
IMAGEHLP_MODULEW64 module
HANDLE handle
ULONG_PTR dbg_hdr_addr

Referenced by SymLoadModuleExW().

◆ pe_load_coff_symbol_table()

static BOOL pe_load_coff_symbol_table ( struct module module)
static

Definition at line 420 of file pe_module.c.

421{
422 struct image_file_map* fmap = &module->format_info[DFI_PE]->u.pe_info->fmap;
423 const IMAGE_SYMBOL* isym;
424 int i, numsym, naux;
425 const char* strtable;
426 char tmp[9];
427 const char* name;
428 const char* lastfilename = NULL;
429 struct symt_compiland* compiland = NULL;
430 const IMAGE_SECTION_HEADER* sect;
431 const char* mapping;
432
433 numsym = fmap->u.pe.ntheader.FileHeader.NumberOfSymbols;
434 if (!fmap->u.pe.ntheader.FileHeader.PointerToSymbolTable || !numsym)
435 return TRUE;
436 if (!(mapping = pe_map_full(fmap, NULL))) return FALSE;
437 isym = (const IMAGE_SYMBOL*)((const char*)mapping + fmap->u.pe.ntheader.FileHeader.PointerToSymbolTable);
438 /* FIXME: no way to get strtable size */
439 strtable = (const char*)&isym[numsym];
441
442 for (i = 0; i < numsym; i+= naux, isym += naux)
443 {
444 if (isym->StorageClass == IMAGE_SYM_CLASS_FILE)
445 {
446 lastfilename = (const char*)(isym + 1);
447 compiland = NULL;
448 }
449 if (isym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL &&
450 isym->SectionNumber > 0 && isym->SectionNumber <= fmap->u.pe.ntheader.FileHeader.NumberOfSections)
451 {
452 if (isym->N.Name.Short)
453 {
454 name = memcpy(tmp, isym->N.ShortName, 8);
455 tmp[8] = '\0';
456 }
457 else name = strtable + isym->N.Name.Long;
458 if (name[0] == '_') name++;
459
460 if (!compiland && lastfilename)
461 compiland = symt_new_compiland(module, 0,
462 source_new(module, NULL, lastfilename));
463
465 symt_new_public(module, compiland, name, FALSE,
466 module->module.BaseOfImage + sect[isym->SectionNumber - 1].VirtualAddress +
467 isym->Value,
468 1);
469 }
470 naux = isym->NumberOfAuxSymbols + 1;
471 }
478 pe_unmap_full(fmap);
479
480 return TRUE;
481}
unsigned source_new(struct module *module, const char *basedir, const char *source) DECLSPEC_HIDDEN
Definition: source.c:66
struct symt_public * symt_new_public(struct module *module, struct symt_compiland *parent, const char *typename, BOOL is_function, ULONG_PTR address, unsigned size) DECLSPEC_HIDDEN
Definition: symbol.c:224
@ DFI_PE
struct symt_compiland * symt_new_compiland(struct module *module, ULONG_PTR address, unsigned src_idx) DECLSPEC_HIDDEN
Definition: symbol.c:207
#define SYMOPT_NO_PUBLICS
Definition: compat.h:993
@ SymCoff
Definition: compat.h:1057
#define IMAGE_SYM_CLASS_EXTERNAL
Definition: compat.h:149
#define IMAGE_SYM_CLASS_FILE
Definition: compat.h:150
unsigned dbghelp_options
Definition: dbghelp.c:73
#define IMAGE_FIRST_SECTION(NtHeader)
Definition: ntimage.h:427
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
DWORD64 BaseOfImage
Definition: compat.h:1070
SYM_TYPE SymType
Definition: compat.h:1075
const char * strtable
struct module_format * format_info[DFI_LAST]

Referenced by pe_load_debug_info().

◆ pe_load_dbg_file()

static BOOL pe_load_dbg_file ( const struct process pcs,
struct module module,
const char dbg_name,
DWORD  timestamp 
)
static

Definition at line 571 of file pe_module.c.

573{
574 WCHAR tmp[MAX_PATH];
576 const BYTE* dbg_mapping = NULL;
577 BOOL ret = FALSE;
578
579 TRACE("Processing DBG file %s\n", debugstr_a(dbg_name));
580
581 if (path_find_symbol_file(pcs, module, dbg_name, DMT_DBG, NULL, timestamp, 0, tmp, &module->module.DbgUnmatched) &&
584 ((hMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != 0) &&
585 ((dbg_mapping = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL))
586 {
588 const IMAGE_SECTION_HEADER* sectp;
589 const IMAGE_DEBUG_DIRECTORY* dbg;
590
591 hdr = (const IMAGE_SEPARATE_DEBUG_HEADER*)dbg_mapping;
592 /* section headers come immediately after debug header */
593 sectp = (const IMAGE_SECTION_HEADER*)(hdr + 1);
594 /* and after that and the exported names comes the debug directory */
595 dbg = (const IMAGE_DEBUG_DIRECTORY*)
596 (dbg_mapping + sizeof(*hdr) +
597 hdr->NumberOfSections * sizeof(IMAGE_SECTION_HEADER) +
598 hdr->ExportedNamesSize);
599
600 ret = pe_load_debug_directory(pcs, module, dbg_mapping, sectp,
601 hdr->NumberOfSections, dbg,
602 hdr->DebugDirectorySize / sizeof(*dbg));
603 }
604 else
605 ERR("Couldn't find .DBG file %s (%s)\n", debugstr_a(dbg_name), debugstr_w(tmp));
606
607 if (dbg_mapping) UnmapViewOfFile(dbg_mapping);
608 if (hMap) CloseHandle(hMap);
610 return ret;
611}
#define ERR(fmt,...)
Definition: debug.h:110
BOOL pe_load_debug_directory(const struct process *pcs, struct module *module, const BYTE *mapping, const IMAGE_SECTION_HEADER *sectp, DWORD nsect, const IMAGE_DEBUG_DIRECTORY *dbg, int nDbg) DECLSPEC_HIDDEN
Definition: msc.c:3391
BOOL path_find_symbol_file(const struct process *pcs, const struct module *module, PCSTR full_path, enum module_type type, const GUID *guid, DWORD dw1, DWORD dw2, WCHAR *buffer, BOOL *is_unmatched) DECLSPEC_HIDDEN
Definition: path.c:596
@ DMT_DBG
#define CloseHandle
Definition: compat.h:739
#define PAGE_READONLY
Definition: compat.h:138
#define UnmapViewOfFile
Definition: compat.h:746
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:744
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_MAP_READ
Definition: compat.h:776
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define MapViewOfFile
Definition: compat.h:745
#define FILE_SHARE_READ
Definition: compat.h:136
unsigned int BOOL
Definition: ntddk_ex.h:94
char hdr[14]
Definition: iptest.cpp:33
#define debugstr_a
Definition: kernel32.h:31
#define debugstr_w
Definition: kernel32.h:32
_In_ HANDLE hFile
Definition: mswsock.h:90
struct _IMAGE_SECTION_HEADER IMAGE_SECTION_HEADER
#define TRACE(s)
Definition: solgame.cpp:4
int ret
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193

Referenced by pe_load_msc_debug_info().

◆ pe_load_debug_info()

BOOL pe_load_debug_info ( const struct process pcs,
struct module module 
)

Definition at line 751 of file pe_module.c.

752{
753 BOOL ret = FALSE;
754
756 {
758 ret = pe_load_stabs(pcs, module) || ret;
760 #ifndef DBGHELP_STATIC_LIB
763 #endif
764
765 ret = ret || pe_load_coff_symbol_table(module); /* FIXME */
766 /* if we still have no debug info (we could only get SymExport at this
767 * point), then do the SymExport except if we have an ELF container,
768 * in which case we'll rely on the export's on the ELF side
769 */
770 }
771 /* FIXME shouldn't we check that? if (!module_get_debug(pcs, module)) */
773 ret = TRUE;
774
775 return ret;
776}
#define SYMOPT_PUBLICS_ONLY
Definition: compat.h:992
BOOL image_check_alternate(struct image_file_map *fmap, const struct module *module) DECLSPEC_HIDDEN
Definition: module.c:701
static BOOL pe_load_coff_symbol_table(struct module *module)
Definition: pe_module.c:420
static BOOL pe_load_dwarf(struct module *module)
Definition: pe_module.c:525
static BOOL pe_load_rsym(struct module *module)
Definition: pe_module.c:545
static BOOL pe_load_export_debug_info(const struct process *pcs, struct module *module)
Definition: pe_module.c:666
static BOOL pe_load_msc_debug_info(const struct process *pcs, struct module *module)
Definition: pe_module.c:618
static BOOL pe_load_stabs(const struct process *pcs, struct module *module)
Definition: pe_module.c:489

Referenced by module_get_debug(), and pe_load_native_module().

◆ pe_load_dwarf()

static BOOL pe_load_dwarf ( struct module module)
static

Definition at line 525 of file pe_module.c.

526{
527 struct image_file_map* fmap = &module->format_info[DFI_PE]->u.pe_info->fmap;
528 BOOL ret;
529
531 module->module.BaseOfImage - fmap->u.pe.ntheader.OptionalHeader.ImageBase,
532 NULL, /* FIXME: some thunks to deal with ? */
533 fmap);
534 TRACE("%s the DWARF debug info\n", ret ? "successfully loaded" : "failed to load");
535
536 return ret;
537}
BOOL dwarf2_parse(struct module *module, ULONG_PTR load_offset, const struct elf_thunk_area *thunks, struct image_file_map *fmap) DECLSPEC_HIDDEN
Definition: dwarf.c:3509

Referenced by pe_load_debug_info().

◆ pe_load_export_debug_info()

static BOOL pe_load_export_debug_info ( const struct process pcs,
struct module module 
)
static

Definition at line 666 of file pe_module.c.

667{
668 struct image_file_map* fmap = &module->format_info[DFI_PE]->u.pe_info->fmap;
669 unsigned int i;
670 const IMAGE_EXPORT_DIRECTORY* exports;
672 DWORD size;
673 IMAGE_NT_HEADERS* nth;
674 void* mapping;
675
677
678 if (!(mapping = pe_map_full(fmap, &nth))) return FALSE;
679#if 0
680 /* Add start of DLL (better use the (yet unimplemented) Exe SymTag for this) */
681 /* FIXME: module.ModuleName isn't correctly set yet if it's passed in SymLoadModule */
683#endif
684
685 /* Add entry point */
686 symt_new_public(module, NULL, "EntryPoint", FALSE,
688#if 0
689 /* FIXME: we'd better store addresses linked to sections rather than
690 absolute values */
692 /* Add start of sections */
694 ((char*)&nth->OptionalHeader + nth->FileHeader.SizeOfOptionalHeader);
695 for (i = 0; i < nth->FileHeader.NumberOfSections; i++, section++)
696 {
698 RtlImageRvaToVa(nth, mapping, section->VirtualAddress, NULL), 1);
699 }
700#endif
701
702 /* Add exported functions */
705 {
706 const WORD* ordinals = NULL;
707 const DWORD_PTR* functions = NULL;
708 const DWORD* names = NULL;
709 unsigned int j;
710 char buffer[16];
711
712 functions = RtlImageRvaToVa(nth, mapping, exports->AddressOfFunctions, NULL);
713 ordinals = RtlImageRvaToVa(nth, mapping, exports->AddressOfNameOrdinals, NULL);
715
716 if (functions && ordinals && names)
717 {
718 for (i = 0; i < exports->NumberOfNames; i++)
719 {
720 if (!names[i]) continue;
723 FALSE,
724 base + functions[ordinals[i]], 1);
725 }
726
727 for (i = 0; i < exports->NumberOfFunctions; i++)
728 {
729 if (!functions[i]) continue;
730 /* Check if we already added it with a name */
731 for (j = 0; j < exports->NumberOfNames; j++)
732 if ((ordinals[j] == i) && names[j]) break;
733 if (j < exports->NumberOfNames) continue;
734 snprintf(buffer, sizeof(buffer), "%d", i + exports->Base);
735 symt_new_public(module, NULL, buffer, FALSE, base + (DWORD)functions[i], 1);
736 }
737 }
738 }
739 /* no real debug info, only entry points */
742 pe_unmap_full(fmap);
743
744 return TRUE;
745}
#define IMAGE_DIRECTORY_ENTRY_EXPORT
Definition: compat.h:151
@ SymDeferred
Definition: compat.h:1061
@ SymExport
Definition: compat.h:1060
#define RtlImageDirectoryEntryToData
Definition: compat.h:809
unsigned short WORD
Definition: ntddk_ex.h:93
GLuint GLuint * names
Definition: glext.h:11545
GLuint buffer
Definition: glext.h:5915
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 GLint GLint j
Definition: glfuncs.h:250
WCHAR ModuleName[32]
Definition: compat.h:1076
DWORD AddressOfNameOrdinals
Definition: compat.h:167
WORD SizeOfOptionalHeader
Definition: ntddk_ex.h:127
struct macho_section section
uint32_t DWORD_PTR
Definition: typedefs.h:65
#define snprintf
Definition: wintirpc.h:48

Referenced by pe_load_debug_info().

◆ pe_load_msc_debug_info()

static BOOL pe_load_msc_debug_info ( const struct process pcs,
struct module module 
)
static

Definition at line 618 of file pe_module.c.

619{
620 struct image_file_map* fmap = &module->format_info[DFI_PE]->u.pe_info->fmap;
621 BOOL ret = FALSE;
622 const IMAGE_DEBUG_DIRECTORY*dbg;
623 ULONG nDbg;
624 void* mapping;
625 IMAGE_NT_HEADERS* nth;
626
627 if (!(mapping = pe_map_full(fmap, &nth))) return FALSE;
628 /* Read in debug directory */
630 if (!dbg || !(nDbg /= sizeof(IMAGE_DEBUG_DIRECTORY))) goto done;
631
632 /* Parse debug directory */
634 {
635 /* Debug info is stripped to .DBG file */
636 const IMAGE_DEBUG_MISC* misc = (const IMAGE_DEBUG_MISC*)
637 ((const char*)mapping + dbg->PointerToRawData);
638
639 if (nDbg != 1 || dbg->Type != IMAGE_DEBUG_TYPE_MISC ||
641 {
642 ERR("-Debug info stripped, but no .DBG file in module %s\n",
644 }
645 else
646 {
647 ret = pe_load_dbg_file(pcs, module, (const char*)misc->Data, nth->FileHeader.TimeDateStamp);
648 }
649 }
650 else
651 {
652 const IMAGE_SECTION_HEADER *sectp = (const IMAGE_SECTION_HEADER*)((const char*)&nth->OptionalHeader + nth->FileHeader.SizeOfOptionalHeader);
653 /* Debug info is embedded into PE module */
655 nth->FileHeader.NumberOfSections, dbg, nDbg);
656 }
657done:
658 pe_unmap_full(fmap);
659 return ret;
660}
#define IMAGE_DIRECTORY_ENTRY_DEBUG
Definition: compat.h:152
#define IMAGE_DEBUG_MISC_EXENAME
Definition: compat.h:154
#define IMAGE_DEBUG_TYPE_MISC
Definition: compat.h:144
static BOOL pe_load_dbg_file(const struct process *pcs, struct module *module, const char *dbg_name, DWORD timestamp)
Definition: pe_module.c:571
#define IMAGE_FILE_DEBUG_STRIPPED
Definition: pedump.c:165
DWORD DataType
Definition: compat.h:170
BYTE Data[1]
Definition: compat.h:174
uint32_t ULONG
Definition: typedefs.h:59

Referenced by pe_load_debug_info().

◆ pe_load_native_module()

struct module * pe_load_native_module ( struct process pcs,
const WCHAR name,
HANDLE  hFile,
DWORD64  base,
DWORD  size 
)

Definition at line 803 of file pe_module.c.

805{
806 struct module* module = NULL;
807 BOOL opened = FALSE;
808 struct module_format* modfmt;
809 WCHAR loaded_name[MAX_PATH];
810
811 loaded_name[0] = '\0';
812 if (!hFile)
813 {
814 assert(name);
815
816 if ((hFile = FindExecutableImageExW(name, pcs->search_path, loaded_name, NULL, NULL)) == NULL)
817 return NULL;
818 opened = TRUE;
819 }
820 else if (name) lstrcpyW(loaded_name, name);
822 FIXME("Trouble ahead (no module name passed in deferred mode)\n");
823 if (!(modfmt = HeapAlloc(GetProcessHeap(), 0, sizeof(struct module_format) + sizeof(struct pe_module_info))))
824 return NULL;
825 modfmt->u.pe_info = (struct pe_module_info*)(modfmt + 1);
826 if (pe_map_file(hFile, &modfmt->u.pe_info->fmap, DMT_PE))
827 {
828#ifndef __REACTOS__
829 struct builtin_search builtin = { NULL };
830 if (modfmt->u.pe_info->fmap.u.pe.builtin && search_dll_path(pcs, loaded_name, search_builtin_pe, &builtin))
831 {
832 TRACE("reloaded %s from %s\n", debugstr_w(loaded_name), debugstr_w(builtin.path));
833 image_unmap_file(&modfmt->u.pe_info->fmap);
834 modfmt->u.pe_info->fmap = builtin.fmap;
835 }
836#endif
837 if (!base) base = modfmt->u.pe_info->fmap.u.pe.ntheader.OptionalHeader.ImageBase;
838 if (!size) size = modfmt->u.pe_info->fmap.u.pe.ntheader.OptionalHeader.SizeOfImage;
839
840 module = module_new(pcs, loaded_name, DMT_PE, FALSE, base, size,
841 modfmt->u.pe_info->fmap.u.pe.ntheader.FileHeader.TimeDateStamp,
842 modfmt->u.pe_info->fmap.u.pe.ntheader.OptionalHeader.CheckSum);
843 if (module)
844 {
845#ifdef __REACTOS__
847#else
848 module->real_path = builtin.path;
849#endif
850 modfmt->module = module;
851 modfmt->remove = pe_module_remove;
852 modfmt->loc_compute = NULL;
853
854 module->format_info[DFI_PE] = modfmt;
857 else
859 module->reloc_delta = base - modfmt->u.pe_info->fmap.u.pe.ntheader.OptionalHeader.ImageBase;
860 }
861 else
862 {
863 ERR("could not load the module '%s'\n", debugstr_w(loaded_name));
864#ifndef __REACTOS__
865 heap_free(builtin.path);
866#endif
867 image_unmap_file(&modfmt->u.pe_info->fmap);
868 }
869 }
870 if (!module) HeapFree(GetProcessHeap(), 0, modfmt);
871
872 if (opened) CloseHandle(hFile);
873
874 return module;
875}
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define FIXME(fmt,...)
Definition: debug.h:111
BOOL search_dll_path(const struct process *process, const WCHAR *name, BOOL(*match)(void *, HANDLE, const WCHAR *), void *param) DECLSPEC_HIDDEN
Definition: path.c:697
#define GetProcessHeap()
Definition: compat.h:736
#define FindExecutableImageExW
Definition: compat.h:1141
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define SYMOPT_DEFERRED_LOADS
Definition: compat.h:989
#define lstrcpyW
Definition: compat.h:749
#define assert(x)
Definition: debug.h:53
static void image_unmap_file(struct image_file_map *fmap)
BOOL pe_map_file(HANDLE file, struct image_file_map *fmap, enum module_type mt)
Definition: pe_module.c:245
BOOL pe_load_debug_info(const struct process *pcs, struct module *module)
Definition: pe_module.c:751
static void pe_module_remove(struct process *pcs, struct module_format *modfmt)
Definition: pe_module.c:345
static BOOL search_builtin_pe(void *param, HANDLE handle, const WCHAR *path)
Definition: pe_module.c:785
WCHAR * path
Definition: pe_module.c:781
struct image_file_map fmap
Definition: pe_module.c:782
struct module * module
struct pe_module_info * pe_info
void(* loc_compute)(struct process *pcs, const struct module_format *modfmt, const struct symt_function *func, struct location *loc)
void(* remove)(struct process *pcs, struct module_format *modfmt)
union module_format::@374 u
DWORD64 reloc_delta
WCHAR * real_path
WCHAR * search_path

Referenced by SymLoadModuleExW().

◆ pe_load_nt_header()

BOOL pe_load_nt_header ( HANDLE  hProc,
DWORD64  base,
IMAGE_NT_HEADERS nth 
)

Definition at line 881 of file pe_module.c.

882{
884
885 return ReadProcessMemory(hProc, (char*)(DWORD_PTR)base, &dos, sizeof(dos), NULL) &&
887 ReadProcessMemory(hProc, (char*)(DWORD_PTR)(base + dos.e_lfanew),
888 nth, sizeof(*nth), NULL) &&
890}
#define ReadProcessMemory(a, b, c, d, e)
Definition: compat.h:758
IMAGE_DOS_HEADER dos
Definition: module.c:49
#define IMAGE_NT_SIGNATURE
Definition: pedump.c:93
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89

Referenced by fetch_pe_module_info_cb(), and pe_load_builtin_module().

◆ pe_load_rsym()

static BOOL pe_load_rsym ( struct module module)
static

Definition at line 545 of file pe_module.c.

546{
547 struct image_file_map* fmap = &module->format_info[DFI_PE]->u.pe_info->fmap;
548 struct image_section_map sect_rsym;
549 BOOL ret = FALSE;
550
551 if (pe_find_section(fmap, ".rossym", &sect_rsym))
552 {
553 const char* rsym = image_map_section(&sect_rsym);
554 if (rsym != IMAGE_NO_MAP)
555 {
557 rsym, image_get_map_size(&sect_rsym));
558 }
559 image_unmap_section(&sect_rsym);
560 }
561 TRACE("%s the RSYM debug info\n", ret ? "successfully loaded" : "failed to load");
562
563 return ret;
564}
BOOL rsym_parse(struct module *module, unsigned long load_offset, const void *rsym, int rsymlen) DECLSPEC_HIDDEN
Definition: rsym.c:79
#define IMAGE_NO_MAP
Definition: image_private.h:24
static void image_unmap_section(struct image_section_map *ism)
static const char * image_map_section(struct image_section_map *ism)
static unsigned image_get_map_size(const struct image_section_map *ism)
static BOOL pe_find_section(struct image_file_map *fmap, const char *name, struct image_section_map *ism)
Definition: pe_module.c:117

Referenced by pe_load_debug_info().

◆ pe_load_stabs()

static BOOL pe_load_stabs ( const struct process pcs,
struct module module 
)
static

Definition at line 489 of file pe_module.c.

490{
491 struct image_file_map* fmap = &module->format_info[DFI_PE]->u.pe_info->fmap;
492 struct image_section_map sect_stabs, sect_stabstr;
493 BOOL ret = FALSE;
494
495 if (pe_find_section(fmap, ".stab", &sect_stabs) && pe_find_section(fmap, ".stabstr", &sect_stabstr))
496 {
497 const char* stab;
498 const char* stabstr;
499
500 stab = image_map_section(&sect_stabs);
501 stabstr = image_map_section(&sect_stabstr);
502 if (stab != IMAGE_NO_MAP && stabstr != IMAGE_NO_MAP)
503 {
505 module->module.BaseOfImage - fmap->u.pe.ntheader.OptionalHeader.ImageBase,
506 stab, image_get_map_size(&sect_stabs) / sizeof(struct stab_nlist), sizeof(struct stab_nlist),
507 stabstr, image_get_map_size(&sect_stabstr),
508 NULL, NULL);
509 }
510 image_unmap_section(&sect_stabs);
511 image_unmap_section(&sect_stabstr);
513 }
514 TRACE("%s the STABS debug info\n", ret ? "successfully loaded" : "failed to load");
515
516 return ret;
517}
BOOL stabs_parse(struct module *module, ULONG_PTR load_offset, const char *stabs, size_t nstab, size_t stabsize, const char *strs, int strtablen, stabs_def_cb callback, void *user) DECLSPEC_HIDDEN
Definition: stabs.c:1241
static BOOL pe_locate_with_coff_symbol_table(struct module *module)
Definition: pe_module.c:359

Referenced by pe_load_debug_info().

◆ pe_locate_with_coff_symbol_table()

static BOOL pe_locate_with_coff_symbol_table ( struct module module)
static

Definition at line 359 of file pe_module.c.

360{
361 struct image_file_map* fmap = &module->format_info[DFI_PE]->u.pe_info->fmap;
362 const IMAGE_SYMBOL* isym;
363 int i, numsym, naux;
364 char tmp[9];
365 const char* name;
366 struct hash_table_iter hti;
367 void* ptr;
368 struct symt_data* sym;
369 const char* mapping;
370
371 numsym = fmap->u.pe.ntheader.FileHeader.NumberOfSymbols;
372 if (!fmap->u.pe.ntheader.FileHeader.PointerToSymbolTable || !numsym)
373 return TRUE;
374 if (!(mapping = pe_map_full(fmap, NULL))) return FALSE;
375 isym = (const IMAGE_SYMBOL*)(mapping + fmap->u.pe.ntheader.FileHeader.PointerToSymbolTable);
376
377 for (i = 0; i < numsym; i+= naux, isym += naux)
378 {
379 if (isym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL &&
380 isym->SectionNumber > 0 && isym->SectionNumber <= fmap->u.pe.ntheader.FileHeader.NumberOfSections)
381 {
382 if (isym->N.Name.Short)
383 {
384 name = memcpy(tmp, isym->N.ShortName, 8);
385 tmp[8] = '\0';
386 }
387 else name = fmap->u.pe.strtable + isym->N.Name.Long;
388 if (name[0] == '_') name++;
390 while ((ptr = hash_table_iter_up(&hti)))
391 {
392 sym = CONTAINING_RECORD(ptr, struct symt_data, hash_elt);
393 if (sym->symt.tag == SymTagData &&
394 (sym->kind == DataIsGlobal || sym->kind == DataIsFileStatic) &&
395 sym->u.var.kind == loc_absolute &&
396 !strcmp(sym->hash_elt.name, name))
397 {
398 TRACE("Changing absolute address for %d.%s: %lx -> %s\n",
399 isym->SectionNumber, name, sym->u.var.offset,
401 fmap->u.pe.sect[isym->SectionNumber - 1].shdr.VirtualAddress +
402 isym->Value));
403 sym->u.var.offset = module->module.BaseOfImage +
404 fmap->u.pe.sect[isym->SectionNumber - 1].shdr.VirtualAddress + isym->Value;
405 break;
406 }
407 }
408 }
409 naux = isym->NumberOfAuxSymbols + 1;
410 }
411 pe_unmap_full(fmap);
412 return TRUE;
413}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
void hash_table_iter_init(const struct hash_table *ht, struct hash_table_iter *hti, const char *name) DECLSPEC_HIDDEN
Definition: storage.c:405
void * hash_table_iter_up(struct hash_table_iter *hti) DECLSPEC_HIDDEN
Definition: storage.c:422
@ loc_absolute
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
@ SymTagData
Definition: compat.h:1588
@ DataIsGlobal
Definition: compat.h:1654
@ DataIsFileStatic
Definition: compat.h:1653
static PVOID ptr
Definition: dispmode.c:27
struct hash_table ht_symbols
union symt_data::@372 u
struct symt symt
struct hash_table_elt hash_elt
struct location var
enum DataKind kind
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by pe_load_stabs().

◆ pe_map_directory()

const char * pe_map_directory ( struct module module,
int  dirno,
DWORD size 
)

Definition at line 331 of file pe_module.c.

332{
333 IMAGE_NT_HEADERS* nth;
334 void* mapping;
335
336 if (module->type != DMT_PE || !module->format_info[DFI_PE]) return NULL;
338 !(mapping = pe_map_full(&module->format_info[DFI_PE]->u.pe_info->fmap, &nth)))
339 return NULL;
340 if (size) *size = nth->OptionalHeader.DataDirectory[dirno].Size;
341 return RtlImageRvaToVa(nth, mapping,
343}
#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES
Definition: ntddk_ex.h:135
enum module_type type

Referenced by x86_64_fetch_minidump_module(), and x86_64_find_runtime_function().

◆ 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
#define WARN(fmt,...)
Definition: debug.h:112
#define GetFileSizeEx
Definition: compat.h:757
LARGE_INTEGER li
Definition: fxtimerapi.cpp:235
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
#define error(str)
Definition: mkdosfs.c:1605
static const struct image_file_map_ops pe_file_map_ops
Definition: pe_module.c:211
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
Definition: fci.c:127
enum module_type modtype
unsigned addr_size
struct image_file_map * alternate
const struct image_file_map_ops * ops
LONGLONG QuadPart
Definition: typedefs.h:114

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

◆ pe_map_full()

static void * pe_map_full ( struct image_file_map fmap,
IMAGE_NT_HEADERS **  nth 
)
static

Definition at line 50 of file pe_module.c.

51{
52 if (!fmap->u.pe.full_map)
53 {
54 fmap->u.pe.full_map = MapViewOfFile(fmap->u.pe.hMap, FILE_MAP_READ, 0, 0, 0);
55 }
56 if (fmap->u.pe.full_map)
57 {
58 if (nth) *nth = RtlImageNtHeader(fmap->u.pe.full_map);
59 fmap->u.pe.full_count++;
60 return fmap->u.pe.full_map;
61 }
62 return NULL;
63}

Referenced by pe_load_coff_symbol_table(), pe_load_export_debug_info(), pe_load_msc_debug_info(), pe_locate_with_coff_symbol_table(), pe_map_directory(), pe_map_file(), and pe_map_section().

◆ pe_map_section()

static const char * pe_map_section ( struct image_section_map ism)
static

Definition at line 79 of file pe_module.c.

80{
81 void* mapping;
82 struct pe_file_map* fmap = &ism->fmap->u.pe;
83
84 if (ism->sidx >= 0 && ism->sidx < fmap->ntheader.FileHeader.NumberOfSections &&
85 fmap->sect[ism->sidx].mapped == IMAGE_NO_MAP)
86 {
88
89 if (fmap->sect[ism->sidx].shdr.Misc.VirtualSize > fmap->sect[ism->sidx].shdr.SizeOfRawData)
90 {
91 FIXME("Section %ld: virtual (0x%x) > raw (0x%x) size - not supported\n",
92 ism->sidx, fmap->sect[ism->sidx].shdr.Misc.VirtualSize,
93 fmap->sect[ism->sidx].shdr.SizeOfRawData);
94 return IMAGE_NO_MAP;
95 }
96 /* FIXME: that's rather drastic, but that will do for now
97 * that's ok if the full file map exists, but we could be less aggressive otherwise and
98 * only map the relevant section
99 */
100 if ((mapping = pe_map_full(ism->fmap, &nth)))
101 {
102 fmap->sect[ism->sidx].mapped = RtlImageRvaToVa(nth, mapping,
103 fmap->sect[ism->sidx].shdr.VirtualAddress,
104 NULL);
105 return fmap->sect[ism->sidx].mapped;
106 }
107 }
108 return IMAGE_NO_MAP;
109}

◆ pe_module_remove()

static void pe_module_remove ( struct process pcs,
struct module_format modfmt 
)
static

Definition at line 345 of file pe_module.c.

346{
347 image_unmap_file(&modfmt->u.pe_info->fmap);
348 HeapFree(GetProcessHeap(), 0, modfmt);
349}

Referenced by pe_load_native_module().

◆ pe_unmap_file()

static void pe_unmap_file ( struct image_file_map fmap)
static

Definition at line 193 of file pe_module.c.

194{
195 if (fmap->u.pe.hMap != 0)
196 {
197 struct image_section_map ism;
198 ism.fmap = fmap;
199 for (ism.sidx = 0; ism.sidx < fmap->u.pe.ntheader.FileHeader.NumberOfSections; ism.sidx++)
200 {
201 pe_unmap_section(&ism);
202 }
203 while (fmap->u.pe.full_count) pe_unmap_full(fmap);
204 HeapFree(GetProcessHeap(), 0, fmap->u.pe.sect);
205 HeapFree(GetProcessHeap(), 0, (void*)fmap->u.pe.strtable); /* FIXME ugly (see pe_map_file) */
206 CloseHandle(fmap->u.pe.hMap);
207 fmap->u.pe.hMap = NULL;
208 }
209}
static void pe_unmap_section(struct image_section_map *ism)
Definition: pe_module.c:154

◆ pe_unmap_full()

static void pe_unmap_full ( struct image_file_map fmap)
static

Definition at line 65 of file pe_module.c.

66{
67 if (fmap->u.pe.full_count && !--fmap->u.pe.full_count)
68 {
69 UnmapViewOfFile(fmap->u.pe.full_map);
70 fmap->u.pe.full_map = NULL;
71 }
72}

Referenced by pe_load_coff_symbol_table(), pe_load_export_debug_info(), pe_load_msc_debug_info(), pe_locate_with_coff_symbol_table(), pe_map_file(), pe_unmap_file(), and pe_unmap_section().

◆ pe_unmap_section()

static void pe_unmap_section ( struct image_section_map ism)
static

Definition at line 154 of file pe_module.c.

155{
156 if (ism->sidx >= 0 && ism->sidx < ism->fmap->u.pe.ntheader.FileHeader.NumberOfSections &&
157 ism->fmap->u.pe.sect[ism->sidx].mapped != IMAGE_NO_MAP)
158 {
159 pe_unmap_full(ism->fmap);
160 ism->fmap->u.pe.sect[ism->sidx].mapped = IMAGE_NO_MAP;
161 }
162}

Referenced by pe_unmap_file().

◆ search_builtin_pe()

static BOOL search_builtin_pe ( void param,
HANDLE  handle,
const WCHAR path 
)
static

Definition at line 785 of file pe_module.c.

786{
787 struct builtin_search *search = param;
788 size_t size;
789
790 if (!pe_map_file(handle, &search->fmap, DMT_PE)) return FALSE;
791
792 size = (lstrlenW(path) + 1) * sizeof(WCHAR);
793 if ((search->path = heap_alloc(size)))
794 memcpy(search->path, path, size);
795 return TRUE;
796}
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
#define lstrlenW
Definition: compat.h:750
GLfloat param
Definition: glext.h:5796
static short search(int val, const short *table, int size)
Definition: msg711.c:255

Referenced by pe_load_native_module().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( dbghelp  )

Variable Documentation

◆ builtin_signature

const char builtin_signature[] = "Wine builtin DLL"
static

Definition at line 48 of file pe_module.c.

Referenced by pe_map_file().

◆ pe_file_map_ops

const struct image_file_map_ops pe_file_map_ops
static
Initial value:
=
{
}
static DWORD_PTR pe_get_map_rva(const struct image_section_map *ism)
Definition: pe_module.c:169
static unsigned pe_get_map_size(const struct image_section_map *ism)
Definition: pe_module.c:181
static const char * pe_map_section(struct image_section_map *ism)
Definition: pe_module.c:79
static void pe_unmap_file(struct image_file_map *fmap)
Definition: pe_module.c:193

Definition at line 211 of file pe_module.c.

Referenced by pe_map_file().