Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/dbghelp/elf_module.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c index e047a7f..e4689a7 100644 --- a/dlls/dbghelp/elf_module.c +++ b/dlls/dbghelp/elf_module.c @@ -346,12 +346,7 @@ static BOOL elf_map_file(struct elf_map_file_data* emfd, struct image_file_map* /* and check for an ELF header */ if (memcmp(fmap->u.elf.elfhdr.e_ident, elf_signature, sizeof(elf_signature))) goto done; - /* and check 32 vs 64 size according to current machine */ -#ifdef _WIN64 - if (fmap->u.elf.elfhdr.e_ident[EI_CLASS] != ELFCLASS64) goto done; -#else - if (fmap->u.elf.elfhdr.e_ident[EI_CLASS] != ELFCLASS32) goto done; -#endif + fmap->addr_size = fmap->u.elf.elfhdr.e_ident[EI_CLASS] == ELFCLASS64 ? 64 : 32; fmap->u.elf.sect = HeapAlloc(GetProcessHeap(), 0, fmap->u.elf.elfhdr.e_shnum * sizeof(fmap->u.elf.sect[0]));
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/dbghelp/elf_module.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c index e4689a7..d0b483a 100644 --- a/dlls/dbghelp/elf_module.c +++ b/dlls/dbghelp/elf_module.c @@ -307,6 +307,7 @@ static BOOL elf_map_file(struct elf_map_file_data* emfd, struct image_file_map* char* filename; unsigned len; BOOL ret = FALSE; + unsigned char e_ident[EI_NIDENT];
switch (emfd->kind) { @@ -340,14 +341,19 @@ static BOOL elf_map_file(struct elf_map_file_data* emfd, struct image_file_map* case from_process: break; } - if (!elf_map_file_read(fmap, emfd, &fmap->u.elf.elfhdr, sizeof(fmap->u.elf.elfhdr), 0)) + + if (!elf_map_file_read(fmap, emfd, e_ident, sizeof(e_ident), 0)) goto done;
/* and check for an ELF header */ - if (memcmp(fmap->u.elf.elfhdr.e_ident, - elf_signature, sizeof(elf_signature))) goto done; + if (memcmp(e_ident, elf_signature, sizeof(elf_signature))) + goto done; + + fmap->addr_size = e_ident[EI_CLASS] == ELFCLASS64 ? 64 : 32; + + if (!elf_map_file_read(fmap, emfd, &fmap->u.elf.elfhdr, sizeof(fmap->u.elf.elfhdr), 0)) + goto done;
- fmap->addr_size = fmap->u.elf.elfhdr.e_ident[EI_CLASS] == ELFCLASS64 ? 64 : 32; fmap->u.elf.sect = HeapAlloc(GetProcessHeap(), 0, fmap->u.elf.elfhdr.e_shnum * sizeof(fmap->u.elf.sect[0])); if (!fmap->u.elf.sect) goto done;
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/dbghelp/elf_module.c | 29 +++++++++++++++++++++++++++-- dlls/dbghelp/image_private.h | 4 +--- 2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c index d0b483a..edf32b5 100644 --- a/dlls/dbghelp/elf_module.c +++ b/dlls/dbghelp/elf_module.c @@ -351,8 +351,33 @@ static BOOL elf_map_file(struct elf_map_file_data* emfd, struct image_file_map*
fmap->addr_size = e_ident[EI_CLASS] == ELFCLASS64 ? 64 : 32;
- if (!elf_map_file_read(fmap, emfd, &fmap->u.elf.elfhdr, sizeof(fmap->u.elf.elfhdr), 0)) - goto done; + if (fmap->addr_size == 32) + { + Elf32_Ehdr elfhdr32; + + if (!elf_map_file_read(fmap, emfd, &elfhdr32, sizeof(elfhdr32), 0)) + goto done; + + memcpy(fmap->u.elf.elfhdr.e_ident, elfhdr32.e_ident, EI_NIDENT); + fmap->u.elf.elfhdr.e_type = elfhdr32.e_type; + fmap->u.elf.elfhdr.e_machine = elfhdr32.e_machine; + fmap->u.elf.elfhdr.e_version = elfhdr32.e_version; + fmap->u.elf.elfhdr.e_entry = elfhdr32.e_entry; + fmap->u.elf.elfhdr.e_phoff = elfhdr32.e_phoff; + fmap->u.elf.elfhdr.e_shoff = elfhdr32.e_shoff; + fmap->u.elf.elfhdr.e_flags = elfhdr32.e_flags; + fmap->u.elf.elfhdr.e_ehsize = elfhdr32.e_ehsize; + fmap->u.elf.elfhdr.e_phentsize = elfhdr32.e_phentsize; + fmap->u.elf.elfhdr.e_phnum = elfhdr32.e_phnum; + fmap->u.elf.elfhdr.e_shentsize = elfhdr32.e_shentsize; + fmap->u.elf.elfhdr.e_shnum = elfhdr32.e_shnum; + fmap->u.elf.elfhdr.e_shstrndx = elfhdr32.e_shstrndx; + } + else + { + if (!elf_map_file_read(fmap, emfd, &fmap->u.elf.elfhdr, sizeof(fmap->u.elf.elfhdr), 0)) + goto done; + }
fmap->u.elf.sect = HeapAlloc(GetProcessHeap(), 0, fmap->u.elf.elfhdr.e_shnum * sizeof(fmap->u.elf.sect[0])); diff --git a/dlls/dbghelp/image_private.h b/dlls/dbghelp/image_private.h index 429b8fb..fa15000 100644 --- a/dlls/dbghelp/image_private.h +++ b/dlls/dbghelp/image_private.h @@ -59,14 +59,12 @@ typedef struct section macho_section; #ifdef __ELF__
#ifdef _WIN64 -#define Elf_Ehdr Elf64_Ehdr #define Elf_Shdr Elf64_Shdr #define Elf_Phdr Elf64_Phdr #define Elf_Dyn Elf64_Dyn #define Elf_Sym Elf64_Sym #define Elf_auxv_t Elf64_auxv_t #else -#define Elf_Ehdr Elf32_Ehdr #define Elf_Shdr Elf32_Shdr #define Elf_Phdr Elf32_Phdr #define Elf_Dyn Elf32_Dyn @@ -97,7 +95,7 @@ struct image_file_map struct image_file_map* alternate; /* another ELF file (linked to this one) */ char* target_copy; #ifdef __ELF__ - Elf_Ehdr elfhdr; + Elf64_Ehdr elfhdr; struct { Elf_Shdr shdr;
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/dbghelp/elf_module.c | 35 ++++++++++++++++++++++++++++++++--- dlls/dbghelp/image_private.h | 4 +--- 2 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c index edf32b5..8049210 100644 --- a/dlls/dbghelp/elf_module.c +++ b/dlls/dbghelp/elf_module.c @@ -292,6 +292,36 @@ static BOOL elf_map_file_read(struct image_file_map* fmap, struct elf_map_file_d } }
+static BOOL elf_map_shdr(struct elf_map_file_data* emfd, struct image_file_map* fmap, unsigned int i) +{ + if (fmap->addr_size == 32) + { + Elf32_Shdr shdr32; + + if (!elf_map_file_read(fmap, emfd, &shdr32, sizeof(shdr32), + fmap->u.elf.elfhdr.e_shoff + i * sizeof(Elf32_Shdr))) + return FALSE; + + fmap->u.elf.sect[i].shdr.sh_name = shdr32.sh_name; + fmap->u.elf.sect[i].shdr.sh_type = shdr32.sh_type; + fmap->u.elf.sect[i].shdr.sh_flags = shdr32.sh_flags; + fmap->u.elf.sect[i].shdr.sh_addr = shdr32.sh_addr; + fmap->u.elf.sect[i].shdr.sh_offset = shdr32.sh_offset; + fmap->u.elf.sect[i].shdr.sh_size = shdr32.sh_size; + fmap->u.elf.sect[i].shdr.sh_link = shdr32.sh_link; + fmap->u.elf.sect[i].shdr.sh_info = shdr32.sh_info; + fmap->u.elf.sect[i].shdr.sh_addralign = shdr32.sh_addralign; + fmap->u.elf.sect[i].shdr.sh_entsize = shdr32.sh_entsize; + } + else + { + if (!elf_map_file_read(fmap, emfd, &fmap->u.elf.sect[i].shdr, sizeof(fmap->u.elf.sect[i].shdr), + fmap->u.elf.elfhdr.e_shoff + i * sizeof(Elf64_Shdr))) + return FALSE; + } + return TRUE; +} + /****************************************************************** * elf_map_file * @@ -385,8 +415,7 @@ static BOOL elf_map_file(struct elf_map_file_data* emfd, struct image_file_map*
for (i = 0; i < fmap->u.elf.elfhdr.e_shnum; i++) { - if (!elf_map_file_read(fmap, emfd, &fmap->u.elf.sect[i].shdr, sizeof(fmap->u.elf.sect[i].shdr), - fmap->u.elf.elfhdr.e_shoff + i * sizeof(fmap->u.elf.sect[i].shdr))) + if (!elf_map_shdr(emfd, fmap, i)) { HeapFree(GetProcessHeap(), 0, fmap->u.elf.sect); fmap->u.elf.sect = NULL; @@ -1225,7 +1254,7 @@ static BOOL elf_load_file_from_fmap(struct process* pcs, const WCHAR* filename, if (elf_find_section(fmap, ".dynamic", SHT_DYNAMIC, &ism)) { Elf_Dyn dyn; - char* ptr = (char*)fmap->u.elf.sect[ism.sidx].shdr.sh_addr; + char* ptr = (char*)(ULONG_PTR)fmap->u.elf.sect[ism.sidx].shdr.sh_addr; unsigned long len;
if (load_offset) ptr += load_offset - fmap->u.elf.elf_start; diff --git a/dlls/dbghelp/image_private.h b/dlls/dbghelp/image_private.h index fa15000..42781e4 100644 --- a/dlls/dbghelp/image_private.h +++ b/dlls/dbghelp/image_private.h @@ -59,13 +59,11 @@ typedef struct section macho_section; #ifdef __ELF__
#ifdef _WIN64 -#define Elf_Shdr Elf64_Shdr #define Elf_Phdr Elf64_Phdr #define Elf_Dyn Elf64_Dyn #define Elf_Sym Elf64_Sym #define Elf_auxv_t Elf64_auxv_t #else -#define Elf_Shdr Elf32_Shdr #define Elf_Phdr Elf32_Phdr #define Elf_Dyn Elf32_Dyn #define Elf_Sym Elf32_Sym @@ -98,7 +96,7 @@ struct image_file_map Elf64_Ehdr elfhdr; struct { - Elf_Shdr shdr; + Elf64_Shdr shdr; const char* mapped; }* sect; #endif