[IMAGEHLP] Sync with Wine Staging 4.18. CORE-16441
authorAmine Khaldi <amine.khaldi@reactos.org>
Sat, 2 Nov 2019 17:33:24 +0000 (18:33 +0100)
committerAmine Khaldi <amine.khaldi@reactos.org>
Sat, 2 Nov 2019 17:33:24 +0000 (18:33 +0100)
dll/win32/imagehlp/access.c
dll/win32/imagehlp/imagehlp_main.c
dll/win32/imagehlp/modify.c
media/doc/README.WINE

index 897f2d5..29315f1 100644 (file)
@@ -33,9 +33,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(imagehlp);
 /***********************************************************************
  *           Data
  */
-LIST_ENTRY image_list = { &image_list, &image_list };
+static LIST_ENTRY image_list = { &image_list, &image_list };
 
-DECLSPEC_HIDDEN extern HANDLE IMAGEHLP_hHeap;
 
 /***********************************************************************
  *             GetImageConfigInformation (IMAGEHLP.@)
@@ -74,12 +73,12 @@ PLOADED_IMAGE WINAPI ImageLoad(PCSTR dll_name, PCSTR dll_path)
 
     TRACE("(%s, %s)\n", dll_name, dll_path);
 
-    image = HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(*image));
+    image = HeapAlloc(GetProcessHeap(), 0, sizeof(*image));
     if (!image) return NULL;
 
     if (!MapAndLoad(dll_name, dll_path, image, TRUE, TRUE))
     {
-        HeapFree(IMAGEHLP_hHeap, 0, image);
+        HeapFree(GetProcessHeap(), 0, image);
         return NULL;
     }
 
@@ -99,14 +98,7 @@ BOOL WINAPI ImageUnload(PLOADED_IMAGE loaded_image)
     LIST_ENTRY *entry, *mark;
     PLOADED_IMAGE image;
 
-    FIXME("(%p)\n", loaded_image);
-
-    if (!loaded_image)
-    {
-        /* No image loaded or null pointer */
-        SetLastError(ERROR_INVALID_PARAMETER);
-        return FALSE;
-    }
+    TRACE("(%p)\n", loaded_image);
 
     /* FIXME: do we really need to check this? */
     mark = &image_list;
@@ -128,7 +120,7 @@ BOOL WINAPI ImageUnload(PLOADED_IMAGE loaded_image)
     entry->Flink->Blink = entry->Blink;
 
     UnMapAndLoad(loaded_image);
-    HeapFree(IMAGEHLP_hHeap, 0, loaded_image);
+    HeapFree(GetProcessHeap(), 0, loaded_image);
 
     return TRUE;
 }
index e505126..183b744 100644 (file)
 #include "imagehlp.h"
 #include "wine/debug.h"
 
-/**********************************************************************/
-DECLSPEC_HIDDEN HANDLE IMAGEHLP_hHeap = NULL;
-
-/***********************************************************************
- *           DllMain (IMAGEHLP.init)
- */
-BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
-{
-  switch(fdwReason)
-    {
-    case DLL_PROCESS_ATTACH:
-      DisableThreadLibraryCalls(hinstDLL);
-      IMAGEHLP_hHeap = HeapCreate(0, 0x10000, 0);
-      break;
-    case DLL_PROCESS_DETACH:
-      if (lpvReserved) break;
-      HeapDestroy(IMAGEHLP_hHeap);
-      break;
-    }
-  return TRUE;
-}
 
 /***********************************************************************
  *           MarkImageAsRunFromSwap (IMAGEHLP.@)
index ee68a4e..66ab07e 100644 (file)
@@ -25,7 +25,6 @@
 #include "winternl.h"
 #include "winerror.h"
 #include "wine/debug.h"
-#include "wine/exception.h"
 #include "imagehlp.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(imagehlp);
@@ -159,25 +158,26 @@ BOOL WINAPI BindImageEx(
 /***********************************************************************
  *             CheckSum (internal)
  */
-static WORD CalcCheckSum(DWORD StartValue, LPVOID BaseAddress, DWORD ByteCount)
+static WORD CalcCheckSum(
+  DWORD StartValue, LPVOID BaseAddress, DWORD WordCount)
 {
-    LPWORD Ptr;
-    DWORD Sum, i;
-
-    Sum = StartValue;
-    Ptr = (LPWORD)BaseAddress;
-    for (i = ByteCount; i > 1; i -= 2)
-    {
-        Sum += *Ptr;
-        if (HIWORD(Sum) != 0)
-            Sum = LOWORD(Sum) + HIWORD(Sum);
-        Ptr++;
-    }
-
-    if (i == 1)
-        Sum += *(BYTE *)Ptr;
-
-    return (WORD)(LOWORD(Sum) + HIWORD(Sum));
+   LPWORD Ptr;
+   DWORD Sum;
+   DWORD i;
+
+   Sum = StartValue;
+   Ptr = (LPWORD)BaseAddress;
+   for (i = 0; i < WordCount; i++)
+     {
+       Sum += *Ptr;
+       if (HIWORD(Sum) != 0)
+         {
+            Sum = LOWORD(Sum) + HIWORD(Sum);
+         }
+       Ptr++;
+     }
+
+   return (WORD)(LOWORD(Sum) + HIWORD(Sum));
 }
 
 
@@ -188,60 +188,19 @@ PIMAGE_NT_HEADERS WINAPI CheckSumMappedFile(
   LPVOID BaseAddress, DWORD FileLength,
   LPDWORD HeaderSum, LPDWORD CheckSum)
 {
-  IMAGE_DOS_HEADER *dos = (IMAGE_DOS_HEADER *) BaseAddress;
-  PIMAGE_NT_HEADERS32 Header32;
-  PIMAGE_NT_HEADERS64 Header64;
-  PIMAGE_NT_HEADERS ret = NULL;
-  DWORD *ChecksumFile;
+  PIMAGE_NT_HEADERS header;
   DWORD CalcSum;
-  DWORD HdrSum = 0;
+  DWORD HdrSum;
 
-  TRACE("(%p, %d, %p, %p)\n",
-    BaseAddress, FileLength, HeaderSum, CheckSum
-  );
+  TRACE("(%p, %d, %p, %p)\n", BaseAddress, FileLength, HeaderSum, CheckSum);
 
-  CalcSum = (DWORD)CalcCheckSum(0, BaseAddress, FileLength);
+  CalcSum = CalcCheckSum(0, BaseAddress, (FileLength + 1) / sizeof(WORD));
+  header = RtlImageNtHeader(BaseAddress);
 
-  __TRY
-  {
-    if (dos->e_magic != IMAGE_DOS_SIGNATURE)
-#ifdef __REACTOS__
-      _SEH2_LEAVE;
-#else
-      break;
-#endif
+  if (!header)
+    return NULL;
 
-    Header32 = (IMAGE_NT_HEADERS32 *)((char *)dos + dos->e_lfanew);
-    if (Header32->Signature != IMAGE_NT_SIGNATURE)
-#ifdef __REACTOS__
-      _SEH2_LEAVE;
-#else
-      break;
-#endif
-
-    ret = (PIMAGE_NT_HEADERS)Header32;
-
-    if (Header32->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
-      ChecksumFile = &Header32->OptionalHeader.CheckSum;
-    else if (Header32->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
-    {
-      Header64 = (IMAGE_NT_HEADERS64 *)Header32;
-      ChecksumFile = &Header64->OptionalHeader.CheckSum;
-    }
-    else
-#ifdef __REACTOS__
-      _SEH2_LEAVE;
-#else
-      break;
-#endif
-
-    HdrSum = *ChecksumFile;
-  }
-  __EXCEPT_PAGE_FAULT
-  {
-    /* nothing */
-  }
-  __ENDTRY
+  *HeaderSum = HdrSum = header->OptionalHeader.CheckSum;
 
   /* Subtract image checksum from calculated checksum. */
   /* fix low word of checksum */
@@ -268,9 +227,8 @@ PIMAGE_NT_HEADERS WINAPI CheckSumMappedFile(
   CalcSum += FileLength;
 
   *CheckSum = CalcSum;
-  *HeaderSum = HdrSum;
 
-  return ret;
+  return header;
 }
 
 /***********************************************************************
index 21b3751..7f08673 100644 (file)
@@ -77,7 +77,7 @@ dll/win32/httpapi             # Synced to WineStaging-4.18
 dll/win32/iccvid              # Synced to WineStaging-4.0
 dll/win32/ieframe             # Synced to WineStaging-4.18
 dll/win32/imaadp32.acm        # Synced to WineStaging-4.0
-dll/win32/imagehlp            # Synced to WineStaging-3.3
+dll/win32/imagehlp            # Synced to WineStaging-4.18
 dll/win32/imm32               # Synced to WineStaging-4.0
 dll/win32/inetcomm            # Synced to WineStaging-4.0
 dll/win32/inetmib1            # Synced to WineStaging-3.17