[ros-diffs] [ion] 24735: - Implement IoSetCompletionRoutineEx, which is a safe way to set completion routines that almost all newer drivers will be using (XP+).

ion at svn.reactos.org ion at svn.reactos.org
Sun Nov 12 23:39:09 CET 2006


Author: ion
Date: Mon Nov 13 01:39:09 2006
New Revision: 24735

URL: http://svn.reactos.org/svn/reactos?rev=24735&view=rev
Log:
- Implement IoSetCompletionRoutineEx, which is a safe way to set completion routines that almost all newer drivers will be using (XP+). 

Modified:
    trunk/reactos/ntoskrnl/include/internal/io.h
    trunk/reactos/ntoskrnl/io/iomgr/iocomp.c

Modified: trunk/reactos/ntoskrnl/include/internal/io.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/io.h?rev=24735&r1=24734&r2=24735&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/io.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/io.h Mon Nov 13 01:39:09 2006
@@ -228,6 +228,16 @@
     PVOID Context;
     IO_STATUS_BLOCK IoStatus;
 } IO_COMPLETION_PACKET, *PIO_COMPLETION_PACKET;
+
+//
+// I/O Completion Context for IoSetIoCompletionRoutineEx
+//
+typedef struct _IO_UNLOAD_SAFE_COMPLETION_CONTEXT
+{
+    PDEVICE_OBJECT DeviceObject;
+    PVOID Context;
+    PIO_COMPLETION_ROUTINE CompletionRoutine;
+} IO_UNLOAD_SAFE_COMPLETION_CONTEXT, *PIO_UNLOAD_SAFE_COMPLETION_CONTEXT;
 
 //
 // I/O Wrapper around the Executive Work Item

Modified: trunk/reactos/ntoskrnl/io/iomgr/iocomp.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/iocomp.c?rev=24735&r1=24734&r2=24735&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/io/iomgr/iocomp.c (original)
+++ trunk/reactos/ntoskrnl/io/iomgr/iocomp.c Mon Nov 13 01:39:09 2006
@@ -33,6 +33,32 @@
 
 /* PRIVATE FUNCTIONS *********************************************************/
 
+NTSTATUS
+NTAPI
+IopUnloadSafeCompletion(IN PDEVICE_OBJECT DeviceObject,
+                        IN PIRP Irp,
+                        IN PVOID Context)
+{
+    NTSTATUS Status;
+    PIO_UNLOAD_SAFE_COMPLETION_CONTEXT UnsafeContext =
+        (PIO_UNLOAD_SAFE_COMPLETION_CONTEXT)Context;
+
+    /* Reference the device object */
+    ObReferenceObject(UnsafeContext->DeviceObject);
+
+    /* Call the completion routine */
+    Status= UnsafeContext->CompletionRoutine(DeviceObject,
+                                             Irp,
+                                             UnsafeContext->Context);
+
+    /* Dereference the device object */
+    ObDereferenceObject(UnsafeContext->DeviceObject);
+
+    /* Free our context */
+    ExFreePool(UnsafeContext);
+    return Status;
+}
+
 VOID
 NTAPI
 IopFreeIoCompletionPacket(PIO_COMPLETION_PACKET Packet)
@@ -187,7 +213,7 @@
 }
 
 /*
- * @unimplemented
+ * @implemented
  */
 NTSTATUS
 NTAPI
@@ -199,8 +225,27 @@
                          IN BOOLEAN InvokeOnError,
                          IN BOOLEAN InvokeOnCancel)
 {
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
+    PIO_UNLOAD_SAFE_COMPLETION_CONTEXT UnloadContext;
+
+    /* Allocate the context */
+    UnloadContext = ExAllocatePoolWithTag(NonPagedPool,
+                                          sizeof(*UnloadContext),
+                                          TAG('I', 'o', 'U', 's'));
+    if (!UnloadContext) return STATUS_INSUFFICIENT_RESOURCES;
+
+    /* Set up the context */
+    UnloadContext->DeviceObject = DeviceObject;
+    UnloadContext->Context = Context;
+    UnloadContext->CompletionRoutine = CompletionRoutine;
+
+    /* Now set the completion routine */
+    IoSetCompletionRoutine(Irp,
+                           IopUnloadSafeCompletion,
+                           UnloadContext,
+                           InvokeOnSuccess,
+                           InvokeOnError,
+                           InvokeOnCancel);
+    return STATUS_SUCCESS;
 }
 
 NTSTATUS




More information about the Ros-diffs mailing list