mirror of
https://github.com/reactos/reactos.git
synced 2025-01-05 22:12:46 +00:00
[AFD]
- Queue the user-mode connect IRP before calling TdiConnect to avoid a race if the TDI_CONNECT IRP is completed before we get a chance to queue the user-mode IRP to accept the connection - Change the non-blocking TDI helper functions to always return STATUS_PENDING if the completion function will be called to avoid duplicate handling of IRPs svn path=/trunk/; revision=52441
This commit is contained in:
parent
b1bcc80fd3
commit
f6485fab90
4 changed files with 53 additions and 60 deletions
|
@ -465,23 +465,30 @@ AfdStreamSocketConnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||||
TargetAddress->UserDataLength = FCB->ConnectDataSize;
|
TargetAddress->UserDataLength = FCB->ConnectDataSize;
|
||||||
TargetAddress->Options = FCB->ConnectOptions;
|
TargetAddress->Options = FCB->ConnectOptions;
|
||||||
TargetAddress->OptionsLength = FCB->ConnectOptionsSize;
|
TargetAddress->OptionsLength = FCB->ConnectOptionsSize;
|
||||||
|
|
||||||
|
FCB->State = SOCKET_STATE_CONNECTING;
|
||||||
|
|
||||||
|
AFD_DbgPrint(MID_TRACE,("Queueing IRP %x\n", Irp));
|
||||||
|
Status = QueueUserModeIrp( FCB, Irp, FUNCTION_CONNECT );
|
||||||
|
if (Status == STATUS_PENDING)
|
||||||
|
{
|
||||||
|
Status = TdiConnect( &FCB->ConnectIrp.InFlightRequest,
|
||||||
|
FCB->Connection.Object,
|
||||||
|
TargetAddress,
|
||||||
|
FCB->ConnectInfo,
|
||||||
|
&FCB->ConnectIrp.Iosb,
|
||||||
|
StreamSocketConnectComplete,
|
||||||
|
FCB );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Status != STATUS_PENDING)
|
||||||
|
FCB->State = SOCKET_STATE_BOUND;
|
||||||
|
|
||||||
Status = TdiConnect( &FCB->ConnectIrp.InFlightRequest,
|
ExFreePool(TargetAddress);
|
||||||
FCB->Connection.Object,
|
|
||||||
TargetAddress,
|
SocketStateUnlock(FCB);
|
||||||
FCB->ConnectInfo,
|
|
||||||
&FCB->ConnectIrp.Iosb,
|
|
||||||
StreamSocketConnectComplete,
|
|
||||||
FCB );
|
|
||||||
|
|
||||||
ExFreePool(TargetAddress);
|
return Status;
|
||||||
|
|
||||||
AFD_DbgPrint(MID_TRACE,("Queueing IRP %x\n", Irp));
|
|
||||||
|
|
||||||
if( Status == STATUS_PENDING ) {
|
|
||||||
FCB->State = SOCKET_STATE_CONNECTING;
|
|
||||||
return LeaveIrpUntilLater( FCB, Irp, FUNCTION_CONNECT );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -287,12 +287,13 @@ NTSTATUS LostSocket( PIRP Irp ) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS LeaveIrpUntilLater( PAFD_FCB FCB, PIRP Irp, UINT Function ) {
|
NTSTATUS QueueUserModeIrp(PAFD_FCB FCB, PIRP Irp, UINT Function)
|
||||||
|
{
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
/* Add the IRP to the queue in all cases (so AfdCancelHandler will work properly) */
|
/* Add the IRP to the queue in all cases (so AfdCancelHandler will work properly) */
|
||||||
InsertTailList( &FCB->PendingIrpList[Function],
|
InsertTailList( &FCB->PendingIrpList[Function],
|
||||||
&Irp->Tail.Overlay.ListEntry );
|
&Irp->Tail.Overlay.ListEntry );
|
||||||
|
|
||||||
/* Acquire the cancel spin lock and check the cancel bit */
|
/* Acquire the cancel spin lock and check the cancel bit */
|
||||||
IoAcquireCancelSpinLock(&Irp->CancelIrql);
|
IoAcquireCancelSpinLock(&Irp->CancelIrql);
|
||||||
|
@ -319,6 +320,14 @@ NTSTATUS LeaveIrpUntilLater( PAFD_FCB FCB, PIRP Irp, UINT Function ) {
|
||||||
Status = STATUS_CANCELLED;
|
Status = STATUS_CANCELLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
NTSTATUS LeaveIrpUntilLater( PAFD_FCB FCB, PIRP Irp, UINT Function ) {
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
|
Status = QueueUserModeIrp(FCB, Irp, Function);
|
||||||
|
|
||||||
SocketStateUnlock( FCB );
|
SocketStateUnlock( FCB );
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
|
|
|
@ -325,7 +325,6 @@ NTSTATUS TdiConnect(
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PDEVICE_OBJECT DeviceObject;
|
PDEVICE_OBJECT DeviceObject;
|
||||||
NTSTATUS Status;
|
|
||||||
|
|
||||||
AFD_DbgPrint(MAX_TRACE, ("Called\n"));
|
AFD_DbgPrint(MAX_TRACE, ("Called\n"));
|
||||||
|
|
||||||
|
@ -360,9 +359,9 @@ NTSTATUS TdiConnect(
|
||||||
ConnectionCallInfo, /* Request connection information */
|
ConnectionCallInfo, /* Request connection information */
|
||||||
ConnectionReturnInfo); /* Return connection information */
|
ConnectionReturnInfo); /* Return connection information */
|
||||||
|
|
||||||
Status = TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
||||||
|
|
||||||
return Status;
|
return STATUS_PENDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -380,7 +379,6 @@ NTSTATUS TdiAssociateAddressFile(
|
||||||
{
|
{
|
||||||
PDEVICE_OBJECT DeviceObject;
|
PDEVICE_OBJECT DeviceObject;
|
||||||
IO_STATUS_BLOCK Iosb;
|
IO_STATUS_BLOCK Iosb;
|
||||||
NTSTATUS Status;
|
|
||||||
KEVENT Event;
|
KEVENT Event;
|
||||||
PIRP Irp;
|
PIRP Irp;
|
||||||
|
|
||||||
|
@ -415,9 +413,7 @@ NTSTATUS TdiAssociateAddressFile(
|
||||||
NULL,
|
NULL,
|
||||||
AddressHandle);
|
AddressHandle);
|
||||||
|
|
||||||
Status = TdiCall(Irp, DeviceObject, &Event, &Iosb);
|
return TdiCall(Irp, DeviceObject, &Event, &Iosb);
|
||||||
|
|
||||||
return Status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS TdiDisassociateAddressFile(
|
NTSTATUS TdiDisassociateAddressFile(
|
||||||
|
@ -432,7 +428,6 @@ NTSTATUS TdiDisassociateAddressFile(
|
||||||
{
|
{
|
||||||
PDEVICE_OBJECT DeviceObject;
|
PDEVICE_OBJECT DeviceObject;
|
||||||
IO_STATUS_BLOCK Iosb;
|
IO_STATUS_BLOCK Iosb;
|
||||||
NTSTATUS Status;
|
|
||||||
KEVENT Event;
|
KEVENT Event;
|
||||||
PIRP Irp;
|
PIRP Irp;
|
||||||
|
|
||||||
|
@ -465,9 +460,7 @@ NTSTATUS TdiDisassociateAddressFile(
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
Status = TdiCall(Irp, DeviceObject, &Event, &Iosb);
|
return TdiCall(Irp, DeviceObject, &Event, &Iosb);
|
||||||
|
|
||||||
return Status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS TdiListen
|
NTSTATUS TdiListen
|
||||||
|
@ -489,7 +482,6 @@ NTSTATUS TdiListen
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PDEVICE_OBJECT DeviceObject;
|
PDEVICE_OBJECT DeviceObject;
|
||||||
NTSTATUS Status;
|
|
||||||
|
|
||||||
AFD_DbgPrint(MAX_TRACE, ("Called\n"));
|
AFD_DbgPrint(MAX_TRACE, ("Called\n"));
|
||||||
|
|
||||||
|
@ -523,9 +515,9 @@ NTSTATUS TdiListen
|
||||||
*RequestConnectionInfo, /* Request connection information */
|
*RequestConnectionInfo, /* Request connection information */
|
||||||
*ReturnConnectionInfo); /* Return connection information */
|
*ReturnConnectionInfo); /* Return connection information */
|
||||||
|
|
||||||
Status = TdiCall(*Irp, DeviceObject, NULL /* Don't wait for completion */, Iosb);
|
TdiCall(*Irp, DeviceObject, NULL /* Don't wait for completion */, Iosb);
|
||||||
|
|
||||||
return Status;
|
return STATUS_PENDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -549,7 +541,6 @@ NTSTATUS TdiSetEventHandler(
|
||||||
{
|
{
|
||||||
PDEVICE_OBJECT DeviceObject;
|
PDEVICE_OBJECT DeviceObject;
|
||||||
IO_STATUS_BLOCK Iosb;
|
IO_STATUS_BLOCK Iosb;
|
||||||
NTSTATUS Status;
|
|
||||||
KEVENT Event;
|
KEVENT Event;
|
||||||
PIRP Irp;
|
PIRP Irp;
|
||||||
|
|
||||||
|
@ -587,9 +578,7 @@ NTSTATUS TdiSetEventHandler(
|
||||||
Handler,
|
Handler,
|
||||||
Context);
|
Context);
|
||||||
|
|
||||||
Status = TdiCall(Irp, DeviceObject, &Event, &Iosb);
|
return TdiCall(Irp, DeviceObject, &Event, &Iosb);
|
||||||
|
|
||||||
return Status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -670,7 +659,6 @@ NTSTATUS TdiQueryInformation(
|
||||||
{
|
{
|
||||||
PDEVICE_OBJECT DeviceObject;
|
PDEVICE_OBJECT DeviceObject;
|
||||||
IO_STATUS_BLOCK Iosb;
|
IO_STATUS_BLOCK Iosb;
|
||||||
NTSTATUS Status;
|
|
||||||
KEVENT Event;
|
KEVENT Event;
|
||||||
PIRP Irp;
|
PIRP Irp;
|
||||||
|
|
||||||
|
@ -705,9 +693,7 @@ NTSTATUS TdiQueryInformation(
|
||||||
QueryType,
|
QueryType,
|
||||||
MdlBuffer);
|
MdlBuffer);
|
||||||
|
|
||||||
Status = TdiCall(Irp, DeviceObject, &Event, &Iosb);
|
return TdiCall(Irp, DeviceObject, &Event, &Iosb);
|
||||||
|
|
||||||
return Status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS TdiQueryInformationEx(
|
NTSTATUS TdiQueryInformationEx(
|
||||||
|
@ -897,7 +883,6 @@ NTSTATUS TdiSend
|
||||||
PVOID CompletionContext )
|
PVOID CompletionContext )
|
||||||
{
|
{
|
||||||
PDEVICE_OBJECT DeviceObject;
|
PDEVICE_OBJECT DeviceObject;
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
|
||||||
PMDL Mdl;
|
PMDL Mdl;
|
||||||
|
|
||||||
ASSERT(*Irp == NULL);
|
ASSERT(*Irp == NULL);
|
||||||
|
@ -960,11 +945,11 @@ NTSTATUS TdiSend
|
||||||
Flags, /* Flags */
|
Flags, /* Flags */
|
||||||
BufferLength); /* Length of data */
|
BufferLength); /* Length of data */
|
||||||
|
|
||||||
Status = TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
||||||
/* Does not block... The MDL is deleted in the receive completion
|
/* Does not block... The MDL is deleted in the receive completion
|
||||||
routine. */
|
routine. */
|
||||||
|
|
||||||
return Status;
|
return STATUS_PENDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS TdiReceive(
|
NTSTATUS TdiReceive(
|
||||||
|
@ -977,7 +962,6 @@ NTSTATUS TdiReceive(
|
||||||
PIO_COMPLETION_ROUTINE CompletionRoutine,
|
PIO_COMPLETION_ROUTINE CompletionRoutine,
|
||||||
PVOID CompletionContext)
|
PVOID CompletionContext)
|
||||||
{
|
{
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
|
||||||
PDEVICE_OBJECT DeviceObject;
|
PDEVICE_OBJECT DeviceObject;
|
||||||
PMDL Mdl;
|
PMDL Mdl;
|
||||||
|
|
||||||
|
@ -1028,7 +1012,7 @@ NTSTATUS TdiReceive(
|
||||||
AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
|
AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
|
||||||
IoFreeMdl(Mdl);
|
IoFreeMdl(Mdl);
|
||||||
IoCompleteRequest(*Irp, IO_NO_INCREMENT);
|
IoCompleteRequest(*Irp, IO_NO_INCREMENT);
|
||||||
*Irp = NULL;
|
*Irp = NULL;
|
||||||
_SEH2_YIELD(return STATUS_INSUFFICIENT_RESOURCES);
|
_SEH2_YIELD(return STATUS_INSUFFICIENT_RESOURCES);
|
||||||
} _SEH2_END;
|
} _SEH2_END;
|
||||||
|
|
||||||
|
@ -1044,14 +1028,11 @@ NTSTATUS TdiReceive(
|
||||||
BufferLength); /* Length of data */
|
BufferLength); /* Length of data */
|
||||||
|
|
||||||
|
|
||||||
Status = TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
||||||
/* Does not block... The MDL is deleted in the receive completion
|
/* Does not block... The MDL is deleted in the receive completion
|
||||||
routine. */
|
routine. */
|
||||||
|
|
||||||
AFD_DbgPrint(MID_TRACE,("Status %x Information %d\n",
|
return STATUS_PENDING;
|
||||||
Status, Iosb->Information));
|
|
||||||
|
|
||||||
return Status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1078,7 +1059,6 @@ NTSTATUS TdiReceiveDatagram(
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PDEVICE_OBJECT DeviceObject;
|
PDEVICE_OBJECT DeviceObject;
|
||||||
NTSTATUS Status;
|
|
||||||
PMDL Mdl;
|
PMDL Mdl;
|
||||||
|
|
||||||
ASSERT(*Irp == NULL);
|
ASSERT(*Irp == NULL);
|
||||||
|
@ -1144,11 +1124,11 @@ NTSTATUS TdiReceiveDatagram(
|
||||||
Addr,
|
Addr,
|
||||||
Flags); /* Length of data */
|
Flags); /* Length of data */
|
||||||
|
|
||||||
Status = TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
||||||
/* Does not block... The MDL is deleted in the receive completion
|
/* Does not block... The MDL is deleted in the receive completion
|
||||||
routine. */
|
routine. */
|
||||||
|
|
||||||
return Status;
|
return STATUS_PENDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1174,7 +1154,6 @@ NTSTATUS TdiSendDatagram(
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PDEVICE_OBJECT DeviceObject;
|
PDEVICE_OBJECT DeviceObject;
|
||||||
NTSTATUS Status;
|
|
||||||
PMDL Mdl;
|
PMDL Mdl;
|
||||||
|
|
||||||
ASSERT(*Irp == NULL);
|
ASSERT(*Irp == NULL);
|
||||||
|
@ -1241,11 +1220,11 @@ NTSTATUS TdiSendDatagram(
|
||||||
BufferLength, /* Bytes to send */
|
BufferLength, /* Bytes to send */
|
||||||
Addr); /* Address */
|
Addr); /* Address */
|
||||||
|
|
||||||
Status = TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
||||||
/* Does not block... The MDL is deleted in the send completion
|
/* Does not block... The MDL is deleted in the send completion
|
||||||
routine. */
|
routine. */
|
||||||
|
|
||||||
return Status;
|
return STATUS_PENDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS TdiDisconnect(
|
NTSTATUS TdiDisconnect(
|
||||||
|
@ -1258,7 +1237,6 @@ NTSTATUS TdiDisconnect(
|
||||||
PTDI_CONNECTION_INFORMATION RequestConnectionInfo,
|
PTDI_CONNECTION_INFORMATION RequestConnectionInfo,
|
||||||
PTDI_CONNECTION_INFORMATION ReturnConnectionInfo) {
|
PTDI_CONNECTION_INFORMATION ReturnConnectionInfo) {
|
||||||
PDEVICE_OBJECT DeviceObject;
|
PDEVICE_OBJECT DeviceObject;
|
||||||
NTSTATUS Status;
|
|
||||||
KEVENT Event;
|
KEVENT Event;
|
||||||
PIRP Irp;
|
PIRP Irp;
|
||||||
|
|
||||||
|
@ -1300,9 +1278,7 @@ NTSTATUS TdiDisconnect(
|
||||||
RequestConnectionInfo, /* Indication of who to disconnect */
|
RequestConnectionInfo, /* Indication of who to disconnect */
|
||||||
ReturnConnectionInfo); /* Indication of who disconnected */
|
ReturnConnectionInfo); /* Indication of who disconnected */
|
||||||
|
|
||||||
Status = TdiCall(Irp, DeviceObject, &Event, Iosb);
|
return TdiCall(Irp, DeviceObject, &Event, Iosb);
|
||||||
|
|
||||||
return Status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -302,11 +302,12 @@ VOID UnlockHandles( PAFD_HANDLE HandleArray, UINT HandleCount );
|
||||||
PVOID LockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp );
|
PVOID LockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp );
|
||||||
VOID UnlockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp );
|
VOID UnlockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp );
|
||||||
PVOID GetLockedData( PIRP Irp, PIO_STACK_LOCATION IrpSp );
|
PVOID GetLockedData( PIRP Irp, PIO_STACK_LOCATION IrpSp );
|
||||||
|
NTSTATUS LeaveIrpUntilLater( PAFD_FCB FCB, PIRP Irp, UINT Function );
|
||||||
|
NTSTATUS QueueUserModeIrp(PAFD_FCB FCB, PIRP Irp, UINT Function);
|
||||||
|
|
||||||
/* main.c */
|
/* main.c */
|
||||||
|
|
||||||
VOID OskitDumpBuffer( PCHAR Buffer, UINT Len );
|
VOID OskitDumpBuffer( PCHAR Buffer, UINT Len );
|
||||||
NTSTATUS LeaveIrpUntilLater( PAFD_FCB FCB, PIRP Irp, UINT Function );
|
|
||||||
VOID DestroySocket( PAFD_FCB FCB );
|
VOID DestroySocket( PAFD_FCB FCB );
|
||||||
VOID NTAPI AfdCancelHandler(PDEVICE_OBJECT DeviceObject,
|
VOID NTAPI AfdCancelHandler(PDEVICE_OBJECT DeviceObject,
|
||||||
PIRP Irp);
|
PIRP Irp);
|
||||||
|
|
Loading…
Reference in a new issue