- Initialize the symbols for boot load driver before the driver entry routine is called.
- Store the symbols for boot load driver within the non paged pool.
Modified: trunk/reactos/ntoskrnl/dbg/kdb_symbols.c
Modified: trunk/reactos/ntoskrnl/include/internal/kd.h
Modified: trunk/reactos/ntoskrnl/io/driver.c

Modified: trunk/reactos/ntoskrnl/dbg/kdb_symbols.c
--- trunk/reactos/ntoskrnl/dbg/kdb_symbols.c	2005-01-05 19:04:25 UTC (rev 12829)
+++ trunk/reactos/ntoskrnl/dbg/kdb_symbols.c	2005-01-05 19:06:05 UTC (rev 12830)
@@ -548,6 +548,7 @@
       DPRINT("Current->FileName %wZ FileName %wZ\n", &Current->FileName, FileName);
       if (RtlEqualUnicodeString(&Current->FileName, FileName, TRUE))
         {
+          Current->RefCount++;
           KeReleaseSpinLock(&SymbolFileListLock, Irql);
           DPRINT("Found cached file!\n");
           return Current;
@@ -690,7 +691,6 @@
   if (CachedSymbolFile != NULL)
     {
       DPRINT("Found cached symbol file %wZ\n", &SymFileName);
-      CachedSymbolFile->RefCount++;
       SymbolInfo->FileBuffer = CachedSymbolFile->FileBuffer;
       SymbolInfo->SymbolsBase = CachedSymbolFile->SymbolsBase;
       SymbolInfo->SymbolsLength = CachedSymbolFile->SymbolsLength;
@@ -897,76 +897,84 @@
  * module.
  * Used to load ntoskrnl and hal symbols before the SystemRoot is available to us.
  *
- * \param ModuleLoadBase  Base address of the loaded symbol file.
- * \param FileName        Filename of the symbol file.
- * \param Length          Length of the loaded symbol file/module.
+ * \param FileName        Filename for which the symbols are loaded.
  */
 VOID
-KdbSymProcessSymbolFile(IN PVOID ModuleLoadBase,
-                        IN PCHAR FileName,
-                        IN ULONG Length)
+KdbSymProcessBootSymbols(IN PCHAR FileName)
 {
   PMODULE_OBJECT ModuleObject;
-  UNICODE_STRING ModuleName;
-  CHAR TmpBaseName[MAX_PATH];
-  CHAR TmpFileName[MAX_PATH];
+  UNICODE_STRING UnicodeString;
+  PLOADER_MODULE KeLoaderModules = (PLOADER_MODULE)KeLoaderBlock.ModsAddr;
+  CHAR SymbolName[MAX_PATH];
   PSYMBOLFILE_HEADER SymbolFileHeader;
   PIMAGE_SYMBOL_INFO SymbolInfo;
   ANSI_STRING AnsiString;
   PCHAR Extension;
   ULONG i;
-  const char *KnownExtension[] = {".exe", ".sys", ".dll"};
 
-  DPRINT("Module %s is a symbol file\n", FileName);
+  DPRINT("KdbSymProcessBootSymbols(%s)\n", FileName);
 
-  strncpy(TmpBaseName, FileName, MAX_PATH-1);
-  TmpBaseName[MAX_PATH-1] = '\0';
-  /* remove the extension '.sym' */
-  Extension = strrchr(TmpBaseName, '.');
-  if (Extension && 0 == _stricmp(Extension, ".sym"))
-    {
-      *Extension = 0;
-    }
+  RtlInitAnsiString(&AnsiString, FileName);
+  RtlAnsiStringToUnicodeString(&UnicodeString, &AnsiString, TRUE);
+  ModuleObject = LdrGetModuleObject(&UnicodeString);
+  RtlFreeUnicodeString(&UnicodeString);
 
-  DPRINT("base: %s (Length %d)\n", TmpBaseName, Length);
-
-  for (i = 0; i < sizeof(KnownExtension) / sizeof(*KnownExtension); i++)
-    {
-      strcpy(TmpFileName, TmpBaseName);
-      strcat(TmpFileName, KnownExtension[i]);
-      RtlInitAnsiString(&AnsiString, TmpFileName);
-
-      RtlAnsiStringToUnicodeString(&ModuleName, &AnsiString, TRUE);
-      ModuleObject = LdrGetModuleObject(&ModuleName);
-      RtlFreeUnicodeString(&ModuleName);
-      if (ModuleObject)
-        {
-	  break;
+  if (ModuleObject != NULL)
+  {
+     strcpy(SymbolName, FileName);
+     Extension = strrchr(SymbolName, '.');
+     if (Extension == NULL)
+     {
+        Extension = SymbolName + strlen(SymbolName);
+     }
+     strcpy(Extension, ".sym");
+     for (i = 0; i < KeLoaderBlock.ModsCount; i++)
+     {
+        if (KeLoaderModules[i].Reserved == 0 && !_stricmp(SymbolName, (PCHAR)KeLoaderModules[i].String))
+	{
+	   break;
 	}
-    }
-  
-  if (ModuleObject != NULL)
-    {
-      SymbolInfo = (PIMAGE_SYMBOL_INFO) &ModuleObject->TextSection->SymbolInfo;
-      if (SymbolInfo->FileBuffer != NULL)
+     }
+     if (i < KeLoaderBlock.ModsCount)
+     {
+        KeLoaderModules[i].Reserved = 1;
+        SymbolInfo = (PIMAGE_SYMBOL_INFO) &ModuleObject->TextSection->SymbolInfo;
+        if (SymbolInfo->FileBuffer != NULL)
         {
-          KdbpSymRemoveCachedFile(SymbolInfo);
+           KdbpSymRemoveCachedFile(SymbolInfo);
         }
 
-      SymbolFileHeader = (PSYMBOLFILE_HEADER) ModuleLoadBase;
-      SymbolInfo->FileBuffer = ModuleLoadBase;
-      SymbolInfo->SymbolsBase = ModuleLoadBase + SymbolFileHeader->StabsOffset;
-      SymbolInfo->SymbolsLength = SymbolFileHeader->StabsLength;
-      SymbolInfo->SymbolStringsBase = ModuleLoadBase + SymbolFileHeader->StabstrOffset;
-      SymbolInfo->SymbolStringsLength = SymbolFileHeader->StabstrLength;
-      DPRINT("Installed stabs: %s@%08x-%08x (%08x-%08x,%08x)\n",
+	SymbolFileHeader = ExAllocatePool(NonPagedPool, KeLoaderModules[i].ModEnd - KeLoaderModules[i].ModStart);
+        if (SymbolFileHeader == NULL)
+        {
+           DPRINT("Could not allocate memory for symbol file\n");
+           return;
+        }
+	memcpy(SymbolFileHeader, 
+	       (PVOID)KeLoaderModules[i].ModStart, 
+	       KeLoaderModules[i].ModEnd - KeLoaderModules[i].ModStart);
+ 
+        SymbolInfo->FileBuffer = SymbolFileHeader;
+        SymbolInfo->SymbolsBase = (PVOID)SymbolFileHeader + SymbolFileHeader->StabsOffset;
+        SymbolInfo->SymbolsLength = SymbolFileHeader->StabsLength;
+        SymbolInfo->SymbolStringsBase = (PVOID)SymbolFileHeader + SymbolFileHeader->StabstrOffset;
+        SymbolInfo->SymbolStringsLength = SymbolFileHeader->StabstrLength;
+
+        /* add file to cache */
+        RtlInitAnsiString(&AnsiString, SymbolName);
+	RtlAnsiStringToUnicodeString(&UnicodeString, &AnsiString, TRUE);
+        KdbpSymAddCachedFile(&UnicodeString, SymbolInfo);
+        RtlFreeUnicodeString(&UnicodeString);
+
+        DPRINT("Installed stabs: %s@%08x-%08x (%08x-%08x,%08x)\n",
 	       FileName,
 	       ModuleObject->Base,
 	       ModuleObject->Length + ModuleObject->Base,
 	       SymbolInfo->SymbolsBase,
 	       SymbolInfo->SymbolsLength + SymbolInfo->SymbolsBase,
 	       SymbolInfo->SymbolStringsBase);
-    }
+     }
+  }
 }
 
 /*! \brief Initializes the KDB symbols implementation.

Modified: trunk/reactos/ntoskrnl/include/internal/kd.h
--- trunk/reactos/ntoskrnl/include/internal/kd.h	2005-01-05 19:04:25 UTC (rev 12829)
+++ trunk/reactos/ntoskrnl/include/internal/kd.h	2005-01-05 19:06:05 UTC (rev 12830)
@@ -1,4 +1,4 @@
-/* $Id: kd.h,v 1.29 2004/12/09 14:20:06 royce Exp $
+/* $Id$
  *
  * kernel debugger prototypes
  */
@@ -109,21 +109,20 @@
 VOID KdPrintMda(PCH pch);
 
 #if !defined(KDBG) && !defined(DBG)
-# define KDB_LOADUSERMODULE_HOOK(LDRMOD) do { } while (0)
-# define KDB_DELETEPROCESS_HOOK(PROCESS) do { } while (0)
-# define KDB_LOADDRIVER_HOOK(FILENAME, MODULE) do { } while (0)
-# define KDB_UNLOADDRIVER_HOOK(MODULE) do { } while (0)
-# define KDB_LOADERINIT_HOOK(NTOS, HAL) do { } while (0)
-# define KDB_SYMBOLFILE_HOOK(LOADBASE, FILENAME, LENGTH) do { } while (0)
-# define KDB_CREATE_THREAD_HOOK(CONTEXT) do { } while (0)
+# define KDB_LOADUSERMODULE_HOOK(LDRMOD)	do { } while (0)
+# define KDB_DELETEPROCESS_HOOK(PROCESS)	do { } while (0)
+# define KDB_LOADDRIVER_HOOK(FILENAME, MODULE)	do { } while (0)
+# define KDB_UNLOADDRIVER_HOOK(MODULE)		do { } while (0)
+# define KDB_LOADERINIT_HOOK(NTOS, HAL)		do { } while (0)
+# define KDB_SYMBOLFILE_HOOK(FILENAME)		do { } while (0)
+# define KDB_CREATE_THREAD_HOOK(CONTEXT)	do { } while (0)
 #else
-# define KDB_LOADUSERMODULE_HOOK(LDRMOD) KdbSymLoadUserModuleSymbols(LDRMOD)
-# define KDB_DELETEPROCESS_HOOK(PROCESS) KdbSymFreeProcessSymbols(PROCESS)
-# define KDB_LOADDRIVER_HOOK(FILENAME, MODULE) KdbSymLoadDriverSymbols(FILENAME, MODULE)
-# define KDB_UNLOADDRIVER_HOOK(MODULE) KdbSymUnloadDriverSymbols(MODULE)
-# define KDB_LOADERINIT_HOOK(NTOS, HAL) KdbSymInit(NTOS, HAL)
-# define KDB_SYMBOLFILE_HOOK(LOADBASE, FILENAME, LENGTH) \
-        KdbSymProcessSymbolFile(LOADBASE, FILENAME, LENGTH)
+# define KDB_LOADUSERMODULE_HOOK(LDRMOD)	KdbSymLoadUserModuleSymbols(LDRMOD)
+# define KDB_DELETEPROCESS_HOOK(PROCESS)	KdbSymFreeProcessSymbols(PROCESS)
+# define KDB_LOADDRIVER_HOOK(FILENAME, MODULE)	KdbSymLoadDriverSymbols(FILENAME, MODULE)
+# define KDB_UNLOADDRIVER_HOOK(MODULE)		KdbSymUnloadDriverSymbols(MODULE)
+# define KDB_LOADERINIT_HOOK(NTOS, HAL)		KdbSymInit(NTOS, HAL)
+# define KDB_SYMBOLFILE_HOOK(FILENAME)		KdbSymProcessBootSymbols(FILENAME)
 /*#define KDB_CREATE_THREAD_HOOK(CONTEXT) \
         KdbCreateThreadHook(CONTEXT)
 */
@@ -141,9 +140,7 @@
 KdbSymUnloadDriverSymbols(IN PMODULE_OBJECT ModuleObject);
 
 VOID
-KdbSymProcessSymbolFile(IN PVOID ModuleLoadBase,
-                        IN PCHAR FileName,
-                        IN ULONG Length);
+KdbSymProcessBootSymbols(IN PCHAR FileName);
 
 VOID
 KdbSymInit(IN PMODULE_TEXT_SECTION NtoskrnlTextSection,

Modified: trunk/reactos/ntoskrnl/io/driver.c
--- trunk/reactos/ntoskrnl/io/driver.c	2005-01-05 19:04:25 UTC (rev 12829)
+++ trunk/reactos/ntoskrnl/io/driver.c	2005-01-05 19:06:05 UTC (rev 12830)
@@ -448,6 +448,8 @@
                   &ServiceImagePath,
                   ModuleObject);
 
+	       KDB_SYMBOLFILE_HOOK(SearchName);
+
                break;
             }
          }
@@ -1135,6 +1137,9 @@
       return Status;
    }
 
+   /* Load symbols */
+   KDB_SYMBOLFILE_HOOK(FileName);
+
    /*
     * Strip the file extension from ServiceName
     */
@@ -1205,13 +1210,11 @@
       if (Extension == NULL)
          Extension = "";
 
-      if (!_stricmp(Extension, ".sym"))
+      if (!_stricmp(Extension, ".exe") || !_stricmp(Extension, ".dll"))
       {
-         /* Pass symbol files to kernel debugger */
-         KDB_SYMBOLFILE_HOOK((PVOID)ModuleStart, ModuleName, ModuleSize);
-      }
-      else if (!_stricmp(Extension, ".exe") || !_stricmp(Extension, ".dll"))
-      {
+        /* Process symbols for *.exe and *.dll */
+        KDB_SYMBOLFILE_HOOK(ModuleName);
+
         /* Log *.exe and *.dll files */
         RtlCreateUnicodeStringFromAsciiz(&DriverName, ModuleName);
         IopBootLog(&DriverName, TRUE);
@@ -1232,20 +1235,16 @@
          }
          BootDriverCount++;
       }
+   }
 
-      /*
-       * Free memory for all boot files, except ntoskrnl.exe
-       * and symbol files, if the kernel debugger is active
-       */
-      if (i != 0 /* ntoskrnl.exe is always the first module */
-#if defined(DBG) || defined(KDBG)
-          && _stricmp(Extension, ".sym")
-#endif
-         )
-      {
-         MiFreeBootDriverMemory((PVOID)KeLoaderModules[i].ModStart,
-            KeLoaderModules[i].ModEnd - KeLoaderModules[i].ModStart);
-      }
+   /*
+    * Free memory for all boot files, except ntoskrnl.exe.
+    */
+   for (i = 1; i < KeLoaderBlock.ModsCount; i++)
+   {
+
+       MiFreeBootDriverMemory((PVOID)KeLoaderModules[i].ModStart,
+                              KeLoaderModules[i].ModEnd - KeLoaderModules[i].ModStart);
    }
 
    if (BootDriverCount == 0)