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
#
@ -132,6 +132,7 @@ OBJECTS_KE = \
OBJECTS_MM = \
mm/aspace.o \
mm/cont.o \
mm/drvlck.o \
mm/freelist.o \
mm/iospace.o \
mm/marea.o \
@ -159,7 +160,7 @@ OBJECTS_MM = \
# I/O Subsystem (Io)
OBJECTS_IO = \
io/adapter.o \
io/arcname.o \
io/arcname.o \
io/buildirp.o \
io/cancel.o \
io/cleanup.o \
@ -167,7 +168,7 @@ OBJECTS_IO = \
io/create.o \
io/device.o \
io/dir.o \
io/drvlck.o \
io/driver.o \
io/errlog.o \
io/error.o \
io/event.o \

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.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
* PROJECT: ReactOS kernel
@ -233,6 +233,9 @@ extern POBJECT_TYPE IoSymbolicLinkType;
VOID
PnpInit(VOID);
VOID
IopInitDriverImplementation(VOID);
NTSTATUS
IopGetSystemPowerDeviceObject(PDEVICE_OBJECT *DeviceObject);
NTSTATUS

View file

@ -15,15 +15,10 @@
#define KERNEL_MODULE_NAME L"ntoskrnl.exe"
#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\\"
NTSTATUS
LdrLoadDriver (
PUNICODE_STRING Filename,
PDEVICE_NODE DeviceNode,
BOOLEAN BootDriversOnly
);
NTSTATUS
LdrLoadInitialProcess (
VOID
@ -36,12 +31,12 @@ VOID
LdrInitModuleManagement (
VOID
);
NTSTATUS
LdrProcessDriver (
IN PVOID ModuleLoadBase,
IN PCHAR FileName,
IN ULONG ModuleLength
);
LdrInitializeBootStartDriver(IN PVOID ModuleLoadBase,
IN PCHAR FileName,
IN ULONG ModuleLength);
NTSTATUS
LdrpMapSystemDll (
HANDLE ProcessHandle,
@ -102,11 +97,8 @@ NTSTATUS
LdrLoadModule(PUNICODE_STRING Filename,
PMODULE_OBJECT *ModuleObject);
NTSTATUS
LdrFindModuleObject(PUNICODE_STRING ModuleName,
PMODULE_OBJECT *ModuleObject);
NTSTATUS LdrpOpenModuleDirectory(PHANDLE Handle);
PMODULE_OBJECT
LdrGetModuleObject(PUNICODE_STRING ModuleName);
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
* PROJECT: ReactOS kernel
@ -34,64 +34,9 @@
/* FUNCTIONS ***************************************************************/
NTSTATUS STDCALL NtUnloadDriver(IN PUNICODE_STRING DriverServiceName)
{
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
)
NTSTATUS STDCALL
IoAttachDeviceByPointer(IN PDEVICE_OBJECT SourceDevice,
IN PDEVICE_OBJECT TargetDevice)
{
PDEVICE_OBJECT AttachedDevice;
@ -108,8 +53,7 @@ IoAttachDeviceByPointer (
}
VOID
STDCALL
VOID STDCALL
IoDeleteDevice(PDEVICE_OBJECT DeviceObject)
{
PDEVICE_OBJECT Previous;
@ -427,8 +371,8 @@ IopInitializeService(
PMODULE_OBJECT ModuleObject;
NTSTATUS Status;
Status = LdrFindModuleObject(&DeviceNode->ServiceName, &ModuleObject);
if (!NT_SUCCESS(Status))
ModuleObject = LdrGetModuleObject(&DeviceNode->ServiceName);
if (ModuleObject == NULL)
{
/* The module is currently not loaded, so load it now */
@ -447,10 +391,9 @@ IopInitializeService(
CPRINT("A driver failed to initialize\n");
return(Status);
}
ObDereferenceObject(ModuleObject);
}
ObDereferenceObject(ModuleObject);
Status = IopInitializeDevice(DeviceNode, TRUE);
return(Status);
@ -483,12 +426,11 @@ IopInitializeDeviceNodeService(PDEVICE_NODE DeviceNode)
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
QueryTable[0].EntryContext = &ImagePath;
Status = RtlQueryRegistryValues(
RTL_REGISTRY_HANDLE,
(PWSTR)KeyHandle,
QueryTable,
NULL,
NULL);
Status = RtlQueryRegistryValues(RTL_REGISTRY_HANDLE,
(PWSTR)KeyHandle,
QueryTable,
NULL,
NULL);
NtClose(KeyHandle);
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
* PROJECT: ReactOS kernel
@ -114,10 +114,12 @@ IopDeleteFile(PVOID ObjectBody)
VOID IoInit (VOID)
{
OBJECT_ATTRIBUTES attr;
HANDLE handle;
UNICODE_STRING UnicodeString;
UNICODE_STRING DeviceName;
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING DirName;
UNICODE_STRING LinkName;
HANDLE Handle;
IopInitDriverImplementation();
/*
* Register iomgr types: DeviceObjectType
@ -182,83 +184,94 @@ VOID IoInit (VOID)
L"File"
);
/*
* Create the '\Device' directory
*/
RtlInitUnicodeString (
& UnicodeString,
L"\\Device"
);
InitializeObjectAttributes (
& attr,
& UnicodeString,
0,
NULL,
NULL
);
ZwCreateDirectoryObject (
& handle,
0,
& attr
);
/*
* Create the '\Driver' object directory
*/
RtlInitUnicodeString(&DirName,
L"\\Driver");
InitializeObjectAttributes(&ObjectAttributes,
&DirName,
0,
NULL,
NULL);
NtCreateDirectoryObject(&Handle,
0,
&ObjectAttributes);
/*
* Create the '\??' directory
*/
RtlInitUnicodeString (
& UnicodeString,
L"\\??"
);
InitializeObjectAttributes (
& attr,
& UnicodeString,
0,
NULL,
NULL
);
ZwCreateDirectoryObject (
& handle,
0,
& attr
);
/*
* Create the '\FileSystem' object directory
*/
RtlInitUnicodeString(&DirName,
L"\\FileSystem");
InitializeObjectAttributes(&ObjectAttributes,
&DirName,
0,
NULL,
NULL);
NtCreateDirectoryObject(&Handle,
0,
&ObjectAttributes);
/*
* Create the '\ArcName' directory
*/
RtlInitUnicodeString (
& UnicodeString,
L"\\ArcName");
InitializeObjectAttributes (
& attr,
& UnicodeString,
0,
NULL,
NULL
);
ZwCreateDirectoryObject (
& handle,
0,
& attr
);
/*
* Create the '\Device' directory
*/
RtlInitUnicodeString(&DirName,
L"\\Device");
InitializeObjectAttributes(&ObjectAttributes,
&DirName,
0,
NULL,
NULL);
ZwCreateDirectoryObject(&Handle,
0,
&ObjectAttributes);
/*
* Initialize remaining subsubsystem
*/
IoInitCancelHandling ();
IoInitSymbolicLinkImplementation ();
IoInitFileSystemImplementation ();
IoInitVpbImplementation ();
IoInitShutdownNotification ();
/*
* Create the '\??' directory
*/
RtlInitUnicodeString(&DirName,
L"\\??");
InitializeObjectAttributes(&ObjectAttributes,
&DirName,
0,
NULL,
NULL);
ZwCreateDirectoryObject(&Handle,
0,
&ObjectAttributes);
/*
* Create link from '\DosDevices' to '\??' directory
*/
RtlInitUnicodeString (&UnicodeString,
L"\\DosDevices");
RtlInitUnicodeString (&DeviceName,
L"\\??");
IoCreateSymbolicLink (&UnicodeString,
&DeviceName);
/*
* Create the '\ArcName' directory
*/
RtlInitUnicodeString(&DirName,
L"\\ArcName");
InitializeObjectAttributes(&ObjectAttributes,
&DirName,
0,
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
@ -270,7 +283,7 @@ VOID IoInit (VOID)
PGENERIC_MAPPING STDCALL
IoGetFileObjectGenericMapping(VOID)
{
return &IopFileMapping;
return(&IopFileMapping);
}
/* EOF */

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: 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
* FILE: ntoskrnl/ke/main.c
@ -978,9 +978,9 @@ ExpInitializeExecutive(VOID)
if (RtlpCheckFileNameExtension(name, ".sys") ||
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);
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
* PROJECT: ReactOS kernel
@ -19,7 +19,8 @@
/* FUNCTIONS *****************************************************************/
#if 0
VOID MmUnlockPagableImageSection(PVOID ImageSectionHandle)
VOID
MmUnlockPagableImageSection(IN PVOID ImageSectionHandle)
/*
* FUNCTION: Releases a section of driver code or driver data, previously
* locked into system space with MmLockPagableCodeSection,
@ -29,52 +30,57 @@ VOID MmUnlockPagableImageSection(PVOID ImageSectionHandle)
* MmLockPagableDataSection
*/
{
// MmUnlockMemoryArea((MEMORY_AREA *)ImageSectionHandle);
UNIMPLEMENTED;
// MmUnlockMemoryArea((MEMORY_AREA *)ImageSectionHandle);
UNIMPLEMENTED;
}
#endif
VOID STDCALL MmLockPagableSectionByHandle(PVOID ImageSectionHandle)
VOID STDCALL
MmLockPagableSectionByHandle(IN PVOID ImageSectionHandle)
{
// MmLockMemoryArea((MEMORY_AREA *)ImageSectionHandle);
UNIMPLEMENTED;
// MmLockMemoryArea((MEMORY_AREA *)ImageSectionHandle);
UNIMPLEMENTED;
}
#if 0
PVOID MmLockPagableCodeSection(PVOID AddressWithinSection)
PVOID
MmLockPagableCodeSection(IN PVOID AddressWithinSection)
{
PVOID Handle;
Handle = MmOpenMemoryAreaByAddress(NULL,AddressWithinSection);
MmLockPagableSectionByHandle(Handle);
return(Handle);
PVOID Handle;
Handle = MmOpenMemoryAreaByAddress(NULL,AddressWithinSection);
MmLockPagableSectionByHandle(Handle);
return(Handle);
}
#endif
PVOID STDCALL MmLockPagableDataSection(PVOID AddressWithinSection)
PVOID STDCALL
MmLockPagableDataSection(IN PVOID AddressWithinSection)
{
PVOID Handle;
Handle = MmOpenMemoryAreaByAddress(NULL,AddressWithinSection);
MmLockPagableSectionByHandle(Handle);
return(Handle);
PVOID Handle;
Handle = MmOpenMemoryAreaByAddress(NULL,AddressWithinSection);
MmLockPagableSectionByHandle(Handle);
return(Handle);
}
VOID
STDCALL
MmUnlockPagableImageSection (
PVOID ImageSectionHandle
)
VOID STDCALL
MmUnlockPagableImageSection(IN 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 */