From 6ac81e79549bc3f32e31b7bfdbeeff60c8232bac Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Mon, 10 Jun 2002 23:04:48 +0000 Subject: [PATCH] Changed data structure which represents driver objects from MODULE_OBJECT to DRIVER_OBJECT. Now a DriverEntry's RegistryPath string is usable automagically. svn path=/trunk/; revision=3044 --- reactos/ntoskrnl/include/internal/io.h | 7 +- reactos/ntoskrnl/io/device.c | 61 +++++++-- reactos/ntoskrnl/io/driver.c | 6 +- reactos/ntoskrnl/io/pnpmgr.c | 4 +- reactos/ntoskrnl/ldr/loader.c | 167 +++++++++---------------- 5 files changed, 114 insertions(+), 131 deletions(-) diff --git a/reactos/ntoskrnl/include/internal/io.h b/reactos/ntoskrnl/include/internal/io.h index df82c10adc7..8a690f92c5a 100644 --- a/reactos/ntoskrnl/include/internal/io.h +++ b/reactos/ntoskrnl/include/internal/io.h @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: io.h,v 1.20 2002/06/10 08:46:06 ekohl Exp $ +/* $Id: io.h,v 1.21 2002/06/10 23:02:44 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -250,9 +250,10 @@ IopInterrogateBusExtender(PDEVICE_NODE DeviceNode, BOOLEAN BootDriversOnly); VOID IopLoadBootStartDrivers(VOID); - NTSTATUS -IopCreateDriverObject(PDRIVER_OBJECT *DriverObject); +IopCreateDriverObject(PDRIVER_OBJECT *DriverObject, + PUNICODE_STRING ServiceName, + BOOLEAN FileSystem); NTSTATUS IopInitializeDeviceNodeService(PDEVICE_NODE DeviceNode); NTSTATUS diff --git a/reactos/ntoskrnl/io/device.c b/reactos/ntoskrnl/io/device.c index 526816ea3d6..aba2f1f4986 100644 --- a/reactos/ntoskrnl/io/device.c +++ b/reactos/ntoskrnl/io/device.c @@ -1,4 +1,4 @@ -/* $Id: device.c,v 1.42 2002/06/10 08:47:20 ekohl Exp $ +/* $Id: device.c,v 1.43 2002/06/10 23:03:33 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -228,30 +228,67 @@ IopDefaultDispatchFunction(PDEVICE_OBJECT DeviceObject, return(STATUS_NOT_IMPLEMENTED); } + NTSTATUS -IopCreateDriverObject(PDRIVER_OBJECT *DriverObject) +IopCreateDriverObject(PDRIVER_OBJECT *DriverObject, + PUNICODE_STRING ServiceName, + BOOLEAN FileSystem) { PDRIVER_OBJECT Object; + HANDLE DriverHandle = 0; ULONG i; + WCHAR NameBuffer[MAX_PATH]; + UNICODE_STRING DriverName; + OBJECT_ATTRIBUTES ObjectAttributes; + NTSTATUS Status; - Object = ExAllocatePoolWithTag(NonPagedPool, - sizeof(DRIVER_OBJECT), - TAG_DRIVER); - if (Object == NULL) + DPRINT1("IopCreateDriverObject(%p '%wZ' %x)\n", DriverObject, ServiceName, FileSystem); + + *DriverObject = NULL; + + /* Create ModuleName string */ + if (ServiceName != NULL) { - return STATUS_INSUFFICIENT_RESOURCES; + if (FileSystem) + wcscpy(NameBuffer, FILESYSTEM_ROOT_NAME); + else + wcscpy(NameBuffer, DRIVER_ROOT_NAME); + wcscat(NameBuffer, ServiceName->Buffer); + + RtlInitUnicodeString(&DriverName, + NameBuffer); + DPRINT1("Driver name: '%wZ'\n", &DriverName); } - RtlZeroMemory(Object, sizeof(DRIVER_OBJECT)); + /* Initialize ObjectAttributes for ModuleObject */ + InitializeObjectAttributes(&ObjectAttributes, + (ServiceName != NULL)? &DriverName : NULL, + OBJ_PERMANENT, + NULL, + NULL); + /* Create module object */ + Status = ObCreateObject(&DriverHandle, + STANDARD_RIGHTS_REQUIRED, + &ObjectAttributes, + IoDriverObjectType, + (PVOID*)&Object); + if (!NT_SUCCESS(Status)) + { + return(Status); + } + + NtClose(DriverHandle); + + /* Create driver extension */ Object->DriverExtension = (PDRIVER_EXTENSION) ExAllocatePoolWithTag(NonPagedPool, sizeof(DRIVER_EXTENSION), TAG_DRIVER_EXTENSION); if (Object->DriverExtension == NULL) { - ExFreePool(Object); - return STATUS_INSUFFICIENT_RESOURCES; + ExFreePool(Object); + return(STATUS_INSUFFICIENT_RESOURCES); } RtlZeroMemory(Object->DriverExtension, sizeof(DRIVER_EXTENSION)); @@ -260,7 +297,7 @@ IopCreateDriverObject(PDRIVER_OBJECT *DriverObject) for (i=0; i<=IRP_MJ_MAXIMUM_FUNCTION; i++) { - Object->MajorFunction[i] = (PDRIVER_DISPATCH) IopDefaultDispatchFunction; + Object->MajorFunction[i] = (PDRIVER_DISPATCH) IopDefaultDispatchFunction; } *DriverObject = Object; @@ -465,7 +502,7 @@ IopInitializeDriver(PDRIVER_INITIALIZE DriverEntry, DPRINT("IopInitializeDriver(DriverEntry %08lx, DeviceNode %08lx)\n", DriverEntry, DeviceNode); - Status = IopCreateDriverObject(&DriverObject); + Status = IopCreateDriverObject(&DriverObject, &DeviceNode->ServiceName, FALSE); if (!NT_SUCCESS(Status)) { return(Status); diff --git a/reactos/ntoskrnl/io/driver.c b/reactos/ntoskrnl/io/driver.c index 1ba889481c9..fce20353bb5 100644 --- a/reactos/ntoskrnl/io/driver.c +++ b/reactos/ntoskrnl/io/driver.c @@ -1,4 +1,4 @@ -/* $Id: driver.c,v 1.1 2002/06/10 08:47:21 ekohl Exp $ +/* $Id: driver.c,v 1.2 2002/06/10 23:03:33 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -61,13 +61,13 @@ IopInitDriverImplementation(VOID) { /* Register the process object type */ IoDriverObjectType = ExAllocatePool(NonPagedPool, sizeof(OBJECT_TYPE)); - IoDriverObjectType->Tag = TAG('D', 'R', 'V', 'T'); + IoDriverObjectType->Tag = TAG('D', 'R', 'V', 'R'); IoDriverObjectType->TotalObjects = 0; IoDriverObjectType->TotalHandles = 0; IoDriverObjectType->MaxObjects = ULONG_MAX; IoDriverObjectType->MaxHandles = ULONG_MAX; IoDriverObjectType->PagedPoolCharge = 0; - IoDriverObjectType->NonpagedPoolCharge = sizeof(MODULE); + IoDriverObjectType->NonpagedPoolCharge = sizeof(DRIVER_OBJECT); IoDriverObjectType->Dump = NULL; IoDriverObjectType->Open = NULL; IoDriverObjectType->Close = NULL; diff --git a/reactos/ntoskrnl/io/pnpmgr.c b/reactos/ntoskrnl/io/pnpmgr.c index 4ba7942e469..14b1378a208 100644 --- a/reactos/ntoskrnl/io/pnpmgr.c +++ b/reactos/ntoskrnl/io/pnpmgr.c @@ -1,4 +1,4 @@ -/* $Id: pnpmgr.c,v 1.4 2001/09/16 13:19:32 chorns Exp $ +/* $Id: pnpmgr.c,v 1.5 2002/06/10 23:03:33 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -1160,7 +1160,7 @@ VOID PnpInit(VOID) KeInitializeSpinLock(&IopDeviceTreeLock); - Status = IopCreateDriverObject(&IopRootDriverObject); + Status = IopCreateDriverObject(&IopRootDriverObject, NULL, FALSE); if (!NT_SUCCESS(Status)) { CPRINT("IoCreateDriverObject() failed\n"); diff --git a/reactos/ntoskrnl/ldr/loader.c b/reactos/ntoskrnl/ldr/loader.c index 1d1c0bc4d2b..a1540d79dec 100644 --- a/reactos/ntoskrnl/ldr/loader.c +++ b/reactos/ntoskrnl/ldr/loader.c @@ -1,4 +1,4 @@ -/* $Id: loader.c,v 1.106 2002/06/10 08:50:29 ekohl Exp $ +/* $Id: loader.c,v 1.107 2002/06/10 23:04:48 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -176,47 +176,17 @@ LdrInitModuleManagement(VOID) { PIMAGE_DOS_HEADER DosHeader; PMODULE_OBJECT ModuleObject; -#if 0 - HANDLE ModuleHandle; - NTSTATUS Status; - WCHAR NameBuffer[60]; - UNICODE_STRING ModuleName; - OBJECT_ATTRIBUTES ObjectAttributes; -#endif /* Initialize the module list and spinlock */ InitializeListHead(&ModuleListHead); KeInitializeSpinLock(&ModuleListLock); /* Create module object for NTOSKRNL */ -#if 0 - wcscpy(NameBuffer, DRIVER_ROOT_NAME); - wcscat(NameBuffer, KERNEL_MODULE_NAME); - RtlInitUnicodeString (&ModuleName, NameBuffer); - DPRINT("Kernel's Module name is: %wZ\n", &ModuleName); - - /* Initialize ObjectAttributes for ModuleObject */ - InitializeObjectAttributes(&ObjectAttributes, - &ModuleName, - 0, - NULL, - NULL); - - /* Create module object */ - ModuleHandle = 0; - Status = ObCreateObject(&ModuleHandle, - STANDARD_RIGHTS_REQUIRED, - &ObjectAttributes, - IoDriverObjectType, - (PVOID*)&ModuleObject); - assert(NT_SUCCESS(Status)); -#endif - ModuleObject = ExAllocatePool(NonPagedPool, sizeof(MODULE_OBJECT)); assert(ModuleObject != NULL); RtlZeroMemory(ModuleObject, sizeof(MODULE_OBJECT)); - /* Initialize ModuleObject data */ + /* Initialize ModuleObject data */ ModuleObject->Base = (PVOID) KERNEL_BASE; ModuleObject->Flags = MODULE_FLAG_PE; RtlCreateUnicodeString(&ModuleObject->FullName, @@ -242,34 +212,11 @@ LdrInitModuleManagement(VOID) &ModuleObject->ListEntry); /* Create module object for HAL */ -#if 0 - wcscpy(NameBuffer, DRIVER_ROOT_NAME); - wcscat(NameBuffer, HAL_MODULE_NAME); - RtlInitUnicodeString (&ModuleName, NameBuffer); - DPRINT("HAL's Module name is: %wZ\n", &ModuleName); - - /* Initialize ObjectAttributes for ModuleObject */ - InitializeObjectAttributes(&ObjectAttributes, - &ModuleName, - 0, - NULL, - NULL); - - /* Create module object */ - ModuleHandle = 0; - Status = ObCreateObject(&ModuleHandle, - STANDARD_RIGHTS_REQUIRED, - &ObjectAttributes, - IoDriverObjectType, - (PVOID*)&ModuleObject); - assert(NT_SUCCESS(Status)); -#endif - ModuleObject = ExAllocatePool(NonPagedPool, sizeof(MODULE_OBJECT)); assert(ModuleObject != NULL); RtlZeroMemory(ModuleObject, sizeof(MODULE_OBJECT)); - /* Initialize ModuleObject data */ + /* Initialize ModuleObject data */ ModuleObject->Base = (PVOID) LdrHalBase; ModuleObject->Flags = MODULE_FLAG_PE; @@ -1044,7 +991,12 @@ LdrInitializeBootStartDriver(PVOID ModuleLoadBase, PDEVICE_NODE DeviceNode; NTSTATUS Status; - CHAR Buffer [256]; + WCHAR Buffer[MAX_PATH]; + ULONG Length; + LPWSTR Start; + LPWSTR Ext; + + CHAR TextBuffer [256]; ULONG x, y, cx, cy; #ifdef KDBG @@ -1056,14 +1008,14 @@ LdrInitializeBootStartDriver(PVOID ModuleLoadBase, #endif HalQueryDisplayParameters(&x, &y, &cx, &cy); - RtlFillMemory(Buffer, x, ' '); - Buffer[x] = '\0'; + RtlFillMemory(TextBuffer, x, ' '); + TextBuffer[x] = '\0'; HalSetDisplayParameters(0, y-1); - HalDisplayString(Buffer); + HalDisplayString(TextBuffer); - sprintf(Buffer, "Initializing %s...\n", FileName); + sprintf(TextBuffer, "Initializing %s...\n", FileName); HalSetDisplayParameters(0, y-1); - HalDisplayString(Buffer); + HalDisplayString(TextBuffer); HalSetDisplayParameters(cx, cy); #ifdef KDBG @@ -1136,6 +1088,24 @@ LdrInitializeBootStartDriver(PVOID ModuleLoadBase, return(STATUS_UNSUCCESSFUL); } + + /* Get the service name from the module name */ + Start = wcsrchr(ModuleObject->BaseName.Buffer, L'\\'); + if (Start == NULL) + Start = ModuleObject->BaseName.Buffer; + else + Start++; + + Ext = wcsrchr(ModuleObject->BaseName.Buffer, L'.'); + if (Ext != NULL) + Length = Ext - Start; + else + Length = wcslen(Start); + + wcsncpy(Buffer, Start, Length); + RtlInitUnicodeString(&DeviceNode->ServiceName, Buffer); + + Status = IopInitializeDriver(ModuleObject->EntryPoint, DeviceNode); if (!NT_SUCCESS(Status)) { @@ -1392,14 +1362,12 @@ LdrPEProcessModule(PVOID ModuleLoadBase, PRELOCATION_DIRECTORY RelocDir; PRELOCATION_ENTRY RelocEntry; PMODULE_OBJECT LibraryModuleObject; - HANDLE ModuleHandle; PMODULE_OBJECT CreatedModuleObject; PVOID *ImportAddressList; PULONG FunctionNameList; PCHAR pName; WORD Hint; - OBJECT_ATTRIBUTES ObjectAttributes; - UNICODE_STRING ModuleName; + UNICODE_STRING ModuleName; WCHAR NameBuffer[60]; MODULE_TEXT_SECTION* ModuleTextSection; NTSTATUS Status; @@ -1654,37 +1622,14 @@ LdrPEProcessModule(PVOID ModuleLoadBase, } } - /* Create ModuleName string */ - wcscpy(NameBuffer, DRIVER_ROOT_NAME); - if (wcsrchr(FileName->Buffer, '\\') != 0) + /* Create the module */ + CreatedModuleObject = ExAllocatePool(NonPagedPool, sizeof(MODULE_OBJECT)); + if (CreatedModuleObject == NULL) { - wcscat(NameBuffer, wcsrchr(FileName->Buffer, '\\') + 1); + return(STATUS_INSUFFICIENT_RESOURCES); } - else - { - wcscat(NameBuffer, FileName->Buffer); - } - RtlInitUnicodeString (&ModuleName, NameBuffer); - CPRINT("Module name is: %wZ\n", &ModuleName); - /* Initialize ObjectAttributes for ModuleObject */ - InitializeObjectAttributes(&ObjectAttributes, - &ModuleName, - 0, - NULL, - NULL); - - /* Create module object */ - ModuleHandle = 0; - Status = ObCreateObject(&ModuleHandle, - STANDARD_RIGHTS_REQUIRED, - &ObjectAttributes, - IoDriverObjectType, - (PVOID*)&CreatedModuleObject); - if (!NT_SUCCESS(Status)) - { - return(Status); - } + RtlZeroMemory(CreatedModuleObject, sizeof(MODULE_OBJECT)); /* Initialize ModuleObject data */ CreatedModuleObject->Base = DriverBase; @@ -1695,7 +1640,7 @@ LdrPEProcessModule(PVOID ModuleLoadBase, LdrpBuildModuleBaseName(&CreatedModuleObject->BaseName, &CreatedModuleObject->FullName); - CreatedModuleObject->EntryPoint = (PVOID) ((DWORD)DriverBase + + CreatedModuleObject->EntryPoint = (PVOID)((DWORD)DriverBase + PEOptionalHeader->AddressOfEntryPoint); CreatedModuleObject->Length = DriverSize; DPRINT("EntryPoint at %x\n", CreatedModuleObject->EntryPoint); @@ -1736,13 +1681,13 @@ LdrPEProcessModule(PVOID ModuleLoadBase, *ModuleObject = CreatedModuleObject; - DPRINT("Loading Module %wZ...\n", FileName); + DPRINT("Loading Module %wZ...\n", FileName); if ((KdDebuggerEnabled == TRUE) && (KdDebugState & KD_DEBUG_GDB)) - { - DbgPrint("Module %wZ loaded at 0x%.08x.\n", - FileName, CreatedModuleObject->Base); - } + { + DbgPrint("Module %wZ loaded at 0x%.08x.\n", + FileName, CreatedModuleObject->Base); + } return STATUS_SUCCESS; } @@ -2050,15 +1995,15 @@ LdrPEGetExportAddress(PMODULE_OBJECT ModuleObject, FunctionList[Hint - ExportDir->Base]); } - if (ExportAddress == 0) - { - CPRINT("Export not found for %d:%s\n", - Hint, - Name != NULL ? Name : "(Ordinal)"); - KeBugCheck(0); - } + if (ExportAddress == 0) + { + CPRINT("Export not found for %d:%s\n", + Hint, + Name != NULL ? Name : "(Ordinal)"); + KeBugCheck(0); + } - return ExportAddress; + return(ExportAddress); } @@ -2114,10 +2059,10 @@ LdrSafePEGetExportAddress(PVOID ImportModuleBase, if (ExportAddress == 0) { - ps("Export not found for %d:%s\n", - Hint, - Name != NULL ? Name : "(Ordinal)"); - for (;;); + ps("Export not found for %d:%s\n", + Hint, + Name != NULL ? Name : "(Ordinal)"); + KeBugCheck(0); } return ExportAddress; }