Commit 1d96af36 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

dbghelp: Introduce generic image_unmap_file.

parent 95a5f829
......@@ -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;
}
......
......@@ -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;
......
......@@ -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,
};
/******************************************************************
......
......@@ -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,
};
/******************************************************************
......@@ -297,29 +321,6 @@ error:
}
/******************************************************************
* 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
*
* Maps a directory content out of a PE file
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment