mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 09:34:43 +00:00
Fixed some unicode initialization bugs
svn path=/trunk/; revision=1020
This commit is contained in:
parent
c0ad0d9b02
commit
c37b4fd7f1
1 changed files with 63 additions and 74 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: loader.c,v 1.47 2000/02/25 00:32:04 ekohl Exp $
|
/* $Id: loader.c,v 1.48 2000/02/27 18:01:44 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -64,8 +64,8 @@ static NTSTATUS LdrCreateModule(PVOID ObjectBody,
|
||||||
|
|
||||||
/* PE Driver load support */
|
/* PE Driver load support */
|
||||||
static PMODULE_OBJECT LdrPEProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING ModuleName);
|
static PMODULE_OBJECT LdrPEProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING ModuleName);
|
||||||
static PVOID LdrPEGetExportAddress(PMODULE_OBJECT ModuleObject,
|
static PVOID LdrPEGetExportAddress(PMODULE_OBJECT ModuleObject,
|
||||||
char *Name,
|
char *Name,
|
||||||
unsigned short Hint);
|
unsigned short Hint);
|
||||||
#if 0
|
#if 0
|
||||||
static unsigned int LdrGetKernelSymbolAddr(char *Name);
|
static unsigned int LdrGetKernelSymbolAddr(char *Name);
|
||||||
|
@ -86,7 +86,7 @@ VOID LdrInitModuleManagement(VOID)
|
||||||
PIMAGE_DOS_HEADER DosHeader;
|
PIMAGE_DOS_HEADER DosHeader;
|
||||||
PMODULE_OBJECT ModuleObject;
|
PMODULE_OBJECT ModuleObject;
|
||||||
|
|
||||||
/* Register the process object type */
|
/* Register the process object type */
|
||||||
ObModuleType = ExAllocatePool(NonPagedPool, sizeof(OBJECT_TYPE));
|
ObModuleType = ExAllocatePool(NonPagedPool, sizeof(OBJECT_TYPE));
|
||||||
ObModuleType->TotalObjects = 0;
|
ObModuleType->TotalObjects = 0;
|
||||||
ObModuleType->TotalHandles = 0;
|
ObModuleType->TotalHandles = 0;
|
||||||
|
@ -109,12 +109,11 @@ VOID LdrInitModuleManagement(VOID)
|
||||||
/* Create Modules object directory */
|
/* Create Modules object directory */
|
||||||
wcscpy(NameBuffer, MODULE_ROOT_NAME);
|
wcscpy(NameBuffer, MODULE_ROOT_NAME);
|
||||||
*(wcsrchr(NameBuffer, L'\\')) = 0;
|
*(wcsrchr(NameBuffer, L'\\')) = 0;
|
||||||
ModuleName.Length = ModuleName.MaximumLength = wcslen(NameBuffer);
|
RtlInitUnicodeString (&ModuleName, NameBuffer);
|
||||||
ModuleName.Buffer = NameBuffer;
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
&ModuleName,
|
||||||
&ModuleName,
|
0,
|
||||||
0,
|
NULL,
|
||||||
NULL,
|
|
||||||
NULL);
|
NULL);
|
||||||
DPRINT("Create dir: %wZ\n", &ModuleName);
|
DPRINT("Create dir: %wZ\n", &ModuleName);
|
||||||
Status = ZwCreateDirectoryObject(&DirHandle, 0, &ObjectAttributes);
|
Status = ZwCreateDirectoryObject(&DirHandle, 0, &ObjectAttributes);
|
||||||
|
@ -123,15 +122,14 @@ VOID LdrInitModuleManagement(VOID)
|
||||||
/* Add module entry for NTOSKRNL */
|
/* Add module entry for NTOSKRNL */
|
||||||
wcscpy(NameBuffer, MODULE_ROOT_NAME);
|
wcscpy(NameBuffer, MODULE_ROOT_NAME);
|
||||||
wcscat(NameBuffer, L"ntoskrnl.exe");
|
wcscat(NameBuffer, L"ntoskrnl.exe");
|
||||||
ModuleName.Length = ModuleName.MaximumLength = wcslen(NameBuffer);
|
RtlInitUnicodeString (&ModuleName, NameBuffer);
|
||||||
ModuleName.Buffer = NameBuffer;
|
|
||||||
DPRINT("Kernel's Module name is: %wZ\n", &ModuleName);
|
DPRINT("Kernel's Module name is: %wZ\n", &ModuleName);
|
||||||
|
|
||||||
/* Initialize ObjectAttributes for ModuleObject */
|
/* Initialize ObjectAttributes for ModuleObject */
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
&ModuleName,
|
&ModuleName,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
/* Create module object */
|
/* Create module object */
|
||||||
|
@ -142,26 +140,26 @@ VOID LdrInitModuleManagement(VOID)
|
||||||
ObModuleType);
|
ObModuleType);
|
||||||
assert(ModuleObject != NULL);
|
assert(ModuleObject != NULL);
|
||||||
|
|
||||||
InitializeListHead(&ModuleListHead);
|
InitializeListHead(&ModuleListHead);
|
||||||
|
|
||||||
/* Initialize ModuleObject data */
|
/* Initialize ModuleObject data */
|
||||||
ModuleObject->Base = (PVOID) KERNEL_BASE;
|
ModuleObject->Base = (PVOID) KERNEL_BASE;
|
||||||
ModuleObject->Flags = MODULE_FLAG_PE;
|
ModuleObject->Flags = MODULE_FLAG_PE;
|
||||||
InsertTailList(&ModuleListHead, &ModuleObject->ListEntry);
|
InsertTailList(&ModuleListHead, &ModuleObject->ListEntry);
|
||||||
ModuleObject->Name = wcsdup(L"ntoskrnl.exe");
|
ModuleObject->Name = wcsdup(L"ntoskrnl.exe");
|
||||||
DosHeader = (PIMAGE_DOS_HEADER) KERNEL_BASE;
|
DosHeader = (PIMAGE_DOS_HEADER) KERNEL_BASE;
|
||||||
ModuleObject->Image.PE.FileHeader =
|
ModuleObject->Image.PE.FileHeader =
|
||||||
(PIMAGE_FILE_HEADER) ((DWORD) ModuleObject->Base +
|
(PIMAGE_FILE_HEADER) ((DWORD) ModuleObject->Base +
|
||||||
DosHeader->e_lfanew + sizeof(ULONG));
|
DosHeader->e_lfanew + sizeof(ULONG));
|
||||||
ModuleObject->Image.PE.OptionalHeader = (PIMAGE_OPTIONAL_HEADER)
|
ModuleObject->Image.PE.OptionalHeader = (PIMAGE_OPTIONAL_HEADER)
|
||||||
((DWORD)ModuleObject->Image.PE.FileHeader + sizeof(IMAGE_FILE_HEADER));
|
((DWORD)ModuleObject->Image.PE.FileHeader + sizeof(IMAGE_FILE_HEADER));
|
||||||
ModuleObject->Image.PE.SectionList = (PIMAGE_SECTION_HEADER)
|
ModuleObject->Image.PE.SectionList = (PIMAGE_SECTION_HEADER)
|
||||||
((DWORD)ModuleObject->Image.PE.OptionalHeader + sizeof(IMAGE_OPTIONAL_HEADER));
|
((DWORD)ModuleObject->Image.PE.OptionalHeader + sizeof(IMAGE_OPTIONAL_HEADER));
|
||||||
ModuleObject->EntryPoint = (PVOID) ((DWORD) ModuleObject->Base +
|
ModuleObject->EntryPoint = (PVOID) ((DWORD) ModuleObject->Base +
|
||||||
ModuleObject->Image.PE.OptionalHeader->AddressOfEntryPoint);
|
ModuleObject->Image.PE.OptionalHeader->AddressOfEntryPoint);
|
||||||
DPRINT("ModuleObject:%08x entrypoint at %x\n", ModuleObject, ModuleObject->EntryPoint);
|
DPRINT("ModuleObject:%08x entrypoint at %x\n", ModuleObject, ModuleObject->EntryPoint);
|
||||||
ModuleObject->Length = ModuleObject->Image.PE.OptionalHeader->SizeOfImage;
|
ModuleObject->Length = ModuleObject->Image.PE.OptionalHeader->SizeOfImage;
|
||||||
|
|
||||||
/* FIXME: Add fake module entry for HAL */
|
/* FIXME: Add fake module entry for HAL */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -174,18 +172,14 @@ static VOID LdrLoadAutoConfigDriver (LPWSTR RelativeDriverName)
|
||||||
WCHAR TmpFileName [MAX_PATH];
|
WCHAR TmpFileName [MAX_PATH];
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
UNICODE_STRING DriverName;
|
UNICODE_STRING DriverName;
|
||||||
|
|
||||||
DbgPrint("Loading %S\n",RelativeDriverName);
|
DbgPrint("Loading %S\n",RelativeDriverName);
|
||||||
|
|
||||||
LdrGetSystemDirectory(TmpFileName, (MAX_PATH * sizeof(WCHAR)));
|
LdrGetSystemDirectory(TmpFileName, (MAX_PATH * sizeof(WCHAR)));
|
||||||
wcscat(TmpFileName, L"\\drivers\\");
|
wcscat(TmpFileName, L"\\drivers\\");
|
||||||
wcscat(TmpFileName, RelativeDriverName);
|
wcscat(TmpFileName, RelativeDriverName);
|
||||||
|
RtlInitUnicodeString (&DriverName, TmpFileName);
|
||||||
|
|
||||||
DriverName.Buffer = TmpFileName;
|
|
||||||
DriverName.Length = wcslen(TmpFileName) * sizeof (WCHAR);
|
|
||||||
DriverName.MaximumLength = DriverName.Length + sizeof(WCHAR);
|
|
||||||
|
|
||||||
|
|
||||||
Status = LdrLoadDriver(&DriverName);
|
Status = LdrLoadDriver(&DriverName);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
|
@ -223,8 +217,8 @@ LdrCreateModule(PVOID ObjectBody,
|
||||||
POBJECT_ATTRIBUTES ObjectAttributes)
|
POBJECT_ATTRIBUTES ObjectAttributes)
|
||||||
{
|
{
|
||||||
DPRINT("LdrCreateModule(ObjectBody %x, Parent %x, RemainingPath %S)\n",
|
DPRINT("LdrCreateModule(ObjectBody %x, Parent %x, RemainingPath %S)\n",
|
||||||
ObjectBody,
|
ObjectBody,
|
||||||
Parent,
|
Parent,
|
||||||
RemainingPath);
|
RemainingPath);
|
||||||
if (RemainingPath != NULL && wcschr(RemainingPath + 1, '\\') != NULL)
|
if (RemainingPath != NULL && wcschr(RemainingPath + 1, '\\') != NULL)
|
||||||
{
|
{
|
||||||
|
@ -257,10 +251,10 @@ NTSTATUS LdrLoadDriver(PUNICODE_STRING Filename)
|
||||||
|
|
||||||
/* FIXME: should we dereference the ModuleObject here? */
|
/* FIXME: should we dereference the ModuleObject here? */
|
||||||
|
|
||||||
return IoInitializeDriver(ModuleObject->EntryPoint);
|
return IoInitializeDriver(ModuleObject->EntryPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
PMODULE_OBJECT
|
PMODULE_OBJECT
|
||||||
LdrLoadModule(PUNICODE_STRING Filename)
|
LdrLoadModule(PUNICODE_STRING Filename)
|
||||||
{
|
{
|
||||||
PVOID ModuleLoadBase;
|
PVOID ModuleLoadBase;
|
||||||
|
@ -283,14 +277,14 @@ LdrLoadModule(PUNICODE_STRING Filename)
|
||||||
|
|
||||||
/* Open the Module */
|
/* Open the Module */
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
Filename,
|
Filename,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
Status = ZwOpenFile(&FileHandle,
|
Status = ZwOpenFile(&FileHandle,
|
||||||
FILE_ALL_ACCESS,
|
FILE_ALL_ACCESS,
|
||||||
&ObjectAttributes,
|
&ObjectAttributes,
|
||||||
NULL, 0, 0);
|
NULL, 0, 0);
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
|
@ -351,10 +345,8 @@ LdrLoadModule(PUNICODE_STRING Filename)
|
||||||
{
|
{
|
||||||
wcscat(NameBuffer, Filename->Buffer);
|
wcscat(NameBuffer, Filename->Buffer);
|
||||||
}
|
}
|
||||||
ModuleName.Length = ModuleName.MaximumLength = wcslen(NameBuffer);
|
RtlInitUnicodeString (&ModuleName, NameBuffer);
|
||||||
ModuleName.Buffer = NameBuffer;
|
|
||||||
|
|
||||||
|
|
||||||
ModuleObject = LdrProcessModule(ModuleLoadBase, &ModuleName);
|
ModuleObject = LdrProcessModule(ModuleLoadBase, &ModuleName);
|
||||||
|
|
||||||
/* Cleanup */
|
/* Cleanup */
|
||||||
|
@ -423,8 +415,7 @@ LdrOpenModule(PUNICODE_STRING Filename)
|
||||||
{
|
{
|
||||||
wcscat(NameBuffer, Filename->Buffer);
|
wcscat(NameBuffer, Filename->Buffer);
|
||||||
}
|
}
|
||||||
ModuleName.Length = ModuleName.MaximumLength = wcslen(NameBuffer);
|
RtlInitUnicodeString (&ModuleName, NameBuffer);
|
||||||
ModuleName.Buffer = NameBuffer;
|
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
&ModuleName,
|
&ModuleName,
|
||||||
0,
|
0,
|
||||||
|
@ -444,9 +435,9 @@ LdrOpenModule(PUNICODE_STRING Filename)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PVOID
|
PVOID
|
||||||
LdrGetExportAddress(PMODULE_OBJECT ModuleObject,
|
LdrGetExportAddress(PMODULE_OBJECT ModuleObject,
|
||||||
char *Name,
|
char *Name,
|
||||||
unsigned short Hint)
|
unsigned short Hint)
|
||||||
{
|
{
|
||||||
if (ModuleObject->Flags & MODULE_FLAG_PE)
|
if (ModuleObject->Flags & MODULE_FLAG_PE)
|
||||||
|
@ -539,10 +530,9 @@ LdrPEProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING pModuleName)
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
|
|
||||||
/* Determine the size of the module */
|
/* Determine the size of the module */
|
||||||
|
DriverSize = PEOptionalHeader->SizeOfImage;
|
||||||
DriverSize = PEOptionalHeader->SizeOfImage;
|
DPRINT("DriverSize %x\n",DriverSize);
|
||||||
DPRINT("DriverSize %x\n",DriverSize);
|
|
||||||
|
|
||||||
/* Allocate a virtual section for the module */
|
/* Allocate a virtual section for the module */
|
||||||
DriverBase = MmAllocateSection(DriverSize);
|
DriverBase = MmAllocateSection(DriverSize);
|
||||||
if (DriverBase == 0)
|
if (DriverBase == 0)
|
||||||
|
@ -678,8 +668,7 @@ LdrPEProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING pModuleName)
|
||||||
NameBuffer[Idx + Idx2] = (WCHAR) pName[Idx2];
|
NameBuffer[Idx + Idx2] = (WCHAR) pName[Idx2];
|
||||||
}
|
}
|
||||||
NameBuffer[Idx + Idx2] = 0;
|
NameBuffer[Idx + Idx2] = 0;
|
||||||
ModuleName.Length = ModuleName.MaximumLength = wcslen(NameBuffer);
|
RtlInitUnicodeString (&ModuleName, NameBuffer);
|
||||||
ModuleName.Buffer = NameBuffer;
|
|
||||||
DPRINT("Import module: %wZ\n", &ModuleName);
|
DPRINT("Import module: %wZ\n", &ModuleName);
|
||||||
|
|
||||||
LibraryModuleObject = LdrLoadModule(&ModuleName);
|
LibraryModuleObject = LdrLoadModule(&ModuleName);
|
||||||
|
@ -729,7 +718,7 @@ LdrPEProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING pModuleName)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DbgPrint("Unresolved kernel symbol: %s\n", pName);
|
DbgPrint("Unresolved kernel symbol: %s\n", pName);
|
||||||
}
|
}
|
||||||
ImportAddressList++;
|
ImportAddressList++;
|
||||||
FunctionNameList++;
|
FunctionNameList++;
|
||||||
|
@ -768,15 +757,14 @@ LdrPEProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING pModuleName)
|
||||||
Idx2++;
|
Idx2++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ModuleName.Length = ModuleName.MaximumLength = wcslen(NameBuffer);
|
RtlInitUnicodeString (&ModuleName, NameBuffer);
|
||||||
ModuleName.Buffer = NameBuffer;
|
|
||||||
DbgPrint("Module name is: %wZ\n", &ModuleName);
|
DbgPrint("Module name is: %wZ\n", &ModuleName);
|
||||||
|
|
||||||
/* Initialize ObjectAttributes for ModuleObject */
|
/* Initialize ObjectAttributes for ModuleObject */
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
&ModuleName,
|
&ModuleName,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
/* Create module object */
|
/* Create module object */
|
||||||
|
@ -790,10 +778,10 @@ LdrPEProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING pModuleName)
|
||||||
ModuleObject->Base = DriverBase;
|
ModuleObject->Base = DriverBase;
|
||||||
ModuleObject->Flags = MODULE_FLAG_PE;
|
ModuleObject->Flags = MODULE_FLAG_PE;
|
||||||
InsertTailList(&ModuleListHead, &ModuleObject->ListEntry);
|
InsertTailList(&ModuleListHead, &ModuleObject->ListEntry);
|
||||||
ModuleObject->Name = wcsdup(NameBuffer);
|
ModuleObject->Name = wcsdup(NameBuffer);
|
||||||
ModuleObject->EntryPoint = (PVOID) ((DWORD)DriverBase +
|
ModuleObject->EntryPoint = (PVOID) ((DWORD)DriverBase +
|
||||||
PEOptionalHeader->AddressOfEntryPoint);
|
PEOptionalHeader->AddressOfEntryPoint);
|
||||||
ModuleObject->Length = DriverSize;
|
ModuleObject->Length = DriverSize;
|
||||||
DPRINT("entrypoint at %x\n", ModuleObject->EntryPoint);
|
DPRINT("entrypoint at %x\n", ModuleObject->EntryPoint);
|
||||||
|
|
||||||
ModuleObject->Image.PE.FileHeader =
|
ModuleObject->Image.PE.FileHeader =
|
||||||
|
@ -813,8 +801,8 @@ LdrPEProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING pModuleName)
|
||||||
}
|
}
|
||||||
|
|
||||||
static PVOID
|
static PVOID
|
||||||
LdrPEGetExportAddress(PMODULE_OBJECT ModuleObject,
|
LdrPEGetExportAddress(PMODULE_OBJECT ModuleObject,
|
||||||
char *Name,
|
char *Name,
|
||||||
unsigned short Hint)
|
unsigned short Hint)
|
||||||
{
|
{
|
||||||
WORD Idx;
|
WORD Idx;
|
||||||
|
@ -877,10 +865,9 @@ LdrPEGetExportAddress(PMODULE_OBJECT ModuleObject,
|
||||||
if (ExportAddress == 0)
|
if (ExportAddress == 0)
|
||||||
{
|
{
|
||||||
DbgPrint("Export not found for %d:%s\n", Hint, Name != NULL ? Name : "(Ordinal)");
|
DbgPrint("Export not found for %d:%s\n", Hint, Name != NULL ? Name : "(Ordinal)");
|
||||||
for(;;) ;
|
for(;;) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return ExportAddress;
|
return ExportAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -901,6 +888,8 @@ LdrPEGetEnclosingSectionHeader(DWORD RVA,
|
||||||
return SectionHeader;
|
return SectionHeader;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* EOF */
|
||||||
|
|
Loading…
Reference in a new issue