use tags for pool allocations, and reformat code
Modified: trunk/reactos/ntoskrnl/ldr/loader.c

Modified: trunk/reactos/ntoskrnl/ldr/loader.c
--- trunk/reactos/ntoskrnl/ldr/loader.c	2005-04-08 11:08:26 UTC (rev 14544)
+++ trunk/reactos/ntoskrnl/ldr/loader.c	2005-04-08 12:54:37 UTC (rev 14545)
@@ -1,5 +1,5 @@
 /* $Id$
- * 
+ *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/ldr/loader.c
@@ -41,10 +41,13 @@
 STATIC MODULE_TEXT_SECTION LdrHalTextSection;
 ULONG_PTR LdrHalBase;
 
-#define TAG_DRIVER_MEM  TAG('D', 'R', 'V', 'M')
+#define TAG_DRIVER_MEM  TAG('D', 'R', 'V', 'M') /* drvm */
+#define TAG_MODULE_OBJECT TAG('k', 'l', 'm', 'o') /* klmo - kernel ldr module object */
+#define TAG_LDR_WSTR TAG('k', 'l', 'w', 's') /* klws - kernel ldr wide string */
+#define TAG_MODULE_TEXT_SECTION TAG('k', 'l', 'm', 't') /* klmt - kernel ldr module text */
 
 #ifndef HIWORD
-#define HIWORD(X)   ((WORD) (((DWORD) (X) >> 16) & 0xFFFF)) 
+#define HIWORD(X)   ((WORD) (((DWORD) (X) >> 16) & 0xFFFF))
 #endif
 #ifndef LOWORD
 #define LOWORD(X)   ((WORD) (X))
@@ -53,1554 +56,1583 @@
 /* FORWARD DECLARATIONS ******************************************************/
 
 NTSTATUS
-LdrProcessModule(PVOID ModuleLoadBase,
-		 PUNICODE_STRING ModuleName,
-		 PMODULE_OBJECT *ModuleObject);
+LdrProcessModule (
+    PVOID ModuleLoadBase,
+    PUNICODE_STRING ModuleName,
+    PMODULE_OBJECT *ModuleObject );
 
 static VOID
-LdrpBuildModuleBaseName(PUNICODE_STRING BaseName,
-			PUNICODE_STRING FullName);
+LdrpBuildModuleBaseName (
+    PUNICODE_STRING BaseName,
+    PUNICODE_STRING FullName );
 
 static LONG
-LdrpCompareModuleNames(IN PUNICODE_STRING String1,
-		       IN PUNICODE_STRING String2);
+LdrpCompareModuleNames (
+    IN PUNICODE_STRING String1,
+    IN PUNICODE_STRING String2 );
 
 
 /*  PE Driver load support  */
-static NTSTATUS LdrPEProcessModule(PVOID ModuleLoadBase,
-                                   PUNICODE_STRING FileName,
-                                   PMODULE_OBJECT *ModuleObject);
+static NTSTATUS
+LdrPEProcessModule (
+    PVOID ModuleLoadBase,
+    PUNICODE_STRING FileName,
+    PMODULE_OBJECT *ModuleObject );
+
 static PVOID
-LdrPEGetExportByName(PVOID BaseAddress,
-                     PUCHAR SymbolName,
-                     WORD Hint);
+LdrPEGetExportByName (
+    PVOID BaseAddress,
+    PUCHAR SymbolName,
+    WORD Hint );
 
 static PVOID
-LdrPEFixupForward(PCHAR ForwardName);
+LdrPEFixupForward ( PCHAR ForwardName );
 
 static NTSTATUS
-LdrPEPerformRelocations(PVOID DriverBase, 
-			ULONG DriverSize);
+LdrPEPerformRelocations (
+    PVOID DriverBase,
+    ULONG DriverSize );
 
 static NTSTATUS
-LdrPEFixupImports(PMODULE_OBJECT Module);
+LdrPEFixupImports ( PMODULE_OBJECT Module );
 
 /* FUNCTIONS *****************************************************************/
 
 VOID
-LdrInitDebug(PLOADER_MODULE Module, PWCH Name)
+LdrInitDebug ( PLOADER_MODULE Module, PWCH Name )
 {
-  PLIST_ENTRY current_entry;
-  MODULE_TEXT_SECTION* current;
+    PLIST_ENTRY current_entry;
+    MODULE_TEXT_SECTION* current;
 
-  current_entry = ModuleTextListHead.Flink;
-  while (current_entry != &ModuleTextListHead)
+    current_entry = ModuleTextListHead.Flink;
+    while (current_entry != &ModuleTextListHead)
     {
-      current = 
-	CONTAINING_RECORD(current_entry, MODULE_TEXT_SECTION, ListEntry);
-      if (wcscmp(current->Name, Name) == 0)
-	{
-	  break;
-	}
-      current_entry = current_entry->Flink;
+        current =
+            CONTAINING_RECORD(current_entry, MODULE_TEXT_SECTION, ListEntry);
+        if (wcscmp(current->Name, Name) == 0)
+        {
+            break;
+        }
+        current_entry = current_entry->Flink;
     }
 
-  if (current_entry == &ModuleTextListHead)
+    if (current_entry == &ModuleTextListHead)
     {
-      return;
+        return;
     }
 }
 
 VOID INIT_FUNCTION
-LdrInit1(VOID)
+LdrInit1 ( VOID )
 {
-  PIMAGE_NT_HEADERS      NtHeader;
-  PIMAGE_SECTION_HEADER  SectionList;
+    PIMAGE_NT_HEADERS      NtHeader;
+    PIMAGE_SECTION_HEADER  SectionList;
 
-  InitializeListHead(&ModuleTextListHead);
+    InitializeListHead(&ModuleTextListHead);
 
-  /* Setup ntoskrnl.exe text section */
-  /*
-   * This isn't the base of the text segment, but the start of the
-   * full image (in memory)
-   * Also, the Length field isn't set to the length of the segment,
-   * but is more like the offset, from the image base, to the end
-   * of the segment.
-   */
-  NtHeader                   = RtlImageNtHeader((PVOID)KERNEL_BASE);
-  SectionList                = IMAGE_FIRST_SECTION(NtHeader);
-  NtoskrnlTextSection.Base   = KERNEL_BASE;
-  NtoskrnlTextSection.Length = SectionList[0].Misc.VirtualSize +
-                               SectionList[0].VirtualAddress;
-  NtoskrnlTextSection.Name = KERNEL_MODULE_NAME;
-  NtoskrnlTextSection.OptionalHeader = OPTHDROFFSET(KERNEL_BASE);
-  InsertTailList(&ModuleTextListHead, &NtoskrnlTextSection.ListEntry);
+    /* Setup ntoskrnl.exe text section */
+    /*
+    * This isn't the base of the text segment, but the start of the
+    * full image (in memory)
+    * Also, the Length field isn't set to the length of the segment,
+    * but is more like the offset, from the image base, to the end
+    * of the segment.
+    */
+    NtHeader                   = RtlImageNtHeader((PVOID)KERNEL_BASE);
+    SectionList                = IMAGE_FIRST_SECTION(NtHeader);
+    NtoskrnlTextSection.Base   = KERNEL_BASE;
+    NtoskrnlTextSection.Length = SectionList[0].Misc.VirtualSize
+        + SectionList[0].VirtualAddress;
+    NtoskrnlTextSection.Name = KERNEL_MODULE_NAME;
+    NtoskrnlTextSection.OptionalHeader = OPTHDROFFSET(KERNEL_BASE);
+    InsertTailList(&ModuleTextListHead, &NtoskrnlTextSection.ListEntry);
 
-  /* Setup hal.dll text section */
-  /* Same comment as above applies */
-  NtHeader                 = RtlImageNtHeader((PVOID)LdrHalBase);
-  SectionList              = IMAGE_FIRST_SECTION(NtHeader);
-  LdrHalTextSection.Base   = LdrHalBase;
-  LdrHalTextSection.Length = SectionList[0].Misc.VirtualSize +
-                             SectionList[0].VirtualAddress;
-  LdrHalTextSection.Name = HAL_MODULE_NAME;
-  LdrHalTextSection.OptionalHeader = OPTHDROFFSET(LdrHalBase);
-  InsertTailList(&ModuleTextListHead, &LdrHalTextSection.ListEntry);
+    /* Setup hal.dll text section */
+    /* Same comment as above applies */
+    NtHeader                 = RtlImageNtHeader((PVOID)LdrHalBase);
+    SectionList              = IMAGE_FIRST_SECTION(NtHeader);
+    LdrHalTextSection.Base   = LdrHalBase;
+    LdrHalTextSection.Length = SectionList[0].Misc.VirtualSize
+        + SectionList[0].VirtualAddress;
+    LdrHalTextSection.Name = HAL_MODULE_NAME;
+    LdrHalTextSection.OptionalHeader = OPTHDROFFSET(LdrHalBase);
+    InsertTailList(&ModuleTextListHead, &LdrHalTextSection.ListEntry);
 
-  /* Hook for KDB on initialization of the loader. */
-  KDB_LOADERINIT_HOOK(&NtoskrnlTextSection, &LdrHalTextSection);
+    /* Hook for KDB on initialization of the loader. */
+    KDB_LOADERINIT_HOOK(&NtoskrnlTextSection, &LdrHalTextSection);
 }
 
 VOID INIT_FUNCTION
-LdrInitModuleManagement(VOID)
+LdrInitModuleManagement ( VOID )
 {
-  PIMAGE_NT_HEADERS NtHeader;
+    PIMAGE_NT_HEADERS NtHeader;
 
-  /* Initialize the module list and spinlock */
-  InitializeListHead(&ModuleListHead);
-  KeInitializeSpinLock(&ModuleListLock);
+    /* Initialize the module list and spinlock */
+    InitializeListHead(&ModuleListHead);
+    KeInitializeSpinLock(&ModuleListLock);
 
-  /* Initialize ModuleObject for NTOSKRNL */
-  RtlZeroMemory(&NtoskrnlModuleObject, sizeof(MODULE_OBJECT));
-  NtoskrnlModuleObject.Base = (PVOID) KERNEL_BASE;
-  NtoskrnlModuleObject.Flags = MODULE_FLAG_PE;
-  RtlInitUnicodeString(&NtoskrnlModuleObject.FullName, KERNEL_MODULE_NAME);
-  LdrpBuildModuleBaseName(&NtoskrnlModuleObject.BaseName, &NtoskrnlModuleObject.FullName);
+    /* Initialize ModuleObject for NTOSKRNL */
+    RtlZeroMemory(&NtoskrnlModuleObject, sizeof(MODULE_OBJECT));
+    NtoskrnlModuleObject.Base = (PVOID) KERNEL_BASE;
+    NtoskrnlModuleObject.Flags = MODULE_FLAG_PE;
+    RtlInitUnicodeString(&NtoskrnlModuleObject.FullName, KERNEL_MODULE_NAME);
+    LdrpBuildModuleBaseName(&NtoskrnlModuleObject.BaseName, &NtoskrnlModuleObject.FullName);
 
-  NtHeader = RtlImageNtHeader((PVOID)KERNEL_BASE);
-  NtoskrnlModuleObject.Image.PE.FileHeader = &NtHeader->FileHeader;
-  NtoskrnlModuleObject.Image.PE.OptionalHeader = &NtHeader->OptionalHeader;
-  NtoskrnlModuleObject.Image.PE.SectionList = IMAGE_FIRST_SECTION(NtHeader);
-  NtoskrnlModuleObject.EntryPoint = (PVOID) ((ULONG_PTR) NtoskrnlModuleObject.Base + NtHeader->OptionalHeader.AddressOfEntryPoint);
-  DPRINT("ModuleObject:%08x  entrypoint at %x\n", &NtoskrnlModuleObject, NtoskrnlModuleObject.EntryPoint);
-  NtoskrnlModuleObject.Length = NtoskrnlModuleObject.Image.PE.OptionalHeader->SizeOfImage;
-  NtoskrnlModuleObject.TextSection = &NtoskrnlTextSection;
+    NtHeader = RtlImageNtHeader((PVOID)KERNEL_BASE);
+    NtoskrnlModuleObject.Image.PE.FileHeader = &NtHeader->FileHeader;
+    NtoskrnlModuleObject.Image.PE.OptionalHeader = &NtHeader->OptionalHeader;
+    NtoskrnlModuleObject.Image.PE.SectionList = IMAGE_FIRST_SECTION(NtHeader);
+    NtoskrnlModuleObject.EntryPoint = (PVOID) ((ULONG_PTR) NtoskrnlModuleObject.Base + NtHeader->OptionalHeader.AddressOfEntryPoint);
+    DPRINT("ModuleObject:%08x  entrypoint at %x\n", &NtoskrnlModuleObject, NtoskrnlModuleObject.EntryPoint);
+    NtoskrnlModuleObject.Length = NtoskrnlModuleObject.Image.PE.OptionalHeader->SizeOfImage;
+    NtoskrnlModuleObject.TextSection = &NtoskrnlTextSection;
 
-  InsertTailList(&ModuleListHead,
-		 &NtoskrnlModuleObject.ListEntry);
+    InsertTailList(&ModuleListHead,
+        &NtoskrnlModuleObject.ListEntry);
 
-  /* Initialize ModuleObject for HAL */
-  RtlZeroMemory(&HalModuleObject, sizeof(MODULE_OBJECT));
-  HalModuleObject.Base = (PVOID) LdrHalBase;
-  HalModuleObject.Flags = MODULE_FLAG_PE;
+    /* Initialize ModuleObject for HAL */
+    RtlZeroMemory(&HalModuleObject, sizeof(MODULE_OBJECT));
+    HalModuleObject.Base = (PVOID) LdrHalBase;
+    HalModuleObject.Flags = MODULE_FLAG_PE;
 
-  RtlInitUnicodeString(&HalModuleObject.FullName, HAL_MODULE_NAME);
-  LdrpBuildModuleBaseName(&HalModuleObject.BaseName, &HalModuleObject.FullName);
+    RtlInitUnicodeString(&HalModuleObject.FullName, HAL_MODULE_NAME);
+    LdrpBuildModuleBaseName(&HalModuleObject.BaseName, &HalModuleObject.FullName);
 
-  NtHeader = RtlImageNtHeader((PVOID)LdrHalBase);
-  HalModuleObject.Image.PE.FileHeader = &NtHeader->FileHeader;
-  HalModuleObject.Image.PE.OptionalHeader = &NtHeader->OptionalHeader;
-  HalModuleObject.Image.PE.SectionList = IMAGE_FIRST_SECTION(NtHeader);
-  HalModuleObject.EntryPoint = (PVOID) ((ULONG_PTR) HalModuleObject.Base + NtHeader->OptionalHeader.AddressOfEntryPoint);
-  DPRINT("ModuleObject:%08x  entrypoint at %x\n", &HalModuleObject, HalModuleObject.EntryPoint);
-  HalModuleObject.Length = HalModuleObject.Image.PE.OptionalHeader->SizeOfImage;
-  HalModuleObject.TextSection = &LdrHalTextSection;
+    NtHeader = RtlImageNtHeader((PVOID)LdrHalBase);
+    HalModuleObject.Image.PE.FileHeader = &NtHeader->FileHeader;
+    HalModuleObject.Image.PE.OptionalHeader = &NtHeader->OptionalHeader;
+    HalModuleObject.Image.PE.SectionList = IMAGE_FIRST_SECTION(NtHeader);
+    HalModuleObject.EntryPoint = (PVOID) ((ULONG_PTR) HalModuleObject.Base + NtHeader->OptionalHeader.AddressOfEntryPoint);
+    DPRINT("ModuleObject:%08x  entrypoint at %x\n", &HalModuleObject, HalModuleObject.EntryPoint);
+    HalModuleObject.Length = HalModuleObject.Image.PE.OptionalHeader->SizeOfImage;
+    HalModuleObject.TextSection = &LdrHalTextSection;
 
-  InsertTailList(&ModuleListHead,
-		 &HalModuleObject.ListEntry);
+    InsertTailList(&ModuleListHead,
+        &HalModuleObject.ListEntry);
 }
 
 NTSTATUS
-LdrpLoadImage(PUNICODE_STRING DriverName,
-	      PVOID *ModuleBase,
-	      PVOID *SectionPointer,
-	      PVOID *EntryPoint,
-	      PVOID *ExportSectionPointer)
+LdrpLoadImage (
+    PUNICODE_STRING DriverName,
+    PVOID *ModuleBase,
+    PVOID *SectionPointer,
+    PVOID *EntryPoint,
+    PVOID *ExportSectionPointer )
 {
-  PMODULE_OBJECT ModuleObject;
-  NTSTATUS Status;
+    PMODULE_OBJECT ModuleObject;
+    NTSTATUS Status;
 
-  ModuleObject = LdrGetModuleObject(DriverName);
-  if (ModuleObject == NULL)
+    ModuleObject = LdrGetModuleObject(DriverName);
+    if (ModuleObject == NULL)
     {
-      Status = LdrLoadModule(DriverName, &ModuleObject);
-      if (!NT_SUCCESS(Status))
-	{
-	  return(Status);
-	}
+        Status = LdrLoadModule(DriverName, &ModuleObject);
+        if (!NT_SUCCESS(Status))
+        {
+            return(Status);
+        }
     }
 
-  if (ModuleBase)
-    *ModuleBase = ModuleObject->Base;
+    if (ModuleBase)
+        *ModuleBase = ModuleObject->Base;
 
-//  if (SectionPointer)
-//    *SectionPointer = ModuleObject->
+    //if (SectionPointer)
+    //    *SectionPointer = ModuleObject->
 
-  if (EntryPoint)
-    *EntryPoint = ModuleObject->EntryPoint;
+    if (EntryPoint)
+        *EntryPoint = ModuleObject->EntryPoint;
 
-//  if (ExportSectionPointer)
-//    *ExportSectionPointer = ModuleObject->
+    //if (ExportSectionPointer)
+    //    *ExportSectionPointer = ModuleObject->
 
-  return(STATUS_SUCCESS);
+    return(STATUS_SUCCESS);
 }
 
 
 NTSTATUS
-LdrpUnloadImage(PVOID ModuleBase)
+LdrpUnloadImage ( PVOID ModuleBase )
 {
-  return(STATUS_NOT_IMPLEMENTED);
+    return(STATUS_NOT_IMPLEMENTED);
 }
 
 
 NTSTATUS
-LdrpLoadAndCallImage(PUNICODE_STRING ModuleName)
+LdrpLoadAndCallImage ( PUNICODE_STRING ModuleName )
 {
-  PDRIVER_INITIALIZE DriverEntry;
-  PMODULE_OBJECT ModuleObject;
-  NTSTATUS Status;
+    PDRIVER_INITIALIZE DriverEntry;
+    PMODULE_OBJECT ModuleObject;
+    NTSTATUS Status;
 
-  ModuleObject = LdrGetModuleObject(ModuleName);
-  if (ModuleObject != NULL)
+    ModuleObject = LdrGetModuleObject(ModuleName);
+    if (ModuleObject != NULL)
     {
-      return(STATUS_IMAGE_ALREADY_LOADED);
+        return(STATUS_IMAGE_ALREADY_LOADED);
     }
 
-  Status = LdrLoadModule(ModuleName, &ModuleObject);
-  if (!NT_SUCCESS(Status))
+    Status = LdrLoadModule(ModuleName, &ModuleObject);
+    if (!NT_SUCCESS(Status))
     {
-      return(Status);
+        return(Status);
     }
 
-  DriverEntry = (PDRIVER_INITIALIZE)ModuleObject->EntryPoint;
+    DriverEntry = (PDRIVER_INITIALIZE)ModuleObject->EntryPoint;
 
-  Status = DriverEntry(NULL, NULL);
-  if (!NT_SUCCESS(Status))
+    Status = DriverEntry(NULL, NULL);
+    if (!NT_SUCCESS(Status))
     {
-      LdrUnloadModule(ModuleObject);
+        LdrUnloadModule(ModuleObject);
     }
 
-  return(Status);
+    return(Status);
 }
 
 
 NTSTATUS
-LdrLoadModule(PUNICODE_STRING Filename,
-	      PMODULE_OBJECT *ModuleObject)
+LdrLoadModule(
+    PUNICODE_STRING Filename,
+    PMODULE_OBJECT *ModuleObject )
 {
-  PVOID ModuleLoadBase;
-  NTSTATUS Status;
-  HANDLE FileHandle;
-  OBJECT_ATTRIBUTES ObjectAttributes;
-  PMODULE_OBJECT Module;
-  FILE_STANDARD_INFORMATION FileStdInfo;
-  IO_STATUS_BLOCK IoStatusBlock;
+    PVOID ModuleLoadBase;
+    NTSTATUS Status;
+    HANDLE FileHandle;
+    OBJECT_ATTRIBUTES ObjectAttributes;
+    PMODULE_OBJECT Module;
+    FILE_STANDARD_INFORMATION FileStdInfo;
+    IO_STATUS_BLOCK IoStatusBlock;
 
-  *ModuleObject = NULL;
+    *ModuleObject = NULL;
 
-  DPRINT("Loading Module %wZ...\n", Filename);
+    DPRINT("Loading Module %wZ...\n", Filename);
 
-  /*  Open the Module  */
-  InitializeObjectAttributes(&ObjectAttributes,
-                             Filename,
-                             OBJ_CASE_INSENSITIVE,
-                             NULL,
-                             NULL);
-  CHECKPOINT;
-  Status = ZwOpenFile(&FileHandle,
-                      FILE_ALL_ACCESS,
-                      &ObjectAttributes,
-                      &IoStatusBlock,
-                      0,
-                      FILE_SYNCHRONOUS_IO_NONALERT);
-  CHECKPOINT;
-  if (!NT_SUCCESS(Status))
+    /*  Open the Module  */
+    InitializeObjectAttributes(&ObjectAttributes,
+        Filename,
+        OBJ_CASE_INSENSITIVE,
+        NULL,
+        NULL);
+    CHECKPOINT;
+    Status = ZwOpenFile(&FileHandle,
+        FILE_ALL_ACCESS,
+        &ObjectAttributes,
+        &IoStatusBlock,
+        0,
+        FILE_SYNCHRONOUS_IO_NONALERT);
+    CHECKPOINT;
+    if (!NT_SUCCESS(Status))
     {
-      CPRINT("Could not open module file: %wZ\n", Filename);
-      return(Status);
+        CPRINT("Could not open module file: %wZ\n", Filename);
+        return(Status);
     }
-  CHECKPOINT;
+    CHECKPOINT;
 
-  /*  Get the size of the file  */
-  Status = ZwQueryInformationFile(FileHandle,
-                                  &IoStatusBlock,
-                                  &FileStdInfo,
-                                  sizeof(FileStdInfo),
-                                  FileStandardInformation);
-  if (!NT_SUCCESS(Status))
+    /*  Get the size of the file  */
+    Status = ZwQueryInformationFile(FileHandle,
+        &IoStatusBlock,
+        &FileStdInfo,
+        sizeof(FileStdInfo),
+        FileStandardInformation);
+    if (!NT_SUCCESS(Status))
     {
-      CPRINT("Could not get file size\n");
-      NtClose(FileHandle);
-      return(Status);
+        CPRINT("Could not get file size\n");
+        NtClose(FileHandle);
+        return(Status);
     }
-  CHECKPOINT;
+    CHECKPOINT;
 
-  /*  Allocate nonpageable memory for driver  */
-  ModuleLoadBase = ExAllocatePoolWithTag(NonPagedPool,
-					 FileStdInfo.EndOfFile.u.LowPart,
-					 TAG_DRIVER_MEM);
-  if (ModuleLoadBase == NULL)
+    /*  Allocate nonpageable memory for driver  */
+    ModuleLoadBase = ExAllocatePoolWithTag(NonPagedPool,
+        FileStdInfo.EndOfFile.u.LowPart,
+        TAG_DRIVER_MEM);
+    if (ModuleLoadBase == NULL)
     {
-      CPRINT("Could not allocate memory for module");
-      NtClose(FileHandle);
-      return(STATUS_INSUFFICIENT_RESOURCES);
+        CPRINT("Could not allocate memory for module");
+        NtClose(FileHandle);
+        return(STATUS_INSUFFICIENT_RESOURCES);
     }
-  CHECKPOINT;
+    CHECKPOINT;
 
-  /*  Load driver into memory chunk  */
-  Status = ZwReadFile(FileHandle,
-                      0, 0, 0,
-                      &IoStatusBlock,
-                      ModuleLoadBase,
-                      FileStdInfo.EndOfFile.u.LowPart,
-                      0, 0);
-  if (!NT_SUCCESS(Status))
+    /*  Load driver into memory chunk  */
+    Status = ZwReadFile(FileHandle,
+        0, 0, 0,
+        &IoStatusBlock,
+        ModuleLoadBase,
+        FileStdInfo.EndOfFile.u.LowPart,
+        0, 0);
+    if (!NT_SUCCESS(Status))
     {
-      CPRINT("Could not read module file into memory");
-      ExFreePool(ModuleLoadBase);
-      NtClose(FileHandle);
-      return(Status);
+        CPRINT("Could not read module file into memory");
+        ExFreePool(ModuleLoadBase);
+        NtClose(FileHandle);
+        return(Status);
     }
-  CHECKPOINT;
+    CHECKPOINT;
 
-  ZwClose(FileHandle);
+    ZwClose(FileHandle);
 
-  Status = LdrProcessModule(ModuleLoadBase,
-                            Filename,
-                            &Module);
-  if (!NT_SUCCESS(Status))
+    Status = LdrProcessModule(ModuleLoadBase,
+        Filename,
+        &Module);
+    if (!NT_SUCCESS(Status))
     {
-      CPRINT("Could not process module\n");
-      ExFreePool(ModuleLoadBase);
-      return(Status);
+        CPRINT("Could not process module\n");
+        ExFreePool(ModuleLoadBase);
+        return(Status);
     }
 
-  /*  Cleanup  */
-  ExFreePool(ModuleLoadBase);
+    /*  Cleanup  */
+    ExFreePool(ModuleLoadBase);
 
-  *ModuleObject = Module;
+    *ModuleObject = Module;
 
-  /* Hook for KDB on loading a driver. */
-  KDB_LOADDRIVER_HOOK(Filename, Module);
+    /* Hook for KDB on loading a driver. */
+    KDB_LOADDRIVER_HOOK(Filename, Module);
 
-  return(STATUS_SUCCESS);
+    return(STATUS_SUCCESS);
 }
 
 
 NTSTATUS
-LdrUnloadModule(PMODULE_OBJECT ModuleObject)
+LdrUnloadModule ( PMODULE_OBJECT ModuleObject )
 {
-  KIRQL Irql;
+    KIRQL Irql;
 
-  /* Remove the module from the module list */
-  KeAcquireSpinLock(&ModuleListLock,&Irql);
-  RemoveEntryList(&ModuleObject->ListEntry);
-  KeReleaseSpinLock(&ModuleListLock, Irql);
+    /* Remove the module from the module list */
+    KeAcquireSpinLock(&ModuleListLock,&Irql);
+    RemoveEntryList(&ModuleObject->ListEntry);
+    KeReleaseSpinLock(&ModuleListLock, Irql);
 
-  /* Hook for KDB on unloading a driver. */
-  KDB_UNLOADDRIVER_HOOK(ModuleObject);
+    /* Hook for KDB on unloading a driver. */
+    KDB_UNLOADDRIVER_HOOK(ModuleObject);
 
-  /* Free text section */
-  if (ModuleObject->TextSection != NULL)
+    /* Free text section */
+    if (ModuleObject->TextSection != NULL)
     {
-      ExFreePool(ModuleObject->TextSection->Name);
-      RemoveEntryList(&ModuleObject->TextSection->ListEntry);
-      ExFreePool(ModuleObject->TextSection);
-      ModuleObject->TextSection = NULL;
+        ExFreePool(ModuleObject->TextSection->Name);
+        RemoveEntryList(&ModuleObject->TextSection->ListEntry);
+        ExFreePool(ModuleObject->TextSection);
+        ModuleObject->TextSection = NULL;
     }
 
-  /* Free module section */
-//  MmFreeSection(ModuleObject->Base);
+    /* Free module section */
+    //  MmFreeSection(ModuleObject->Base);
 
-  ExFreePool(ModuleObject->FullName.Buffer);
-  ExFreePool(ModuleObject);
+    ExFreePool(ModuleObject->FullName.Buffer);
+    ExFreePool(ModuleObject);
 
-  return(STATUS_SUCCESS);
+    return(STATUS_SUCCESS);
 }
 
 
 NTSTATUS
-LdrProcessModule(PVOID ModuleLoadBase,
-		 PUNICODE_STRING ModuleName,
-		 PMODULE_OBJECT *ModuleObject)
+LdrProcessModule(
+    PVOID ModuleLoadBase,
+    PUNICODE_STRING ModuleName,
+    PMODULE_OBJECT *ModuleObject )
 {
-  PIMAGE_DOS_HEADER PEDosHeader;
+    PIMAGE_DOS_HEADER PEDosHeader;
 
-  /*  If MZ header exists  */
-  PEDosHeader = (PIMAGE_DOS_HEADER) ModuleLoadBase;
-  if (PEDosHeader->e_magic == IMAGE_DOS_SIGNATURE && PEDosHeader->e_lfanew != 0L)
+    /*  If MZ header exists  */
+    PEDosHeader = (PIMAGE_DOS_HEADER) ModuleLoadBase;
+    if (PEDosHeader->e_magic == IMAGE_DOS_SIGNATURE && PEDosHeader->e_lfanew != 0L)
     {
-      return LdrPEProcessModule(ModuleLoadBase,
-				ModuleName,
-				ModuleObject);
+        return LdrPEProcessModule(ModuleLoadBase,
+            ModuleName,
+            ModuleObject);
     }
 
-  CPRINT("Module wasn't PE\n");
-  return STATUS_UNSUCCESSFUL;
+    CPRINT("Module wasn't PE\n");
+    return STATUS_UNSUCCESSFUL;
 }
 
 NTSTATUS
-LdrpQueryModuleInformation(PVOID Buffer,
-			   ULONG Size,
-			   PULONG ReqSize)
+LdrpQueryModuleInformation (
+    PVOID Buffer,
+    ULONG Size,
+    PULONG ReqSize )
 {
-  PLIST_ENTRY current_entry;
-  PMODULE_OBJECT current;
-  ULONG ModuleCount = 0;
-  PSYSTEM_MODULE_INFORMATION Smi;
-  ANSI_STRING AnsiName;
-  PCHAR p;
-  KIRQL Irql;
+    PLIST_ENTRY current_entry;
+    PMODULE_OBJECT current;
+    ULONG ModuleCount = 0;
+    PSYSTEM_MODULE_INFORMATION Smi;
+    ANSI_STRING AnsiName;
+    PCHAR p;
+    KIRQL Irql;
 
-  KeAcquireSpinLock(&ModuleListLock,&Irql);
+    KeAcquireSpinLock(&ModuleListLock,&Irql);
 
-  /* calculate required size */
-  current_entry = ModuleListHead.Flink;
-  while (current_entry != (&ModuleListHead))
+    /* calculate required size */
+    current_entry = ModuleListHead.Flink;
+    while (current_entry != (&ModuleListHead))
     {
-      ModuleCount++;
-      current_entry = current_entry->Flink;
+        ModuleCount++;
+        current_entry = current_entry->Flink;
     }
 
-  *ReqSize = sizeof(SYSTEM_MODULE_INFORMATION)+
-    (ModuleCount - 1) * sizeof(SYSTEM_MODULE_INFORMATION_ENTRY);
+    *ReqSize = sizeof(SYSTEM_MODULE_INFORMATION)+
+        (ModuleCount - 1) * sizeof(SYSTEM_MODULE_INFORMATION_ENTRY);
 
-  if (Size < *ReqSize)
+    if (Size < *ReqSize)
     {
-      KeReleaseSpinLock(&ModuleListLock, Irql);
-      return(STATUS_INFO_LENGTH_MISMATCH);
+        KeReleaseSpinLock(&ModuleListLock, Irql);
+        return(STATUS_INFO_LENGTH_MISMATCH);
     }
 
-  /* fill the buffer */
-  memset(Buffer, '=', Size);
+    /* fill the buffer */
+    memset(Buffer, '=', Size);
 
-  Smi = (PSYSTEM_MODULE_INFORMATION)Buffer;
-  Smi->Count = ModuleCount;
+    Smi = (PSYSTEM_MODULE_INFORMATION)Buffer;
+    Smi->Count = ModuleCount;
 
-  ModuleCount = 0;
-  current_entry = ModuleListHead.Flink;
-  while (current_entry != (&ModuleListHead))
+    ModuleCount = 0;
+    current_entry = ModuleListHead.Flink;
+    while (current_entry != (&ModuleListHead))
     {
-      current = CONTAINING_RECORD(current_entry,MODULE_OBJECT,ListEntry);
+        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].Base = current->Base;
-      Smi->Module[ModuleCount].Size = current->Length;
-      Smi->Module[ModuleCount].Flags = 0;		/* Flags ??? (GN) */
-      Smi->Module[ModuleCount].Index = (USHORT)ModuleCount;
-      Smi->Module[ModuleCount].NameLength = 0;
-      Smi->Module[ModuleCount].LoadCount = 0; /* FIXME */
+        Smi->Module[ModuleCount].Unknown1 = 0;                /* Always 0 */
+        Smi->Module[ModuleCount].Unknown2 = 0;                /* Always 0 */
+        Smi->Module[ModuleCount].Base = current->Base;
+        Smi->Module[ModuleCount].Size = current->Length;
+        Smi->Module[ModuleCount].Flags = 0;                /* Flags ??? (GN) */
+        Smi->Module[ModuleCount].Index = (USHORT)ModuleCount;
+        Smi->Module[ModuleCount].NameLength = 0;
+        Smi->Module[ModuleCount].LoadCount = 0; /* FIXME */
 
-      AnsiName.Length = 0;
-      AnsiName.MaximumLength = 256;
-      AnsiName.Buffer = Smi->Module[ModuleCount].ImageName;
-      RtlUnicodeStringToAnsiString(&AnsiName,
-				   &current->FullName,
-				   FALSE);
+        AnsiName.Length = 0;
+        AnsiName.MaximumLength = 256;
+        AnsiName.Buffer = Smi->Module[ModuleCount].ImageName;
+        RtlUnicodeStringToAnsiString(&AnsiName,
+            &current->FullName,
+            FALSE);
 
-      p = strrchr(AnsiName.Buffer, '\\');
-      if (p == NULL)
-	{
-	  Smi->Module[ModuleCount].PathLength = 0;
-	}
-      else
-	{
-	  p++;
-	  Smi->Module[ModuleCount].PathLength = p - AnsiName.Buffer;
-	}
+        p = strrchr(AnsiName.Buffer, '\\');
+        if (p == NULL)
+        {
+            Smi->Module[ModuleCount].PathLength = 0;
+        }
+        else
+        {
+            p++;
+            Smi->Module[ModuleCount].PathLength = p - AnsiName.Buffer;
+        }
 
-      ModuleCount++;
-      current_entry = current_entry->Flink;
+        ModuleCount++;
+        current_entry = current_entry->Flink;
     }
 
-  KeReleaseSpinLock(&ModuleListLock, Irql);
+    KeReleaseSpinLock(&ModuleListLock, Irql);
 
-  return(STATUS_SUCCESS);
+    return(STATUS_SUCCESS);
 }
 
 
 static VOID
-LdrpBuildModuleBaseName(PUNICODE_STRING BaseName,
-			PUNICODE_STRING FullName)
+LdrpBuildModuleBaseName (
+    PUNICODE_STRING BaseName,
+    PUNICODE_STRING FullName )
 {
-   PWCHAR p;
+    PWCHAR p;
 
-   DPRINT("LdrpBuildModuleBaseName()\n");
-   DPRINT("FullName %wZ\n", FullName);
+    DPRINT("LdrpBuildModuleBaseName()\n");
+    DPRINT("FullName %wZ\n", FullName);
 
-   p = wcsrchr(FullName->Buffer, L'\\');
-   if (p == NULL)
-     {
-	p = FullName->Buffer;
-     }
-   else
-     {
-	p++;
-     }
+    p = wcsrchr(FullName->Buffer, L'\\');
+    if (p == NULL)
+    {
+        p = FullName->Buffer;
+    }
+    else
+    {
+        p++;
+    }
 
-   DPRINT("p %S\n", p);
+    DPRINT("p %S\n", p);
 
-   RtlInitUnicodeString(BaseName, p);
+    RtlInitUnicodeString(BaseName, p);
 }
 
 
 static LONG
-LdrpCompareModuleNames(IN PUNICODE_STRING String1,
-		       IN PUNICODE_STRING String2)
+LdrpCompareModuleNames (
+    IN PUNICODE_STRING String1,
+    IN PUNICODE_STRING String2 )
 {
-  ULONG len1, len2, i;
-  PWCHAR s1, s2, p;
-  WCHAR  c1, c2;
+    ULONG len1, len2, i;
+    PWCHAR s1, s2, p;
+    WCHAR  c1, c2;
 
-  if (String1 && String2)
+    if (String1 && String2)
     {
-      /* Search String1 for last path component */
-      len1 = String1->Length / sizeof(WCHAR);
-      s1 = String1->Buffer;
-      for (i = 0, p = String1->Buffer; i < String1->Length; i = i + sizeof(WCHAR), p++)
-	{
-	  if (*p == L'\\')
-	    {
-	      if (i == String1->Length - sizeof(WCHAR))
-		{
-		  s1 = NULL;
-		  len1 = 0;
-		}
-	      else
-		{
-		  s1 = p + 1;
-		  len1 = (String1->Length - i) / sizeof(WCHAR);
-		}
-	    }
-	}
+        /* Search String1 for last path component */
+        len1 = String1->Length / sizeof(WCHAR);
+        s1 = String1->Buffer;
+        for (i = 0, p = String1->Buffer; i < String1->Length; i = i + sizeof(WCHAR), p++)
+        {
+            if (*p == L'\\')
+            {
+                if (i == String1->Length - sizeof(WCHAR))
+                {
+                    s1 = NULL;
+                    len1 = 0;
+                }
+                else
+                {
+                    s1 = p + 1;
+                    len1 = (String1->Length - i) / sizeof(WCHAR);
+                }
+            }
+        }
 
-      /* Search String2 for last path component */
-      len2 = String2->Length / sizeof(WCHAR);
-      s2 = String2->Buffer;
-      for (i = 0, p = String2->Buffer; i < String2->Length; i = i + sizeof(WCHAR), p++)
-	{
-	  if (*p == L'\\')
-	    {
-	      if (i == String2->Length - sizeof(WCHAR))
-		{
-		  s2 = NULL;
-		  len2 = 0;
-		}
-	      else
-		{
-		  s2 = p + 1;
-		  len2 = (String2->Length - i) / sizeof(WCHAR);
-		}
-	    }
-	}
+        /* Search String2 for last path component */
+        len2 = String2->Length / sizeof(WCHAR);
+        s2 = String2->Buffer;
+        for (i = 0, p = String2->Buffer; i < String2->Length; i = i + sizeof(WCHAR), p++)
+        {
+            if (*p == L'\\')
+            {
+                if (i == String2->Length - sizeof(WCHAR))
+                {
+                    s2 = NULL;
+                    len2 = 0;
+                }
+                else
+                {
+                    s2 = p + 1;
+                    len2 = (String2->Length - i) / sizeof(WCHAR);
+                }
+            }
+        }
 
-      /* Compare last path components */
-      if (s1 && s2)
-	{
-	  while (1)
-	    {
-	      c1 = len1-- ? RtlUpcaseUnicodeChar (*s1++) : 0;
-	      c2 = len2-- ? RtlUpcaseUnicodeChar (*s2++) : 0;
-	      if ((c1 == 0 && c2 == L'.') || (c1 == L'.' && c2 == 0))
-		return(0);
-	      if (!c1 || !c2 || c1 != c2)
-		return(c1 - c2);
-	    }
-	}
+        /* Compare last path components */
+        if (s1 && s2)
+        {
+            while (1)
+            {
+                c1 = len1-- ? RtlUpcaseUnicodeChar (*s1++) : 0;
+                c2 = len2-- ? RtlUpcaseUnicodeChar (*s2++) : 0;
+                if ((c1 == 0 && c2 == L'.') || (c1 == L'.' && c2 == 0))
+                    return(0);
+                if (!c1 || !c2 || c1 != c2)
+                    return(c1 - c2);
+            }
+        }
     }
 
-  return(0);
+    return(0);
 }
 
 PMODULE_OBJECT
-LdrGetModuleObject(PUNICODE_STRING ModuleName)
+LdrGetModuleObject ( PUNICODE_STRING ModuleName )
 {
-  PMODULE_OBJECT Module;
-  PLIST_ENTRY Entry;
-  KIRQL Irql;
+    PMODULE_OBJECT Module;
+    PLIST_ENTRY Entry;
+    KIRQL Irql;
 
-  DPRINT("LdrGetModuleObject(%wZ) called\n", ModuleName);
+    DPRINT("LdrGetModuleObject(%wZ) called\n", ModuleName);
 
-  KeAcquireSpinLock(&ModuleListLock,&Irql);
+    KeAcquireSpinLock(&ModuleListLock,&Irql);
 
-  Entry = ModuleListHead.Flink;
-  while (Entry != &ModuleListHead)
+    Entry = ModuleListHead.Flink;
+    while (Entry != &ModuleListHead)
     {
-      Module = CONTAINING_RECORD(Entry, MODULE_OBJECT, ListEntry);
+        Module = CONTAINING_RECORD(Entry, MODULE_OBJECT, ListEntry);
 
-      DPRINT("Comparing %wZ and %wZ\n",
-	     &Module->BaseName,
[truncated at 1000 lines; 1790 more skipped]