Added check for loaded module prior to loading it.
authorEric Kohl <eric.kohl@reactos.org>
Thu, 27 Jun 2002 17:52:32 +0000 (17:52 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Thu, 27 Jun 2002 17:52:32 +0000 (17:52 +0000)
svn path=/trunk/; revision=3157

reactos/ntoskrnl/io/driver.c
reactos/ntoskrnl/ldr/loader.c

index 49c9df5..3417ee8 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: driver.c,v 1.7 2002/06/18 07:11:44 ekohl Exp $
+/* $Id: driver.c,v 1.8 2002/06/27 17:49:34 ekohl Exp $
  *
  * COPYRIGHT:      See COPYING in the top level directory
  * PROJECT:        ReactOS kernel
@@ -198,6 +198,12 @@ NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
       return(Status);
     }
 
+  ModuleObject = LdrGetModuleObject(DriverServiceName);
+  if (ModuleObject != NULL)
+    {
+      return(STATUS_IMAGE_ALREADY_LOADED);
+    }
+
   Status = LdrLoadModule(&FullImagePath, &ModuleObject);
   if (!NT_SUCCESS(Status))
     {
index be2c81d..8bd8556 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: loader.c,v 1.113 2002/06/16 11:44:34 ekohl Exp $
+/* $Id: loader.c,v 1.114 2002/06/27 17:52:32 ekohl Exp $
  * 
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -736,10 +736,14 @@ LdrpLoadImage(PUNICODE_STRING DriverName,
   PMODULE_OBJECT ModuleObject;
   NTSTATUS Status;
 
-  Status = LdrLoadModule(DriverName, &ModuleObject);
-  if (!NT_SUCCESS(Status))
+  ModuleObject = LdrGetModuleObject(DriverName);
+  if (ModuleObject == NULL)
     {
-      return(Status);
+      Status = LdrLoadModule(DriverName, &ModuleObject);
+      if (!NT_SUCCESS(Status))
+       {
+         return(Status);
+       }
     }
 
   if (ModuleBase)
@@ -772,6 +776,12 @@ LdrpLoadAndCallImage(PUNICODE_STRING ModuleName)
   PMODULE_OBJECT ModuleObject;
   NTSTATUS Status;
 
+  ModuleObject = LdrGetModuleObject(ModuleName);
+  if (ModuleObject != NULL)
+    {
+      return(STATUS_IMAGE_ALREADY_LOADED);
+    }
+
   Status = LdrLoadModule(ModuleName, &ModuleObject);
   if (!NT_SUCCESS(Status))
     {
@@ -804,14 +814,6 @@ LdrLoadModule(PUNICODE_STRING Filename,
 
   *ModuleObject = NULL;
 
-  /*  Check for module already loaded  */
-  Module = LdrGetModuleObject(Filename);
-  if (Module != NULL)
-    {
-      *ModuleObject = Module;
-      return(STATUS_SUCCESS);
-    }
-
   DPRINT("Loading Module %wZ...\n", Filename);
 
   /*  Open the Module  */
@@ -1329,7 +1331,7 @@ LdrGetModuleObject(PUNICODE_STRING ModuleName)
 
   KeReleaseSpinLock(&ModuleListLock, Irql);
 
-  CPRINT("LdrpGetModuleObject: Failed to find module %wZ\n", ModuleName);
+  DPRINT("Could not find module '%wZ'\n", ModuleName);
 
   return(NULL);
 }
@@ -1558,7 +1560,7 @@ LdrPEProcessModule(PVOID ModuleLoadBase,
           LibraryModuleObject = LdrGetModuleObject(&ModuleName);
           if (LibraryModuleObject == NULL)
             {
-              DPRINT("Module '%wZ' not loaded\n", &ModuleName);
+              CPRINT("Module '%wZ' not loaded yet\n", &ModuleName);
               wcscpy(NameBuffer, L"\\SystemRoot\\system32\\drivers\\");
               wcscat(NameBuffer, ModuleName.Buffer);
               RtlInitUnicodeString(&NameString, NameBuffer);
@@ -1997,7 +1999,7 @@ LdrPEGetExportAddress(PMODULE_OBJECT ModuleObject,
         FunctionList[Hint - ExportDir->Base]);
     }
 
-  if (ExportAddress == 0)
+  if (ExportAddress == NULL)
     {
       CPRINT("Export not found for %d:%s\n",
             Hint,