[NTDLL]
[reactos.git] / reactos / dll / ntdll / ldr / utils.c
index 2b77c3a..e4b1a61 100644 (file)
@@ -1388,7 +1388,7 @@ LdrPerformRelocations(PIMAGE_NT_HEADERS NTHeaders,
   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)
@@ -1518,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);
 
@@ -1600,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*);
@@ -2063,24 +2066,25 @@ Success:
              }
            ImportModuleDirectoryCurrent++;
          }
-         if(!NT_SUCCESS(Status))
+
+         if (!NT_SUCCESS(Status))
            {
             NTSTATUS errorStatus = Status;
 
-            while(ImportModuleDirectoryCurrent-- >= ImportModuleDirectory)
+            while (ImportModuleDirectoryCurrent >= ImportModuleDirectory)
               {
                 ImportedName = (PCHAR)Module->DllBase + ImportModuleDirectoryCurrent->Name;
 
                 Status = LdrpGetOrLoadModule(NULL, ImportedName, &ImportedModule, FALSE);
-                if(NT_SUCCESS(Status) && Module != ImportedModule)
+                if (NT_SUCCESS(Status) && Module != ImportedModule)
                   {
                     Status = LdrpUnloadModule(ImportedModule, FALSE);
                     if (!NT_SUCCESS(Status)) DPRINT1("unable to unload %s\n", ImportedName);
                   }
+                ImportModuleDirectoryCurrent--;
               }
             return errorStatus;
            }
-
      }
 
    if (TlsDirectory && TlsSize > 0)
@@ -2295,8 +2299,8 @@ LdrpLoadModule(IN PWSTR SearchPath OPTIONAL,
         /* Map the dll into the process */
         ViewSize = 0;
         ImageBase = 0;
-        ArbitraryUserPointer = NtCurrentTeb()->Tib.ArbitraryUserPointer;
-        NtCurrentTeb()->Tib.ArbitraryUserPointer = FullDosName.Buffer;
+        ArbitraryUserPointer = NtCurrentTeb()->NtTib.ArbitraryUserPointer;
+        NtCurrentTeb()->NtTib.ArbitraryUserPointer = FullDosName.Buffer;
         Status = NtMapViewOfSection(SectionHandle,
                                     NtCurrentProcess(),
                                     &ImageBase,
@@ -2307,7 +2311,7 @@ LdrpLoadModule(IN PWSTR SearchPath OPTIONAL,
                                     ViewShare,
                                     0,
                                     PAGE_READONLY);
-        NtCurrentTeb()->Tib.ArbitraryUserPointer = ArbitraryUserPointer;
+        NtCurrentTeb()->NtTib.ArbitraryUserPointer = ArbitraryUserPointer;
         if (!NT_SUCCESS(Status))
           {
             DPRINT1("map view of section failed (Status 0x%08lx)\n", Status);