From: Cameron Gutman Date: Sat, 7 Nov 2009 20:41:57 +0000 (+0000) Subject: - Stop using the TCPLock to protect all entries into the IP lib X-Git-Tag: ReactOS-0.3.11~121 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=024d413ccb509a5451aed6213aaaa287faaca25f - Stop using the TCPLock to protect all entries into the IP lib - Instead use TCPLock only to protect entries into oskittcp svn path=/trunk/; revision=44021 --- diff --git a/reactos/drivers/network/tcpip/include/lock.h b/reactos/drivers/network/tcpip/include/lock.h index f5c15f5aefa..b7cad5d720d 100644 --- a/reactos/drivers/network/tcpip/include/lock.h +++ b/reactos/drivers/network/tcpip/include/lock.h @@ -13,8 +13,7 @@ extern VOID TcpipInterlockedInsertTailList( PLIST_ENTRY ListHead, extern VOID TcpipAcquireFastMutex( PFAST_MUTEX Mutex ); extern VOID TcpipReleaseFastMutex( PFAST_MUTEX Mutex ); extern VOID TcpipRecursiveMutexInit( PRECURSIVE_MUTEX RecMutex ); -extern VOID TcpipRecursiveMutexEnter( PRECURSIVE_MUTEX RecMutex, - BOOLEAN ToWrite ); +extern VOID TcpipRecursiveMutexEnter( PRECURSIVE_MUTEX RecMutex ); extern VOID TcpipRecursiveMutexLeave( PRECURSIVE_MUTEX RecMutex ); #endif/*_LOCK_H*/ diff --git a/reactos/drivers/network/tcpip/tcpip/dispatch.c b/reactos/drivers/network/tcpip/tcpip/dispatch.c index f4e38b8fc50..182330928af 100644 --- a/reactos/drivers/network/tcpip/tcpip/dispatch.c +++ b/reactos/drivers/network/tcpip/tcpip/dispatch.c @@ -352,8 +352,6 @@ NTSTATUS DispTdiConnect( /* Get associated connection endpoint file object. Quit if none exists */ - TcpipRecursiveMutexEnter( &TCPLock, TRUE ); - TranContext = IrpSp->FileObject->FsContext; if (!TranContext) { TI_DbgPrint(MID_TRACE, ("Bad transport context.\n")); @@ -384,8 +382,6 @@ NTSTATUS DispTdiConnect( } done: - TcpipRecursiveMutexLeave( &TCPLock ); - if (Status != STATUS_PENDING) { DispDataRequestComplete(Irp, Status, 0); } else @@ -465,8 +461,6 @@ NTSTATUS DispTdiDisconnect( IrpSp = IoGetCurrentIrpStackLocation(Irp); DisReq = (PTDI_REQUEST_KERNEL_DISCONNECT)&IrpSp->Parameters; - TcpipRecursiveMutexEnter( &TCPLock, TRUE ); - /* Get associated connection endpoint file object. Quit if none exists */ TranContext = IrpSp->FileObject->FsContext; @@ -492,8 +486,6 @@ NTSTATUS DispTdiDisconnect( Irp ); done: - TcpipRecursiveMutexLeave( &TCPLock ); - if (Status != STATUS_PENDING) { DispDataRequestComplete(Irp, Status, 0); } else @@ -527,8 +519,6 @@ NTSTATUS DispTdiListen( /* Get associated connection endpoint file object. Quit if none exists */ - TcpipRecursiveMutexEnter( &TCPLock, TRUE ); - TranContext = IrpSp->FileObject->FsContext; if (TranContext == NULL) { @@ -593,8 +583,6 @@ NTSTATUS DispTdiListen( } done: - TcpipRecursiveMutexLeave( &TCPLock ); - if (Status != STATUS_PENDING) { DispDataRequestComplete(Irp, Status, 0); } else @@ -621,19 +609,15 @@ NTSTATUS DispTdiQueryInformation( PTDI_REQUEST_KERNEL_QUERY_INFORMATION Parameters; PTRANSPORT_CONTEXT TranContext; PIO_STACK_LOCATION IrpSp; - NTSTATUS Status; TI_DbgPrint(DEBUG_IRP, ("Called.\n")); IrpSp = IoGetCurrentIrpStackLocation(Irp); Parameters = (PTDI_REQUEST_KERNEL_QUERY_INFORMATION)&IrpSp->Parameters; - TcpipRecursiveMutexEnter( &TCPLock, TRUE ); - TranContext = IrpSp->FileObject->FsContext; if (!TranContext) { TI_DbgPrint(MID_TRACE, ("Bad transport context.\n")); - TcpipRecursiveMutexLeave(&TCPLock); return STATUS_INVALID_PARAMETER; } @@ -651,7 +635,6 @@ NTSTATUS DispTdiQueryInformation( (FIELD_OFFSET(TDI_ADDRESS_INFO, Address.Address[0].Address) + sizeof(TDI_ADDRESS_IP))) { TI_DbgPrint(MID_TRACE, ("MDL buffer too small.\n")); - TcpipRecursiveMutexLeave(&TCPLock); return STATUS_BUFFER_TOO_SMALL; } @@ -670,7 +653,6 @@ NTSTATUS DispTdiQueryInformation( RtlZeroMemory( &Address->Address[0].Address[0].sin_zero, sizeof(Address->Address[0].Address[0].sin_zero)); - TcpipRecursiveMutexLeave(&TCPLock); return STATUS_SUCCESS; case TDI_CONNECTION_FILE: @@ -681,12 +663,10 @@ NTSTATUS DispTdiQueryInformation( RtlZeroMemory( &Address->Address[0].Address[0].sin_zero, sizeof(Address->Address[0].Address[0].sin_zero)); - TcpipRecursiveMutexLeave(&TCPLock); return STATUS_SUCCESS; default: TI_DbgPrint(MIN_TRACE, ("Invalid transport context\n")); - TcpipRecursiveMutexLeave(&TCPLock); return STATUS_INVALID_PARAMETER; } } @@ -701,7 +681,6 @@ NTSTATUS DispTdiQueryInformation( (FIELD_OFFSET(TDI_CONNECTION_INFORMATION, RemoteAddress) + sizeof(PVOID))) { TI_DbgPrint(MID_TRACE, ("MDL buffer too small (ptr).\n")); - TcpipRecursiveMutexLeave(&TCPLock); return STATUS_BUFFER_TOO_SMALL; } @@ -721,24 +700,18 @@ NTSTATUS DispTdiQueryInformation( default: TI_DbgPrint(MIN_TRACE, ("Invalid transport context\n")); - TcpipRecursiveMutexLeave(&TCPLock); return STATUS_INVALID_PARAMETER; } if (!Endpoint) { TI_DbgPrint(MID_TRACE, ("No connection object.\n")); - TcpipRecursiveMutexLeave(&TCPLock); return STATUS_INVALID_PARAMETER; } - Status = TCPGetSockAddress( Endpoint, AddressInfo->RemoteAddress, TRUE ); - - TcpipRecursiveMutexLeave(&TCPLock); - return Status; + return TCPGetSockAddress( Endpoint, AddressInfo->RemoteAddress, TRUE ); } } - TcpipRecursiveMutexLeave(&TCPLock); return STATUS_NOT_IMPLEMENTED; } @@ -764,8 +737,6 @@ NTSTATUS DispTdiReceive( IrpSp = IoGetCurrentIrpStackLocation(Irp); ReceiveInfo = (PTDI_REQUEST_KERNEL_RECEIVE)&(IrpSp->Parameters); - TcpipRecursiveMutexEnter( &TCPLock, TRUE ); - TranContext = IrpSp->FileObject->FsContext; if (TranContext == NULL) { @@ -801,8 +772,6 @@ NTSTATUS DispTdiReceive( } done: - TcpipRecursiveMutexLeave( &TCPLock ); - if (Status != STATUS_PENDING) { DispDataRequestComplete(Irp, Status, BytesReceived); } else @@ -836,8 +805,6 @@ NTSTATUS DispTdiReceiveDatagram( IrpSp = IoGetCurrentIrpStackLocation(Irp); DgramInfo = (PTDI_REQUEST_KERNEL_RECEIVEDG)&(IrpSp->Parameters); - TcpipRecursiveMutexEnter( &TCPLock, TRUE ); - TranContext = IrpSp->FileObject->FsContext; if (TranContext == NULL) { @@ -879,8 +846,6 @@ NTSTATUS DispTdiReceiveDatagram( } done: - TcpipRecursiveMutexLeave( &TCPLock ); - if (Status != STATUS_PENDING) { DispDataRequestComplete(Irp, Status, BytesReceived); } else @@ -913,8 +878,6 @@ NTSTATUS DispTdiSend( IrpSp = IoGetCurrentIrpStackLocation(Irp); SendInfo = (PTDI_REQUEST_KERNEL_SEND)&(IrpSp->Parameters); - TcpipRecursiveMutexEnter( &TCPLock, TRUE ); - TranContext = IrpSp->FileObject->FsContext; if (TranContext == NULL) { @@ -955,8 +918,6 @@ NTSTATUS DispTdiSend( } done: - TcpipRecursiveMutexLeave( &TCPLock ); - if (Status != STATUS_PENDING) { DispDataRequestComplete(Irp, Status, BytesSent); } else @@ -989,8 +950,6 @@ NTSTATUS DispTdiSendDatagram( IrpSp = IoGetCurrentIrpStackLocation(Irp); DgramInfo = (PTDI_REQUEST_KERNEL_SENDDG)&(IrpSp->Parameters); - TcpipRecursiveMutexEnter( &TCPLock, TRUE ); - TranContext = IrpSp->FileObject->FsContext; if (TranContext == NULL) { @@ -1037,8 +996,6 @@ NTSTATUS DispTdiSendDatagram( } done: - TcpipRecursiveMutexLeave( &TCPLock ); - if (Status != STATUS_PENDING) { DispDataRequestComplete(Irp, Status, Irp->IoStatus.Information); } else diff --git a/reactos/drivers/network/tcpip/tcpip/fileobjs.c b/reactos/drivers/network/tcpip/tcpip/fileobjs.c index 866e9ff0694..85808f9c0bf 100644 --- a/reactos/drivers/network/tcpip/tcpip/fileobjs.c +++ b/reactos/drivers/network/tcpip/tcpip/fileobjs.c @@ -382,9 +382,7 @@ NTSTATUS FileCloseAddress( case IPPROTO_TCP: TCPFreePort( AddrFile->Port ); if( AddrFile->Listener ) { - TcpipRecursiveMutexEnter(&TCPLock, TRUE); TCPClose( AddrFile->Listener ); - TcpipRecursiveMutexLeave(&TCPLock); exFreePool( AddrFile->Listener ); } break; @@ -425,9 +423,7 @@ NTSTATUS FileOpenConnection( if( !Connection ) return STATUS_NO_MEMORY; - TcpipRecursiveMutexEnter(&TCPLock, TRUE); Status = TCPSocket( Connection, AF_INET, SOCK_STREAM, IPPROTO_TCP ); - TcpipRecursiveMutexLeave(&TCPLock); if( !NT_SUCCESS(Status) ) { TCPFreeConnectionEndpoint( Connection ); @@ -500,9 +496,7 @@ NTSTATUS FileCloseConnection( RemoveEntryList(&Connection->ListEntry); TcpipReleaseSpinLock(&ConnectionEndpointListLock, OldIrql); - TcpipRecursiveMutexEnter( &TCPLock, TRUE ); TCPClose( Connection ); - TcpipRecursiveMutexLeave( &TCPLock ); TCPFreeConnectionEndpoint(Connection); diff --git a/reactos/drivers/network/tcpip/tcpip/lock.c b/reactos/drivers/network/tcpip/tcpip/lock.c index db8ef244f33..3f9d823c857 100644 --- a/reactos/drivers/network/tcpip/tcpip/lock.c +++ b/reactos/drivers/network/tcpip/tcpip/lock.c @@ -48,7 +48,7 @@ VOID TcpipRecursiveMutexInit( PRECURSIVE_MUTEX RecMutex ) { RecursiveMutexInit( RecMutex ); } -VOID TcpipRecursiveMutexEnter( PRECURSIVE_MUTEX RecMutex, BOOLEAN ToWrite ) { +VOID TcpipRecursiveMutexEnter( PRECURSIVE_MUTEX RecMutex ) { //TI_DbgPrint(DEBUG_LOCK,("Locking\n")); RecursiveMutexEnter( RecMutex ); } diff --git a/reactos/drivers/network/tcpip/tcpip/mocklock.c b/reactos/drivers/network/tcpip/tcpip/mocklock.c index d2ef46b3a56..0042ef8b803 100644 --- a/reactos/drivers/network/tcpip/tcpip/mocklock.c +++ b/reactos/drivers/network/tcpip/tcpip/mocklock.c @@ -48,8 +48,7 @@ VOID TcpipReleaseFastMutex( PFAST_MUTEX Mutex ) { VOID TcpipRecursiveMutexInit( PRECURSIVE_MUTEX RecMutex ) { } -UINT TcpipRecursiveMutexEnter( PRECURSIVE_MUTEX RecMutex, BOOL ToWrite ) { - return 0; +VOID TcpipRecursiveMutexEnter( PRECURSIVE_MUTEX RecMutex ) { } VOID TcpipRecursiveMutexLeave( PRECURSIVE_MUTEX RecMutex ) { diff --git a/reactos/lib/drivers/ip/transport/tcp/accept.c b/reactos/lib/drivers/ip/transport/tcp/accept.c index ee1f3bf38d0..f44c0c918ec 100644 --- a/reactos/lib/drivers/ip/transport/tcp/accept.c +++ b/reactos/lib/drivers/ip/transport/tcp/accept.c @@ -19,8 +19,6 @@ NTSTATUS TCPServiceListeningSocket( PCONNECTION_ENDPOINT Listener, PTA_IP_ADDRESS RequestAddressReturn; PTDI_CONNECTION_INFORMATION WhoIsConnecting; - ASSERT_LOCKED(&TCPLock); - /* Unpack TDI info -- We need the return connection information * struct to return the address so it can be filtered if needed * by WSAAccept -- The returned address will be passed on to @@ -28,6 +26,8 @@ NTSTATUS TCPServiceListeningSocket( PCONNECTION_ENDPOINT Listener, WhoIsConnecting = (PTDI_CONNECTION_INFORMATION) Request->ReturnConnectionInformation; + TcpipRecursiveMutexEnter(&TCPLock); + Status = TCPTranslateError ( OskitTCPAccept( Listener->SocketContext, &Connection->SocketContext, @@ -36,6 +36,8 @@ NTSTATUS TCPServiceListeningSocket( PCONNECTION_ENDPOINT Listener, &OutAddrLen, Request->RequestFlags & TDI_QUERY_ACCEPT ? 0 : 1 ) ); + TcpipRecursiveMutexLeave(&TCPLock); + TI_DbgPrint(DEBUG_TCP,("Status %x\n", Status)); if( NT_SUCCESS(Status) && Status != STATUS_PENDING ) { @@ -70,8 +72,6 @@ NTSTATUS TCPListen( PCONNECTION_ENDPOINT Connection, UINT Backlog ) { NTSTATUS Status = STATUS_SUCCESS; SOCKADDR_IN AddressToBind; - TcpipRecursiveMutexEnter( &TCPLock, TRUE ); - ASSERT(Connection); ASSERT_KM_POINTER(Connection->SocketContext); ASSERT_KM_POINTER(Connection->AddressFile); @@ -89,6 +89,8 @@ NTSTATUS TCPListen( PCONNECTION_ENDPOINT Connection, UINT Backlog ) { TI_DbgPrint(DEBUG_TCP,("AddressToBind - %x:%x\n", AddressToBind.sin_addr, AddressToBind.sin_port)); + TcpipRecursiveMutexEnter( &TCPLock ); + Status = TCPTranslateError( OskitTCPBind( Connection->SocketContext, &AddressToBind, sizeof(AddressToBind) ) ); @@ -138,13 +140,9 @@ NTSTATUS TCPAccept ( PTDI_REQUEST Request, TI_DbgPrint(DEBUG_TCP,("TCPAccept started\n")); - TcpipRecursiveMutexEnter( &TCPLock, TRUE ); - Status = TCPServiceListeningSocket( Listener, Connection, (PTDI_REQUEST_KERNEL)Request ); - TcpipRecursiveMutexLeave( &TCPLock ); - if( Status == STATUS_PENDING ) { Bucket = exAllocatePool( NonPagedPool, sizeof(*Bucket) ); diff --git a/reactos/lib/drivers/ip/transport/tcp/event.c b/reactos/lib/drivers/ip/transport/tcp/event.c index c4c88a7bc80..ba9e867457b 100644 --- a/reactos/lib/drivers/ip/transport/tcp/event.c +++ b/reactos/lib/drivers/ip/transport/tcp/event.c @@ -44,8 +44,16 @@ int TCPSocketState(void *ClientData, Connection->SignalState |= NewState; + TcpipRecursiveMutexLeave(&TCPLock); + + /* We must not be locked when handling signalled connections + * because a completion could trigger another IOCTL which + * would cause a deadlock + */ NewState = HandleSignalledConnection(Connection); + TcpipRecursiveMutexEnter(&TCPLock); + KeAcquireSpinLock(&SignalledConnectionsLock, &OldIrql); if ((NewState == 0 || NewState == SEL_FIN) && (OldState != 0 && OldState != SEL_FIN)) diff --git a/reactos/lib/drivers/ip/transport/tcp/tcp.c b/reactos/lib/drivers/ip/transport/tcp/tcp.c index d256e899b46..a9907abf810 100644 --- a/reactos/lib/drivers/ip/transport/tcp/tcp.c +++ b/reactos/lib/drivers/ip/transport/tcp/tcp.c @@ -28,8 +28,6 @@ ULONG HandleSignalledConnection( PCONNECTION_ENDPOINT Connection ) { PIRP Irp; PMDL Mdl; - ASSERT_LOCKED(&TCPLock); - TI_DbgPrint(MID_TRACE,("Handling signalled state on %x (%x)\n", Connection, Connection->SocketContext)); @@ -337,7 +335,7 @@ NTSTATUS TCPSocket( PCONNECTION_ENDPOINT Connection, UINT Family, UINT Type, UINT Proto ) { NTSTATUS Status; - ASSERT_LOCKED(&TCPLock); + TcpipRecursiveMutexEnter(&TCPLock); TI_DbgPrint(DEBUG_TCP,("Called: Connection %x, Family %d, Type %d, " "Proto %d\n", @@ -354,6 +352,8 @@ NTSTATUS TCPSocket( PCONNECTION_ENDPOINT Connection, TI_DbgPrint(DEBUG_TCP,("Connection->SocketContext %x\n", Connection->SocketContext)); + TcpipRecursiveMutexLeave(&TCPLock); + return Status; } @@ -370,7 +370,7 @@ VOID TCPReceive(PIP_INTERFACE Interface, PIP_PACKET IPPacket) IPPacket->TotalSize, IPPacket->HeaderSize)); - TcpipRecursiveMutexEnter( &TCPLock, TRUE ); + TcpipRecursiveMutexEnter( &TCPLock ); OskitTCPReceiveDatagram( IPPacket->Header, IPPacket->TotalSize, @@ -447,12 +447,13 @@ TimerThread(PVOID Context) PsTerminateSystemThread(Status); } - TcpipRecursiveMutexEnter( &TCPLock, TRUE ); + TcpipRecursiveMutexEnter( &TCPLock ); TimerOskitTCP( Next == NextFast, Next == NextSlow ); + TcpipRecursiveMutexLeave( &TCPLock ); + if (Next == NextSlow) { DrainSignals(); } - TcpipRecursiveMutexLeave( &TCPLock ); Current = Next; if (10 <= Current) { @@ -496,7 +497,7 @@ NTSTATUS TCPStartup(VOID) return Status; } - TcpipRecursiveMutexEnter(&TCPLock, TRUE); + TcpipRecursiveMutexEnter(&TCPLock); RegisterOskitTCPEventHandlers( &EventHandlers ); InitOskitTCP(); TcpipRecursiveMutexLeave(&TCPLock); @@ -544,7 +545,9 @@ NTSTATUS TCPShutdown(VOID) TCPInitialized = FALSE; + TcpipRecursiveMutexEnter(&TCPLock); DeinitOskitTCP(); + TcpipRecursiveMutexLeave(&TCPLock); PortsShutdown( &TCPPorts ); @@ -597,8 +600,6 @@ NTSTATUS TCPConnect TI_DbgPrint(DEBUG_TCP,("TCPConnect: Called\n")); - ASSERT_LOCKED(&TCPLock); - Status = AddrBuildAddress ((PTRANSPORT_ADDRESS)ConnInfo->RemoteAddress, &RemoteAddress, @@ -624,6 +625,8 @@ NTSTATUS TCPConnect AddressToBind = AddressToConnect; AddressToBind.sin_addr.s_addr = NCE->Interface->Unicast.Address.IPv4Address; + TcpipRecursiveMutexEnter(&TCPLock); + Status = TCPTranslateError ( OskitTCPBind( Connection->SocketContext, &AddressToBind, @@ -655,6 +658,8 @@ NTSTATUS TCPConnect } } + TcpipRecursiveMutexLeave(&TCPLock); + return Status; } @@ -671,12 +676,16 @@ NTSTATUS TCPDisconnect TI_DbgPrint(DEBUG_TCP,("started\n")); + TcpipRecursiveMutexEnter(&TCPLock); + if (Flags & TDI_DISCONNECT_RELEASE) Status = TCPTranslateError(OskitTCPDisconnect(Connection->SocketContext)); if ((Flags & TDI_DISCONNECT_ABORT) || !Flags) Status = TCPTranslateError(OskitTCPShutdown(Connection->SocketContext, FWRITE | FREAD)); + TcpipRecursiveMutexLeave(&TCPLock); + TI_DbgPrint(DEBUG_TCP,("finished %x\n", Status)); return Status; @@ -688,16 +697,18 @@ NTSTATUS TCPClose TI_DbgPrint(DEBUG_TCP,("TCPClose started\n")); - ASSERT_LOCKED(&TCPLock); - /* Make our code remove all pending IRPs */ Connection->SignalState |= SEL_FIN; HandleSignalledConnection(Connection); + TcpipRecursiveMutexEnter(&TCPLock); + Status = TCPTranslateError( OskitTCPClose( Connection->SocketContext ) ); if (Status == STATUS_SUCCESS) Connection->SocketContext = NULL; + TcpipRecursiveMutexLeave(&TCPLock); + TI_DbgPrint(DEBUG_TCP,("TCPClose finished %x\n", Status)); return Status; @@ -719,14 +730,14 @@ NTSTATUS TCPReceiveData TI_DbgPrint(DEBUG_TCP,("Called for %d bytes (on socket %x)\n", ReceiveLength, Connection->SocketContext)); - ASSERT_LOCKED(&TCPLock); - ASSERT_KM_POINTER(Connection->SocketContext); NdisQueryBuffer( Buffer, &DataBuffer, &DataLen ); TI_DbgPrint(DEBUG_TCP,("TCP>|< Got an MDL %x (%x:%d)\n", Buffer, DataBuffer, DataLen)); + TcpipRecursiveMutexEnter(&TCPLock); + Status = TCPTranslateError ( OskitTCPRecv ( Connection->SocketContext, @@ -735,6 +746,8 @@ NTSTATUS TCPReceiveData &Received, ReceiveFlags ) ); + TcpipRecursiveMutexLeave(&TCPLock); + TI_DbgPrint(DEBUG_TCP,("OskitTCPReceive: %x, %d\n", Status, Received)); /* Keep this request around ... there was no data yet */ @@ -787,12 +800,15 @@ NTSTATUS TCPSendData TI_DbgPrint(DEBUG_TCP,("Connection->SocketContext = %x\n", Connection->SocketContext)); + TcpipRecursiveMutexEnter(&TCPLock); Status = TCPTranslateError ( OskitTCPSend( Connection->SocketContext, (OSK_PCHAR)BufferData, SendLength, &Sent, 0 ) ); + TcpipRecursiveMutexLeave(&TCPLock); + TI_DbgPrint(DEBUG_TCP,("OskitTCPSend: %x, %d\n", Status, Sent)); /* Keep this request around ... there was no data yet */ @@ -850,11 +866,14 @@ NTSTATUS TCPGetSockAddress PTA_IP_ADDRESS AddressIP = (PTA_IP_ADDRESS)Address; NTSTATUS Status; - ASSERT_LOCKED(&TCPLock); + TcpipRecursiveMutexEnter(&TCPLock); Status = TCPTranslateError(OskitTCPGetAddress(Connection->SocketContext, &LocalAddress, &LocalPort, &RemoteAddress, &RemotePort)); + + TcpipRecursiveMutexLeave(&TCPLock); + if (!NT_SUCCESS(Status)) return Status;