- Fix some bugs in the kernel related to driver loading, which were hindering FreeLDR 2.5 support.

- Make FreeLDR relocate and process the import tables of drivers as well. This is almost FreeLDR 2.5 but is still missing some minor functionality before being completely done.

svn path=/trunk/; revision=26067
This commit is contained in:
Alex Ionescu 2007-03-12 17:30:57 +00:00
parent 8d8e5ea06e
commit a97f262ed8
3 changed files with 22 additions and 18 deletions

View file

@ -521,7 +521,6 @@ LdrPEFixupImports(IN PVOID DllBase,
Status = LdrPEGetOrLoadModule(DllName, ImportedName, &ImportedModule);
if (!NT_SUCCESS(Status)) return Status;
//DbgPrint("Import Base: %p\n", ImportedModule->ModStart);
Status = LdrPEProcessImportDirectoryEntry(DllBase, ImportedModule, ImportModuleDirectory);
if (!NT_SUCCESS(Status)) return Status;
@ -574,7 +573,7 @@ FrLdrReMapImage(IN PVOID Base,
}
else
{
/* BSS */
/* Clear the BSS area */
RtlZeroMemory((PVOID)((ULONG_PTR)LoadBase +
Section[i].VirtualAddress),
Section[i].Misc.VirtualSize);
@ -595,6 +594,7 @@ FrLdrMapImage(IN FILE *Image,
PVOID ImageBase, LoadBase, ReadBuffer;
ULONG ImageId = LoaderBlock.ModsCount;
ULONG ImageSize;
NTSTATUS Status = STATUS_SUCCESS;
/* Set the virtual (image) and physical (load) addresses */
LoadBase = (PVOID)NextModuleBase;
@ -619,13 +619,19 @@ FrLdrMapImage(IN FILE *Image,
MmFreeMemory(ReadBuffer);
/* Calculate Difference between Real Base and Compiled Base*/
if (ImageType != 2) LdrRelocateImageWithBias(LoadBase,
(ULONG_PTR)ImageBase -
(ULONG_PTR)LoadBase,
"FreeLdr",
STATUS_SUCCESS,
STATUS_UNSUCCESSFUL,
STATUS_UNSUCCESSFUL);
Status = LdrRelocateImageWithBias(LoadBase,
(ULONG_PTR)ImageBase -
(ULONG_PTR)LoadBase,
"FreeLdr",
STATUS_SUCCESS,
STATUS_UNSUCCESSFUL,
STATUS_UNSUCCESSFUL);
if (!NT_SUCCESS(Status))
{
/* Fail */
DbgPrint("Failed to relocate image: %s\n", Name);
return NULL;
}
/* Fill out Module Data Structure */
reactos_modules[ImageId].ModStart = (ULONG_PTR)ImageBase;
@ -637,14 +643,11 @@ FrLdrMapImage(IN FILE *Image,
/* Increase the next Load Base */
NextModuleBase = ROUND_UP(NextModuleBase + ImageSize, PAGE_SIZE);
/* Successful load! */
//DbgPrint("Image: %s loaded at: %p\n", Name, ImageBase);
/* Load HAL if this is the kernel */
if (ImageType == 1) FrLdrLoadImage("hal.dll", 10, FALSE);
/* Perform import fixups */
if (ImageType != 2) LdrPEFixupImports(LoadBase, Name);
LdrPEFixupImports(LoadBase, Name);
/* Return the final mapped address */
return LoadBase;

View file

@ -157,7 +157,7 @@ IopDisplayLoadingMessage(PVOID ServiceName,
if (ExpInTextModeSetup) return;
if (Unicode)
{
if (wcsstr(ServiceName, L".sys")) Extra = "";
if (wcsstr(_wcsupr(ServiceName), L".SYS")) Extra = "";
sprintf(TextBuffer,
"%s%s%s\\%S%s\n",
KeLoaderBlock->ArcBootDeviceName,
@ -168,7 +168,7 @@ IopDisplayLoadingMessage(PVOID ServiceName,
}
else
{
if (strstr(ServiceName, ".sys")) Extra = "";
if (strstr(_strupr(ServiceName), ".SYS")) Extra = "";
sprintf(TextBuffer,
"%s%s%s\\%s%s\n",
KeLoaderBlock->ArcBootDeviceName,
@ -733,7 +733,6 @@ IopInitializeBuiltinDriver(IN PLDR_DATA_TABLE_ENTRY LdrEntry)
PLDR_DATA_TABLE_ENTRY ModuleObject;
#endif
/*
* Display 'Loading XXX...' message
*/
@ -887,7 +886,7 @@ IopInitializeBootDrivers(VOID)
* HACK: Make sure we're loading a driver
* (we should be using BootDriverListHead!)
*/
if (wcsstr(LdrEntry->BaseDllName.Buffer, L".sys"))
if (wcsstr(_wcsupr(LdrEntry->BaseDllName.Buffer), L".SYS"))
{
/* Make sure we didn't load this driver already */
if (!(LdrEntry->Flags & LDRP_ENTRY_INSERTED))

View file

@ -1221,7 +1221,9 @@ MiReloadBootLoadedDrivers(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
/* Sanity check */
ASSERT(*(PULONG)NewImageAddress == *(PULONG)DllBase);
/* Set the image base to the old address */
/* Set the image base to the address where the loader put it */
NtHeader->OptionalHeader.ImageBase = (ULONG_PTR)DllBase;
NtHeader = RtlImageNtHeader(NewImageAddress);
NtHeader->OptionalHeader.ImageBase = (ULONG_PTR)DllBase;
/* Check if we had relocations */