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
This commit is contained in:
Eric Kohl 2002-06-10 23:04:48 +00:00
parent 0ddc3e2715
commit 6ac81e7954
5 changed files with 114 additions and 131 deletions

View file

@ -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

View file

@ -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,22 +228,59 @@ 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),
@ -251,7 +288,7 @@ IopCreateDriverObject(PDRIVER_OBJECT *DriverObject)
if (Object->DriverExtension == NULL)
{
ExFreePool(Object);
return STATUS_INSUFFICIENT_RESOURCES;
return(STATUS_INSUFFICIENT_RESOURCES);
}
RtlZeroMemory(Object->DriverExtension, sizeof(DRIVER_EXTENSION));
@ -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);

View file

@ -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;

View file

@ -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");

View file

@ -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,42 +176,12 @@ 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));
@ -242,29 +212,6 @@ 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));
@ -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,13 +1362,11 @@ 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;
WCHAR NameBuffer[60];
MODULE_TEXT_SECTION* ModuleTextSection;
@ -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);
@ -2058,7 +2003,7 @@ LdrPEGetExportAddress(PMODULE_OBJECT ModuleObject,
KeBugCheck(0);
}
return ExportAddress;
return(ExportAddress);
}
@ -2117,7 +2062,7 @@ LdrSafePEGetExportAddress(PVOID ImportModuleBase,
ps("Export not found for %d:%s\n",
Hint,
Name != NULL ? Name : "(Ordinal)");
for (;;);
KeBugCheck(0);
}
return ExportAddress;
}