Jacek Caban : dbghelp: Don't store entire mach header in image_file_map.
Alexandre Julliard
julliard at winehq.org
Wed Apr 1 15:50:59 CDT 2020
Module: wine
Branch: master
Commit: 7254579417f337063734933975b25d21da4d31f3
URL: https://source.winehq.org/git/wine.git/?a=commit;h=7254579417f337063734933975b25d21da4d31f3
Author: Jacek Caban <jacek at codeweavers.com>
Date: Wed Apr 1 20:27:59 2020 +0200
dbghelp: Don't store entire mach header in image_file_map.
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/dbghelp/image_private.h | 5 +++--
dlls/dbghelp/macho_module.c | 20 +++++++++++---------
2 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/dlls/dbghelp/image_private.h b/dlls/dbghelp/image_private.h
index 2b414b9607..9f015c2707 100644
--- a/dlls/dbghelp/image_private.h
+++ b/dlls/dbghelp/image_private.h
@@ -94,10 +94,11 @@ struct image_file_map
size_t segs_start;
HANDLE handle;
struct image_file_map* dsym; /* the debug symbols file associated with this one */
+ size_t header_size; /* size of real header in file */
+ size_t commands_size;
+ size_t commands_count;
#ifdef HAVE_MACH_O_LOADER_H
- struct mach_header mach_header;
- size_t header_size; /* size of real header in file */
const struct load_command* load_commands;
const struct uuid_command* uuid;
diff --git a/dlls/dbghelp/macho_module.c b/dlls/dbghelp/macho_module.c
index 1e01d84c19..5d3f8615e8 100644
--- a/dlls/dbghelp/macho_module.c
+++ b/dlls/dbghelp/macho_module.c
@@ -448,7 +448,7 @@ static const struct load_command* macho_map_load_commands(struct macho_file_map*
if (fmap->load_commands == IMAGE_NO_MAP)
{
fmap->load_commands = (const struct load_command*) macho_map_range(
- fmap, fmap->header_size, fmap->mach_header.sizeofcmds, NULL);
+ fmap, fmap->header_size, fmap->commands_size, NULL);
TRACE("Mapped load commands: %p\n", fmap->load_commands);
}
@@ -466,7 +466,7 @@ static void macho_unmap_load_commands(struct macho_file_map* fmap)
{
TRACE("Unmapping load commands: %p\n", fmap->load_commands);
macho_unmap_range(NULL, (const void**)&fmap->load_commands, fmap,
- fmap->header_size, fmap->mach_header.sizeofcmds);
+ fmap->header_size, fmap->commands_size);
}
}
@@ -504,9 +504,9 @@ static int macho_enum_load_commands(struct image_file_map *ifm, unsigned cmd,
if ((lc = macho_map_load_commands(fmap)) == IMAGE_NO_MAP) return -1;
- TRACE("%d total commands\n", fmap->mach_header.ncmds);
+ TRACE("%lu total commands\n", fmap->commands_count);
- for (i = 0; i < fmap->mach_header.ncmds; i++, lc = macho_next_load_command(lc))
+ for (i = 0; i < fmap->commands_count; i++, lc = macho_next_load_command(lc))
{
int result;
@@ -683,6 +683,7 @@ static BOOL macho_map_file(struct process *pcs, const WCHAR *filenameW,
{
struct macho_file_map* fmap = &ifm->u.macho;
struct fat_header fat_header;
+ struct mach_header mach_header;
int i;
WCHAR* filename;
struct section_info info;
@@ -745,15 +746,16 @@ static BOOL macho_map_file(struct process *pcs, const WCHAR *filenameW,
/* Individual architecture (standalone or within a fat file) is in its native byte order. */
SetFilePointer(fmap->handle, fmap->arch_offset, 0, FILE_BEGIN);
- if (!ReadFile(fmap->handle, &fmap->mach_header, sizeof(fmap->mach_header), &bytes_read, NULL)
- || bytes_read != sizeof(fmap->mach_header))
+ if (!ReadFile(fmap->handle, &mach_header, sizeof(mach_header), &bytes_read, NULL)
+ || bytes_read != sizeof(mach_header))
goto done;
TRACE("... got possible Mach header\n");
/* and check for a Mach-O header */
- if (fmap->mach_header.magic != target_magic ||
- fmap->mach_header.cputype != target_cpu) goto done;
+ if (mach_header.magic != target_magic || mach_header.cputype != target_cpu) goto done;
+ fmap->commands_size = mach_header.sizeofcmds;
+ fmap->commands_count = mach_header.ncmds;
/* Make sure the file type is one of the ones we expect. */
- switch (fmap->mach_header.filetype)
+ switch (mach_header.filetype)
{
case MH_EXECUTE:
case MH_DYLIB:
More information about the wine-cvs
mailing list