+User acceptable message on incompatible W32 binary modules.
[reactos.git] / ntoskrnl / ldr / loader.c
index 960db41..90a6200 100644 (file)
@@ -18,6 +18,7 @@
  *   JF   26/01/2000 Recoded some parts to retrieve export details correctly
  *   DW   27/06/2000 Removed redundant header files
  *   CSH  11/04/2001 Added automatic loading of module symbols if they exist
+ *   KJK  02/04/2003 Nebbet-ized a couple of type names
  */
 
 
 #define NDEBUG
 #include <internal/debug.h>
 
+#ifdef LIBCAPTIVE
+#include <glib/gmessages.h>
+#endif /* LIBCAPTIVE */
+
 /* GLOBALS *******************************************************************/
 
 LIST_ENTRY ModuleListHead;
@@ -544,10 +549,13 @@ LdrInitializeBootStartDriver(PVOID ModuleLoadBase,
     Length = wcslen(Start);
 
   wcsncpy(Buffer, Start, Length);
+  Buffer[Length] = 0;
   RtlCreateUnicodeString(&DeviceNode->ServiceName, Buffer);
 
   Status = IopInitializeDriver(ModuleObject->EntryPoint,
-                              DeviceNode, FALSE);
+                              DeviceNode, FALSE,
+                              ModuleObject->Base,
+                              ModuleObject->Length);
   if (!NT_SUCCESS(Status))
     {
       IopFreeDeviceNode(DeviceNode);
@@ -621,7 +629,7 @@ LdrpQueryModuleInformation(PVOID Buffer,
     }
 
   *ReqSize = sizeof(SYSTEM_MODULE_INFORMATION)+
-    (ModuleCount - 1) * sizeof(SYSTEM_MODULE_ENTRY);
+    (ModuleCount - 1) * sizeof(SYSTEM_MODULE_INFORMATION_ENTRY);
 
   if (Size < *ReqSize)
     {
@@ -641,15 +649,18 @@ LdrpQueryModuleInformation(PVOID Buffer,
     {
       current = CONTAINING_RECORD(current_entry,MODULE_OBJECT,ListEntry);
 
+      Smi->Module[ModuleCount].Unknown1 = 0;           /* Always 0 */
       Smi->Module[ModuleCount].Unknown2 = 0;           /* Always 0 */
-      Smi->Module[ModuleCount].BaseAddress = current->Base;
+      Smi->Module[ModuleCount].Base = current->Base;
       Smi->Module[ModuleCount].Size = current->Length;
       Smi->Module[ModuleCount].Flags = 0;              /* Flags ??? (GN) */
-      Smi->Module[ModuleCount].EntryIndex = ModuleCount;
+      Smi->Module[ModuleCount].Index = ModuleCount;
+      Smi->Module[ModuleCount].NameLength = 0;
+      Smi->Module[ModuleCount].LoadCount = 0; /* FIXME */
 
       AnsiName.Length = 0;
       AnsiName.MaximumLength = 256;
-      AnsiName.Buffer = Smi->Module[ModuleCount].Name;
+      AnsiName.Buffer = Smi->Module[ModuleCount].ImageName;
       RtlUnicodeStringToAnsiString(&AnsiName,
                                   &current->FullName,
                                   FALSE);
@@ -658,13 +669,11 @@ LdrpQueryModuleInformation(PVOID Buffer,
       if (p == NULL)
        {
          Smi->Module[ModuleCount].PathLength = 0;
-         Smi->Module[ModuleCount].NameLength = strlen(AnsiName.Buffer);
        }
       else
        {
          p++;
          Smi->Module[ModuleCount].PathLength = p - AnsiName.Buffer;
-         Smi->Module[ModuleCount].NameLength = strlen(p);
        }
 
       ModuleCount++;
@@ -1084,15 +1093,22 @@ LdrPEProcessModule(PVOID ModuleLoadBase,
           LibraryModuleObject = LdrGetModuleObject(&ModuleName);
           if (LibraryModuleObject == NULL)
             {
-              CPRINT("Module '%wZ' not loaded yet\n", &ModuleName);
+              DPRINT("Module '%wZ' not loaded yet\n", &ModuleName);
               wcscpy(NameBuffer, REACTOS_UCS2(L"\\SystemRoot\\system32\\drivers\\"));
               wcscat(NameBuffer, ModuleName.Buffer);
               RtlInitUnicodeString(&NameString, NameBuffer);
               Status = LdrLoadModule(&NameString, &LibraryModuleObject);
               if (!NT_SUCCESS(Status))
                 {
-                  CPRINT("Unknown import module: %wZ (Status %lx)\n", &ModuleName, Status);
-                  return(Status);
+                  wcscpy(NameBuffer, REACTOS_UCS2(L"\\SystemRoot\\system32\\"));
+                  wcscat(NameBuffer, ModuleName.Buffer);
+                  RtlInitUnicodeString(&NameString, NameBuffer);
+                  Status = LdrLoadModule(&NameString, &LibraryModuleObject);
+                  if (!NT_SUCCESS(Status))
+                    {
+                      DPRINT1("Unknown import module: %wZ (Status %lx)\n", &ModuleName, Status);
+                      return(Status);
+                    }
                 }
             }
           /*  Get the import address list  */
@@ -1402,7 +1418,7 @@ LdrSafePEProcessModule(PVOID ModuleLoadBase,
         {
          ULONG Offset;
          ULONG Type;
-         PDWORD RelocItem;
+         PULONG RelocItem;
 
          Offset = RelocEntry[Idx].TypeOffset & 0xfff;
          Type = (RelocEntry[Idx].TypeOffset >> 12) & 0xf;
@@ -1570,10 +1586,14 @@ LdrPEGetExportAddress(PMODULE_OBJECT ModuleObject,
 
   if (ExportAddress == NULL)
     {
-      CPRINT("Export not found for %d:%s\n",
+      DbgPrint("Export not found for %d:%s\n",
             Hint,
             Name != NULL ? Name : "(Ordinal)");
-      KeBugCheck(0);
+#ifdef LIBCAPTIVE
+      g_error("Please check the versions of \"ntfs.sys\" and \"ntoskrnl.exe\" - do they match each other?\n"
+              "Because export not found for: %d:%s",Hint,(Name ? Name : "(Ordinal)"));
+#endif /* LIBCAPTIVE */
+      KEBUGCHECK(0);
     }
 
   return(ExportAddress);
@@ -1636,7 +1656,7 @@ LdrSafePEGetExportAddress(PVOID ImportModuleBase,
       ps("Export not found for %d:%s\n",
         Hint,
         Name != NULL ? Name : "(Ordinal)");
-      KeBugCheck(0);
+      KEBUGCHECK(0);
     }
   return ExportAddress;
 }