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/…
==============================================================================
--- 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…
==============================================================================
--- 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