Author: tkreuzer Date: Mon Oct 3 08:14:00 2011 New Revision: 53947 URL: http://svn.reactos.org/svn/reactos?rev=53947&view=rev Log: [FREELDR] - Pass the module list head to a number of pe loader functions instead of the loader block. - use static for some functions - remove unneeded prototypes
Modified: trunk/reactos/boot/freeldr/freeldr/disk/scsiport.c trunk/reactos/boot/freeldr/freeldr/include/winldr.h trunk/reactos/boot/freeldr/freeldr/windows/peloader.c trunk/reactos/boot/freeldr/freeldr/windows/winldr.c trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c Modified: trunk/reactos/boot/freeldr/freeldr/disk/scsiport.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/disk/scsiport.c?rev=53947&r1=53946&r2=53947&view=diff ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/disk/scsiport.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/disk/scsiport.c [iso-8859-1] Mon Oct 3 08:14:00 2011 @@ -1563,7 +1563,7 @@ LoadBootDeviceDriver(VOID) { PIMAGE_NT_HEADERS NtHeaders; - LOADER_PARAMETER_BLOCK LoaderBlock; + LIST_ENTRY ModuleListHead; PIMAGE_IMPORT_DESCRIPTOR ImportTable; ULONG ImportTableSize; PLDR_DATA_TABLE_ENTRY BootDdDTE, FreeldrDTE; @@ -1572,9 +1572,8 @@ ULONG (NTAPI *EntryPoint)(IN PVOID DriverObject, IN PVOID RegistryPath); BOOLEAN Status; - /* Some initialization of our temporary loader block */ - RtlZeroMemory(&LoaderBlock, sizeof(LOADER_PARAMETER_BLOCK)); - InitializeListHead(&LoaderBlock.LoadOrderListHead); + /* Initialize the loaded module list */ + InitializeListHead(&ModuleListHead); /* Create full ntbootdd.sys path */ MachDiskGetBootPath(NtBootDdPath, sizeof(NtBootDdPath)); @@ -1589,14 +1588,14 @@ } /* Allocate a DTE for ntbootdd */ - Status = WinLdrAllocateDataTableEntry(&LoaderBlock, "ntbootdd.sys", + Status = WinLdrAllocateDataTableEntry(&ModuleListHead, "ntbootdd.sys", "NTBOOTDD.SYS", ImageBase, &BootDdDTE); if (!Status) return EIO; /* Add the PE part of freeldr.sys to the list of loaded executables, it contains Scsiport* exports, imported by ntbootdd.sys */ - Status = WinLdrAllocateDataTableEntry(&LoaderBlock, "scsiport.sys", + Status = WinLdrAllocateDataTableEntry(&ModuleListHead, "scsiport.sys", "FREELDR.SYS", &__ImageBase, &FreeldrDTE); if (!Status) { @@ -1605,7 +1604,7 @@ } /* Fix imports */ - Status = WinLdrScanImportDescriptorTable(&LoaderBlock, "", BootDdDTE); + Status = WinLdrScanImportDescriptorTable(&ModuleListHead, "", BootDdDTE); /* Now unlinkt the DTEs, they won't be valid later */ RemoveEntryList(&BootDdDTE->InLoadOrderLinks); Modified: trunk/reactos/boot/freeldr/freeldr/include/winldr.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/include/winldr.h?rev=53947&r1=53946&r2=53947&view=diff ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/winldr.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/winldr.h [iso-8859-1] Mon Oct 3 08:14:00 2011 @@ -107,14 +107,14 @@ BOOLEAN -WinLdrAllocateDataTableEntry(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, +WinLdrAllocateDataTableEntry(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH BaseDllName, IN PCCH FullDllName, IN PVOID BasePA, OUT PLDR_DATA_TABLE_ENTRY *NewEntry); BOOLEAN -WinLdrScanImportDescriptorTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, +WinLdrScanImportDescriptorTable(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH DirectoryPath, IN PLDR_DATA_TABLE_ENTRY ScanDTE); @@ -135,12 +135,9 @@ BOOLEAN -WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, +WinLdrCheckForLoadedDll(IN OUT PLIST_ENTRY ModuleListHead, IN PCH DllName, OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry); - -BOOLEAN -WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock, LPSTR BootPath); VOID WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock, Modified: trunk/reactos/boot/freeldr/freeldr/windows/peloader.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windows/peloader.c?rev=53947&r1=53946&r2=53947&view=diff ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/peloader.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/peloader.c [iso-8859-1] Mon Oct 3 08:14:00 2011 @@ -19,12 +19,12 @@ DBG_DEFAULT_CHANNEL(PELOADER); -BOOLEAN +static BOOLEAN WinLdrpCompareDllName(IN PCH DllName, IN PUNICODE_STRING UnicodeName); -BOOLEAN -WinLdrpBindImportName(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, +static BOOLEAN +WinLdrpBindImportName(IN OUT PLIST_ENTRY ModuleListHead, IN PVOID DllBase, IN PVOID ImageBase, IN PIMAGE_THUNK_DATA ThunkData, @@ -32,14 +32,14 @@ IN ULONG ExportSize, IN BOOLEAN ProcessForwards); -BOOLEAN -WinLdrpLoadAndScanReferencedDll(PLOADER_PARAMETER_BLOCK WinLdrBlock, +static BOOLEAN +WinLdrpLoadAndScanReferencedDll(PLIST_ENTRY ModuleListHead, PCCH DirectoryPath, PCH ImportName, PLDR_DATA_TABLE_ENTRY *DataTableEntry); -BOOLEAN -WinLdrpScanImportAddressTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, +static BOOLEAN +WinLdrpScanImportAddressTable(IN OUT PLIST_ENTRY ModuleListHead, IN PVOID DllBase, IN PVOID ImageBase, IN PIMAGE_THUNK_DATA ThunkData); @@ -50,7 +50,7 @@ /* Returns TRUE if DLL has already been loaded - looks in LoadOrderList in LPB */ BOOLEAN -WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, +WinLdrCheckForLoadedDll(IN OUT PLIST_ENTRY ModuleListHead, IN PCH DllName, OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry) { @@ -62,16 +62,17 @@ /* Just go through each entry in the LoadOrderList and compare loaded module's name with a given name */ - ModuleEntry = WinLdrBlock->LoadOrderListHead.Flink; - while (ModuleEntry != &WinLdrBlock->LoadOrderListHead) + ModuleEntry = ModuleListHead->Flink; + while (ModuleEntry != ModuleListHead) { /* Get pointer to the current DTE */ DataTableEntry = CONTAINING_RECORD(ModuleEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks); - TRACE("WinLdrCheckForLoadedDll: DTE %p, EP %p\n", - DataTableEntry, DataTableEntry->EntryPoint); + TRACE("WinLdrCheckForLoadedDll: DTE %p, EP %p, base %p name '%ws'\n", + DataTableEntry, DataTableEntry->EntryPoint, DataTableEntry->DllBase, + VaToPa(DataTableEntry->BaseDllName.Buffer)); /* Compare names */ if (WinLdrpCompareDllName(DllName, &DataTableEntry->BaseDllName)) @@ -93,7 +94,7 @@ } BOOLEAN -WinLdrScanImportDescriptorTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, +WinLdrScanImportDescriptorTable(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH DirectoryPath, IN PLDR_DATA_TABLE_ENTRY ScanDTE) { @@ -132,9 +133,9 @@ continue; /* Load the DLL if it is not already loaded */ - if (!WinLdrCheckForLoadedDll(WinLdrBlock, ImportName, &DataTableEntry)) - { - Status = WinLdrpLoadAndScanReferencedDll(WinLdrBlock, + if (!WinLdrCheckForLoadedDll(ModuleListHead, ImportName, &DataTableEntry)) + { + Status = WinLdrpLoadAndScanReferencedDll(ModuleListHead, DirectoryPath, ImportName, &DataTableEntry); @@ -148,7 +149,7 @@ /* Scan its import address table */ Status = WinLdrpScanImportAddressTable( - WinLdrBlock, + ModuleListHead, DataTableEntry->DllBase, ScanDTE->DllBase, (PIMAGE_THUNK_DATA)RVA(ScanDTE->DllBase, ImportTable->FirstThunk)); @@ -164,7 +165,7 @@ } BOOLEAN -WinLdrAllocateDataTableEntry(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, +WinLdrAllocateDataTableEntry(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH BaseDllName, IN PCCH FullDllName, IN PVOID BasePA, @@ -175,6 +176,8 @@ PLDR_DATA_TABLE_ENTRY DataTableEntry; PIMAGE_NT_HEADERS NtHeaders; USHORT Length; + TRACE("WinLdrAllocateDataTableEntry(, '%s', '%s', %p)\n", + BaseDllName, FullDllName, BasePA); /* Allocate memory for a data table entry, zero-initialize it */ DataTableEntry = (PLDR_DATA_TABLE_ENTRY)MmHeapAlloc(sizeof(LDR_DATA_TABLE_ENTRY)); @@ -236,7 +239,9 @@ DataTableEntry->LoadCount = 1; /* Insert this DTE to a list in the LPB */ - InsertTailList(&WinLdrBlock->LoadOrderListHead, &DataTableEntry->InLoadOrderLinks); + InsertTailList(ModuleListHead, &DataTableEntry->InLoadOrderLinks); + TRACE("Inserting DTE %p, name='%S' DllBase=%p \n", DataTableEntry, + DataTableEntry->BaseDllName.Buffer, DataTableEntry->DllBase); /* Save pointer to a newly allocated and initialized entry */ *NewEntry = DataTableEntry; @@ -442,7 +447,7 @@ /* PRIVATE FUNCTIONS *******************************************************/ /* DllName - physical, UnicodeString->Buffer - virtual */ -BOOLEAN +static BOOLEAN WinLdrpCompareDllName(IN PCH DllName, IN PUNICODE_STRING UnicodeName) { @@ -488,8 +493,8 @@ return FALSE; } -BOOLEAN -WinLdrpBindImportName(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, +static BOOLEAN +WinLdrpBindImportName(IN OUT PLIST_ENTRY ModuleListHead, IN PVOID DllBase, IN PVOID ImageBase, IN PIMAGE_THUNK_DATA ThunkData, @@ -651,7 +656,7 @@ *strchr(ForwardDllName,'.') = '\0'; TRACE("WinLdrpBindImportName(): ForwardDllName %s\n", ForwardDllName); - if (!WinLdrCheckForLoadedDll(WinLdrBlock, ForwardDllName, &DataTableEntry)) + if (!WinLdrCheckForLoadedDll(ModuleListHead, ForwardDllName, &DataTableEntry)) { /* We can't continue if DLL couldn't be loaded, so bomb out with an error */ //Print(L"Error loading DLL!\n"); @@ -692,7 +697,7 @@ /* And recursively call ourselves */ Status = WinLdrpBindImportName( - WinLdrBlock, + ModuleListHead, DataTableEntry->DllBase, ImageBase, &RefThunkData, @@ -717,8 +722,8 @@ return TRUE; } -BOOLEAN -WinLdrpLoadAndScanReferencedDll(PLOADER_PARAMETER_BLOCK WinLdrBlock, +static BOOLEAN +WinLdrpLoadAndScanReferencedDll(PLIST_ENTRY ModuleListHead, PCCH DirectoryPath, PCH ImportName, PLDR_DATA_TABLE_ENTRY *DataTableEntry) @@ -744,7 +749,7 @@ } /* Allocate DTE for newly loaded DLL */ - Status = WinLdrAllocateDataTableEntry(WinLdrBlock, + Status = WinLdrAllocateDataTableEntry(ModuleListHead, ImportName, FullDllName, BasePA, @@ -759,7 +764,7 @@ /* Scan its dependencies too */ TRACE("WinLdrScanImportDescriptorTable() calling ourselves for %S\n", VaToPa((*DataTableEntry)->BaseDllName.Buffer)); - Status = WinLdrScanImportDescriptorTable(WinLdrBlock, DirectoryPath, *DataTableEntry); + Status = WinLdrScanImportDescriptorTable(ModuleListHead, DirectoryPath, *DataTableEntry); if (!Status) { @@ -770,8 +775,8 @@ return TRUE; } -BOOLEAN -WinLdrpScanImportAddressTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, +static BOOLEAN +WinLdrpScanImportAddressTable(IN OUT PLIST_ENTRY ModuleListHead, IN PVOID DllBase, IN PVOID ImageBase, IN PIMAGE_THUNK_DATA ThunkData) @@ -786,7 +791,7 @@ /* Obtain the export table from the DLL's base */ if (DllBase == NULL) { - //Print(L"Error, DllBase == NULL!\n"); + ERR("Error, DllBase == NULL!\n"); return FALSE; } else @@ -802,14 +807,17 @@ /* If pointer to Export Directory is */ if (ExportDirectory == NULL) - return FALSE; + { + ERR("DllBase=%p(%p)\n", DllBase, VaToPa(DllBase)); + return FALSE; + } /* Go through each entry in the thunk table and bind it */ while (((PIMAGE_THUNK_DATA)VaToPa(ThunkData))->u1.AddressOfData != 0) { /* Bind it */ Status = WinLdrpBindImportName( - WinLdrBlock, + ModuleListHead, DllBase, ImageBase, ThunkData, Modified: trunk/reactos/boot/freeldr/freeldr/windows/winldr.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windows/winldr.c?rev=53947&r1=53946&r2=53947&view=diff ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/winldr.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/winldr.c [iso-8859-1] Mon Oct 3 08:14:00 2011 @@ -214,6 +214,7 @@ if (LoaderBlock->SetupLdrBlock) LoaderBlock->SetupLdrBlock = PaToVa(LoaderBlock->SetupLdrBlock); + TRACE("WinLdrInitializePhase1() completed\n"); } BOOLEAN @@ -252,7 +253,7 @@ // Check if driver is already loaded - Status = WinLdrCheckForLoadedDll(LoaderBlock, DllName, DriverDTE); + Status = WinLdrCheckForLoadedDll(&LoaderBlock->LoadOrderListHead, DllName, DriverDTE); if (Status) { // We've got the pointer to its DTE, just return success @@ -266,7 +267,7 @@ return FALSE; // Allocate a DTE for it - Status = WinLdrAllocateDataTableEntry(LoaderBlock, DllName, DllName, DriverBase, DriverDTE); + Status = WinLdrAllocateDataTableEntry(&LoaderBlock->LoadOrderListHead, DllName, DllName, DriverBase, DriverDTE); if (!Status) { ERR("WinLdrAllocateDataTableEntry() failed\n"); @@ -278,7 +279,7 @@ // Look for any dependencies it may have, and load them too sprintf(FullPath,"%s%s", BootPath, DriverPath); - Status = WinLdrScanImportDescriptorTable(LoaderBlock, FullPath, *DriverDTE); + Status = WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, FullPath, *DriverDTE); if (!Status) { ERR("WinLdrScanImportDescriptorTable() failed for %s\n", FullPath); @@ -439,7 +440,7 @@ strcpy(FullFileName, "WINDOWS\\SYSTEM32\\"); strcat(FullFileName, File); - WinLdrAllocateDataTableEntry(LoaderBlock, File, + WinLdrAllocateDataTableEntry(&LoaderBlock->LoadOrderListHead, File, FullFileName, BaseAdress, Dte); return BaseAdress; @@ -587,10 +588,10 @@ /* Load all referenced DLLs for kernel, HAL and kdcom.dll */ strcpy(FileName, BootPath); strcat(FileName, "system32\\"); - Status = WinLdrScanImportDescriptorTable(LoaderBlock, FileName, KernelDTE); - Status &= WinLdrScanImportDescriptorTable(LoaderBlock, FileName, HalDTE); + Status = WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, FileName, KernelDTE); + Status &= WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, FileName, HalDTE); if (KdComDTE) - Status &= WinLdrScanImportDescriptorTable(LoaderBlock, FileName, KdComDTE); + Status &= WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, FileName, KdComDTE); if (!Status) { Modified: trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c?rev=53947&r1=53946&r2=53947&view=diff ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c [iso-8859-1] Mon Oct 3 08:14:00 2011 @@ -16,26 +16,15 @@ // The only global var here, used to mark mem pages as NLS in WinLdrSetupMemoryLayout() ULONG TotalNLSSize = 0; -BOOLEAN WinLdrGetNLSNames(LPSTR AnsiName, - LPSTR OemName, - LPSTR LangName); - -BOOLEAN -WinLdrLoadNLSData(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, - IN LPCSTR DirectoryPath, - IN LPCSTR AnsiFileName, - IN LPCSTR OemFileName, - IN LPCSTR LanguageFileName); - -VOID -WinLdrScanRegistry(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, +static BOOLEAN +WinLdrGetNLSNames(LPSTR AnsiName, + LPSTR OemName, + LPSTR LangName); + +static VOID +WinLdrScanRegistry(IN OUT PLIST_ENTRY BootDriverListHead, IN LPCSTR DirectoryPath); -BOOLEAN -WinLdrAddDriverToList(LIST_ENTRY *BootDriverListHead, - LPWSTR RegistryPath, - LPWSTR ImagePath, - LPWSTR ServiceName); /* FUNCTIONS **************************************************************/ @@ -173,7 +162,7 @@ BOOLEAN Status; // Scan registry and prepare boot drivers list - WinLdrScanRegistry(LoaderBlock, DirectoryPath); + WinLdrScanRegistry(&LoaderBlock->BootDriverListHead, DirectoryPath); // Get names of NLS files Status = WinLdrGetNLSNames(AnsiName, OemName, LangName); @@ -201,9 +190,10 @@ /* PRIVATE FUNCTIONS ******************************************************/ // Queries registry for those three file names -BOOLEAN WinLdrGetNLSNames(LPSTR AnsiName, - LPSTR OemName, - LPSTR LangName) +static BOOLEAN +WinLdrGetNLSNames(LPSTR AnsiName, + LPSTR OemName, + LPSTR LangName) { LONG rc = ERROR_SUCCESS; FRLDRHKEY hKey; @@ -459,8 +449,8 @@ return FALSE; } -VOID -WinLdrScanRegistry(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, +static VOID +WinLdrScanRegistry(IN OUT PLIST_ENTRY BootDriverListHead, IN LPCSTR DirectoryPath) { LONG rc = 0; @@ -602,7 +592,7 @@ TRACE("Adding boot driver: '%s'\n", ImagePath); - Status = WinLdrAddDriverToList(&LoaderBlock->BootDriverListHead, + Status = WinLdrAddDriverToList(BootDriverListHead, L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\", TempImagePath, ServiceName); @@ -680,7 +670,7 @@ } TRACE(" Adding boot driver: '%s'\n", ImagePath); - Status = WinLdrAddDriverToList(&LoaderBlock->BootDriverListHead, + Status = WinLdrAddDriverToList(BootDriverListHead, L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\", TempImagePath, ServiceName);