Moved io/drvlck.c to mm.

Minimize access to the module object via the object manager.
Use module list for internal module management.
Protect module list with a spinlock.

svn path=/trunk/; revision=3031
This commit is contained in:
Eric Kohl 2002-06-10 08:50:55 +00:00
parent c9e12ce035
commit c4d4559cce
9 changed files with 752 additions and 790 deletions

View file

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.69 2002/06/05 16:53:36 ekohl Exp $ # $Id: Makefile,v 1.70 2002/06/10 08:45:40 ekohl Exp $
# #
# ReactOS Operating System # ReactOS Operating System
# #
@ -132,6 +132,7 @@ OBJECTS_KE = \
OBJECTS_MM = \ OBJECTS_MM = \
mm/aspace.o \ mm/aspace.o \
mm/cont.o \ mm/cont.o \
mm/drvlck.o \
mm/freelist.o \ mm/freelist.o \
mm/iospace.o \ mm/iospace.o \
mm/marea.o \ mm/marea.o \
@ -159,7 +160,7 @@ OBJECTS_MM = \
# I/O Subsystem (Io) # I/O Subsystem (Io)
OBJECTS_IO = \ OBJECTS_IO = \
io/adapter.o \ io/adapter.o \
io/arcname.o \ io/arcname.o \
io/buildirp.o \ io/buildirp.o \
io/cancel.o \ io/cancel.o \
io/cleanup.o \ io/cleanup.o \
@ -167,7 +168,7 @@ OBJECTS_IO = \
io/create.o \ io/create.o \
io/device.o \ io/device.o \
io/dir.o \ io/dir.o \
io/drvlck.o \ io/driver.o \
io/errlog.o \ io/errlog.o \
io/error.o \ io/error.o \
io/event.o \ io/event.o \

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: io.h,v 1.19 2002/05/15 09:38:35 ekohl Exp $ /* $Id: io.h,v 1.20 2002/06/10 08:46:06 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -233,6 +233,9 @@ extern POBJECT_TYPE IoSymbolicLinkType;
VOID VOID
PnpInit(VOID); PnpInit(VOID);
VOID
IopInitDriverImplementation(VOID);
NTSTATUS NTSTATUS
IopGetSystemPowerDeviceObject(PDEVICE_OBJECT *DeviceObject); IopGetSystemPowerDeviceObject(PDEVICE_OBJECT *DeviceObject);
NTSTATUS NTSTATUS

View file

@ -15,15 +15,10 @@
#define KERNEL_MODULE_NAME L"ntoskrnl.exe" #define KERNEL_MODULE_NAME L"ntoskrnl.exe"
#define HAL_MODULE_NAME L"hal.dll" #define HAL_MODULE_NAME L"hal.dll"
#define MODULE_ROOT_NAME L"\\Modules\\" #define DRIVER_ROOT_NAME L"\\Driver\\"
#define FILESYSTEM_ROOT_NAME L"\\FileSystem\\" #define FILESYSTEM_ROOT_NAME L"\\FileSystem\\"
NTSTATUS
LdrLoadDriver (
PUNICODE_STRING Filename,
PDEVICE_NODE DeviceNode,
BOOLEAN BootDriversOnly
);
NTSTATUS NTSTATUS
LdrLoadInitialProcess ( LdrLoadInitialProcess (
VOID VOID
@ -36,12 +31,12 @@ VOID
LdrInitModuleManagement ( LdrInitModuleManagement (
VOID VOID
); );
NTSTATUS NTSTATUS
LdrProcessDriver ( LdrInitializeBootStartDriver(IN PVOID ModuleLoadBase,
IN PVOID ModuleLoadBase, IN PCHAR FileName,
IN PCHAR FileName, IN ULONG ModuleLength);
IN ULONG ModuleLength
);
NTSTATUS NTSTATUS
LdrpMapSystemDll ( LdrpMapSystemDll (
HANDLE ProcessHandle, HANDLE ProcessHandle,
@ -102,11 +97,8 @@ NTSTATUS
LdrLoadModule(PUNICODE_STRING Filename, LdrLoadModule(PUNICODE_STRING Filename,
PMODULE_OBJECT *ModuleObject); PMODULE_OBJECT *ModuleObject);
NTSTATUS PMODULE_OBJECT
LdrFindModuleObject(PUNICODE_STRING ModuleName, LdrGetModuleObject(PUNICODE_STRING ModuleName);
PMODULE_OBJECT *ModuleObject);
NTSTATUS LdrpOpenModuleDirectory(PHANDLE Handle);
extern ULONG_PTR LdrHalBase; extern ULONG_PTR LdrHalBase;

View file

@ -1,4 +1,4 @@
/* $Id: device.c,v 1.41 2002/05/16 06:40:29 ekohl Exp $ /* $Id: device.c,v 1.42 2002/06/10 08:47:20 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -34,64 +34,9 @@
/* FUNCTIONS ***************************************************************/ /* FUNCTIONS ***************************************************************/
NTSTATUS STDCALL
NTSTATUS STDCALL NtUnloadDriver(IN PUNICODE_STRING DriverServiceName) IoAttachDeviceByPointer(IN PDEVICE_OBJECT SourceDevice,
{ IN PDEVICE_OBJECT TargetDevice)
UNIMPLEMENTED;
}
/**********************************************************************
* NAME EXPORTED
* NtLoadDriver
*
* DESCRIPTION
* Loads a device driver.
*
* ARGUMENTS
* DriverServiceName
* Name of the service to load (registry key).
*
* RETURN VALUE
* Status.
*
* REVISIONS
*/
NTSTATUS
STDCALL
NtLoadDriver (
PUNICODE_STRING DriverServiceName
)
{
PDEVICE_NODE DeviceNode;
NTSTATUS Status;
/* FIXME: this should lookup the filename from the registry and then call LdrLoadDriver */
/* Use IopRootDeviceNode for now */
Status = IopCreateDeviceNode(IopRootDeviceNode, NULL, &DeviceNode);
if (!NT_SUCCESS(Status))
{
return(Status);
}
Status = LdrLoadDriver (DriverServiceName, DeviceNode, FALSE);
if (!NT_SUCCESS(Status))
{
IopFreeDeviceNode(DeviceNode);
DPRINT("Driver load failed, status (%x)\n", Status);
}
return Status;
}
NTSTATUS
STDCALL
IoAttachDeviceByPointer (
IN PDEVICE_OBJECT SourceDevice,
IN PDEVICE_OBJECT TargetDevice
)
{ {
PDEVICE_OBJECT AttachedDevice; PDEVICE_OBJECT AttachedDevice;
@ -108,8 +53,7 @@ IoAttachDeviceByPointer (
} }
VOID VOID STDCALL
STDCALL
IoDeleteDevice(PDEVICE_OBJECT DeviceObject) IoDeleteDevice(PDEVICE_OBJECT DeviceObject)
{ {
PDEVICE_OBJECT Previous; PDEVICE_OBJECT Previous;
@ -427,8 +371,8 @@ IopInitializeService(
PMODULE_OBJECT ModuleObject; PMODULE_OBJECT ModuleObject;
NTSTATUS Status; NTSTATUS Status;
Status = LdrFindModuleObject(&DeviceNode->ServiceName, &ModuleObject); ModuleObject = LdrGetModuleObject(&DeviceNode->ServiceName);
if (!NT_SUCCESS(Status)) if (ModuleObject == NULL)
{ {
/* The module is currently not loaded, so load it now */ /* The module is currently not loaded, so load it now */
@ -447,10 +391,9 @@ IopInitializeService(
CPRINT("A driver failed to initialize\n"); CPRINT("A driver failed to initialize\n");
return(Status); return(Status);
} }
ObDereferenceObject(ModuleObject);
} }
ObDereferenceObject(ModuleObject);
Status = IopInitializeDevice(DeviceNode, TRUE); Status = IopInitializeDevice(DeviceNode, TRUE);
return(Status); return(Status);
@ -483,12 +426,11 @@ IopInitializeDeviceNodeService(PDEVICE_NODE DeviceNode)
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT; QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
QueryTable[0].EntryContext = &ImagePath; QueryTable[0].EntryContext = &ImagePath;
Status = RtlQueryRegistryValues( Status = RtlQueryRegistryValues(RTL_REGISTRY_HANDLE,
RTL_REGISTRY_HANDLE, (PWSTR)KeyHandle,
(PWSTR)KeyHandle, QueryTable,
QueryTable, NULL,
NULL, NULL);
NULL);
NtClose(KeyHandle); NtClose(KeyHandle);
DPRINT("RtlQueryRegistryValues() returned status %x\n", Status); DPRINT("RtlQueryRegistryValues() returned status %x\n", Status);

View file

@ -0,0 +1,166 @@
/* $Id: driver.c,v 1.1 2002/06/10 08:47:21 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/driver.c
* PURPOSE: Manage devices
* PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY:
* 15/05/98: Created
*/
/* INCLUDES ****************************************************************/
#include <limits.h>
#include <ddk/ntddk.h>
#include <internal/io.h>
#include <internal/po.h>
#include <internal/ldr.h>
#include <internal/id.h>
#include <internal/pool.h>
#include <internal/registry.h>
#include <roscfg.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS *******************************************************************/
POBJECT_TYPE EXPORTED IoDriverObjectType = NULL;
#define TAG_DRIVER TAG('D', 'R', 'V', 'R')
#define TAG_DRIVER_EXTENSION TAG('D', 'R', 'V', 'E')
#define DRIVER_REGISTRY_KEY_BASENAME L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\"
/* FUNCTIONS ***************************************************************/
NTSTATUS STDCALL
IopCreateDriver(PVOID ObjectBody,
PVOID Parent,
PWSTR RemainingPath,
POBJECT_ATTRIBUTES ObjectAttributes)
{
DPRINT("LdrCreateModule(ObjectBody %x, Parent %x, RemainingPath %S)\n",
ObjectBody,
Parent,
RemainingPath);
if (RemainingPath != NULL && wcschr(RemainingPath + 1, '\\') != NULL)
{
return(STATUS_UNSUCCESSFUL);
}
return(STATUS_SUCCESS);
}
VOID
IopInitDriverImplementation(VOID)
{
/* Register the process object type */
IoDriverObjectType = ExAllocatePool(NonPagedPool, sizeof(OBJECT_TYPE));
IoDriverObjectType->Tag = TAG('D', 'R', 'V', 'T');
IoDriverObjectType->TotalObjects = 0;
IoDriverObjectType->TotalHandles = 0;
IoDriverObjectType->MaxObjects = ULONG_MAX;
IoDriverObjectType->MaxHandles = ULONG_MAX;
IoDriverObjectType->PagedPoolCharge = 0;
IoDriverObjectType->NonpagedPoolCharge = sizeof(MODULE);
IoDriverObjectType->Dump = NULL;
IoDriverObjectType->Open = NULL;
IoDriverObjectType->Close = NULL;
IoDriverObjectType->Delete = NULL;
IoDriverObjectType->Parse = NULL;
IoDriverObjectType->Security = NULL;
IoDriverObjectType->QueryName = NULL;
IoDriverObjectType->OkayToClose = NULL;
IoDriverObjectType->Create = IopCreateDriver;
IoDriverObjectType->DuplicationNotify = NULL;
RtlInitUnicodeString(&IoDriverObjectType->TypeName, L"Driver");
}
/**********************************************************************
* NAME EXPORTED
* NtLoadDriver
*
* DESCRIPTION
* Loads a device driver.
*
* ARGUMENTS
* DriverServiceName
* Name of the service to load (registry key).
*
* RETURN VALUE
* Status.
*
* REVISIONS
*/
NTSTATUS STDCALL
NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
{
PDEVICE_NODE DeviceNode;
NTSTATUS Status;
PMODULE_OBJECT ModuleObject;
WCHAR Buffer[MAX_PATH];
ULONG Length;
LPWSTR Start;
LPWSTR Ext;
/* FIXME: this should lookup the filename from the registry */
/* Use IopRootDeviceNode for now */
Status = IopCreateDeviceNode(IopRootDeviceNode, NULL, &DeviceNode);
if (!NT_SUCCESS(Status))
{
return(Status);
}
Status = LdrLoadModule(DriverServiceName, &ModuleObject);
if (!NT_SUCCESS(Status))
{
DPRINT1("LdrLoadModule() failed (Status %lx)\n", Status);
IopFreeDeviceNode(DeviceNode);
return(Status);
}
/* Set a service name for the device node */
/* 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))
{
DPRINT1("IopInitializeDriver() failed (Status %lx)\n", Status);
ObDereferenceObject(ModuleObject);
IopFreeDeviceNode(DeviceNode);
}
return(Status);
}
NTSTATUS STDCALL
NtUnloadDriver(IN PUNICODE_STRING DriverServiceName)
{
UNIMPLEMENTED;
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: iomgr.c,v 1.21 2001/12/05 01:40:24 dwelch Exp $ /* $Id: iomgr.c,v 1.22 2002/06/10 08:47:21 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -114,10 +114,12 @@ IopDeleteFile(PVOID ObjectBody)
VOID IoInit (VOID) VOID IoInit (VOID)
{ {
OBJECT_ATTRIBUTES attr; OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE handle; UNICODE_STRING DirName;
UNICODE_STRING UnicodeString; UNICODE_STRING LinkName;
UNICODE_STRING DeviceName; HANDLE Handle;
IopInitDriverImplementation();
/* /*
* Register iomgr types: DeviceObjectType * Register iomgr types: DeviceObjectType
@ -182,83 +184,94 @@ VOID IoInit (VOID)
L"File" L"File"
); );
/* /*
* Create the '\Device' directory * Create the '\Driver' object directory
*/ */
RtlInitUnicodeString ( RtlInitUnicodeString(&DirName,
& UnicodeString, L"\\Driver");
L"\\Device" InitializeObjectAttributes(&ObjectAttributes,
); &DirName,
InitializeObjectAttributes ( 0,
& attr, NULL,
& UnicodeString, NULL);
0, NtCreateDirectoryObject(&Handle,
NULL, 0,
NULL &ObjectAttributes);
);
ZwCreateDirectoryObject (
& handle,
0,
& attr
);
/* /*
* Create the '\??' directory * Create the '\FileSystem' object directory
*/ */
RtlInitUnicodeString ( RtlInitUnicodeString(&DirName,
& UnicodeString, L"\\FileSystem");
L"\\??" InitializeObjectAttributes(&ObjectAttributes,
); &DirName,
InitializeObjectAttributes ( 0,
& attr, NULL,
& UnicodeString, NULL);
0, NtCreateDirectoryObject(&Handle,
NULL, 0,
NULL &ObjectAttributes);
);
ZwCreateDirectoryObject (
& handle,
0,
& attr
);
/* /*
* Create the '\ArcName' directory * Create the '\Device' directory
*/ */
RtlInitUnicodeString ( RtlInitUnicodeString(&DirName,
& UnicodeString, L"\\Device");
L"\\ArcName"); InitializeObjectAttributes(&ObjectAttributes,
InitializeObjectAttributes ( &DirName,
& attr, 0,
& UnicodeString, NULL,
0, NULL);
NULL, ZwCreateDirectoryObject(&Handle,
NULL 0,
); &ObjectAttributes);
ZwCreateDirectoryObject (
& handle,
0,
& attr
);
/* /*
* Initialize remaining subsubsystem * Create the '\??' directory
*/ */
IoInitCancelHandling (); RtlInitUnicodeString(&DirName,
IoInitSymbolicLinkImplementation (); L"\\??");
IoInitFileSystemImplementation (); InitializeObjectAttributes(&ObjectAttributes,
IoInitVpbImplementation (); &DirName,
IoInitShutdownNotification (); 0,
NULL,
NULL);
ZwCreateDirectoryObject(&Handle,
0,
&ObjectAttributes);
/* /*
* Create link from '\DosDevices' to '\??' directory * Create the '\ArcName' directory
*/ */
RtlInitUnicodeString (&UnicodeString, RtlInitUnicodeString(&DirName,
L"\\DosDevices"); L"\\ArcName");
RtlInitUnicodeString (&DeviceName, InitializeObjectAttributes(&ObjectAttributes,
L"\\??"); &DirName,
IoCreateSymbolicLink (&UnicodeString, 0,
&DeviceName); NULL,
NULL);
ZwCreateDirectoryObject(&Handle,
0,
&ObjectAttributes);
/*
* Initialize remaining subsubsystem
*/
IoInitCancelHandling();
IoInitSymbolicLinkImplementation();
IoInitFileSystemImplementation();
IoInitVpbImplementation();
IoInitShutdownNotification();
/*
* Create link from '\DosDevices' to '\??' directory
*/
RtlInitUnicodeString(&LinkName,
L"\\DosDevices");
RtlInitUnicodeString(&DirName,
L"\\??");
IoCreateSymbolicLink(&LinkName,
&DirName);
/* /*
* Initialize PnP manager * Initialize PnP manager
@ -270,7 +283,7 @@ VOID IoInit (VOID)
PGENERIC_MAPPING STDCALL PGENERIC_MAPPING STDCALL
IoGetFileObjectGenericMapping(VOID) IoGetFileObjectGenericMapping(VOID)
{ {
return &IopFileMapping; return(&IopFileMapping);
} }
/* EOF */ /* EOF */

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: main.c,v 1.121 2002/05/05 14:57:44 chorns Exp $ /* $Id: main.c,v 1.122 2002/06/10 08:48:14 ekohl Exp $
* *
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/main.c * FILE: ntoskrnl/ke/main.c
@ -978,9 +978,9 @@ ExpInitializeExecutive(VOID)
if (RtlpCheckFileNameExtension(name, ".sys") || if (RtlpCheckFileNameExtension(name, ".sys") ||
RtlpCheckFileNameExtension(name, ".sym")) RtlpCheckFileNameExtension(name, ".sym"))
{ {
CPRINT("Processing module '%s' at %08lx, length 0x%08lx\n", CPRINT("Initializing driver '%s' at %08lx, length 0x%08lx\n",
name, start, length); name, start, length);
LdrProcessDriver((PVOID)start, name, length); LdrInitializeBootStartDriver((PVOID)start, name, length);
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
/* $Id: drvlck.c,v 1.3 2000/04/02 13:32:41 ea Exp $ /* $Id: drvlck.c,v 1.1 2002/06/10 08:50:55 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -19,7 +19,8 @@
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
#if 0 #if 0
VOID MmUnlockPagableImageSection(PVOID ImageSectionHandle) VOID
MmUnlockPagableImageSection(IN PVOID ImageSectionHandle)
/* /*
* FUNCTION: Releases a section of driver code or driver data, previously * FUNCTION: Releases a section of driver code or driver data, previously
* locked into system space with MmLockPagableCodeSection, * locked into system space with MmLockPagableCodeSection,
@ -29,52 +30,57 @@ VOID MmUnlockPagableImageSection(PVOID ImageSectionHandle)
* MmLockPagableDataSection * MmLockPagableDataSection
*/ */
{ {
// MmUnlockMemoryArea((MEMORY_AREA *)ImageSectionHandle); // MmUnlockMemoryArea((MEMORY_AREA *)ImageSectionHandle);
UNIMPLEMENTED; UNIMPLEMENTED;
} }
#endif #endif
VOID STDCALL MmLockPagableSectionByHandle(PVOID ImageSectionHandle)
VOID STDCALL
MmLockPagableSectionByHandle(IN PVOID ImageSectionHandle)
{ {
// MmLockMemoryArea((MEMORY_AREA *)ImageSectionHandle); // MmLockMemoryArea((MEMORY_AREA *)ImageSectionHandle);
UNIMPLEMENTED; UNIMPLEMENTED;
} }
#if 0 #if 0
PVOID MmLockPagableCodeSection(PVOID AddressWithinSection) PVOID
MmLockPagableCodeSection(IN PVOID AddressWithinSection)
{ {
PVOID Handle; PVOID Handle;
Handle = MmOpenMemoryAreaByAddress(NULL,AddressWithinSection); Handle = MmOpenMemoryAreaByAddress(NULL,AddressWithinSection);
MmLockPagableSectionByHandle(Handle); MmLockPagableSectionByHandle(Handle);
return(Handle); return(Handle);
} }
#endif #endif
PVOID STDCALL MmLockPagableDataSection(PVOID AddressWithinSection)
PVOID STDCALL
MmLockPagableDataSection(IN PVOID AddressWithinSection)
{ {
PVOID Handle; PVOID Handle;
Handle = MmOpenMemoryAreaByAddress(NULL,AddressWithinSection); Handle = MmOpenMemoryAreaByAddress(NULL,AddressWithinSection);
MmLockPagableSectionByHandle(Handle); MmLockPagableSectionByHandle(Handle);
return(Handle); return(Handle);
} }
VOID VOID STDCALL
STDCALL MmUnlockPagableImageSection(IN PVOID ImageSectionHandle)
MmUnlockPagableImageSection (
PVOID ImageSectionHandle
)
{ {
} }
VOID STDCALL MmPageEntireDriver(PVOID AddressWithinSection) VOID STDCALL
MmPageEntireDriver(IN PVOID AddressWithinSection)
{ {
} }
VOID STDCALL MmResetDriverPaging(PVOID AddressWithinSection)
VOID STDCALL
MmResetDriverPaging(IN PVOID AddressWithinSection)
{ {
} }
/* EOF */ /* EOF */