Commit in reactos/ntoskrnl on MAIN
include/internal/io.h+7-11.41 -> 1.42
io/driver.c+193-1391.39 -> 1.40
+200-140
2 modified files
- Minor cleanup and fixed few memory leaks on driver unload.

reactos/ntoskrnl/include/internal
io.h 1.41 -> 1.42
diff -u -r1.41 -r1.42
--- io.h	27 Mar 2004 19:41:31 -0000	1.41
+++ io.h	28 Mar 2004 09:48:13 -0000	1.42
@@ -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.41 2004/03/27 19:41:31 navaraf Exp $
+/* $Id: io.h,v 1.42 2004/03/28 09:48:13 navaraf Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -57,6 +57,12 @@
    struct _DEVICE_NODE *DeviceNode;
 } DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
 
+typedef struct _PRIVATE_DRIVER_EXTENSIONS {
+   struct _PRIVATE_DRIVER_EXTENSIONS *Link;
+   PVOID ClientIdentificationAddress;
+   CHAR Extension[1];
+} PRIVATE_DRIVER_EXTENSIONS, *PPRIVATE_DRIVER_EXTENSIONS;
+
 typedef struct _DEVICE_NODE
 {
   struct _DEVICE_NODE *Parent;

reactos/ntoskrnl/io
driver.c 1.39 -> 1.40
diff -u -r1.39 -r1.40
--- driver.c	27 Mar 2004 19:41:32 -0000	1.39
+++ driver.c	28 Mar 2004 09:48:13 -0000	1.40
@@ -1,4 +1,4 @@
-/* $Id: driver.c,v 1.39 2004/03/27 19:41:32 navaraf Exp $
+/* $Id: driver.c,v 1.40 2004/03/28 09:48:13 navaraf Exp $
  *
  * COPYRIGHT:      See COPYING in the top level directory
  * PROJECT:        ReactOS kernel
@@ -85,24 +85,19 @@
 
 #define DRIVER_REGISTRY_KEY_BASENAME  L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\"
 
-/* PRIVATE FUNCTIONS **********************************************************/
+/* DECLARATIONS ***************************************************************/
 
 NTSTATUS STDCALL
 IopCreateDriver(
    PVOID ObjectBody,
    PVOID Parent,
    PWSTR RemainingPath,
-   POBJECT_ATTRIBUTES ObjectAttributes)
-{
-   DPRINT("LdrCreateModule(ObjectBody %x, Parent %x, RemainingPath %S)\n",
-      ObjectBody, Parent, RemainingPath);
+   POBJECT_ATTRIBUTES ObjectAttributes);
 
-   if (RemainingPath != NULL && wcschr(RemainingPath + 1, '\\') != NULL)
-      return STATUS_UNSUCCESSFUL;
-
-   return STATUS_SUCCESS;
-}
+VOID STDCALL
+IopDeleteDriver(PVOID ObjectBody);
 
+/* PRIVATE FUNCTIONS **********************************************************/
 
 VOID INIT_FUNCTION
 IopInitDriverImplementation(VOID)
@@ -119,7 +114,7 @@
    IoDriverObjectType->Dump = NULL;
    IoDriverObjectType->Open = NULL;
    IoDriverObjectType->Close = NULL;
-   IoDriverObjectType->Delete = NULL;
+   IoDriverObjectType->Delete = IopDeleteDriver;
    IoDriverObjectType->Parse = NULL;
    IoDriverObjectType->Security = NULL;
    IoDriverObjectType->QueryName = NULL;
@@ -136,7 +131,7 @@
 }
 
 NTSTATUS STDCALL
-IopDefaultDispatchFunction(
+IopInvalidDeviceRequest(
    PDEVICE_OBJECT DeviceObject,
    PIRP Irp)
 {
@@ -146,6 +141,68 @@
    return STATUS_NOT_IMPLEMENTED;
 }
 
+NTSTATUS STDCALL
+IopCreateDriver(
+   PVOID ObjectBody,
+   PVOID Parent,
+   PWSTR RemainingPath,
+   POBJECT_ATTRIBUTES ObjectAttributes)
+{
+   PDRIVER_OBJECT Object = ObjectBody;
+   ULONG i;
+
+   DPRINT("IopCreateDriver(ObjectBody %x, Parent %x, RemainingPath %S)\n",
+      ObjectBody, Parent, RemainingPath);
+
+   if (RemainingPath != NULL && wcschr(RemainingPath + 1, '\\') != NULL)
+      return STATUS_UNSUCCESSFUL;
+
+   /* Create driver extension */
+   Object->DriverExtension = (PDRIVER_EXTENSION)
+      ExAllocatePoolWithTag(
+         NonPagedPool,
+         sizeof(DRIVER_EXTENSION),
+         TAG_DRIVER_EXTENSION);
+
+   if (Object->DriverExtension == NULL)
+   {
+      return STATUS_NO_MEMORY;
+   }
+
+   RtlZeroMemory(Object->DriverExtension, sizeof(DRIVER_EXTENSION));
+
+   Object->Type = InternalDriverType;
+
+   for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
+      Object->MajorFunction[i] = IopInvalidDeviceRequest;
+
+   return STATUS_SUCCESS;
+}
+
+VOID STDCALL
+IopDeleteDriver(PVOID ObjectBody)
+{
+   PDRIVER_OBJECT Object = ObjectBody;
+   KIRQL OldIrql;
+   PPRIVATE_DRIVER_EXTENSIONS DriverExtension, NextDriverExtension;
+
+   DPRINT("IopDeleteDriver(ObjectBody %x)\n", ObjectBody);
+
+   ExFreePool(Object->DriverExtension);
+
+   OldIrql = KeRaiseIrqlToDpcLevel();
+
+   for (DriverExtension = Object->DriverSection;
+        DriverExtension != NULL;
+        DriverExtension = NextDriverExtension)
+   {
+      NextDriverExtension = DriverExtension->Link;
+      ExFreePool(DriverExtension);
+   }
+
+   KfLowerIrql(OldIrql);
+}
+
 NTSTATUS FASTCALL
 IopCreateDriverObject(
    PDRIVER_OBJECT *DriverObject,
@@ -155,7 +212,6 @@
    ULONG DriverImageSize)
 {
    PDRIVER_OBJECT Object;
-   ULONG i;
    WCHAR NameBuffer[MAX_PATH];
    UNICODE_STRING DriverName;
    OBJECT_ATTRIBUTES ObjectAttributes;
@@ -208,28 +264,9 @@
       return Status;
    }
 
-   /* Create driver extension */
-   Object->DriverExtension = (PDRIVER_EXTENSION)
-      ExAllocatePoolWithTag(
-         NonPagedPool,
-         sizeof(DRIVER_EXTENSION),
-         TAG_DRIVER_EXTENSION);
-
-   if (Object->DriverExtension == NULL)
-   {
-      ExFreePool(Object);
-      return STATUS_NO_MEMORY;
-   }
-
-   RtlZeroMemory(Object->DriverExtension, sizeof(DRIVER_EXTENSION));
-
-   Object->Type = InternalDriverType;
    Object->DriverStart = DriverImageStart;
    Object->DriverSize = DriverImageSize;
 
-   for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
-      Object->MajorFunction[i] = IopDefaultDispatchFunction;
-
    *DriverObject = Object;
 
    return STATUS_SUCCESS;
@@ -551,7 +588,6 @@
    PMODULE_OBJECT ModuleObject;
    PDRIVER_OBJECT DriverObject;
    NTSTATUS Status;
-
    
    for (Filters = ValueData;
         ((ULONG_PTR)Filters - (ULONG_PTR)ValueData) < ValueLength &&
@@ -681,13 +717,6 @@
    return STATUS_SUCCESS;
 }
 
-
-
-
-
-
-
-
 static NTSTATUS STDCALL
 IopCreateGroupListEntry(PWSTR ValueName,
 			ULONG ValueType,
@@ -964,12 +993,12 @@
 VOID STATIC
 MiFreeBootDriverMemory(PVOID StartAddress, ULONG Length)
 {
-  ULONG i;
+   ULONG i;
 
-  for (i = 0; i < PAGE_ROUND_UP(Length)/PAGE_SIZE; i++)
-  {
-     MmDeleteVirtualMapping(NULL, (char*)StartAddress + i * PAGE_SIZE, TRUE, NULL, NULL);
-  }
+   for (i = 0; i < PAGE_ROUND_UP(Length) / PAGE_SIZE; i++)
+   {
+      MmDeleteVirtualMapping(NULL, (char*)StartAddress + i * PAGE_SIZE, TRUE, NULL, NULL);
+   }
 }
 
 /*
@@ -999,12 +1028,14 @@
    /*
     * Display 'Initializing XXX...' message
     */
+
    sprintf(TextBuffer, "Initializing %s...\n", FileName);
    HalDisplayString(TextBuffer);
 
    /*
     * Determine the right device object
     */
+
    if (ModuleDeviceNode == NULL)
    {
       /* Use IopRootDeviceNode for now */
@@ -1022,6 +1053,7 @@
    /*
     * Generate filename without path (not needed by freeldr)
     */
+
    FileNameWithoutPath = strrchr(FileName, '\\');
    if (FileNameWithoutPath == NULL)
    {
@@ -1031,6 +1063,7 @@
    /*
     * Load the module
     */
+
    RtlCreateUnicodeStringFromAsciiz(&DeviceNode->ServiceName,
       FileNameWithoutPath);
    Status = LdrProcessModule(ModuleLoadBase, &DeviceNode->ServiceName,
@@ -1046,6 +1079,7 @@
    /*
     * Strip the file extension from ServiceName
     */
+
    FileExtension = wcsrchr(DeviceNode->ServiceName.Buffer, '.');
    if (FileExtension != NULL)
    {
@@ -1056,6 +1090,7 @@
    /*
     * Initialize the driver
     */
+
    Status = IopInitializeDriverModule(DeviceNode, ModuleObject, FALSE,
       &DriverObject);
    
@@ -1112,6 +1147,7 @@
       /*
        * Pass symbol files to kernel debugger
        */
+
       if (!_stricmp(Extension, ".sym"))
       {
          KDB_SYMBOLFILE_HOOK((PVOID)ModuleStart, ModuleName, ModuleSize);
@@ -1120,6 +1156,7 @@
       /*
        * Load builtin driver
        */
+
       if (!_stricmp(Extension, ".sys"))
       {
          if (!ModuleLoaded)
@@ -1133,6 +1170,7 @@
       /*
        * Free memory for all boot files, except ntoskrnl.exe and hal.dll
        */
+
 #ifdef KDBG
       /*
        * Do not free the memory from symbol files, if the kernel debugger
@@ -1371,7 +1409,72 @@
    return STATUS_SUCCESS;
 }
 
-/* FUNCTIONS ******************************************************************/
+VOID FASTCALL
+IopMarkLastReinitializeDriver(VOID)
+{
+  KIRQL Irql;
+
+  KeAcquireSpinLock(&DriverReinitListLock,
+		    &Irql);
+
+  if (IsListEmpty(&DriverReinitListHead))
+  {
+    DriverReinitTailEntry = NULL;
+  }
+  else
+  {
+    DriverReinitTailEntry = DriverReinitListHead.Blink;
+  }
+
+  KeReleaseSpinLock(&DriverReinitListLock,
+		    Irql);
+}
+
+
+VOID FASTCALL
+IopReinitializeDrivers(VOID)
+{
+  PDRIVER_REINIT_ITEM ReinitItem;
+  PLIST_ENTRY Entry;
+  KIRQL Irql;
+
+  KeAcquireSpinLock(&DriverReinitListLock,
+		    &Irql);
+
+  if (DriverReinitTailEntry == NULL)
+  {
+    KeReleaseSpinLock(&DriverReinitListLock,
+		      Irql);
+    return;
+  }
+
+  KeReleaseSpinLock(&DriverReinitListLock,
+		    Irql);
+
+  for (;;)
+  {
+    Entry = ExInterlockedRemoveHeadList(&DriverReinitListHead,
+				        &DriverReinitListLock);
+    if (Entry == NULL)
+      return;
+
+    ReinitItem = (PDRIVER_REINIT_ITEM)CONTAINING_RECORD(Entry, DRIVER_REINIT_ITEM, ItemEntry);
+
+    /* Increment reinitialization counter */
+    ReinitItem->DriverObject->DriverExtension->Count++;
+
+    ReinitItem->ReinitRoutine(ReinitItem->DriverObject,
+			      ReinitItem->Context,
+			      ReinitItem->DriverObject->DriverExtension->Count);
+
+    ExFreePool(Entry);
+
+    if (Entry == DriverReinitTailEntry)
+      return;
+  }
+}
+
+/* PUBLIC FUNCTIONS ***********************************************************/
 
 /*
  * NtLoadDriver
@@ -1384,6 +1487,9 @@
  *		
  * Return Value
  *    Status
+ *
+ * Status
+ *    implemented
  */
 
 NTSTATUS STDCALL
@@ -1405,10 +1511,8 @@
     * Check security privileges
     */
 
-#if 0
    if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege, KeGetPreviousMode()))
       return STATUS_PRIVILEGE_NOT_HELD;
-#endif
 
    RtlInitUnicodeString(&ImagePath, NULL);
 
@@ -1468,6 +1572,7 @@
    /*
     * See, if the driver module isn't already loaded
     */
+
    ModuleObject = LdrGetModuleObject(&ImagePath);
    if (ModuleObject != NULL)
    {
@@ -1518,13 +1623,13 @@
    Status = IopInitializeDriverModule(
       DeviceNode,
       ModuleObject,
-      (Type == 2 /*SERVICE_FILE_SYSTEM_DRIVER*/ ||
-       Type == 8 /*SERVICE_RECOGNIZER_DRIVER*/),
+      (Type == 2 /* SERVICE_FILE_SYSTEM_DRIVER */ ||
+       Type == 8 /* SERVICE_RECOGNIZER_DRIVER */),
       &DriverObject);
 
    if (!NT_SUCCESS(Status))
    {
-      DPRINT1("IopInitializeDriver() failed (Status %lx)\n", Status);
+      DPRINT("IopInitializeDriver() failed (Status %lx)\n", Status);
       LdrUnloadModule(ModuleObject);
       IopFreeDeviceNode(DeviceNode);
       return Status;
@@ -1546,6 +1651,9 @@
  *		
  * Return Value
  *    Status
+ *
+ * Status
+ *    implemented
  */
 
 NTSTATUS STDCALL
@@ -1554,102 +1662,41 @@
    return IopUnloadDriver(DriverServiceName, FALSE);
 }
 
-
 /*
- * @implemented
+ * IoRegisterDriverReinitialization
+ *
+ * Status
+ *    @implemented
  */
-VOID STDCALL
-IoRegisterDriverReinitialization(PDRIVER_OBJECT DriverObject,
-				 PDRIVER_REINITIALIZE ReinitRoutine,
-				 PVOID Context)
-{
-  PDRIVER_REINIT_ITEM ReinitItem;
-
-  ReinitItem = ExAllocatePool(NonPagedPool,
-			      sizeof(DRIVER_REINIT_ITEM));
-  if (ReinitItem == NULL)
-    return;
-
-  ReinitItem->DriverObject = DriverObject;
-  ReinitItem->ReinitRoutine = ReinitRoutine;
-  ReinitItem->Context = Context;
-
-  ExInterlockedInsertTailList(&DriverReinitListHead,
-			      &ReinitItem->ItemEntry,
-			      &DriverReinitListLock);
-}
-
-
-VOID FASTCALL
-IopMarkLastReinitializeDriver(VOID)
-{
-  KIRQL Irql;
-
-  KeAcquireSpinLock(&DriverReinitListLock,
-		    &Irql);
-
-  if (IsListEmpty(&DriverReinitListHead))
-  {
-    DriverReinitTailEntry = NULL;
-  }
-  else
-  {
-    DriverReinitTailEntry = DriverReinitListHead.Blink;
-  }
-
-  KeReleaseSpinLock(&DriverReinitListLock,
-		    Irql);
-}
-
 
-VOID FASTCALL
-IopReinitializeDrivers(VOID)
+VOID STDCALL
+IoRegisterDriverReinitialization(
+   PDRIVER_OBJECT DriverObject,
+   PDRIVER_REINITIALIZE ReinitRoutine,
+   PVOID Context)
 {
-  PDRIVER_REINIT_ITEM ReinitItem;
-  PLIST_ENTRY Entry;
-  KIRQL Irql;
-
-  KeAcquireSpinLock(&DriverReinitListLock,
-		    &Irql);
-
-  if (DriverReinitTailEntry == NULL)
-  {
-    KeReleaseSpinLock(&DriverReinitListLock,
-		      Irql);
-    return;
-  }
-
-  KeReleaseSpinLock(&DriverReinitListLock,
-		    Irql);
+   PDRIVER_REINIT_ITEM ReinitItem;
 
-  for (;;)
-  {
-    Entry = ExInterlockedRemoveHeadList(&DriverReinitListHead,
-				        &DriverReinitListLock);
-    if (Entry == NULL)
+   ReinitItem = ExAllocatePool(NonPagedPool, sizeof(DRIVER_REINIT_ITEM));
+   if (ReinitItem == NULL)
       return;
 
-    ReinitItem = (PDRIVER_REINIT_ITEM)CONTAINING_RECORD(Entry, DRIVER_REINIT_ITEM, ItemEntry);
-
-    /* Increment reinitialization counter */
-    ReinitItem->DriverObject->DriverExtension->Count++;
-
-    ReinitItem->ReinitRoutine(ReinitItem->DriverObject,
-			      ReinitItem->Context,
-			      ReinitItem->DriverObject->DriverExtension->Count);
-
-    ExFreePool(Entry);
-
-    if (Entry == DriverReinitTailEntry)
-      return;
-  }
+   ReinitItem->DriverObject = DriverObject;
+   ReinitItem->ReinitRoutine = ReinitRoutine;
+   ReinitItem->Context = Context;
+
+   ExInterlockedInsertTailList(
+      &DriverReinitListHead,
+      &ReinitItem->ItemEntry,
+      &DriverReinitListLock);
 }
 
-typedef struct _PRIVATE_DRIVER_EXTENSIONS {
-   struct _PRIVATE_DRIVER_EXTENSIONS *Link;
-   PVOID ClientIdentificationAddress;
-   CHAR Extension[1];
-} PRIVATE_DRIVER_EXTENSIONS, *PPRIVATE_DRIVER_EXTENSIONS;
+/*
+ * IoAllocateDriverObjectExtension
+ *
+ * Status
+ *    @implemented
+ */
 
 NTSTATUS STDCALL
 IoAllocateDriverObjectExtension(
@@ -1699,6 +1746,13 @@
    return STATUS_SUCCESS;      
 }
 
+/*
+ * IoGetDriverObjectExtension
+ *
+ * Status
+ *    @implemented
+ */
+
 PVOID STDCALL
 IoGetDriverObjectExtension(
    PDRIVER_OBJECT DriverObject,
CVSspam 0.2.8