Check for failed allocations. Spotted by Martin Bealby.
[reactos.git] / reactos / lib / ntdll / ldr / utils.c
index aae4079..76cabd3 100644 (file)
@@ -104,7 +104,7 @@ static __inline LONG LdrpDecrementLoadCount(PLDR_DATA_TABLE_ENTRY Module, BOOLEA
        RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
      }
    LoadCount = Module->LoadCount;
-   if (Module->LoadCount > 0)
+   if (Module->LoadCount > 0 && Module->LoadCount != 0xFFFF)
      {
        Module->LoadCount--;
      }
@@ -237,6 +237,7 @@ LdrpInitializeTlsForProccess(VOID)
    PLDR_DATA_TABLE_ENTRY Module;
    PIMAGE_TLS_DIRECTORY TlsDirectory;
    PTLS_DATA TlsData;
+   ULONG Size;
 
    DPRINT("LdrpInitializeTlsForProccess() called for %wZ\n", &ExeModule->BaseDllName);
 
@@ -263,14 +264,14 @@ LdrpInitializeTlsForProccess(VOID)
                                  RtlImageDirectoryEntryToData(Module->DllBase,
                                                               TRUE,
                                                               IMAGE_DIRECTORY_ENTRY_TLS,
-                                                              NULL);
+                                                              &Size);
                ASSERT(Module->TlsIndex < LdrpTlsCount);
                TlsData = &LdrpTlsArray[Module->TlsIndex];
                TlsData->StartAddressOfRawData = (PVOID)TlsDirectory->StartAddressOfRawData;
                TlsData->TlsDataSize = TlsDirectory->EndAddressOfRawData - TlsDirectory->StartAddressOfRawData;
                TlsData->TlsZeroSize = TlsDirectory->SizeOfZeroFill;
                if (TlsDirectory->AddressOfCallBacks)
-                 TlsData->TlsAddressOfCallBacks = *TlsDirectory->AddressOfCallBacks;
+                 TlsData->TlsAddressOfCallBacks = *(PIMAGE_TLS_CALLBACK*)TlsDirectory->AddressOfCallBacks;
                else
                  TlsData->TlsAddressOfCallBacks = NULL;
                TlsData->Module = Module;
@@ -533,7 +534,7 @@ LdrpMapKnownDll(IN PUNICODE_STRING DllName,
                          &ObjectAttributes);
   if (!NT_SUCCESS(Status))
     {
-      DPRINT("NtOpenSection() failed for '%wZ' (Status %lx)\n", DllName, Status);
+      DPRINT("NtOpenSection() failed for '%wZ' (Status 0x%08lx)\n", DllName, Status);
       return Status;
     }
 
@@ -638,7 +639,7 @@ LdrpMapDllImageFile(IN PWSTR SearchPath OPTIONAL,
                       FILE_SYNCHRONOUS_IO_NONALERT);
   if (!NT_SUCCESS(Status))
     {
-      DPRINT1("Dll open of %wZ failed: Status = 0x%08x\n",
+      DPRINT1("Dll open of %wZ failed: Status = 0x%08lx\n",
                &FullNtFileName, Status);
       RtlFreeUnicodeString (&FullNtFileName);
       return Status;
@@ -656,7 +657,7 @@ LdrpMapDllImageFile(IN PWSTR SearchPath OPTIONAL,
                       NULL);
   if (!NT_SUCCESS(Status))
     {
-      DPRINT("Dll header read failed: Status = 0x%08x\n", Status);
+      DPRINT("Dll header read failed: Status = 0x%08lx\n", Status);
       NtClose(FileHandle);
       return Status;
     }
@@ -693,7 +694,7 @@ LdrpMapDllImageFile(IN PWSTR SearchPath OPTIONAL,
 
   if (!NT_SUCCESS(Status))
     {
-      DPRINT("NTDLL create section failed: Status = 0x%08x\n", Status);
+      DPRINT("NTDLL create section failed: Status = 0x%08lx\n", Status);
       return Status;
     }
 
@@ -721,7 +722,7 @@ LdrpMapDllImageFile(IN PWSTR SearchPath OPTIONAL,
  *
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 LdrLoadDll (IN PWSTR SearchPath OPTIONAL,
             IN ULONG LoadFlags,
             IN PUNICODE_STRING Name,
@@ -774,7 +775,7 @@ LdrLoadDll (IN PWSTR SearchPath OPTIONAL,
  *
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 LdrFindEntryForAddress(PVOID Address,
                        PLDR_DATA_TABLE_ENTRY *Module)
 {
@@ -1030,7 +1031,7 @@ LdrGetExportByOrdinal (
                         ExportDir->AddressOfFunctions
                         );
         DPRINT(
-                "LdrGetExportByOrdinal(Ordinal %d) = %p\n",
+                "LdrGetExportByOrdinal(Ordinal %lu) = %p\n",
                 Ordinal,
                 RVA(BaseAddress, ExFunctions[Ordinal - ExportDir->Base] )
                 );
@@ -1076,14 +1077,13 @@ LdrGetExportByName(PVOID BaseAddress,
    PDWORD                       * ExFunctions;
    PDWORD                       * ExNames;
    USHORT                       * ExOrdinals;
-   ULONG                        i;
    PVOID                        ExName;
    ULONG                        Ordinal;
    PVOID                        Function;
    LONG minn, maxn;
    ULONG ExportDirSize;
 
-   DPRINT("LdrGetExportByName %x %s %hu\n", BaseAddress, SymbolName, Hint);
+   DPRINT("LdrGetExportByName %p %s %hu\n", BaseAddress, SymbolName, Hint);
 
    ExportDir = (PIMAGE_EXPORT_DIRECTORY)
      RtlImageDirectoryEntryToData(BaseAddress,
@@ -1141,7 +1141,7 @@ LdrGetExportByName(PVOID BaseAddress,
      }
 
    /*
-    * Try a binary search first
+    * Binary search
     */
    minn = 0;
    maxn = ExportDir->NumberOfNames - 1;
@@ -1187,31 +1187,6 @@ LdrGetExportByName(PVOID BaseAddress,
           }
      }
 
-   /*
-    * Fall back on a linear search
-    */
-   DPRINT("LdrGetExportByName(): Falling back on a linear search of export table\n");
-   for (i = 0; i < ExportDir->NumberOfNames; i++)
-     {
-        ExName = RVA(BaseAddress, ExNames[i]);
-        if (strcmp(ExName, (PCHAR)SymbolName) == 0)
-          {
-             Ordinal = ExOrdinals[i];
-             Function = RVA(BaseAddress, ExFunctions[Ordinal]);
-             DPRINT("%x %x %x\n", Function, ExportDir, ExportDir + ExportDirSize);
-             if (((ULONG)Function >= (ULONG)ExportDir) &&
-                 ((ULONG)Function < (ULONG)ExportDir + (ULONG)ExportDirSize))
-               {
-                  DPRINT("Forward: %s\n", (PCHAR)Function);
-                  Function = LdrFixupForward((PCHAR)Function);
-               }
-             if (Function == NULL)
-               {
-                 break;
-               }
-             return Function;
-          }
-     }
    DPRINT1("LdrGetExportByName(): failed to find %s\n",SymbolName);
    return (PVOID)NULL;
 }
@@ -1476,8 +1451,9 @@ LdrpProcessImportDirectory(
    NTSTATUS Status;
    PIMAGE_IMPORT_DESCRIPTOR ImportModuleDirectory;
    PCHAR Name;
+   ULONG Size;
 
-   DPRINT("LdrpProcessImportDirectory(%x '%wZ', '%s')\n",
+   DPRINT("LdrpProcessImportDirectory(%p '%wZ', '%s')\n",
           Module, &Module->BaseDllName, ImportedName);
 
 
@@ -1485,7 +1461,7 @@ LdrpProcessImportDirectory(
                              RtlImageDirectoryEntryToData(Module->DllBase,
                                                           TRUE,
                                                           IMAGE_DIRECTORY_ENTRY_IMPORT,
-                                                          NULL);
+                                                          &Size);
    if (ImportModuleDirectory == NULL)
      {
        return STATUS_UNSUCCESSFUL;
@@ -1529,15 +1505,16 @@ LdrpAdjustImportDirectory(PLDR_DATA_TABLE_ENTRY Module,
    ULONG IATSize;
    PIMAGE_NT_HEADERS NTHeaders;
    PCHAR Name;
+   ULONG Size;
 
-   DPRINT("LdrpAdjustImportDirectory(Module %x '%wZ', %x '%wZ', %x '%s')\n",
+   DPRINT("LdrpAdjustImportDirectory(Module %p '%wZ', %p '%wZ', '%s')\n",
           Module, &Module->BaseDllName, ImportedModule, &ImportedModule->BaseDllName, ImportedName);
 
    ImportModuleDirectory = (PIMAGE_IMPORT_DESCRIPTOR)
                               RtlImageDirectoryEntryToData(Module->DllBase,
                                                            TRUE,
                                                            IMAGE_DIRECTORY_ENTRY_IMPORT,
-                                                           NULL);
+                                                           &Size);
    if (ImportModuleDirectory == NULL)
      {
        return STATUS_UNSUCCESSFUL;
@@ -1647,15 +1624,16 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
    NTSTATUS Status;
    PLDR_DATA_TABLE_ENTRY ImportedModule;
    PCHAR ImportedName;
+   ULONG Size;
 
-   DPRINT("LdrFixupImports(SearchPath %x, Module %x)\n", SearchPath, Module);
+   DPRINT("LdrFixupImports(SearchPath %S, Module %p)\n", SearchPath, Module);
 
    /* Check for tls data */
    TlsDirectory = (PIMAGE_TLS_DIRECTORY)
                      RtlImageDirectoryEntryToData(Module->DllBase,
                                                   TRUE,
                                                   IMAGE_DIRECTORY_ENTRY_TLS,
-                                                  NULL);
+                                                  &Size);
    if (TlsDirectory)
      {
        TlsSize = TlsDirectory->EndAddressOfRawData
@@ -1676,13 +1654,13 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
                               RtlImageDirectoryEntryToData(Module->DllBase,
                                                            TRUE,
                                                            IMAGE_DIRECTORY_ENTRY_IMPORT,
-                                                           NULL);
+                                                           &Size);
 
    BoundImportDescriptor = (PIMAGE_BOUND_IMPORT_DESCRIPTOR)
                               RtlImageDirectoryEntryToData(Module->DllBase,
                                                            TRUE,
                                                            IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT,
-                                                           NULL);
+                                                           &Size);
 
    if (BoundImportDescriptor != NULL && ImportModuleDirectory == NULL)
      {
@@ -1691,7 +1669,7 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
      }
    if (BoundImportDescriptor)
      {
-       DPRINT("BoundImportDescriptor %x\n", BoundImportDescriptor);
+       DPRINT("BoundImportDescriptor %p\n", BoundImportDescriptor);
 
        BoundImportDescriptorCurrent = BoundImportDescriptor;
        while (BoundImportDescriptorCurrent->OffsetModuleName)
@@ -1816,7 +1794,7 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
      }
    else if (ImportModuleDirectory)
      {
-       DPRINT("ImportModuleDirectory %x\n", ImportModuleDirectory);
+       DPRINT("ImportModuleDirectory %p\n", ImportModuleDirectory);
 
        ImportModuleDirectoryCurrent = ImportModuleDirectory;
        while (ImportModuleDirectoryCurrent->Name)
@@ -1895,8 +1873,8 @@ PEPFUNC LdrPEStartup (PVOID  ImageBase,
    PIMAGE_NT_HEADERS    NTHeaders;
    PLDR_DATA_TABLE_ENTRY tmpModule;
 
-   DPRINT("LdrPEStartup(ImageBase %x SectionHandle %x)\n",
-           ImageBase, (ULONG)SectionHandle);
+   DPRINT("LdrPEStartup(ImageBase %p SectionHandle %p)\n",
+           ImageBase, SectionHandle);
 
    /*
     * Overlay DOS and WNT headers structures
@@ -1974,14 +1952,14 @@ PEPFUNC LdrPEStartup (PVOID  ImageBase,
    /*
     * Compute the DLL's entry point's address.
     */
-   DPRINT("ImageBase = %x\n",(ULONG)ImageBase);
-   DPRINT("AddressOfEntryPoint = %x\n",(ULONG)NTHeaders->OptionalHeader.AddressOfEntryPoint);
+   DPRINT("ImageBase = %p\n", ImageBase);
+   DPRINT("AddressOfEntryPoint = 0x%lx\n",(ULONG)NTHeaders->OptionalHeader.AddressOfEntryPoint);
    if (NTHeaders->OptionalHeader.AddressOfEntryPoint != 0)
      {
         EntryPoint = (PEPFUNC) ((ULONG_PTR)ImageBase
                            + NTHeaders->OptionalHeader.AddressOfEntryPoint);
      }
-   DPRINT("LdrPEStartup() = %x\n",EntryPoint);
+   DPRINT("LdrPEStartup() = %p\n",EntryPoint);
    return EntryPoint;
 }
 
@@ -2054,7 +2032,7 @@ LdrpLoadModule(IN PWSTR SearchPath OPTIONAL,
                                     PAGE_READONLY);
         if (!NT_SUCCESS(Status))
           {
-            DPRINT1("map view of section failed (Status %x)\n", Status);
+            DPRINT1("map view of section failed (Status 0x%08lx)\n", Status);
             RtlFreeUnicodeString(&FullDosName);
             NtClose(SectionHandle);
             return(Status);
@@ -2091,7 +2069,7 @@ LdrpLoadModule(IN PWSTR SearchPath OPTIONAL,
          * relocation. */
         if (ImageBase != (PVOID) NtHeaders->OptionalHeader.ImageBase)
           {
-            DPRINT1("Relocating (%x -> %x) %wZ\n",
+            DPRINT1("Relocating (%lx -> %p) %wZ\n",
               NtHeaders->OptionalHeader.ImageBase, ImageBase, &FullDosName);
             Status = LdrPerformRelocations(NtHeaders, ImageBase);
             if (!NT_SUCCESS(Status))
@@ -2142,7 +2120,7 @@ LdrpUnloadModule(PLDR_DATA_TABLE_ENTRY Module,
    PLDR_DATA_TABLE_ENTRY ImportedModule;
    NTSTATUS Status;
    LONG LoadCount;
-
+   ULONG Size;
 
    if (Unload)
      {
@@ -2163,7 +2141,7 @@ LdrpUnloadModule(PLDR_DATA_TABLE_ENTRY Module,
                                  RtlImageDirectoryEntryToData(Module->DllBase,
                                                               TRUE,
                                                               IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT,
-                                                              NULL);
+                                                              &Size);
        if (BoundImportDescriptor)
         {
           /* dereferencing all imported modules, use the bound import descriptor */
@@ -2197,7 +2175,7 @@ LdrpUnloadModule(PLDR_DATA_TABLE_ENTRY Module,
                                       RtlImageDirectoryEntryToData(Module->DllBase,
                                                                    TRUE,
                                                                    IMAGE_DIRECTORY_ENTRY_IMPORT,
-                                                                   NULL);
+                                                                   &Size);
            if (ImportModuleDirectory)
              {
                /* dereferencing all imported modules, use the import descriptor */
@@ -2239,7 +2217,7 @@ LdrpUnloadModule(PLDR_DATA_TABLE_ENTRY Module,
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 LdrUnloadDll (IN PVOID BaseAddress)
 {
    PLDR_DATA_TABLE_ENTRY Module;
@@ -2268,7 +2246,7 @@ LdrUnloadDll (IN PVOID BaseAddress)
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 LdrDisableThreadCalloutsForDll(IN PVOID BaseAddress)
 {
     PLIST_ENTRY ModuleListHead;
@@ -2276,7 +2254,7 @@ LdrDisableThreadCalloutsForDll(IN PVOID BaseAddress)
     PLDR_DATA_TABLE_ENTRY Module;
     NTSTATUS Status;
 
-    DPRINT("LdrDisableThreadCalloutsForDll (BaseAddress %x)\n", BaseAddress);
+    DPRINT("LdrDisableThreadCalloutsForDll (BaseAddress %p)\n", BaseAddress);
 
     Status = STATUS_DLL_NOT_FOUND;
     RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
@@ -2286,7 +2264,7 @@ LdrDisableThreadCalloutsForDll(IN PVOID BaseAddress)
       {
         Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InLoadOrderModuleList);
 
-        DPRINT("BaseDllName %wZ BaseAddress %x\n", &Module->BaseDllName, Module->DllBase);
+        DPRINT("BaseDllName %wZ BaseAddress %p\n", &Module->BaseDllName, Module->DllBase);
 
         if (Module->DllBase == BaseAddress)
           {
@@ -2306,34 +2284,35 @@ LdrDisableThreadCalloutsForDll(IN PVOID BaseAddress)
 /*
  * @implemented
  */
-NTSTATUS STDCALL
-LdrGetDllHandle(IN PWCHAR Path OPTIONAL,
-                IN ULONG Unknown2,
+NTSTATUS NTAPI
+LdrGetDllHandle(IN PWSTR DllPath OPTIONAL,
+                IN PULONG DllCharacteristics,
                 IN PUNICODE_STRING DllName,
-                OUT PVOID* BaseAddress)
+                OUT PVOID *DllHandle)
 {
     PLDR_DATA_TABLE_ENTRY Module;
     NTSTATUS Status;
 
-    TRACE_LDR("LdrGetDllHandle, searching for %wZ from %S\n", DllName, Path ? Path : L"");
+    TRACE_LDR("LdrGetDllHandle, searching for %wZ from %S\n",
+               DllName, DllPath ? DllPath : L"");
 
     /* NULL is the current executable */
     if (DllName == NULL)
       {
-        *BaseAddress = ExeModule->DllBase;
-        DPRINT("BaseAddress %x\n", *BaseAddress);
+        *DllHandle = ExeModule->DllBase;
+        DPRINT("BaseAddress 0x%lx\n", *DllHandle);
         return STATUS_SUCCESS;
       }
 
     Status = LdrFindEntryForName(DllName, &Module, FALSE);
     if (NT_SUCCESS(Status))
       {
-        *BaseAddress = Module->DllBase;
+        *DllHandle = Module->DllBase;
         return STATUS_SUCCESS;
       }
 
     DPRINT("Failed to find dll %wZ\n", DllName);
-    *BaseAddress = NULL;
+    *DllHandle = NULL;
     return STATUS_DLL_NOT_FOUND;
 }
 
@@ -2341,7 +2320,7 @@ LdrGetDllHandle(IN PWCHAR Path OPTIONAL,
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 LdrGetProcedureAddress (IN PVOID BaseAddress,
                         IN PANSI_STRING Name,
                         IN ULONG Ordinal,
@@ -2356,7 +2335,7 @@ LdrGetProcedureAddress (IN PVOID BaseAddress,
        TRACE_LDR("LdrGetProcedureAddress by ORDINAL - %d\n", Ordinal);
      }
 
-   DPRINT("LdrGetProcedureAddress (BaseAddress %x Name %Z Ordinal %lu ProcedureAddress %x)\n",
+   DPRINT("LdrGetProcedureAddress (BaseAddress %p Name %Z Ordinal %lu ProcedureAddress %p)\n",
           BaseAddress, Name, Ordinal, ProcedureAddress);
 
    if (Name && Name->Length)
@@ -2378,7 +2357,7 @@ LdrGetProcedureAddress (IN PVOID BaseAddress,
          {
            return STATUS_SUCCESS;
          }
-       DPRINT("LdrGetProcedureAddress: Can't resolve symbol @%d\n", Ordinal);
+       DPRINT("LdrGetProcedureAddress: Can't resolve symbol @%lu\n", Ordinal);
      }
    return STATUS_PROCEDURE_NOT_FOUND;
 }
@@ -2419,7 +2398,7 @@ LdrpDetachProcess(BOOLEAN UnloadAll)
    while (Entry != ModuleListHead)
      {
        Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderModuleList);
-       if (((UnloadAll && Module->LoadCount <= 0) || Module->LoadCount == 0) &&
+       if (((UnloadAll && Module->LoadCount == 0xFFFF) || Module->LoadCount == 0) &&
            Module->Flags & LDRP_ENTRY_PROCESSED &&
            !(Module->Flags & LDRP_UNLOAD_IN_PROGRESS))
          {
@@ -2544,7 +2523,7 @@ LdrpAttachProcess(VOID)
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 LdrShutdownProcess (VOID)
 {
   LdrpDetachProcess(TRUE);
@@ -2605,7 +2584,7 @@ LdrpAttachThread (VOID)
 /*
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 LdrShutdownThread (VOID)
 {
    PLIST_ENTRY ModuleListHead;
@@ -2663,15 +2642,15 @@ LdrShutdownThread (VOID)
  *
  * @implemented
  */
-NTSTATUS STDCALL
-LdrQueryProcessModuleInformation(IN PMODULE_INFORMATION ModuleInformation OPTIONAL,
+NTSTATUS NTAPI
+LdrQueryProcessModuleInformation(IN PRTL_PROCESS_MODULES ModuleInformation OPTIONAL,
                                  IN ULONG Size OPTIONAL,
                                  OUT PULONG ReturnedSize)
 {
   PLIST_ENTRY ModuleListHead;
   PLIST_ENTRY Entry;
   PLDR_DATA_TABLE_ENTRY Module;
-  PDEBUG_MODULE_INFORMATION ModulePtr = NULL;
+  PRTL_PROCESS_MODULE_INFORMATION ModulePtr = NULL;
   NTSTATUS Status = STATUS_SUCCESS;
   ULONG UsedSize = sizeof(ULONG);
   ANSI_STRING AnsiString;
@@ -2731,7 +2710,7 @@ LdrQueryProcessModuleInformation(IN PMODULE_INFORMATION ModuleInformation OPTION
           ModulePtr++;
           ModuleInformation->ModuleCount++;
         }
-      UsedSize += sizeof(DEBUG_MODULE_INFORMATION);
+      UsedSize += sizeof(RTL_PROCESS_MODULE_INFORMATION);
 
       Entry = Entry->Flink;
     }
@@ -2860,7 +2839,7 @@ LdrpGetResidentSize(PIMAGE_NT_HEADERS NTHeaders)
  *
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 LdrVerifyImageMatchesChecksum (IN HANDLE FileHandle,
                                ULONG Unknown1,
                                ULONG Unknown2,
@@ -2954,7 +2933,7 @@ LdrVerifyImageMatchesChecksum (IN HANDLE FileHandle,
  *
  * @implemented
  */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
 LdrQueryImageFileExecutionOptions (IN PUNICODE_STRING SubKey,
                                    IN PCWSTR ValueName,
                                    IN ULONG Type,
@@ -3007,6 +2986,11 @@ LdrQueryImageFileExecutionOptions (IN PUNICODE_STRING SubKey,
   KeyInfo = RtlAllocateHeap (RtlGetProcessHeap(),
                              HEAP_ZERO_MEMORY,
                              KeyInfoSize);
+  if (KeyInfo == NULL)
+    {
+      NtClose (KeyHandle);
+      return STATUS_INSUFFICIENT_RESOURCES;
+    }
 
   RtlInitUnicodeString (&ValueNameString,
                         (PWSTR)ValueName);
@@ -3028,7 +3012,7 @@ LdrQueryImageFileExecutionOptions (IN PUNICODE_STRING SubKey,
       if (KeyInfo == NULL)
         {
           NtClose (KeyHandle);
-          return Status;
+          return STATUS_INSUFFICIENT_RESOURCES;
         }
 
       Status = NtQueryValueKey (KeyHandle,
@@ -3085,7 +3069,7 @@ LdrQueryImageFileExecutionOptions (IN PUNICODE_STRING SubKey,
 }
 
 
-PIMAGE_BASE_RELOCATION STDCALL
+PIMAGE_BASE_RELOCATION NTAPI
 LdrProcessRelocationBlock(IN PVOID Address,
                          IN USHORT Count,
                          IN PUSHORT TypeOffset,