https://git.reactos.org/?p=reactos.git;a=commitdiff;h=fff3c0ca2c4c1054212cf…
commit fff3c0ca2c4c1054212cf70d379db4a1f93f88a1
Author: winesync <ros-dev(a)reactos.org>
AuthorDate: Fri Sep 11 17:01:17 2020 +0200
Commit: Jérôme Gardou <jerome.gardou(a)reactos.org>
CommitDate: Wed Sep 16 10:35:44 2020 +0200
[WINESYNC] dbghelp: Use vtbl to handle different image_file_map types.
Signed-off-by: Jacek Caban <jacek(a)codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard(a)winehq.org>
wine commit id 95a5f8296188d7dd8ffb86afd4f0c3280e2f5656 by Jacek Caban
<jacek(a)codeweavers.com>
---
dll/win32/dbghelp/elf_module.c | 44 +++++++------------
dll/win32/dbghelp/image_private.h | 89 ++++++---------------------------------
dll/win32/dbghelp/macho_module.c | 41 +++++++-----------
dll/win32/dbghelp/pe_module.c | 24 ++++++++---
sdk/tools/winesync/dbghelp.cfg | 2 +-
5 files changed, 63 insertions(+), 137 deletions(-)
diff --git a/dll/win32/dbghelp/elf_module.c b/dll/win32/dbghelp/elf_module.c
index a5b7c1dc5ca..300926f88b9 100644
--- a/dll/win32/dbghelp/elf_module.c
+++ b/dll/win32/dbghelp/elf_module.c
@@ -134,7 +134,7 @@ struct elf_module_info
*
* Maps a single section into memory from an ELF file
*/
-const char* elf_map_section(struct image_section_map* ism)
+static const char* elf_map_section(struct image_section_map* ism)
{
struct elf_file_map* fmap = &ism->fmap->u.elf;
SYSTEM_INFO sysinfo;
@@ -176,7 +176,7 @@ const char* elf_map_section(struct image_section_map* ism)
* Finds a section by name (and type) into memory from an ELF file
* or its alternate if any
*/
-BOOL elf_find_section(struct image_file_map* _fmap, const char* name, struct
image_section_map* ism)
+static BOOL elf_find_section(struct image_file_map* _fmap, const char* name, struct
image_section_map* ism)
{
struct elf_file_map* fmap = &_fmap->u.elf;
unsigned i;
@@ -233,7 +233,7 @@ static BOOL elf_find_section_type(struct image_file_map* _fmap, const
char* name
*
* Unmaps a single section from memory
*/
-void elf_unmap_section(struct image_section_map* ism)
+static void elf_unmap_section(struct image_section_map* ism)
{
struct elf_file_map* fmap = &ism->fmap->u.elf;
@@ -265,7 +265,7 @@ static void elf_end_find(struct image_file_map* fmap)
*
* Get the RVA of an ELF section
*/
-DWORD_PTR elf_get_map_rva(const struct image_section_map* ism)
+static DWORD_PTR elf_get_map_rva(const struct image_section_map* ism)
{
if (ism->sidx < 0 || ism->sidx >= ism->fmap->u.elf.elfhdr.e_shnum)
return 0;
@@ -277,15 +277,25 @@ DWORD_PTR elf_get_map_rva(const struct image_section_map* ism)
*
* Get the size of an ELF section
*/
-unsigned elf_get_map_size(const struct image_section_map* ism)
+static unsigned elf_get_map_size(const struct image_section_map* ism)
{
if (ism->sidx < 0 || ism->sidx >= ism->fmap->u.elf.elfhdr.e_shnum)
return 0;
return ism->fmap->u.elf.sect[ism->sidx].shdr.sh_size;
}
+static const struct image_file_map_ops elf_file_map_ops =
+{
+ elf_map_section,
+ elf_unmap_section,
+ elf_find_section,
+ elf_get_map_rva,
+ elf_get_map_size,
+};
+
static inline void elf_reset_file_map(struct image_file_map* fmap)
{
+ fmap->ops = &elf_file_map_ops;
fmap->alternate = NULL;
fmap->u.elf.handle = INVALID_HANDLE_VALUE;
fmap->u.elf.shstrtab = IMAGE_NO_MAP;
@@ -2036,30 +2046,6 @@ BOOL elf_synchronize_module_list(struct process* pcs)
#else /* !__ELF__ */
-BOOL elf_find_section(struct image_file_map* fmap, const char* name,
- struct image_section_map* ism)
-{
- return FALSE;
-}
-
-const char* elf_map_section(struct image_section_map* ism)
-{
- return NULL;
-}
-
-void elf_unmap_section(struct image_section_map* ism)
-{}
-
-unsigned elf_get_map_size(const struct image_section_map* ism)
-{
- return 0;
-}
-
-DWORD_PTR elf_get_map_rva(const struct image_section_map* ism)
-{
- return 0;
-}
-
BOOL elf_synchronize_module_list(struct process* pcs)
{
return FALSE;
diff --git a/dll/win32/dbghelp/image_private.h b/dll/win32/dbghelp/image_private.h
index 072c956c3e5..8543cdc2e84 100644
--- a/dll/win32/dbghelp/image_private.h
+++ b/dll/win32/dbghelp/image_private.h
@@ -62,6 +62,7 @@
struct image_file_map
{
enum module_type modtype;
+ const struct image_file_map_ops *ops;
unsigned addr_size; /* either 16 (not used), 32 or 64 */
struct image_file_map* alternate; /* another file linked to this one */
union
@@ -131,47 +132,21 @@ struct image_section_map
long sidx;
};
-extern BOOL elf_find_section(struct image_file_map* fmap, const char* name,
- struct image_section_map* ism) DECLSPEC_HIDDEN;
-extern const char* elf_map_section(struct image_section_map* ism) DECLSPEC_HIDDEN;
-extern void elf_unmap_section(struct image_section_map* ism) DECLSPEC_HIDDEN;
-extern DWORD_PTR elf_get_map_rva(const struct image_section_map* ism)
DECLSPEC_HIDDEN;
-extern unsigned elf_get_map_size(const struct image_section_map* ism)
DECLSPEC_HIDDEN;
-
-extern BOOL macho_find_section(struct image_file_map* ifm, const char* segname,
- const char* sectname, struct image_section_map*
ism) DECLSPEC_HIDDEN;
-extern const char* macho_map_section(struct image_section_map* ism) DECLSPEC_HIDDEN;
-extern void macho_unmap_section(struct image_section_map* ism) DECLSPEC_HIDDEN;
-extern DWORD_PTR macho_get_map_rva(const struct image_section_map* ism)
DECLSPEC_HIDDEN;
-extern unsigned macho_get_map_size(const struct image_section_map* ism)
DECLSPEC_HIDDEN;
-
-extern BOOL pe_find_section(struct image_file_map* fmap, const char* name,
- struct image_section_map* ism) DECLSPEC_HIDDEN;
-extern const char* pe_map_section(struct image_section_map* psm) DECLSPEC_HIDDEN;
-extern void pe_unmap_section(struct image_section_map* psm) DECLSPEC_HIDDEN;
-extern DWORD_PTR pe_get_map_rva(const struct image_section_map* psm) DECLSPEC_HIDDEN;
-extern unsigned pe_get_map_size(const struct image_section_map* psm)
DECLSPEC_HIDDEN;
+struct image_file_map_ops
+{
+ const char* (*map_section)(struct image_section_map* ism);
+ void (*unmap_section)(struct image_section_map* ism);
+ 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);
+};
static inline BOOL image_find_section(struct image_file_map* fmap, const char* name,
struct image_section_map* ism)
{
while (fmap)
{
- switch (fmap->modtype)
- {
-#ifndef DBGHELP_STATIC_LIB
- case DMT_ELF:
- if (elf_find_section(fmap, name, ism)) return TRUE;
- break;
- case DMT_MACHO:
- if (macho_find_section(fmap, NULL, name, ism)) return TRUE;
- break;
-#endif
- case DMT_PE:
- if (pe_find_section(fmap, name, ism)) return TRUE;
- break;
- default: assert(0); return FALSE;
- }
+ if (fmap->ops->find_section(fmap, name, ism)) return TRUE;
fmap = fmap->alternate;
}
ism->fmap = NULL;
@@ -181,56 +156,20 @@ static inline BOOL image_find_section(struct image_file_map* fmap,
const char* n
static inline const char* image_map_section(struct image_section_map* ism)
{
- if (!ism->fmap) return NULL;
- switch (ism->fmap->modtype)
- {
-#ifndef DBGHELP_STATIC_LIB
- case DMT_ELF: return elf_map_section(ism);
- case DMT_MACHO: return macho_map_section(ism);
-#endif
- case DMT_PE: return pe_map_section(ism);
- default: assert(0); return NULL;
- }
+ return ism->fmap ? ism->fmap->ops->map_section(ism) : NULL;
}
static inline void image_unmap_section(struct image_section_map* ism)
{
- if (!ism->fmap) return;
- switch (ism->fmap->modtype)
- {
-#ifndef DBGHELP_STATIC_LIB
- case DMT_ELF: elf_unmap_section(ism); break;
- case DMT_MACHO: macho_unmap_section(ism); break;
-#endif
- case DMT_PE: pe_unmap_section(ism); break;
- default: assert(0); return;
- }
+ if (ism->fmap) ism->fmap->ops->unmap_section(ism);
}
static inline DWORD_PTR image_get_map_rva(const struct image_section_map* ism)
{
- if (!ism->fmap) return 0;
- switch (ism->fmap->modtype)
- {
-#ifndef DBGHELP_STATIC_LIB
- case DMT_ELF: return elf_get_map_rva(ism);
- case DMT_MACHO: return macho_get_map_rva(ism);
-#endif
- case DMT_PE: return pe_get_map_rva(ism);
- default: assert(0); return 0;
- }
+ return ism->fmap ? ism->fmap->ops->get_map_rva(ism) : 0;
}
static inline unsigned image_get_map_size(const struct image_section_map* ism)
{
- if (!ism->fmap) return 0;
- switch (ism->fmap->modtype)
- {
-#ifndef DBGHELP_STATIC_LIB
- case DMT_ELF: return elf_get_map_size(ism);
- case DMT_MACHO: return macho_get_map_size(ism);
-#endif
- case DMT_PE: return pe_get_map_size(ism);
- default: assert(0); return 0;
- }
+ return ism->fmap ? ism->fmap->ops->get_map_size(ism) : 0;
}
diff --git a/dll/win32/dbghelp/macho_module.c b/dll/win32/dbghelp/macho_module.c
index 1df48c8a951..a9a086ea767 100644
--- a/dll/win32/dbghelp/macho_module.c
+++ b/dll/win32/dbghelp/macho_module.c
@@ -332,7 +332,7 @@ static void macho_unmap_ranges(const struct macho_file_map* fmap,
/******************************************************************
* macho_find_section
*/
-BOOL macho_find_section(struct image_file_map* ifm, const char* segname, const char*
sectname, struct image_section_map* ism)
+static BOOL macho_find_segment_section(struct image_file_map* ifm, const char* segname,
const char* sectname, struct image_section_map* ism)
{
struct macho_file_map* fmap;
unsigned i;
@@ -369,6 +369,11 @@ BOOL macho_find_section(struct image_file_map* ifm, const char*
segname, const c
return FALSE;
}
+static BOOL macho_find_section(struct image_file_map* ifm, const char* sectname, struct
image_section_map* ism)
+{
+ return macho_find_segment_section(ifm, NULL, sectname, ism);
+}
+
/******************************************************************
* macho_map_section
*/
@@ -420,6 +425,15 @@ unsigned macho_get_map_size(const struct image_section_map* ism)
return ism->fmap->u.macho.sect[ism->sidx].section.size;
}
+static const struct image_file_map_ops macho_file_map_ops =
+{
+ macho_map_section,
+ macho_unmap_section,
+ macho_find_section,
+ macho_get_map_rva,
+ macho_get_map_size,
+};
+
/******************************************************************
* macho_map_load_commands
*
@@ -680,6 +694,7 @@ static BOOL macho_map_file(struct process *pcs, const WCHAR
*filenameW,
reset_file_map(ifm);
ifm->modtype = DMT_MACHO;
+ ifm->ops = &macho_file_map_ops;
ifm->alternate = NULL;
ifm->addr_size = (pcs->is_64bit) ? 64 : 32;
fmap->header_size = (pcs->is_64bit) ? sizeof(struct mach_header_64) :
sizeof(struct mach_header);
@@ -1998,30 +2013,6 @@ struct module* macho_load_module(struct process* pcs, const WCHAR*
name, unsign
#else /* HAVE_MACH_O_LOADER_H */
-BOOL macho_find_section(struct image_file_map* ifm, const char* segname, const char*
sectname, struct image_section_map* ism)
-{
- return FALSE;
-}
-
-const char* macho_map_section(struct image_section_map* ism)
-{
- return NULL;
-}
-
-void macho_unmap_section(struct image_section_map* ism)
-{
-}
-
-DWORD_PTR macho_get_map_rva(const struct image_section_map* ism)
-{
- return 0;
-}
-
-unsigned macho_get_map_size(const struct image_section_map* ism)
-{
- return 0;
-}
-
BOOL macho_synchronize_module_list(struct process* pcs)
{
return FALSE;
diff --git a/dll/win32/dbghelp/pe_module.c b/dll/win32/dbghelp/pe_module.c
index 2134804ccaa..d92e4333a5d 100644
--- a/dll/win32/dbghelp/pe_module.c
+++ b/dll/win32/dbghelp/pe_module.c
@@ -75,7 +75,7 @@ static void pe_unmap_full(struct image_file_map* fmap)
*
* Maps a single section into memory from an PE file
*/
-const char* pe_map_section(struct image_section_map* ism)
+static const char* pe_map_section(struct image_section_map* ism)
{
void* mapping;
struct pe_file_map* fmap = &ism->fmap->u.pe;
@@ -113,8 +113,8 @@ const char* pe_map_section(struct image_section_map* ism)
* Finds a section by name (and type) into memory from an PE file
* or its alternate if any
*/
-BOOL pe_find_section(struct image_file_map* fmap, const char* name,
- struct image_section_map* ism)
+static BOOL pe_find_section(struct image_file_map* fmap, const char* name,
+ struct image_section_map* ism)
{
const char* sectname;
unsigned i;
@@ -150,7 +150,7 @@ BOOL pe_find_section(struct image_file_map* fmap, const char* name,
*
* Unmaps a single section from memory
*/
-void pe_unmap_section(struct image_section_map* ism)
+static void pe_unmap_section(struct image_section_map* ism)
{
if (ism->sidx >= 0 && ism->sidx <
ism->fmap->u.pe.ntheader.FileHeader.NumberOfSections &&
ism->fmap->u.pe.sect[ism->sidx].mapped != IMAGE_NO_MAP)
@@ -165,7 +165,7 @@ void pe_unmap_section(struct image_section_map* ism)
*
* Get the RVA of an PE section
*/
-DWORD_PTR pe_get_map_rva(const struct image_section_map* ism)
+static DWORD_PTR pe_get_map_rva(const struct image_section_map* ism)
{
if (ism->sidx < 0 || ism->sidx >=
ism->fmap->u.pe.ntheader.FileHeader.NumberOfSections)
return 0;
@@ -177,13 +177,22 @@ DWORD_PTR pe_get_map_rva(const struct image_section_map* ism)
*
* Get the size of a PE section
*/
-unsigned pe_get_map_size(const struct image_section_map* ism)
+static unsigned pe_get_map_size(const struct image_section_map* ism)
{
if (ism->sidx < 0 || ism->sidx >=
ism->fmap->u.pe.ntheader.FileHeader.NumberOfSections)
return 0;
return ism->fmap->u.pe.sect[ism->sidx].shdr.Misc.VirtualSize;
}
+static const struct image_file_map_ops pe_file_map_ops =
+{
+ pe_map_section,
+ pe_unmap_section,
+ pe_find_section,
+ pe_get_map_rva,
+ pe_get_map_size,
+};
+
/******************************************************************
* pe_is_valid_pointer_table
*
@@ -208,11 +217,12 @@ static BOOL pe_is_valid_pointer_table(const IMAGE_NT_HEADERS* nthdr,
const void*
*
* Maps an PE file into memory (and checks it's a real PE file)
*/
-static BOOL pe_map_file(HANDLE file, struct image_file_map* fmap, enum module_type mt)
+BOOL pe_map_file(HANDLE file, struct image_file_map* fmap, enum module_type mt)
{
void* mapping;
fmap->modtype = mt;
+ fmap->ops = &pe_file_map_ops;
fmap->alternate = NULL;
fmap->u.pe.hMap = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
if (fmap->u.pe.hMap == 0) return FALSE;
diff --git a/sdk/tools/winesync/dbghelp.cfg b/sdk/tools/winesync/dbghelp.cfg
index d04078ef2a3..a172fa15fd5 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: 02dfd959ca6f2295ca279ab65f6b6429cd53673c
+ wine: 95a5f8296188d7dd8ffb86afd4f0c3280e2f5656