- Implement IRP cancellation for AFD
authorCameron Gutman <aicommander@gmail.com>
Sat, 3 Oct 2009 20:52:54 +0000 (20:52 +0000)
committerCameron Gutman <aicommander@gmail.com>
Sat, 3 Oct 2009 20:52:54 +0000 (20:52 +0000)
 - Fixes "Broken driver did not complete!" showing up in the debug log (especially during winetests)

svn path=/trunk/; revision=43274

reactos/drivers/network/afd/afd/connect.c
reactos/drivers/network/afd/afd/listen.c
reactos/drivers/network/afd/afd/lock.c
reactos/drivers/network/afd/afd/main.c
reactos/drivers/network/afd/afd/read.c
reactos/drivers/network/afd/afd/write.c
reactos/drivers/network/afd/include/afd.h

index 984ed49..bcc7873 100644 (file)
@@ -99,6 +99,7 @@ static NTSTATUS NTAPI StreamSocketConnectComplete
               NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
               NextIrp->IoStatus.Information = 0;
               if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
               NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
               NextIrp->IoStatus.Information = 0;
               if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
+               (void)IoSetCancelRoutine(NextIrp, NULL);
               IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
         }
        SocketStateUnlock( FCB );
               IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
         }
        SocketStateUnlock( FCB );
@@ -120,6 +121,7 @@ static NTSTATUS NTAPI StreamSocketConnectComplete
        NextIrp->IoStatus.Status = Status;
        NextIrp->IoStatus.Information = 0;
        if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
        NextIrp->IoStatus.Status = Status;
        NextIrp->IoStatus.Information = 0;
        if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
+        (void)IoSetCancelRoutine(NextIrp, NULL);
        IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
     }
 
        IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
     }
 
index 6aaad3a..76d90e8 100644 (file)
@@ -60,6 +60,7 @@ static NTSTATUS SatisfyPreAccept( PIRP Irp, PAFD_TDI_OBJECT_QELT Qelt ) {
        if( Irp->MdlAddress ) UnlockRequest( Irp, IoGetCurrentIrpStackLocation( Irp ) );
        Irp->IoStatus.Status = STATUS_NO_MEMORY;
        Irp->IoStatus.Information = 0;
        if( Irp->MdlAddress ) UnlockRequest( Irp, IoGetCurrentIrpStackLocation( Irp ) );
        Irp->IoStatus.Status = STATUS_NO_MEMORY;
        Irp->IoStatus.Information = 0;
+        (void)IoSetCancelRoutine(Irp, NULL);
        IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
         return STATUS_NO_MEMORY;
     }
        IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
         return STATUS_NO_MEMORY;
     }
@@ -79,6 +80,7 @@ static NTSTATUS SatisfyPreAccept( PIRP Irp, PAFD_TDI_OBJECT_QELT Qelt ) {
 
     Irp->IoStatus.Information = ((PCHAR)&IPAddr[1]) - ((PCHAR)ListenReceive);
     Irp->IoStatus.Status = STATUS_SUCCESS;
 
     Irp->IoStatus.Information = ((PCHAR)&IPAddr[1]) - ((PCHAR)ListenReceive);
     Irp->IoStatus.Status = STATUS_SUCCESS;
+    (void)IoSetCancelRoutine(Irp, NULL);
     IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
     return STATUS_SUCCESS;
 }
     IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
     return STATUS_SUCCESS;
 }
@@ -106,6 +108,7 @@ static NTSTATUS NTAPI ListenComplete
               NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
               NextIrp->IoStatus.Information = 0;
               if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
               NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
               NextIrp->IoStatus.Information = 0;
               if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
+               (void)IoSetCancelRoutine(NextIrp, NULL);
               IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
         }
 
               IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
         }
 
index 18e1084..62263aa 100644 (file)
@@ -302,6 +302,7 @@ NTSTATUS NTAPI UnlockAndMaybeComplete
        SocketStateUnlock( FCB );
     } else {
        if ( Irp->MdlAddress ) UnlockRequest( Irp, IoGetCurrentIrpStackLocation( Irp ) );
        SocketStateUnlock( FCB );
     } else {
        if ( Irp->MdlAddress ) UnlockRequest( Irp, IoGetCurrentIrpStackLocation( Irp ) );
+        (void)IoSetCancelRoutine(Irp, NULL);
        SocketStateUnlock( FCB );
        IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
     }
        SocketStateUnlock( FCB );
        IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
     }
@@ -322,7 +323,7 @@ NTSTATUS LostSocket( PIRP Irp ) {
 NTSTATUS LeaveIrpUntilLater( PAFD_FCB FCB, PIRP Irp, UINT Function ) {
     InsertTailList( &FCB->PendingIrpList[Function],
                    &Irp->Tail.Overlay.ListEntry );
 NTSTATUS LeaveIrpUntilLater( PAFD_FCB FCB, PIRP Irp, UINT Function ) {
     InsertTailList( &FCB->PendingIrpList[Function],
                    &Irp->Tail.Overlay.ListEntry );
-       IoMarkIrpPending(Irp);
-       Irp->IoStatus.Status = STATUS_PENDING;
+    IoMarkIrpPending(Irp);
+    (void)IoSetCancelRoutine(Irp, AfdCancelHandler);
     return UnlockAndMaybeComplete( FCB, STATUS_PENDING, Irp, 0 );
 }
     return UnlockAndMaybeComplete( FCB, STATUS_PENDING, Irp, 0 );
 }
index 5618f3a..a20c47b 100644 (file)
@@ -505,6 +505,78 @@ AfdDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
     return (Status);
 }
 
     return (Status);
 }
 
+VOID NTAPI
+AfdCancelHandler(PDEVICE_OBJECT DeviceObject,
+                 PIRP Irp)
+{
+    PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
+    PFILE_OBJECT FileObject = IrpSp->FileObject;
+    PAFD_FCB FCB = FileObject->FsContext;
+    UINT Function;
+    PAFD_RECV_INFO RecvReq;
+    PAFD_SEND_INFO SendReq;
+    PLIST_ENTRY CurrentEntry;
+    PIRP CurrentIrp;
+
+    IoReleaseCancelSpinLock(Irp->CancelIrql);
+
+    if (!SocketAcquireStateLock(FCB))
+        return;
+
+    ASSERT(IrpSp->MajorFunction == IRP_MJ_DEVICE_CONTROL);
+
+    switch (IrpSp->Parameters.DeviceIoControl.IoControlCode)
+    {
+        case IOCTL_AFD_RECV:
+        RecvReq = IrpSp->Parameters.DeviceIoControl.Type3InputBuffer;
+       UnlockBuffers(RecvReq->BufferArray, RecvReq->BufferCount, FALSE);
+        /* Fall through */
+
+        case IOCTL_AFD_RECV_DATAGRAM:
+        Function = FUNCTION_RECV;
+        break;
+
+        case IOCTL_AFD_SEND:
+        SendReq = IrpSp->Parameters.DeviceIoControl.Type3InputBuffer;
+        UnlockBuffers(SendReq->BufferArray, SendReq->BufferCount, FALSE);
+        /* Fall through */
+
+        case IOCTL_AFD_SEND_DATAGRAM:
+        Function = FUNCTION_SEND;
+        break;
+
+        case IOCTL_AFD_CONNECT:
+        Function = FUNCTION_CONNECT;
+        break;
+
+        case IOCTL_AFD_WAIT_FOR_LISTEN:
+        Function = FUNCTION_PREACCEPT;
+        break;
+
+        default:
+        ASSERT(FALSE);
+        break;
+    }
+
+    CurrentEntry = FCB->PendingIrpList[Function].Flink;
+    while (CurrentEntry != &FCB->PendingIrpList[Function])
+    {
+        CurrentIrp = CONTAINING_RECORD(CurrentEntry, IRP, Tail.Overlay.ListEntry);
+
+        if (CurrentIrp == Irp)
+        {
+            RemoveEntryList(CurrentEntry);
+            break;
+        }
+        else
+        {
+            CurrentEntry = CurrentEntry->Flink;
+        }
+    }
+    
+    UnlockAndMaybeComplete(FCB, STATUS_CANCELLED, Irp, 0);
+}
+
 static VOID NTAPI
 AfdUnload(PDRIVER_OBJECT DriverObject)
 {
 static VOID NTAPI
 AfdUnload(PDRIVER_OBJECT DriverObject)
 {
index 10d2ea9..0c69073 100644 (file)
@@ -154,6 +154,7 @@ static NTSTATUS ReceiveActivity( PAFD_FCB FCB, PIRP Irp ) {
                        RetBytesCopied = TotalBytesCopied;
                }
                if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
                        RetBytesCopied = TotalBytesCopied;
                }
                if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
+                (void)IoSetCancelRoutine(NextIrp, NULL);
                IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
           }
     }
                IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
           }
     }
@@ -210,6 +211,7 @@ NTSTATUS NTAPI ReceiveComplete
               NextIrp->IoStatus.Information = 0;
               UnlockBuffers(RecvReq->BufferArray, RecvReq->BufferCount, FALSE);
               if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
               NextIrp->IoStatus.Information = 0;
               UnlockBuffers(RecvReq->BufferArray, RecvReq->BufferCount, FALSE);
               if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
+               (void)IoSetCancelRoutine(NextIrp, NULL);
               IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
         }
        SocketStateUnlock( FCB );
               IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
         }
        SocketStateUnlock( FCB );
@@ -292,6 +294,7 @@ AfdConnectedSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
     } else if( Status == STATUS_PENDING ) {
         AFD_DbgPrint(MID_TRACE,("Leaving read irp\n"));
         IoMarkIrpPending( Irp );
     } else if( Status == STATUS_PENDING ) {
         AFD_DbgPrint(MID_TRACE,("Leaving read irp\n"));
         IoMarkIrpPending( Irp );
+        (void)IoSetCancelRoutine(Irp, AfdCancelHandler);
     } else {
         AFD_DbgPrint(MID_TRACE,("Completed with status %x\n", Status));
     }
     } else {
         AFD_DbgPrint(MID_TRACE,("Completed with status %x\n", Status));
     }
@@ -427,6 +430,7 @@ PacketSocketRecvComplete(
               NextIrp->IoStatus.Information = 0;
               UnlockBuffers(RecvReq->BufferArray, RecvReq->BufferCount, FALSE);
               if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
               NextIrp->IoStatus.Information = 0;
               UnlockBuffers(RecvReq->BufferArray, RecvReq->BufferCount, FALSE);
               if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
+               (void)IoSetCancelRoutine(NextIrp, NULL);
               IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
         }
 
               IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
         }
 
@@ -489,6 +493,7 @@ PacketSocketRecvComplete(
                        NextIrp->IoStatus.Information = DatagramRecv->Len;
                        UnlockBuffers( RecvReq->BufferArray, RecvReq->BufferCount, TRUE );
             if ( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
                        NextIrp->IoStatus.Information = DatagramRecv->Len;
                        UnlockBuffers( RecvReq->BufferArray, RecvReq->BufferCount, TRUE );
             if ( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
+                        (void)IoSetCancelRoutine(NextIrp, NULL);
                        IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
                } else {
                        AFD_DbgPrint(MID_TRACE,("Satisfying\n"));
                        IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
                } else {
                        AFD_DbgPrint(MID_TRACE,("Satisfying\n"));
@@ -499,6 +504,7 @@ PacketSocketRecvComplete(
                        UnlockBuffers( RecvReq->BufferArray, RecvReq->BufferCount, TRUE );
             if ( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
                        AFD_DbgPrint(MID_TRACE,("Completing\n"));
                        UnlockBuffers( RecvReq->BufferArray, RecvReq->BufferCount, TRUE );
             if ( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
                        AFD_DbgPrint(MID_TRACE,("Completing\n"));
+                        (void)IoSetCancelRoutine(NextIrp, NULL);
                        IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
                }
     }
                        IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
                }
     }
index e7c5c36..fffde26 100644 (file)
@@ -57,6 +57,7 @@ static NTSTATUS NTAPI SendComplete
               NextIrp->IoStatus.Information = 0;
               UnlockBuffers(SendReq->BufferArray, SendReq->BufferCount, FALSE);
               if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
               NextIrp->IoStatus.Information = 0;
               UnlockBuffers(SendReq->BufferArray, SendReq->BufferCount, FALSE);
               if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
+               (void)IoSetCancelRoutine(NextIrp, NULL);
               IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
         }
        SocketStateUnlock( FCB );
               IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
         }
        SocketStateUnlock( FCB );
@@ -82,7 +83,7 @@ static NTSTATUS NTAPI SendComplete
                        NextIrp->IoStatus.Information = 0;
 
                        if ( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
                        NextIrp->IoStatus.Information = 0;
 
                        if ( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
-
+                        (void)IoSetCancelRoutine(NextIrp, NULL);
                        IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
                }
 
                        IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
                }
 
@@ -197,6 +198,7 @@ static NTSTATUS NTAPI PacketSocketSendComplete
               NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
               NextIrp->IoStatus.Information = 0;
               if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
               NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
               NextIrp->IoStatus.Information = 0;
               if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
+               (void)IoSetCancelRoutine(NextIrp, NULL);
               IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
         }
        SocketStateUnlock( FCB );
               IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
         }
        SocketStateUnlock( FCB );
index b45fe38..c4db601 100644 (file)
@@ -279,6 +279,8 @@ VOID UnlockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp );
 VOID OskitDumpBuffer( PCHAR Buffer, UINT Len );
 NTSTATUS LeaveIrpUntilLater( PAFD_FCB FCB, PIRP Irp, UINT Function );
 VOID DestroySocket( PAFD_FCB FCB );
 VOID OskitDumpBuffer( PCHAR Buffer, UINT Len );
 NTSTATUS LeaveIrpUntilLater( PAFD_FCB FCB, PIRP Irp, UINT Function );
 VOID DestroySocket( PAFD_FCB FCB );
+VOID NTAPI AfdCancelHandler(PDEVICE_OBJECT DeviceObject,
+                 PIRP Irp);
 
 /* read.c */
 
 
 /* read.c */