https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6a1595b09d010232727dd…
commit 6a1595b09d010232727dd88879403ab97f923973
Author: winesync <ros-dev(a)reactos.org>
AuthorDate: Fri Sep 11 17:05:16 2020 +0200
Commit: Jérôme Gardou <jerome.gardou(a)reactos.org>
CommitDate: Wed Sep 16 10:35:45 2020 +0200
[WINESYNC] dbghelp: Introduce generic image_unmap_file.
Signed-off-by: Jacek Caban <jacek(a)codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard(a)winehq.org>
wine commit id 1d96af362789aa8aaa0be94a046b0afba2ecefb3 by Jacek Caban
<jacek(a)codeweavers.com>
---
dll/win32/dbghelp/elf_module.c | 57 +++++++++++++++++++--------------------
dll/win32/dbghelp/image_private.h | 10 +++++++
dll/win32/dbghelp/macho_module.c | 1 +
dll/win32/dbghelp/pe_module.c | 53 ++++++++++++++++++------------------
sdk/tools/winesync/dbghelp.cfg | 2 +-
5 files changed, 66 insertions(+), 57 deletions(-)
diff --git a/dll/win32/dbghelp/elf_module.c b/dll/win32/dbghelp/elf_module.c
index 300926f88b9..961fece7462 100644
--- a/dll/win32/dbghelp/elf_module.c
+++ b/dll/win32/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/dll/win32/dbghelp/image_private.h b/dll/win32/dbghelp/image_private.h
index 8543cdc2e84..8a8cd9a4454 100644
--- a/dll/win32/dbghelp/image_private.h
+++ b/dll/win32/dbghelp/image_private.h
@@ -139,6 +139,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,
@@ -154,6 +155,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/dll/win32/dbghelp/macho_module.c b/dll/win32/dbghelp/macho_module.c
index a9a086ea767..9d4fc4e47a2 100644
--- a/dll/win32/dbghelp/macho_module.c
+++ b/dll/win32/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/dll/win32/dbghelp/pe_module.c b/dll/win32/dbghelp/pe_module.c
index d92e4333a5d..b50a3cb8e35 100644
--- a/dll/win32/dbghelp/pe_module.c
+++ b/dll/win32/dbghelp/pe_module.c
@@ -184,6 +184,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,
@@ -191,6 +214,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,
};
/******************************************************************
@@ -298,29 +322,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
*
@@ -342,7 +343,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);
}
@@ -876,7 +877,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);
@@ -912,7 +913,7 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR*
name,
#ifndef __REACTOS__
heap_free(module->real_path);
#endif
- pe_unmap_file(&modfmt->u.pe_info->fmap);
+ image_unmap_file(&modfmt->u.pe_info->fmap);
}
}
if (!module) HeapFree(GetProcessHeap(), 0, modfmt);
diff --git a/sdk/tools/winesync/dbghelp.cfg b/sdk/tools/winesync/dbghelp.cfg
index a172fa15fd5..de1470784a2 100644
--- a/sdk/tools/winesync/dbghelp.cfg
+++ b/sdk/tools/winesync/dbghelp.cfg
@@ -4,4 +4,4 @@ files:
include/dbghelp.h: sdk/include/psdk/dbghelp.h
include/wine/mscvpdb.h: sdk/include/reactos/wine/mscvpdb.h
tags:
- wine: 95a5f8296188d7dd8ffb86afd4f0c3280e2f5656
+ wine: 1d96af362789aa8aaa0be94a046b0afba2ecefb3