[WINESYNC] dbghelp: Introduce generic image_unmap_file.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>

wine commit id 1d96af362789aa8aaa0be94a046b0afba2ecefb3 by Jacek Caban <jacek@codeweavers.com>
This commit is contained in:
winesync 2020-09-11 17:05:16 +02:00 committed by Jérôme Gardou
parent fff3c0ca2c
commit 6a1595b09d
5 changed files with 66 additions and 57 deletions

View file

@ -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; 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 = static const struct image_file_map_ops elf_file_map_ops =
{ {
elf_map_section, elf_map_section,
@ -291,6 +312,7 @@ static const struct image_file_map_ops elf_file_map_ops =
elf_find_section, elf_find_section,
elf_get_map_rva, elf_get_map_rva,
elf_get_map_size, elf_get_map_size,
elf_unmap_file,
}; };
static inline void elf_reset_file_map(struct image_file_map* fmap) 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; 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) 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); 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) if (crc != link_crc)
{ {
WARN("Bad CRC for file %s (got %08x while expecting %08x)\n", debugstr_w(file), 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 FALSE;
} }
return TRUE; 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); image_unmap_section(&buildid_sect);
} }
elf_unmap_file(fmap_link); image_unmap_file(fmap_link);
} }
TRACE("not found\n"); 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; if (base) *base = fmap.u.elf.elf_start;
*size = fmap.u.elf.elf_size; *size = fmap.u.elf.elf_size;
*checksum = calc_crc(fmap.u.elf.handle); *checksum = calc_crc(fmap.u.elf.handle);
elf_unmap_file(&fmap); image_unmap_file(&fmap);
return TRUE; 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); 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; return ret;
} }

View file

@ -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); 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); DWORD_PTR (*get_map_rva)(const struct image_section_map* ism);
unsigned (*get_map_size)(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, 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; 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) static inline const char* image_map_section(struct image_section_map* ism)
{ {
return ism->fmap ? ism->fmap->ops->map_section(ism) : NULL; return ism->fmap ? ism->fmap->ops->map_section(ism) : NULL;

View file

@ -432,6 +432,7 @@ static const struct image_file_map_ops macho_file_map_ops =
macho_find_section, macho_find_section,
macho_get_map_rva, macho_get_map_rva,
macho_get_map_size, macho_get_map_size,
macho_unmap_file,
}; };
/****************************************************************** /******************************************************************

View file

@ -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; 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 = static const struct image_file_map_ops pe_file_map_ops =
{ {
pe_map_section, pe_map_section,
@ -191,6 +214,7 @@ static const struct image_file_map_ops pe_file_map_ops =
pe_find_section, pe_find_section,
pe_get_map_rva, pe_get_map_rva,
pe_get_map_size, pe_get_map_size,
pe_unmap_file,
}; };
/****************************************************************** /******************************************************************
@ -298,29 +322,6 @@ error:
return FALSE; 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 * 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) 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); 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)) if (pe_map_file(builtin_module, &builtin_fmap, DMT_PE))
{ {
TRACE("reloaded %s from %s\n", debugstr_w(loaded_name), debugstr_w(builtin_path)); 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; modfmt->u.pe_info->fmap = builtin_fmap;
} }
CloseHandle(builtin_module); CloseHandle(builtin_module);
@ -912,7 +913,7 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name,
#ifndef __REACTOS__ #ifndef __REACTOS__
heap_free(module->real_path); heap_free(module->real_path);
#endif #endif
pe_unmap_file(&modfmt->u.pe_info->fmap); image_unmap_file(&modfmt->u.pe_info->fmap);
} }
} }
if (!module) HeapFree(GetProcessHeap(), 0, modfmt); if (!module) HeapFree(GetProcessHeap(), 0, modfmt);

View file

@ -4,4 +4,4 @@ files:
include/dbghelp.h: sdk/include/psdk/dbghelp.h include/dbghelp.h: sdk/include/psdk/dbghelp.h
include/wine/mscvpdb.h: sdk/include/reactos/wine/mscvpdb.h include/wine/mscvpdb.h: sdk/include/reactos/wine/mscvpdb.h
tags: tags:
wine: 95a5f8296188d7dd8ffb86afd4f0c3280e2f5656 wine: 1d96af362789aa8aaa0be94a046b0afba2ecefb3