Eric Pouech : dbghelp: Split elf_load_file into two functions ( one for creating a file-map, another one for loading info out of a file-map ).
Alexandre Julliard
julliard at winehq.org
Tue Dec 28 10:48:17 CST 2010
Module: wine
Branch: master
Commit: 655247354a5396147ac9ad766509020c2f2f6dee
URL: http://source.winehq.org/git/wine.git/?a=commit;h=655247354a5396147ac9ad766509020c2f2f6dee
Author: Eric Pouech <eric.pouech at orange.fr>
Date: Mon Dec 27 15:03:18 2010 +0100
dbghelp: Split elf_load_file into two functions (one for creating a file-map, another one for loading info out of a file-map).
---
dlls/dbghelp/elf_module.c | 97 +++++++++++++++++++++++++--------------------
1 files changed, 54 insertions(+), 43 deletions(-)
diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c
index b8ddfcb..53b7f55 100644
--- a/dlls/dbghelp/elf_module.c
+++ b/dlls/dbghelp/elf_module.c
@@ -987,51 +987,27 @@ BOOL elf_fetch_file_info(const WCHAR* name, DWORD_PTR* base,
return TRUE;
}
-/******************************************************************
- * elf_load_file
- *
- * Loads the information for ELF module stored in 'filename'
- * the module has been loaded at 'load_offset' address
- * returns
- * -1 if the file cannot be found/opened
- * 0 if the file doesn't contain symbolic info (or this info cannot be
- * read or parsed)
- * 1 on success
- */
-static BOOL elf_load_file(struct process* pcs, const WCHAR* filename,
- unsigned long load_offset, unsigned long dyn_addr,
- struct elf_info* elf_info)
+static BOOL elf_load_file_from_fmap(struct process* pcs, const WCHAR* filename,
+ struct image_file_map* fmap, unsigned long load_offset,
+ unsigned long dyn_addr, struct elf_info* elf_info)
{
- BOOL ret = FALSE;
- struct image_file_map fmap;
-
- TRACE("Processing elf file '%s' at %08lx\n", debugstr_w(filename), load_offset);
-
- if (!elf_map_file(filename, &fmap)) return ret;
-
- /* Next, we need to find a few of the internal ELF headers within
- * this thing. We need the main executable header, and the section
- * table.
- */
- if (!fmap.u.elf.elf_start && !load_offset)
- ERR("Relocatable ELF %s, but no load address. Loading at 0x0000000\n",
- debugstr_w(filename));
+ BOOL ret = FALSE;
if (elf_info->flags & ELF_INFO_DEBUG_HEADER)
{
struct image_section_map ism;
- if (elf_find_section(&fmap, ".dynamic", SHT_DYNAMIC, &ism))
+ 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*)fmap->u.elf.sect[ism.sidx].shdr.sh_addr;
unsigned long len;
do
{
if (!ReadProcessMemory(pcs->handle, ptr, &dyn, sizeof(dyn), &len) ||
len != sizeof(dyn))
- goto leave;
+ return ret;
if (dyn.d_tag == DT_DEBUG)
{
elf_info->dbg_hdr_addr = dyn.d_un.d_ptr;
@@ -1042,9 +1018,9 @@ static BOOL elf_load_file(struct process* pcs, const WCHAR* filename,
}
ptr += sizeof(dyn);
} while (dyn.d_tag != DT_NULL);
- if (dyn.d_tag == DT_NULL) goto leave;
+ if (dyn.d_tag == DT_NULL) return ret;
}
- elf_end_find(&fmap);
+ elf_end_find(fmap);
}
if (elf_info->flags & ELF_INFO_MODULE)
@@ -1054,12 +1030,12 @@ static BOOL elf_load_file(struct process* pcs, const WCHAR* filename,
struct image_section_map ism;
unsigned long modbase = load_offset;
- if (elf_find_section(&fmap, ".dynamic", SHT_DYNAMIC, &ism))
+ if (elf_find_section(fmap, ".dynamic", SHT_DYNAMIC, &ism))
{
unsigned long rva_dyn = elf_get_map_rva(&ism);
TRACE("For module %s, got ELF (start=%lx dyn=%lx), link_map (start=%lx dyn=%lx)\n",
- debugstr_w(filename), (unsigned long)fmap.u.elf.elf_start, rva_dyn,
+ debugstr_w(filename), (unsigned long)fmap->u.elf.elf_start, rva_dyn,
load_offset, dyn_addr);
if (dyn_addr && load_offset + rva_dyn != dyn_addr)
{
@@ -1067,19 +1043,19 @@ static BOOL elf_load_file(struct process* pcs, const WCHAR* filename,
modbase = dyn_addr - rva_dyn;
}
} else WARN("For module %s, no .dynamic section\n", debugstr_w(filename));
- elf_end_find(&fmap);
+ elf_end_find(fmap);
modfmt = HeapAlloc(GetProcessHeap(), 0,
sizeof(struct module_format) + sizeof(struct elf_module_info));
- if (!modfmt) goto leave;
+ if (!modfmt) return FALSE;
elf_info->module = module_new(pcs, filename, DMT_ELF, FALSE, modbase,
- fmap.u.elf.elf_size, 0, calc_crc32(fmap.u.elf.fd));
+ fmap->u.elf.elf_size, 0, calc_crc32(fmap->u.elf.fd));
if (!elf_info->module)
{
HeapFree(GetProcessHeap(), 0, modfmt);
- goto leave;
+ return FALSE;
}
- elf_info->module->reloc_delta = elf_info->module->module.BaseOfImage - fmap.u.elf.elf_start;
+ elf_info->module->reloc_delta = elf_info->module->module.BaseOfImage - fmap->u.elf.elf_start;
elf_module_info = (void*)(modfmt + 1);
elf_info->module->format_info[DFI_ELF] = modfmt;
modfmt->module = elf_info->module;
@@ -1089,8 +1065,8 @@ static BOOL elf_load_file(struct process* pcs, const WCHAR* filename,
elf_module_info->elf_addr = load_offset;
- elf_module_info->file_map = fmap;
- elf_reset_file_map(&fmap);
+ elf_module_info->file_map = *fmap;
+ elf_reset_file_map(fmap);
if (dbghelp_options & SYMOPT_DEFERRED_LOADS)
{
elf_info->module->module.SymType = SymDeferred;
@@ -1113,7 +1089,42 @@ static BOOL elf_load_file(struct process* pcs, const WCHAR* filename,
}
else ret = FALSE;
}
-leave:
+
+ return ret;
+}
+
+/******************************************************************
+ * elf_load_file
+ *
+ * Loads the information for ELF module stored in 'filename'
+ * the module has been loaded at 'load_offset' address
+ * returns
+ * -1 if the file cannot be found/opened
+ * 0 if the file doesn't contain symbolic info (or this info cannot be
+ * read or parsed)
+ * 1 on success
+ */
+static BOOL elf_load_file(struct process* pcs, const WCHAR* filename,
+ unsigned long load_offset, unsigned long dyn_addr,
+ struct elf_info* elf_info)
+{
+ BOOL ret = FALSE;
+ struct image_file_map fmap;
+
+ TRACE("Processing elf file '%s' at %08lx\n", debugstr_w(filename), load_offset);
+
+ if (!elf_map_file(filename, &fmap)) return ret;
+
+ /* Next, we need to find a few of the internal ELF headers within
+ * this thing. We need the main executable header, and the section
+ * table.
+ */
+ if (!fmap.u.elf.elf_start && !load_offset)
+ ERR("Relocatable ELF %s, but no load address. Loading at 0x0000000\n",
+ debugstr_w(filename));
+
+ ret = elf_load_file_from_fmap(pcs, filename, &fmap, load_offset, dyn_addr, elf_info);
+
elf_unmap_file(&fmap);
return ret;
More information about the wine-cvs
mailing list