Jacek Caban : dbghelp: Move HANDLE-based crc32 helper to dbghelp.c.

Alexandre Julliard julliard at winehq.org
Mon Mar 16 16:49:07 CDT 2020


Module: wine
Branch: master
Commit: a5a6b0dcb65d8e3576e34d350c80f4789dcfdb7a
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=a5a6b0dcb65d8e3576e34d350c80f4789dcfdb7a

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Mar 16 16:06:10 2020 +0100

dbghelp: Move HANDLE-based crc32 helper to dbghelp.c.

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

---

 dlls/dbghelp/dbghelp.c         |  8 ++++----
 dlls/dbghelp/dbghelp_private.h |  2 +-
 dlls/dbghelp/elf_module.c      | 18 +++---------------
 dlls/dbghelp/macho_module.c    | 16 ++++++++++++++--
 4 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/dlls/dbghelp/dbghelp.c b/dlls/dbghelp/dbghelp.c
index 413d89eb59..03e721f0c9 100644
--- a/dlls/dbghelp/dbghelp.c
+++ b/dlls/dbghelp/dbghelp.c
@@ -723,14 +723,14 @@ void WINAPI WinDbgExtensionDllInit(PWINDBG_EXTENSION_APIS lpExtensionApis,
 {
 }
 
-DWORD calc_crc32(int fd)
+DWORD calc_crc32(HANDLE handle)
 {
     BYTE buffer[8192];
     DWORD crc = 0;
-    int len;
+    DWORD len;
 
-    lseek(fd, 0, SEEK_SET);
-    while ((len = read(fd, buffer, sizeof(buffer))) > 0)
+    SetFilePointer(handle, 0, 0, FILE_BEGIN);
+    while (ReadFile(handle, buffer, sizeof(buffer), &len, NULL) && len)
         crc = RtlComputeCrc32(crc, buffer, len);
     return crc;
 }
diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h
index eea966d6b3..b143216dd0 100644
--- a/dlls/dbghelp/dbghelp_private.h
+++ b/dlls/dbghelp/dbghelp_private.h
@@ -588,7 +588,7 @@ extern BOOL         pcs_callback(const struct process* pcs, ULONG action, void*
 extern void*        fetch_buffer(struct process* pcs, unsigned size) DECLSPEC_HIDDEN;
 extern const char*  wine_dbgstr_addr(const ADDRESS64* addr) DECLSPEC_HIDDEN;
 extern struct cpu*  cpu_find(DWORD) DECLSPEC_HIDDEN;
-extern DWORD calc_crc32(int fd) DECLSPEC_HIDDEN;
+extern DWORD calc_crc32(HANDLE handle) DECLSPEC_HIDDEN;
 
 typedef BOOL (*enum_modules_cb)(const WCHAR*, unsigned long addr, void* user);
 
diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c
index 961fece746..e0ae195cd8 100644
--- a/dlls/dbghelp/elf_module.c
+++ b/dlls/dbghelp/elf_module.c
@@ -966,18 +966,6 @@ static int elf_new_public_symbols(struct module* module, const struct hash_table
     return TRUE;
 }
 
-static DWORD calc_crc(HANDLE handle)
-{
-    BYTE buffer[8192];
-    DWORD crc = 0;
-    DWORD len;
-
-    SetFilePointer(handle, 0, 0, FILE_BEGIN);
-    while (ReadFile(handle, buffer, sizeof(buffer), &len, NULL) && len)
-        crc = RtlComputeCrc32(crc, buffer, len);
-    return crc;
-}
-
 static BOOL elf_check_debug_link(const WCHAR* file, struct image_file_map* fmap, DWORD link_crc)
 {
     struct elf_map_file_data    emfd;
@@ -987,7 +975,7 @@ static BOOL elf_check_debug_link(const WCHAR* file, struct image_file_map* fmap,
     emfd.u.file.filename = file;
     if (!elf_map_file(&emfd, fmap)) return FALSE;
 
-    crc = calc_crc(fmap->u.elf.handle);
+    crc = calc_crc32(fmap->u.elf.handle);
     if (crc != link_crc)
     {
         WARN("Bad CRC for file %s (got %08x while expecting %08x)\n",  debugstr_w(file), crc, link_crc);
@@ -1336,7 +1324,7 @@ BOOL elf_fetch_file_info(const WCHAR* name, DWORD_PTR* base,
     if (!elf_map_file(&emfd, &fmap)) return FALSE;
     if (base) *base = fmap.u.elf.elf_start;
     *size = fmap.u.elf.elf_size;
-    *checksum = calc_crc(fmap.u.elf.handle);
+    *checksum = calc_crc32(fmap.u.elf.handle);
     image_unmap_file(&fmap);
     return TRUE;
 }
@@ -1432,7 +1420,7 @@ static BOOL elf_load_file_from_fmap(struct process* pcs, const WCHAR* filename,
                           sizeof(struct module_format) + sizeof(struct elf_module_info));
         if (!modfmt) return FALSE;
         elf_info->module = module_new(pcs, filename, DMT_ELF, FALSE, modbase,
-                                      fmap->u.elf.elf_size, 0, calc_crc(fmap->u.elf.handle));
+                                      fmap->u.elf.elf_size, 0, calc_crc32(fmap->u.elf.handle));
         if (!elf_info->module)
         {
             HeapFree(GetProcessHeap(), 0, modfmt);
diff --git a/dlls/dbghelp/macho_module.c b/dlls/dbghelp/macho_module.c
index 9d4fc4e47a..5960b0dfc3 100644
--- a/dlls/dbghelp/macho_module.c
+++ b/dlls/dbghelp/macho_module.c
@@ -152,6 +152,18 @@ static char* format_uuid(const uint8_t uuid[16], char out[UUID_STRING_LEN])
     return out;
 }
 
+static DWORD macho_calc_crc32(int fd)
+{
+    BYTE buffer[8192];
+    DWORD crc = 0;
+    int len;
+
+    lseek(fd, 0, SEEK_SET);
+    while ((len = read(fd, buffer, sizeof(buffer))) > 0)
+        crc = RtlComputeCrc32(crc, buffer, len);
+    return crc;
+}
+
 /******************************************************************
  *              macho_calc_range
  *
@@ -1369,7 +1381,7 @@ BOOL macho_fetch_file_info(HANDLE process, const WCHAR* name, unsigned long load
     if (!macho_map_file(pcs, name, split_segs, &fmap)) return FALSE;
     if (base) *base = fmap.u.macho.segs_start;
     *size = fmap.u.macho.segs_size;
-    *checksum = calc_crc32(fmap.u.macho.fd);
+    *checksum = macho_calc_crc32(fmap.u.macho.fd);
     macho_unmap_file(&fmap);
     return TRUE;
 }
@@ -1484,7 +1496,7 @@ static BOOL macho_load_file(struct process* pcs, const WCHAR* filename,
         if (!load_addr)
             load_addr = fmap.u.macho.segs_start;
         macho_info->module = module_new(pcs, filename, DMT_MACHO, FALSE, load_addr,
-                                        fmap.u.macho.segs_size, 0, calc_crc32(fmap.u.macho.fd));
+                                        fmap.u.macho.segs_size, 0, macho_calc_crc32(fmap.u.macho.fd));
         if (!macho_info->module)
         {
             HeapFree(GetProcessHeap(), 0, modfmt);




More information about the wine-cvs mailing list