[PATCH 01/22] [DbgHelp]: elf
Eric Pouech
eric.pouech at wanadoo.fr
Fri Nov 24 15:17:04 CST 2006
- simplify code with function to get section's size
- made the NO_MAP macro generic
A+
---
dlls/dbghelp/dbghelp_private.h | 1 +
dlls/dbghelp/dwarf.c | 4 +--
dlls/dbghelp/elf_module.c | 49 ++++++++++++++++++++++++----------------
3 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h
index 2dff1f0..3d9647c 100644
--- a/dlls/dbghelp/dbghelp_private.h
+++ b/dlls/dbghelp/dbghelp_private.h
@@ -367,6 +367,7 @@ extern BOOL pcs_callback(const s
extern void* fetch_buffer(struct process* pcs, unsigned size);
/* elf_module.c */
+#define ELF_NO_MAP ((const void*)0xffffffff)
typedef BOOL (*elf_enum_modules_cb)(const char*, unsigned long addr, void* user);
extern BOOL elf_enum_modules(HANDLE hProc, elf_enum_modules_cb, void*);
extern BOOL elf_fetch_file_info(const char* name, DWORD* base, DWORD* size, DWORD* checksum);
diff --git a/dlls/dbghelp/dwarf.c b/dlls/dbghelp/dwarf.c
index 4253413..aa5aa89 100644
--- a/dlls/dbghelp/dwarf.c
+++ b/dlls/dbghelp/dwarf.c
@@ -150,8 +150,6 @@ typedef struct dwarf2_debug_info_s
struct vector children;
} dwarf2_debug_info_t;
-#define NO_MAP ((const void*)0xffffffff)
-
typedef struct dwarf2_section_s
{
const unsigned char* address;
@@ -1597,7 +1595,7 @@ static BOOL dwarf2_parse_line_numbers(co
const char** p;
/* section with line numbers stripped */
- if (sections[section_line].address == NO_MAP)
+ if (sections[section_line].address == ELF_NO_MAP)
return FALSE;
traverse.data = sections[section_line].address + offset;
diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c
index 0e5267b..5f795be 100644
--- a/dlls/dbghelp/elf_module.c
+++ b/dlls/dbghelp/elf_module.c
@@ -98,7 +98,6 @@ struct elf_info
const char* module_name; /* OUT found module name (if ELF_INFO_NAME is set) */
};
-#define NO_MAP ((const void*)0xffffffff)
/* structure holding information while handling an ELF image
* allows one by one section mapping for memory savings
*/
@@ -145,13 +144,13 @@ static const char* elf_map_section(struc
if (sidx < 0 || sidx >= fmap->elfhdr.e_shnum ||
fmap->sect[sidx].shdr.sh_type == SHT_NOBITS)
- return NO_MAP;
+ return ELF_NO_MAP;
/* align required information on page size (we assume pagesize is a power of 2) */
ofst = fmap->sect[sidx].shdr.sh_offset & ~(pgsz - 1);
size = (fmap->sect[sidx].shdr.sh_offset +
fmap->sect[sidx].shdr.sh_size + pgsz - 1) & ~(pgsz - 1);
fmap->sect[sidx].mapped = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fmap->fd, ofst);
- if (fmap->sect[sidx].mapped == NO_MAP) return NO_MAP;
+ if (fmap->sect[sidx].mapped == ELF_NO_MAP) return ELF_NO_MAP;
return fmap->sect[sidx].mapped + (fmap->sect[sidx].shdr.sh_offset & (pgsz - 1));
}
@@ -162,14 +161,26 @@ static const char* elf_map_section(struc
*/
static void elf_unmap_section(struct elf_file_map* fmap, int sidx)
{
- if (sidx >= 0 && sidx < fmap->elfhdr.e_shnum && fmap->sect[sidx].mapped != NO_MAP)
+ if (sidx >= 0 && sidx < fmap->elfhdr.e_shnum && fmap->sect[sidx].mapped != ELF_NO_MAP)
{
munmap((char*)fmap->sect[sidx].mapped, fmap->sect[sidx].shdr.sh_size);
- fmap->sect[sidx].mapped = NO_MAP;
+ fmap->sect[sidx].mapped = ELF_NO_MAP;
}
}
/******************************************************************
+ * elf_get_map_size
+ *
+ * Get the size of an ELF section
+ */
+static inline unsigned elf_get_map_size(struct elf_file_map* fmap, int sidx)
+{
+ if (sidx < 0 || sidx >= fmap->elfhdr.e_shnum)
+ return 0;
+ return fmap->sect[sidx].shdr.sh_size;
+}
+
+/******************************************************************
* elf_map_file
*
* Maps an ELF file into memory (and checks it's a real ELF file)
@@ -206,7 +217,7 @@ static BOOL elf_map_file(const char* fil
for (i = 0; i < fmap->elfhdr.e_shnum; i++)
{
read(fmap->fd, &fmap->sect[i].shdr, sizeof(fmap->sect[i].shdr));
- fmap->sect[i].mapped = NO_MAP;
+ fmap->sect[i].mapped = ELF_NO_MAP;
}
/* grab size of module once loaded in memory */
@@ -287,9 +298,9 @@ static void elf_hash_symtab(struct modul
symp = (const Elf32_Sym*)elf_map_section(fmap, symtab_idx);
strp = elf_map_section(fmap, fmap->sect[symtab_idx].shdr.sh_link);
- if (symp == NO_MAP || strp == NO_MAP) return;
+ if (symp == ELF_NO_MAP || strp == ELF_NO_MAP) return;
- nsym = fmap->sect[symtab_idx].shdr.sh_size / sizeof(*symp);
+ nsym = elf_get_map_size(fmap, symtab_idx) / sizeof(*symp);
for (j = 0; thunks[j].symname; j++)
thunks[j].rva_start = thunks[j].rva_end = 0;
@@ -806,7 +817,7 @@ static BOOL elf_load_debug_info_from_map
* table.
*/
shstrtab = elf_map_section(fmap, fmap->elfhdr.e_shstrndx);
- if (shstrtab == NO_MAP) return FALSE;
+ if (shstrtab == ELF_NO_MAP) return FALSE;
symtab_sect = dynsym_sect = stab_sect = stabstr_sect = -1;
debug_sect = debug_str_sect = debug_abbrev_sect = debug_line_sect = -1;
@@ -862,12 +873,12 @@ static BOOL elf_load_debug_info_from_map
stab = elf_map_section(fmap, stab_sect);
stabstr = elf_map_section(fmap, stabstr_sect);
- if (stab != NO_MAP && stabstr != NO_MAP)
+ if (stab != ELF_NO_MAP && stabstr != ELF_NO_MAP)
{
/* OK, now just parse all of the stabs. */
lret = stabs_parse(module, module->elf_info->elf_addr,
- stab, fmap->sect[stab_sect].shdr.sh_size,
- stabstr, fmap->sect[stabstr_sect].shdr.sh_size);
+ stab, elf_get_map_size(fmap, stab_sect),
+ stabstr, elf_get_map_size(fmap, stabstr_sect));
if (lret)
/* and fill in the missing information for stabs */
elf_finish_stabs_info(module, ht_symtab);
@@ -894,14 +905,14 @@ static BOOL elf_load_debug_info_from_map
dw2_debug_abbrev = (const BYTE*) elf_map_section(fmap, debug_abbrev_sect);
dw2_debug_str = (const BYTE*) elf_map_section(fmap, debug_str_sect);
dw2_debug_line = (const BYTE*) elf_map_section(fmap, debug_line_sect);
- if (dw2_debug != NO_MAP && NO_MAP != dw2_debug_abbrev && dw2_debug_str != NO_MAP)
+ if (dw2_debug != ELF_NO_MAP && ELF_NO_MAP != dw2_debug_abbrev && dw2_debug_str != ELF_NO_MAP)
{
/* OK, now just parse dwarf2 debug infos. */
lret = dwarf2_parse(module, module->elf_info->elf_addr, thunks,
- dw2_debug, fmap->sect[debug_sect].shdr.sh_size,
- dw2_debug_abbrev, fmap->sect[debug_abbrev_sect].shdr.sh_size,
- dw2_debug_str, fmap->sect[debug_str_sect].shdr.sh_size,
- dw2_debug_line, dw2_debug_line != NO_MAP ? fmap->sect[debug_line_sect].shdr.sh_size : 0);
+ dw2_debug, elf_get_map_size(fmap, debug_sect),
+ dw2_debug_abbrev, elf_get_map_size(fmap, debug_abbrev_sect),
+ dw2_debug_str, elf_get_map_size(fmap, debug_str_sect),
+ dw2_debug_line, elf_get_map_size(fmap, debug_line_sect));
if (!lret)
WARN("Couldn't correctly read stabs\n");
ret = ret || lret;
@@ -924,7 +935,7 @@ static BOOL elf_load_debug_info_from_map
* 2/ padding on 4 byte boundary
* 3/ CRC of the linked ELF file
*/
- if (dbg_link != NO_MAP && elf_map_file(dbg_link, &fmap_link))
+ if (dbg_link != ELF_NO_MAP && elf_map_file(dbg_link, &fmap_link))
{
fmap_link.crc = *(const DWORD*)(dbg_link + ((DWORD_PTR)(strlen(dbg_link) + 4) & ~3));
fmap_link.with_crc = 1;
@@ -1067,7 +1078,7 @@ static BOOL elf_load_file(struct process
if (elf_info->flags & ELF_INFO_DEBUG_HEADER)
{
const char* shstrtab = elf_map_section(&fmap, fmap.elfhdr.e_shstrndx);
- if (shstrtab == NO_MAP) goto leave;
+ if (shstrtab == ELF_NO_MAP) goto leave;
for (i = 0; i < fmap.elfhdr.e_shnum; i++)
{
if (strcmp(shstrtab + fmap.sect[i].shdr.sh_name, ".dynamic") == 0 &&
More information about the wine-patches
mailing list