Author: cgutman
Date: Sat Nov 7 21:41:57 2009
New Revision: 44021
URL:
http://svn.reactos.org/svn/reactos?rev=44021&view=rev
Log:
- Stop using the TCPLock to protect all entries into the IP lib
- Instead use TCPLock only to protect entries into oskittcp
Modified:
trunk/reactos/drivers/network/tcpip/include/lock.h
trunk/reactos/drivers/network/tcpip/tcpip/dispatch.c
trunk/reactos/drivers/network/tcpip/tcpip/fileobjs.c
trunk/reactos/drivers/network/tcpip/tcpip/lock.c
trunk/reactos/drivers/network/tcpip/tcpip/mocklock.c
trunk/reactos/lib/drivers/ip/transport/tcp/accept.c
trunk/reactos/lib/drivers/ip/transport/tcp/event.c
trunk/reactos/lib/drivers/ip/transport/tcp/tcp.c
Modified: trunk/reactos/drivers/network/tcpip/include/lock.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/incl…
==============================================================================
--- trunk/reactos/drivers/network/tcpip/include/lock.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/include/lock.h [iso-8859-1] Sat Nov 7 21:41:57
2009
@@ -13,8 +13,7 @@
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*/
Modified: trunk/reactos/drivers/network/tcpip/tcpip/dispatch.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/tcpi…
==============================================================================
--- trunk/reactos/drivers/network/tcpip/tcpip/dispatch.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/tcpip/dispatch.c [iso-8859-1] Sat Nov 7 21:41:57
2009
@@ -352,8 +352,6 @@
/* 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 @@
}
done:
- TcpipRecursiveMutexLeave( &TCPLock );
-
if (Status != STATUS_PENDING) {
DispDataRequestComplete(Irp, Status, 0);
} else
@@ -464,8 +460,6 @@
IrpSp = IoGetCurrentIrpStackLocation(Irp);
DisReq = (PTDI_REQUEST_KERNEL_DISCONNECT)&IrpSp->Parameters;
-
- TcpipRecursiveMutexEnter( &TCPLock, TRUE );
/* Get associated connection endpoint file object. Quit if none exists */
@@ -492,8 +486,6 @@
Irp );
done:
- TcpipRecursiveMutexLeave( &TCPLock );
-
if (Status != STATUS_PENDING) {
DispDataRequestComplete(Irp, Status, 0);
} else
@@ -526,8 +518,6 @@
IrpSp = IoGetCurrentIrpStackLocation(Irp);
/* Get associated connection endpoint file object. Quit if none exists */
-
- TcpipRecursiveMutexEnter( &TCPLock, TRUE );
TranContext = IrpSp->FileObject->FsContext;
if (TranContext == NULL)
@@ -593,8 +583,6 @@
}
done:
- TcpipRecursiveMutexLeave( &TCPLock );
-
if (Status != STATUS_PENDING) {
DispDataRequestComplete(Irp, Status, 0);
} else
@@ -621,19 +609,15 @@
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 @@
(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 @@
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 @@
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 @@
(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 @@
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;
}
@@ -763,8 +736,6 @@
IrpSp = IoGetCurrentIrpStackLocation(Irp);
ReceiveInfo = (PTDI_REQUEST_KERNEL_RECEIVE)&(IrpSp->Parameters);
-
- TcpipRecursiveMutexEnter( &TCPLock, TRUE );
TranContext = IrpSp->FileObject->FsContext;
if (TranContext == NULL)
@@ -801,8 +772,6 @@
}
done:
- TcpipRecursiveMutexLeave( &TCPLock );
-
if (Status != STATUS_PENDING) {
DispDataRequestComplete(Irp, Status, BytesReceived);
} else
@@ -835,8 +804,6 @@
IrpSp = IoGetCurrentIrpStackLocation(Irp);
DgramInfo = (PTDI_REQUEST_KERNEL_RECEIVEDG)&(IrpSp->Parameters);
-
- TcpipRecursiveMutexEnter( &TCPLock, TRUE );
TranContext = IrpSp->FileObject->FsContext;
if (TranContext == NULL)
@@ -879,8 +846,6 @@
}
done:
- TcpipRecursiveMutexLeave( &TCPLock );
-
if (Status != STATUS_PENDING) {
DispDataRequestComplete(Irp, Status, BytesReceived);
} else
@@ -912,8 +877,6 @@
IrpSp = IoGetCurrentIrpStackLocation(Irp);
SendInfo = (PTDI_REQUEST_KERNEL_SEND)&(IrpSp->Parameters);
-
- TcpipRecursiveMutexEnter( &TCPLock, TRUE );
TranContext = IrpSp->FileObject->FsContext;
if (TranContext == NULL)
@@ -955,8 +918,6 @@
}
done:
- TcpipRecursiveMutexLeave( &TCPLock );
-
if (Status != STATUS_PENDING) {
DispDataRequestComplete(Irp, Status, BytesSent);
} else
@@ -988,8 +949,6 @@
IrpSp = IoGetCurrentIrpStackLocation(Irp);
DgramInfo = (PTDI_REQUEST_KERNEL_SENDDG)&(IrpSp->Parameters);
-
- TcpipRecursiveMutexEnter( &TCPLock, TRUE );
TranContext = IrpSp->FileObject->FsContext;
if (TranContext == NULL)
@@ -1037,8 +996,6 @@
}
done:
- TcpipRecursiveMutexLeave( &TCPLock );
-
if (Status != STATUS_PENDING) {
DispDataRequestComplete(Irp, Status, Irp->IoStatus.Information);
} else
Modified: trunk/reactos/drivers/network/tcpip/tcpip/fileobjs.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/tcpi…
==============================================================================
--- trunk/reactos/drivers/network/tcpip/tcpip/fileobjs.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/tcpip/fileobjs.c [iso-8859-1] Sat Nov 7 21:41:57
2009
@@ -382,9 +382,7 @@
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 @@
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 @@
RemoveEntryList(&Connection->ListEntry);
TcpipReleaseSpinLock(&ConnectionEndpointListLock, OldIrql);
- TcpipRecursiveMutexEnter( &TCPLock, TRUE );
TCPClose( Connection );
- TcpipRecursiveMutexLeave( &TCPLock );
TCPFreeConnectionEndpoint(Connection);
Modified: trunk/reactos/drivers/network/tcpip/tcpip/lock.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/tcpi…
==============================================================================
--- trunk/reactos/drivers/network/tcpip/tcpip/lock.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/tcpip/lock.c [iso-8859-1] Sat Nov 7 21:41:57
2009
@@ -48,7 +48,7 @@
RecursiveMutexInit( RecMutex );
}
-VOID TcpipRecursiveMutexEnter( PRECURSIVE_MUTEX RecMutex, BOOLEAN ToWrite ) {
+VOID TcpipRecursiveMutexEnter( PRECURSIVE_MUTEX RecMutex ) {
//TI_DbgPrint(DEBUG_LOCK,("Locking\n"));
RecursiveMutexEnter( RecMutex );
}
Modified: trunk/reactos/drivers/network/tcpip/tcpip/mocklock.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/tcpi…
==============================================================================
--- trunk/reactos/drivers/network/tcpip/tcpip/mocklock.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/tcpip/mocklock.c [iso-8859-1] Sat Nov 7 21:41:57
2009
@@ -48,8 +48,7 @@
VOID TcpipRecursiveMutexInit( PRECURSIVE_MUTEX RecMutex ) {
}
-UINT TcpipRecursiveMutexEnter( PRECURSIVE_MUTEX RecMutex, BOOL ToWrite ) {
- return 0;
+VOID TcpipRecursiveMutexEnter( PRECURSIVE_MUTEX RecMutex ) {
}
VOID TcpipRecursiveMutexLeave( PRECURSIVE_MUTEX RecMutex ) {
Modified: trunk/reactos/lib/drivers/ip/transport/tcp/accept.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/transport/t…
==============================================================================
--- trunk/reactos/lib/drivers/ip/transport/tcp/accept.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/transport/tcp/accept.c [iso-8859-1] Sat Nov 7 21:41:57
2009
@@ -19,14 +19,14 @@
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
* userland after we complete this irp */
WhoIsConnecting = (PTDI_CONNECTION_INFORMATION)
Request->ReturnConnectionInformation;
+
+ TcpipRecursiveMutexEnter(&TCPLock);
Status = TCPTranslateError
( OskitTCPAccept( Listener->SocketContext,
@@ -35,6 +35,8 @@
sizeof(OutAddr),
&OutAddrLen,
Request->RequestFlags & TDI_QUERY_ACCEPT ? 0 : 1 ) );
+
+ TcpipRecursiveMutexLeave(&TCPLock);
TI_DbgPrint(DEBUG_TCP,("Status %x\n", Status));
@@ -70,8 +72,6 @@
NTSTATUS Status = STATUS_SUCCESS;
SOCKADDR_IN AddressToBind;
- TcpipRecursiveMutexEnter( &TCPLock, TRUE );
-
ASSERT(Connection);
ASSERT_KM_POINTER(Connection->SocketContext);
ASSERT_KM_POINTER(Connection->AddressFile);
@@ -88,6 +88,8 @@
AddressToBind.sin_port = Connection->AddressFile->Port;
TI_DbgPrint(DEBUG_TCP,("AddressToBind - %x:%x\n", AddressToBind.sin_addr,
AddressToBind.sin_port));
+
+ TcpipRecursiveMutexEnter( &TCPLock );
Status = TCPTranslateError( OskitTCPBind( Connection->SocketContext,
&AddressToBind,
@@ -138,12 +140,8 @@
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) );
Modified: trunk/reactos/lib/drivers/ip/transport/tcp/event.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/transport/t…
==============================================================================
--- trunk/reactos/lib/drivers/ip/transport/tcp/event.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/transport/tcp/event.c [iso-8859-1] Sat Nov 7 21:41:57
2009
@@ -44,7 +44,15 @@
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) &&
Modified: trunk/reactos/lib/drivers/ip/transport/tcp/tcp.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/transport/t…
==============================================================================
--- trunk/reactos/lib/drivers/ip/transport/tcp/tcp.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/transport/tcp/tcp.c [iso-8859-1] Sat Nov 7 21:41:57
2009
@@ -27,8 +27,6 @@
PLIST_ENTRY Entry;
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 @@
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",
@@ -353,6 +351,8 @@
TI_DbgPrint(DEBUG_TCP,("Connection->SocketContext %x\n",
Connection->SocketContext));
+
+ TcpipRecursiveMutexLeave(&TCPLock);
return Status;
}
@@ -370,7 +370,7 @@
IPPacket->TotalSize,
IPPacket->HeaderSize));
- TcpipRecursiveMutexEnter( &TCPLock, TRUE );
+ TcpipRecursiveMutexEnter( &TCPLock );
OskitTCPReceiveDatagram( IPPacket->Header,
IPPacket->TotalSize,
@@ -447,12 +447,13 @@
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 @@
return Status;
}
- TcpipRecursiveMutexEnter(&TCPLock, TRUE);
+ TcpipRecursiveMutexEnter(&TCPLock);
RegisterOskitTCPEventHandlers( &EventHandlers );
InitOskitTCP();
TcpipRecursiveMutexLeave(&TCPLock);
@@ -544,7 +545,9 @@
TCPInitialized = FALSE;
+ TcpipRecursiveMutexEnter(&TCPLock);
DeinitOskitTCP();
+ TcpipRecursiveMutexLeave(&TCPLock);
PortsShutdown( &TCPPorts );
@@ -597,8 +600,6 @@
TI_DbgPrint(DEBUG_TCP,("TCPConnect: Called\n"));
- ASSERT_LOCKED(&TCPLock);
-
Status = AddrBuildAddress
((PTRANSPORT_ADDRESS)ConnInfo->RemoteAddress,
&RemoteAddress,
@@ -623,6 +624,8 @@
AddressToConnect.sin_family = AF_INET;
AddressToBind = AddressToConnect;
AddressToBind.sin_addr.s_addr = NCE->Interface->Unicast.Address.IPv4Address;
+
+ TcpipRecursiveMutexEnter(&TCPLock);
Status = TCPTranslateError
( OskitTCPBind( Connection->SocketContext,
@@ -655,6 +658,8 @@
}
}
+ TcpipRecursiveMutexLeave(&TCPLock);
+
return Status;
}
@@ -671,11 +676,15 @@
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));
@@ -688,15 +697,17 @@
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));
@@ -719,13 +730,13 @@
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
@@ -734,6 +745,8 @@
DataLen,
&Received,
ReceiveFlags ) );
+
+ TcpipRecursiveMutexLeave(&TCPLock);
TI_DbgPrint(DEBUG_TCP,("OskitTCPReceive: %x, %d\n", Status, Received));
@@ -787,11 +800,14 @@
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));
@@ -850,11 +866,14 @@
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;