[ros-diffs] [arty] 27444: Resolve imports at boot time by loading the appropriate modules. We still need to fix the same stuff in ntoskrnl for pnp loading. Thanks to hpoussin for fixing pnp so this works.

arty at svn.reactos.org arty at svn.reactos.org
Sat Jul 7 06:43:08 CEST 2007


Author: arty
Date: Sat Jul  7 08:43:08 2007
New Revision: 27444

URL: http://svn.reactos.org/svn/reactos?rev=27444&view=rev
Log:
Resolve imports at boot time by loading the appropriate modules.  We still need
to fix the same stuff in ntoskrnl for pnp loading.
Thanks to hpoussin for fixing pnp so this works.

Modified:
    trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c
    trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c
    trunk/reactos/boot/freeldr/freeldr/reactos/setupldr.c

Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c?rev=27444&r1=27443&r2=27444&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c Sat Jul  7 08:43:08 2007
@@ -454,6 +454,8 @@
     return STATUS_SUCCESS;
 }
 
+extern BOOLEAN FrLdrLoadDriver(PCHAR szFileName, INT nPos);
+
 NTSTATUS
 NTAPI
 LdrPEGetOrLoadModule(IN PCHAR ModuleName,
@@ -465,31 +467,15 @@
     *ImportedModule = LdrGetModuleObject(ImportedName);
     if (*ImportedModule == NULL)
     {
-        /*
-         * For now, we only support import-loading the HAL.
-         * Later, FrLdrLoadDriver should be made to share the same
-         * code, and we'll just call it instead.
-         */
-        if (!_stricmp(ImportedName, "hal.dll") ||
-            !_stricmp(ImportedName, "kdcom.dll") ||
-            !_stricmp(ImportedName, "bootvid.dll"))
-        {
-            /* Load the HAL */
-            FrLdrLoadImage(ImportedName, 10, FALSE);
-
-            /* Return the new module */
-            *ImportedModule = LdrGetModuleObject(ImportedName);
-            if (*ImportedModule == NULL)
-            {
-                DbgPrint("Error loading import: %s\n", ImportedName);
-                return STATUS_UNSUCCESSFUL;
-            }
-        }
-        else
-        {
-            DbgPrint("Don't yet support loading new modules from imports\n");
-            Status = STATUS_NOT_IMPLEMENTED;
-        }
+	if (!FrLdrLoadDriver(ImportedName, 0))
+	{
+	    return STATUS_UNSUCCESSFUL;
+	}
+	else
+	{
+	    return LdrPEGetOrLoadModule
+		(ModuleName, ImportedName, ImportedModule);
+	}
     }
 
     return Status;
@@ -512,7 +498,7 @@
                                      TRUE,
                                      IMAGE_DIRECTORY_ENTRY_IMPORT,
                                      &Size);
-    while (ImportModuleDirectory->Name)
+    while (ImportModuleDirectory && ImportModuleDirectory->Name)
     {
         /*  Check to make sure that import lib is kernel  */
         ImportedName = (PCHAR) DllBase + ImportModuleDirectory->Name;
@@ -651,9 +637,6 @@
     /* Increase the next Load Base */
     NextModuleBase = ROUND_UP(NextModuleBase + ImageSize, PAGE_SIZE);
 
-    /* Load HAL if this is the kernel */
-    if (ImageType == 1) FrLdrLoadImage("hal.dll", 10, FALSE);
-
     /* Perform import fixups */
     if (!NT_SUCCESS(LdrPEFixupImports(LoadBase, Name)))
     {

Modified: trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c?rev=27444&r1=27443&r2=27444&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c Sat Jul  7 08:43:08 2007
@@ -33,9 +33,92 @@
 unsigned long           reactos_disk_count = 0;
 CHAR szHalName[255];
 CHAR szBootPath[255];
+CHAR SystemRoot[255];
 static CHAR szLoadingMsg[] = "Loading ReactOS...";
 BOOLEAN FrLdrBootType;
 extern ULONG_PTR KernelBase, KernelEntry;
+
+BOOLEAN
+FrLdrLoadDriver(PCHAR szFileName,
+                INT nPos)
+{
+    PFILE FilePointer;
+    CHAR value[256], *FinalSlash;
+    LPSTR p;
+
+    if (!_stricmp(szFileName, "hal.dll"))
+    {
+        /* Use the boot.ini name instead */
+        szFileName = szHalName;
+    }
+
+    FinalSlash = strrchr(szFileName, '\\');
+    if(FinalSlash)
+	szFileName = FinalSlash + 1;
+
+    /* Open the Driver */
+    FilePointer = FsOpenFile(szFileName);
+
+    /* Try under the system root in the main dir and drivers */
+    if (FilePointer == NULL)
+    {
+	strcpy(value, SystemRoot);
+	if(value[strlen(value)-1] != '\\')
+	    strcat(value, "\\");
+	strcat(value, szFileName);
+	FilePointer = FsOpenFile(value);
+    }
+
+    if (FilePointer == NULL)
+    {
+	strcpy(value, SystemRoot);
+	if(value[strlen(value)-1] != '\\')
+	    strcat(value, "\\");
+	strcat(value, "SYSTEM32\\");
+	strcat(value, szFileName);
+	FilePointer = FsOpenFile(value);
+    }
+
+    if (FilePointer == NULL)
+    {
+	strcpy(value, SystemRoot);
+	if(value[strlen(value)-1] != '\\')
+	    strcat(value, "\\");
+	strcat(value, "SYSTEM32\\DRIVERS\\");
+	strcat(value, szFileName);
+	FilePointer = FsOpenFile(value);
+    }
+
+    /* Make sure we did */
+    if (FilePointer == NULL) {
+
+        /* Fail if file wasn't opened */
+        strcpy(value, szFileName);
+        strcat(value, " not found.");
+        return(FALSE);
+    }
+
+    /* Update the status bar with the current file */
+    strcpy(value, "Reading ");
+    p = strrchr(szFileName, '\\');
+    if (p == NULL) {
+
+        strcat(value, szFileName);
+
+    } else {
+
+        strcat(value, p + 1);
+
+    }
+    UiDrawStatusText(value);
+
+    /* Load the driver */
+    FrLdrMapImage(FilePointer, szFileName, 0);
+
+    /* Update status and return */
+    UiDrawProgressBarCenter(nPos, 100, szLoadingMsg);
+    return(TRUE);
+}
 
 PVOID
 NTAPI
@@ -47,13 +130,6 @@
     PCHAR szShortName;
     CHAR szBuffer[256], szFullPath[256];
     PVOID LoadBase;
-
-    /* Check if this the HAL being loaded */
-    if (!_stricmp(szFileName, "hal.dll"))
-    {
-        /* Use the boot.ini name instead */
-        szFileName = szHalName;
-    }
 
     /* Extract filename without path */
     szShortName = strrchr(szFileName, '\\');
@@ -618,6 +694,7 @@
 		strcat(szBootPath, "\\");
 
 	DbgPrint((DPRINT_REACTOS,"SystemRoot: '%s'\n", szBootPath));
+	strcpy(SystemRoot, szBootPath);
 
 	/*
 	 * Find the kernel image name

Modified: trunk/reactos/boot/freeldr/freeldr/reactos/setupldr.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/reactos/setupldr.c?rev=27444&r1=27443&r2=27444&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/reactos/setupldr.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/reactos/setupldr.c Sat Jul  7 08:43:08 2007
@@ -30,8 +30,10 @@
 memory_map_t			reactos_memory_map[32];		// Memory map
 char szBootPath[256];
 char szHalName[256];
+CHAR SystemRoot[255];
 extern ULONG_PTR KernelBase, KernelEntry;
 
+extern BOOLEAN FrLdrLoadDriver(PCHAR szFileName, INT nPos);
 
 #define USE_UI
 
@@ -91,65 +93,7 @@
 static BOOLEAN
 LoadDriver(PCSTR szSourcePath, PCSTR szFileName)
 {
-  CHAR szFullName[256];
-#ifdef USE_UI
-  CHAR szBuffer[80];
-#endif
-  PFILE FilePointer;
-  PCSTR szShortName;
-
-  if (szSourcePath[0] != '\\')
-    {
-      strcpy(szFullName, "\\");
-      strcat(szFullName, szSourcePath);
-    }
-  else
-    {
-      strcpy(szFullName, szSourcePath);
-    }
-
-  if (szFullName[strlen(szFullName)] != '\\')
-    {
-      strcat(szFullName, "\\");
-    }
-
-  if (szFileName[0] != '\\')
-    {
-      strcat(szFullName, szFileName);
-    }
-  else
-    {
-      strcat(szFullName, szFileName + 1);
-    }
-
-  szShortName = strrchr(szFileName, '\\');
-  if (szShortName == NULL)
-    szShortName = szFileName;
-  else
-    szShortName = szShortName + 1;
-
-
-  FilePointer = FsOpenFile(szFullName);
-  if (FilePointer == NULL)
-    {
-      printf("Could not find %s\n", szFileName);
-      return(FALSE);
-    }
-
-  /*
-   * Update the status bar with the current file
-   */
-#ifdef USE_UI
-  sprintf(szBuffer, "Setup is loading files (%s)", szShortName);
-  UiDrawStatusText(szBuffer);
-#else
-  printf("Reading %s\n", szShortName);
-#endif
-
-  /* Load the driver */
-  FrLdrMapImage(FilePointer, (LPSTR)szFileName, 2);
-
-  return(TRUE);
+    return FrLdrLoadDriver((PCHAR)szFileName, 0);
 }
 
 
@@ -342,6 +286,9 @@
   strcat(strcat(strcat(reactos_kernel_cmdline, SourcePath), " "),
          LoadOptions);
 
+  strcpy(SystemRoot, SourcePath);
+  strcat(SystemRoot, "\\");
+  
     /* Setup the boot path and kernel path */
     strcpy(szBootPath, SourcePath);
     strcpy(szKernelName, szBootPath);




More information about the Ros-diffs mailing list