Jacek Caban : dbghelp: Introduce generic image_unmap_file.
Alexandre Julliard
julliard at winehq.org
Mon Mar 16 16:49:06 CDT 2020
Module: wine
Branch: master
Commit: 1d96af362789aa8aaa0be94a046b0afba2ecefb3
URL: https://source.winehq.org/git/wine.git/?a=commit;h=1d96af362789aa8aaa0be94a046b0afba2ecefb3
Author: Jacek Caban <jacek at codeweavers.com>
Date: Mon Mar 16 16:05:54 2020 +0100
dbghelp: Introduce generic image_unmap_file.
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/dbghelp/elf_module.c | 57 +++++++++++++++++++++-----------------------
dlls/dbghelp/image_private.h | 10 ++++++++
dlls/dbghelp/macho_module.c | 1 +
dlls/dbghelp/pe_module.c | 53 ++++++++++++++++++++--------------------
4 files changed, 65 insertions(+), 56 deletions(-)
diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c
index 300926f88b..961fece746 100644
--- a/dlls/dbghelp/elf_module.c
+++ b/dlls/dbghelp/elf_module.c
@@ -284,6 +284,27 @@ static unsigned elf_get_map_size(const struct image_section_map* ism)
return ism->fmap->u.elf.sect[ism->sidx].shdr.sh_size;
}
+/******************************************************************
+ * elf_unmap_file
+ *
+ * Unmaps an ELF file from memory (previously mapped with elf_map_file)
+ */
+static void elf_unmap_file(struct image_file_map* fmap)
+{
+ if (fmap->u.elf.handle != INVALID_HANDLE_VALUE)
+ {
+ struct image_section_map ism;
+ ism.fmap = fmap;
+ for (ism.sidx = 0; ism.sidx < fmap->u.elf.elfhdr.e_shnum; ism.sidx++)
+ {
+ elf_unmap_section(&ism);
+ }
+ HeapFree(GetProcessHeap(), 0, fmap->u.elf.sect);
+ CloseHandle(fmap->u.elf.handle);
+ }
+ HeapFree(GetProcessHeap(), 0, fmap->u.elf.target_copy);
+}
+
static const struct image_file_map_ops elf_file_map_ops =
{
elf_map_section,
@@ -291,6 +312,7 @@ static const struct image_file_map_ops elf_file_map_ops =
elf_find_section,
elf_get_map_rva,
elf_get_map_size,
+ elf_unmap_file,
};
static inline void elf_reset_file_map(struct image_file_map* fmap)
@@ -536,34 +558,9 @@ static BOOL elf_map_file(struct elf_map_file_data* emfd, struct image_file_map*
return TRUE;
}
-/******************************************************************
- * elf_unmap_file
- *
- * Unmaps an ELF file from memory (previously mapped with elf_map_file)
- */
-static void elf_unmap_file(struct image_file_map* fmap)
-{
- while (fmap && fmap->modtype == DMT_ELF)
- {
- if (fmap->u.elf.handle != INVALID_HANDLE_VALUE)
- {
- struct image_section_map ism;
- ism.fmap = fmap;
- for (ism.sidx = 0; ism.sidx < fmap->u.elf.elfhdr.e_shnum; ism.sidx++)
- {
- elf_unmap_section(&ism);
- }
- HeapFree(GetProcessHeap(), 0, fmap->u.elf.sect);
- CloseHandle(fmap->u.elf.handle);
- }
- HeapFree(GetProcessHeap(), 0, fmap->u.elf.target_copy);
- fmap = fmap->alternate;
- }
-}
-
static void elf_module_remove(struct process* pcs, struct module_format* modfmt)
{
- elf_unmap_file(&modfmt->u.elf_info->file_map);
+ image_unmap_file(&modfmt->u.elf_info->file_map);
HeapFree(GetProcessHeap(), 0, modfmt);
}
@@ -994,7 +991,7 @@ static BOOL elf_check_debug_link(const WCHAR* file, struct image_file_map* fmap,
if (crc != link_crc)
{
WARN("Bad CRC for file %s (got %08x while expecting %08x)\n", debugstr_w(file), crc, link_crc);
- elf_unmap_file(fmap);
+ image_unmap_file(fmap);
return FALSE;
}
return TRUE;
@@ -1148,7 +1145,7 @@ static BOOL elf_locate_build_id_target(struct image_file_map* fmap, const BYTE*
}
image_unmap_section(&buildid_sect);
}
- elf_unmap_file(fmap_link);
+ image_unmap_file(fmap_link);
}
TRACE("not found\n");
@@ -1340,7 +1337,7 @@ BOOL elf_fetch_file_info(const WCHAR* name, DWORD_PTR* base,
if (base) *base = fmap.u.elf.elf_start;
*size = fmap.u.elf.elf_size;
*checksum = calc_crc(fmap.u.elf.handle);
- elf_unmap_file(&fmap);
+ image_unmap_file(&fmap);
return TRUE;
}
@@ -1514,7 +1511,7 @@ static BOOL elf_load_file(struct process* pcs, const WCHAR* filename,
ret = elf_load_file_from_fmap(pcs, filename, &fmap, load_offset, dyn_addr, elf_info);
- elf_unmap_file(&fmap);
+ image_unmap_file(&fmap);
return ret;
}
diff --git a/dlls/dbghelp/image_private.h b/dlls/dbghelp/image_private.h
index e0790b4c7b..803d3b5ddc 100644
--- a/dlls/dbghelp/image_private.h
+++ b/dlls/dbghelp/image_private.h
@@ -137,6 +137,7 @@ struct image_file_map_ops
BOOL (*find_section)(struct image_file_map* fmap, const char* name, struct image_section_map* ism);
DWORD_PTR (*get_map_rva)(const struct image_section_map* ism);
unsigned (*get_map_size)(const struct image_section_map* ism);
+ void (*unmap_file)(struct image_file_map *fmap);
};
static inline BOOL image_find_section(struct image_file_map* fmap, const char* name,
@@ -152,6 +153,15 @@ static inline BOOL image_find_section(struct image_file_map* fmap, const char* n
return FALSE;
}
+static inline void image_unmap_file(struct image_file_map* fmap)
+{
+ while (fmap)
+ {
+ fmap->ops->unmap_file(fmap);
+ fmap = fmap->alternate;
+ }
+}
+
static inline const char* image_map_section(struct image_section_map* ism)
{
return ism->fmap ? ism->fmap->ops->map_section(ism) : NULL;
diff --git a/dlls/dbghelp/macho_module.c b/dlls/dbghelp/macho_module.c
index a9a086ea76..9d4fc4e47a 100644
--- a/dlls/dbghelp/macho_module.c
+++ b/dlls/dbghelp/macho_module.c
@@ -432,6 +432,7 @@ static const struct image_file_map_ops macho_file_map_ops =
macho_find_section,
macho_get_map_rva,
macho_get_map_size,
+ macho_unmap_file,
};
/******************************************************************
diff --git a/dlls/dbghelp/pe_module.c b/dlls/dbghelp/pe_module.c
index a12a375ec5..17db805515 100644
--- a/dlls/dbghelp/pe_module.c
+++ b/dlls/dbghelp/pe_module.c
@@ -182,6 +182,29 @@ static unsigned pe_get_map_size(const struct image_section_map* ism)
return ism->fmap->u.pe.sect[ism->sidx].shdr.Misc.VirtualSize;
}
+/******************************************************************
+ * pe_unmap_file
+ *
+ * Unmaps an PE file from memory (previously mapped with pe_map_file)
+ */
+static void pe_unmap_file(struct image_file_map* fmap)
+{
+ if (fmap->u.pe.hMap != 0)
+ {
+ struct image_section_map ism;
+ ism.fmap = fmap;
+ for (ism.sidx = 0; ism.sidx < fmap->u.pe.ntheader.FileHeader.NumberOfSections; ism.sidx++)
+ {
+ pe_unmap_section(&ism);
+ }
+ while (fmap->u.pe.full_count) pe_unmap_full(fmap);
+ HeapFree(GetProcessHeap(), 0, fmap->u.pe.sect);
+ HeapFree(GetProcessHeap(), 0, (void*)fmap->u.pe.strtable); /* FIXME ugly (see pe_map_file) */
+ CloseHandle(fmap->u.pe.hMap);
+ fmap->u.pe.hMap = NULL;
+ }
+}
+
static const struct image_file_map_ops pe_file_map_ops =
{
pe_map_section,
@@ -189,6 +212,7 @@ static const struct image_file_map_ops pe_file_map_ops =
pe_find_section,
pe_get_map_rva,
pe_get_map_size,
+ pe_unmap_file,
};
/******************************************************************
@@ -296,29 +320,6 @@ error:
return FALSE;
}
-/******************************************************************
- * pe_unmap_file
- *
- * Unmaps an PE file from memory (previously mapped with pe_map_file)
- */
-static void pe_unmap_file(struct image_file_map* fmap)
-{
- if (fmap->u.pe.hMap != 0)
- {
- struct image_section_map ism;
- ism.fmap = fmap;
- for (ism.sidx = 0; ism.sidx < fmap->u.pe.ntheader.FileHeader.NumberOfSections; ism.sidx++)
- {
- pe_unmap_section(&ism);
- }
- while (fmap->u.pe.full_count) pe_unmap_full(fmap);
- HeapFree(GetProcessHeap(), 0, fmap->u.pe.sect);
- HeapFree(GetProcessHeap(), 0, (void*)fmap->u.pe.strtable); /* FIXME ugly (see pe_map_file) */
- CloseHandle(fmap->u.pe.hMap);
- fmap->u.pe.hMap = NULL;
- }
-}
-
/******************************************************************
* pe_map_directory
*
@@ -340,7 +341,7 @@ const char* pe_map_directory(struct module* module, int dirno, DWORD* size)
static void pe_module_remove(struct process* pcs, struct module_format* modfmt)
{
- pe_unmap_file(&modfmt->u.pe_info->fmap);
+ image_unmap_file(&modfmt->u.pe_info->fmap);
HeapFree(GetProcessHeap(), 0, modfmt);
}
@@ -839,7 +840,7 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name,
if (pe_map_file(builtin_module, &builtin_fmap, DMT_PE))
{
TRACE("reloaded %s from %s\n", debugstr_w(loaded_name), debugstr_w(builtin_path));
- pe_unmap_file(&modfmt->u.pe_info->fmap);
+ image_unmap_file(&modfmt->u.pe_info->fmap);
modfmt->u.pe_info->fmap = builtin_fmap;
}
CloseHandle(builtin_module);
@@ -868,7 +869,7 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name,
{
ERR("could not load the module '%s'\n", debugstr_w(loaded_name));
heap_free(module->real_path);
- pe_unmap_file(&modfmt->u.pe_info->fmap);
+ image_unmap_file(&modfmt->u.pe_info->fmap);
}
}
if (!module) HeapFree(GetProcessHeap(), 0, modfmt);
More information about the wine-cvs
mailing list