[NTDLL]
[reactos.git] / reactos / dll / ntdll / ldr / utils.c
index 10b6ee5..e4b1a61 100644 (file)
@@ -562,7 +562,7 @@ LdrAddModuleEntry(PVOID ImageBase,
   ASSERT(Module);
   memset(Module, 0, sizeof(LDR_DATA_TABLE_ENTRY));
   Module->DllBase = (PVOID)ImageBase;
-  Module->EntryPoint = (PVOID)(ULONG_PTR)NTHeaders->OptionalHeader.AddressOfEntryPoint;
+  Module->EntryPoint = (PVOID)NTHeaders->OptionalHeader.AddressOfEntryPoint;
   if (Module->EntryPoint != 0)
     Module->EntryPoint = (PVOID)((ULONG_PTR)Module->EntryPoint + (ULONG_PTR)Module->DllBase);
   Module->SizeOfImage = LdrpGetResidentSize(NTHeaders);
@@ -1210,8 +1210,8 @@ LdrGetExportByOrdinal (
                     ? RVA(BaseAddress, ExFunctions[Ordinal - ExportDir->Base] )
                     : NULL);
 
-        if (((ULONG_PTR)Function >= (ULONG_PTR)ExportDir) &&
-            ((ULONG_PTR)Function < (ULONG_PTR)ExportDir + (ULONG_PTR)ExportDirSize))
+        if (((ULONG)Function >= (ULONG)ExportDir) &&
+            ((ULONG)Function < (ULONG)ExportDir + (ULONG)ExportDirSize))
           {
              DPRINT("Forward: %s\n", (PCHAR)Function);
              Function = LdrFixupForward((PCHAR)Function);
@@ -1295,8 +1295,8 @@ LdrGetExportByName(PVOID BaseAddress,
           {
              Ordinal = ExOrdinals[Hint];
              Function = RVA(BaseAddress, ExFunctions[Ordinal]);
-             if (((ULONG_PTR)Function >= (ULONG_PTR)ExportDir) &&
-                 ((ULONG_PTR)Function < (ULONG_PTR)ExportDir + (ULONG_PTR)ExportDirSize))
+             if (((ULONG)Function >= (ULONG)ExportDir) &&
+                 ((ULONG)Function < (ULONG)ExportDir + (ULONG)ExportDirSize))
                {
                   DPRINT("Forward: %s\n", (PCHAR)Function);
                   Function = LdrFixupForward((PCHAR)Function);
@@ -1329,8 +1329,8 @@ LdrGetExportByName(PVOID BaseAddress,
           {
              Ordinal = ExOrdinals[mid];
              Function = RVA(BaseAddress, ExFunctions[Ordinal]);
-             if (((ULONG_PTR)Function >= (ULONG_PTR)ExportDir) &&
-                 ((ULONG_PTR)Function < (ULONG_PTR)ExportDir + (ULONG_PTR)ExportDirSize))
+             if (((ULONG)Function >= (ULONG)ExportDir) &&
+                 ((ULONG)Function < (ULONG)ExportDir + (ULONG)ExportDirSize))
                {
                   DPRINT("Forward: %s\n", (PCHAR)Function);
                   Function = LdrFixupForward((PCHAR)Function);
@@ -1385,11 +1385,10 @@ LdrPerformRelocations(PIMAGE_NT_HEADERS NTHeaders,
 {
   PIMAGE_DATA_DIRECTORY RelocationDDir;
   PIMAGE_BASE_RELOCATION RelocationDir, RelocationEnd;
-  ULONG Count, OldProtect, OldProtect2;
-  SIZE_T ProtectSize;
+  ULONG Count, ProtectSize, OldProtect, OldProtect2;
   PVOID Page, ProtectPage, ProtectPage2;
   PUSHORT TypeOffset;
-  ULONG_PTR Delta;
+  LONG_PTR Delta;
   NTSTATUS Status;
 
   if (NTHeaders->FileHeader.Characteristics & IMAGE_FILE_RELOCS_STRIPPED)
@@ -1519,7 +1518,7 @@ LdrpGetOrLoadModule(PWCHAR SearchPath,
        if (!NT_SUCCESS(Status))
          {
            ULONG ErrorResponse;
-           ULONG_PTR ErrorParameter = (ULONG_PTR)&DllName;
+           ULONG_PTR ErrorParameter = (ULONG_PTR)&AnsiDllName;
 
            DPRINT1("failed to load %wZ\n", &DllName);
 
@@ -1574,7 +1573,7 @@ LdrpProcessImportDirectoryEntry(PLDR_DATA_TABLE_ENTRY Module,
    PVOID IATBase;
    ULONG OldProtect;
    ULONG Ordinal;
-   SIZE_T IATSize;
+   ULONG IATSize;
 
    if (ImportModuleDirectory == NULL || ImportModuleDirectory->Name == 0)
      {
@@ -1601,6 +1600,9 @@ LdrpProcessImportDirectoryEntry(PLDR_DATA_TABLE_ENTRY Module,
        IATSize++;
      }
 
+   /* No need to fixup anything if IAT is empty */
+   if (IATSize == 0) return STATUS_SUCCESS;
+
    /* Unprotect the region we are about to write into. */
    IATBase = (PVOID)ImportAddressList;
    IATSize *= sizeof(PVOID*);
@@ -1720,7 +1722,7 @@ LdrpAdjustImportDirectory(PLDR_DATA_TABLE_ENTRY Module,
    PVOID IATBase;
    ULONG OldProtect;
    ULONG Offset;
-   SIZE_T IATSize;
+   ULONG IATSize;
    PIMAGE_NT_HEADERS NTHeaders;
    PCHAR Name;
    ULONG Size;
@@ -2391,7 +2393,7 @@ LdrpLoadModule(IN PWSTR SearchPath OPTIONAL,
 
         RtlEnterCriticalSection(NtCurrentPeb()->LoaderLock);
         InsertTailList(&NtCurrentPeb()->Ldr->InInitializationOrderModuleList,
-                       &(*Module)->InInitializationOrderLinks);
+                       &(*Module)->InInitializationOrderModuleList);
         RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock);
       }
     return STATUS_SUCCESS;
@@ -2779,7 +2781,7 @@ LdrpDetachProcess(BOOLEAN UnloadAll)
    Entry = ModuleListHead->Blink;
    while (Entry != ModuleListHead)
      {
-       Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks);
+       Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderModuleList);
        if (((UnloadAll && Module->LoadCount == LDRP_PROCESS_CREATION_TIME) || Module->LoadCount == 0) &&
            Module->Flags & LDRP_ENTRY_PROCESSED &&
            !(Module->Flags & LDRP_UNLOAD_IN_PROGRESS))
@@ -2793,7 +2795,7 @@ LdrpDetachProcess(BOOLEAN UnloadAll)
              {
                TRACE_LDR("Unload %wZ - Calling entry point at %x\n",
                          &Module->BaseDllName, Module->EntryPoint);
-               LdrpCallDllEntry(Module, DLL_PROCESS_DETACH, (PVOID)(INT_PTR)(Module->LoadCount == LDRP_PROCESS_CREATION_TIME ? 1 : 0));
+               LdrpCallDllEntry(Module, DLL_PROCESS_DETACH, (PVOID)(Module->LoadCount == LDRP_PROCESS_CREATION_TIME ? 1 : 0));
              }
            else
              {
@@ -2812,14 +2814,14 @@ LdrpDetachProcess(BOOLEAN UnloadAll)
        Entry = ModuleListHead->Blink;
        while (Entry != ModuleListHead)
          {
-           Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks);
+           Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderModuleList);
            Entry = Entry->Blink;
            if (Module->Flags & LDRP_UNLOAD_IN_PROGRESS &&
                ((UnloadAll && Module->LoadCount != LDRP_PROCESS_CREATION_TIME) || Module->LoadCount == 0))
              {
                /* remove the module entry from the list */
                RemoveEntryList (&Module->InLoadOrderLinks);
-               RemoveEntryList (&Module->InInitializationOrderLinks);
+               RemoveEntryList (&Module->InInitializationOrderModuleList);
 
                NtUnmapViewOfSection (NtCurrentProcess (), Module->DllBase);
                NtClose (Module->SectionPointer);
@@ -2872,13 +2874,13 @@ LdrpAttachProcess(VOID)
    Entry = ModuleListHead->Flink;
    while (Entry != ModuleListHead)
      {
-       Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks);
+       Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderModuleList);
        if (!(Module->Flags & (LDRP_LOAD_IN_PROGRESS|LDRP_UNLOAD_IN_PROGRESS|LDRP_ENTRY_PROCESSED)))
          {
            Module->Flags |= LDRP_LOAD_IN_PROGRESS;
            TRACE_LDR("%wZ loaded - Calling init routine at %x for process attaching\n",
                      &Module->BaseDllName, Module->EntryPoint);
-           Result = LdrpCallDllEntry(Module, DLL_PROCESS_ATTACH, (PVOID)(INT_PTR)(Module->LoadCount == LDRP_PROCESS_CREATION_TIME ? 1 : 0));
+           Result = LdrpCallDllEntry(Module, DLL_PROCESS_ATTACH, (PVOID)(Module->LoadCount == LDRP_PROCESS_CREATION_TIME ? 1 : 0));
            if (!Result)
              {
                Status = STATUS_DLL_INIT_FAILED;
@@ -2947,7 +2949,7 @@ LdrpAttachThread (VOID)
 
       while (Entry != ModuleListHead)
         {
-          Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks);
+          Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderModuleList);
           if (Module->Flags & LDRP_PROCESS_ATTACH_CALLED &&
               !(Module->Flags & LDRP_DONT_CALL_FOR_THREADS) &&
               !(Module->Flags & LDRP_UNLOAD_IN_PROGRESS))
@@ -2991,7 +2993,7 @@ LdrShutdownThread (VOID)
    Entry = ModuleListHead->Blink;
    while (Entry != ModuleListHead)
      {
-       Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks);
+       Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderModuleList);
 
        if (Module->Flags & LDRP_PROCESS_ATTACH_CALLED &&
            !(Module->Flags & LDRP_DONT_CALL_FOR_THREADS) &&
@@ -3498,12 +3500,6 @@ LdrProcessRelocationBlock(IN ULONG_PTR Address,
             LongPtr = (PULONG)((ULONG_PTR)Address + Offset);
             *LongPtr += Delta;
             break;
-#ifdef _WIN64
-          case IMAGE_REL_BASED_DIR64:
-            LongPtr = (PULONG)((ULONG_PTR)Address + Offset);
-            *LongPtr += Delta;
-            break;
-#endif
 
           case IMAGE_REL_BASED_HIGHADJ:
           case IMAGE_REL_BASED_MIPS_JMPADDR:
@@ -3571,7 +3567,7 @@ LdrLockLoaderLock(IN ULONG Flags,
     }
 
     /* FIXME: Cookie is based on part of the thread id */
-    *Cookie = (ULONG_PTR)NtCurrentTeb()->RealClientId.UniqueThread;
+    *Cookie = (ULONG)NtCurrentTeb()->RealClientId.UniqueThread;
     return Status;
 }
 
@@ -3583,7 +3579,7 @@ LdrUnlockLoaderLock(IN ULONG Flags,
     if (Flags != 0x01)
         return STATUS_INVALID_PARAMETER_1;
 
-    if (Cookie != (ULONG_PTR)NtCurrentTeb()->RealClientId.UniqueThread)
+    if (Cookie != (ULONG)NtCurrentTeb()->RealClientId.UniqueThread)
         return STATUS_INVALID_PARAMETER_2;
 
     RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);