https://git.reactos.org/?p=reactos.git;a=commitdiff;h=15e1489c7f4986d93d72b6...
commit 15e1489c7f4986d93d72b61a4a3da7e61f219f24 Author: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org AuthorDate: Fri Feb 11 02:55:13 2022 +0100 Commit: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org CommitDate: Fri Feb 18 20:24:48 2022 +0100
[FREELDR:NTLDR] Add some error handling for LoadModule(). Based on PR #4294 by Serge Gautherie.
Co-authored-by: Serge Gautherie reactos-git_serge_171003@gautherie.fr --- boot/freeldr/freeldr/ntldr/winldr.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/boot/freeldr/freeldr/ntldr/winldr.c b/boot/freeldr/freeldr/ntldr/winldr.c index 66954e27d5e..2721ce4f0ed 100644 --- a/boot/freeldr/freeldr/ntldr/winldr.c +++ b/boot/freeldr/freeldr/ntldr/winldr.c @@ -324,13 +324,16 @@ WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead, NtLdrOutputLoadMsg(FullPath, NULL); Success = PeLdrLoadImage(FullPath, LoaderBootDriver, &DriverBase); if (!Success) + { + ERR("PeLdrLoadImage('%s') failed\n", DllName); return FALSE; + }
// Allocate a DTE for it Success = PeLdrAllocateDataTableEntry(LoadOrderListHead, DllName, DllName, DriverBase, DriverDTE); if (!Success) { - ERR("PeLdrAllocateDataTableEntry() failed\n"); + ERR("PeLdrAllocateDataTableEntry('%s') failed\n", DllName); return FALSE; }
@@ -342,7 +345,7 @@ WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead, Success = PeLdrScanImportDescriptorTable(LoadOrderListHead, FullPath, *DriverDTE); if (!Success) { - ERR("PeLdrScanImportDescriptorTable() failed for %s\n", FullPath); + ERR("PeLdrScanImportDescriptorTable('%s') failed\n", FullPath); return FALSE; }
@@ -504,7 +507,7 @@ LoadModule( Success = PeLdrLoadImage(FullFileName, MemoryType, &BaseAddress); if (!Success) { - TRACE("Loading %s failed\n", File); + ERR("PeLdrLoadImage('%s') failed\n", File); return FALSE; } TRACE("%s loaded successfully at %p\n", File, BaseAddress); @@ -519,6 +522,10 @@ LoadModule( FullFileName, BaseAddress, Dte); + if (!Success) + { + ERR("PeLdrAllocateDataTableEntry('%s') failed\n", FullFileName); + }
return Success; } @@ -579,10 +586,18 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion, TRACE("HAL file = '%s' ; Kernel file = '%s'\n", HalFileName, KernelFileName);
/* Load the Kernel */ - LoadModule(LoaderBlock, DirPath, KernelFileName, "ntoskrnl.exe", LoaderSystemCode, KernelDTE, 30); + if (!LoadModule(LoaderBlock, DirPath, KernelFileName, "ntoskrnl.exe", LoaderSystemCode, KernelDTE, 30)) + { + ERR("LoadModule() failed for %s\n", KernelFileName); + return FALSE; + }
/* Load the HAL */ - LoadModule(LoaderBlock, DirPath, HalFileName, "hal.dll", LoaderHalCode, &HalDTE, 45); + if (!LoadModule(LoaderBlock, DirPath, HalFileName, "hal.dll", LoaderHalCode, &HalDTE, 45)) + { + ERR("LoadModule() failed for %s\n", HalFileName); + return FALSE; + }
/* Load the Kernel Debugger Transport DLL */ if (OperatingSystemVersion > _WIN32_WINNT_WIN2K) @@ -636,7 +651,11 @@ LoadWindowsCore(IN USHORT OperatingSystemVersion, * Load the transport DLL. Override the base DLL name of the * loaded transport DLL to the default "KDCOM.DLL" name. */ - LoadModule(LoaderBlock, DirPath, KdDllName, "kdcom.dll", LoaderSystemCode, &KdComDTE, 60); + if (!LoadModule(LoaderBlock, DirPath, KdDllName, "kdcom.dll", LoaderSystemCode, &KdComDTE, 60)) + { + /* The transport DLL being optional, just ignore the failure */ + WARN("LoadModule() failed for %s\n", KdDllName); + } } }