Author: zhu
Date: Tue Aug 16 21:42:21 2016
New Revision: 72237
URL:
http://svn.reactos.org/svn/reactos?rev=72237&view=rev
Log:
Set Irp->CancelRoutine when enqueueing IRPs.
More detailed debug printouts. Deleted old debug printouts.
Modified:
branches/GSoC_2016/lwIP-tcpip/base/applications/network/tcpclient/main.c
branches/GSoC_2016/lwIP-tcpip/drivers/network/tcpip/address.c
branches/GSoC_2016/lwIP-tcpip/drivers/network/tcpip/address.h
branches/GSoC_2016/lwIP-tcpip/drivers/network/tcpip/main.c
Modified: branches/GSoC_2016/lwIP-tcpip/base/applications/network/tcpclient/main.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2016/lwIP-tcpip/base/appli…
==============================================================================
--- branches/GSoC_2016/lwIP-tcpip/base/applications/network/tcpclient/main.c [iso-8859-1]
(original)
+++ branches/GSoC_2016/lwIP-tcpip/base/applications/network/tcpclient/main.c [iso-8859-1]
Tue Aug 16 21:42:21 2016
@@ -3,7 +3,7 @@
#include <winsock2.h>
#define LENGTH 255
-#define NUM_CLIENTS 1
+#define NUM_CLIENTS 2
DWORD WINAPI ClientThreadMain(LPVOID lpParam) {
SOCKET Sock;
@@ -30,7 +30,7 @@
ServerAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
ServerAddr.sin_port = htons(10000);
- printf("Client %d attempting to connect\n", self);
+ printf("Client %d attempting to connect\n", self);
ret = connect(Sock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in));
if (ret == SOCKET_ERROR) {
printf("Client %d failed to connect: %d\n", self, WSAGetLastError());
@@ -40,7 +40,7 @@
sprintf(buff, "Client %d pinging server", self);
len = strlen(buff);
- printf("Client %d attempting to send\n", self);
+ printf("Client %d attempting to send\n", self);
ret = send(Sock, buff, len, 0);
if (ret != len) {
printf("Client %d failed to send properly. Should send %d bytes, send()
returned %d\n WSA Error: %d\n",
@@ -49,7 +49,7 @@
return 1;
}
- printf("Client %d attempting to receive\n", self);
+ printf("Client %d attempting to receive\n", self);
ret = recv(Sock, buff, LENGTH, 0);
buff[LENGTH - 1] = '\0';
if (ret <= 0) {
Modified: branches/GSoC_2016/lwIP-tcpip/drivers/network/tcpip/address.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2016/lwIP-tcpip/drivers/ne…
==============================================================================
--- branches/GSoC_2016/lwIP-tcpip/drivers/network/tcpip/address.c [iso-8859-1] (original)
+++ branches/GSoC_2016/lwIP-tcpip/drivers/network/tcpip/address.c [iso-8859-1] Tue Aug 16
21:42:21 2016
@@ -230,6 +230,13 @@
#define AddrIsUnspecified(Address) ((Address->in_addr == 0) || (Address->in_addr ==
0xFFFFFFFF))
#define TCP_SET_STATE(State,Context) \
+ Context->TcpState = State
+#define TCP_ADD_STATE(State,Context) \
+ Context->TcpState |= State
+#define TCP_RMV_STATE(State,Context) \
+ Context->TcpState &= ~(State)
+/*
+#define TCP_SET_STATE(State,Context) \
DPRINT("Setting Context %p State to %s\n", Context, #State); \
Context->TcpState = State
#define TCP_ADD_STATE(State,Context) \
@@ -238,7 +245,7 @@
#define TCP_RMV_STATE(State,Context) \
DPRINT("Removing State %s from Context %p\n", #State, Context); \
Context->TcpState &= ~(State)
-
+*/
/**
* Context mutex functions
**/
@@ -256,7 +263,19 @@
PTCP_CONTEXT Context
)
{
+/*
+#ifndef NDEBUG
+ PKTHREAD Thread;
+ Thread = KeGetCurrentThread();
+ DPRINT("Thread %p acquiring lock on Context %p\n", Thread, Context);
+#endif
+*/
KeWaitForMutexObject(&Context->Mutex, Executive, KernelMode, FALSE, NULL);
+/*
+#ifndef NDEBUG
+ DPRINT("Thread %p acquired lock on Context %p\n", Thread, Context);
+#endif
+*/
}
VOID
@@ -264,7 +283,19 @@
PTCP_CONTEXT Context
)
{
+/*
+#ifndef NDEBUG
+ PKTHREAD Thread;
+ Thread = KeGetCurrentThread();
+ DPRINT("Thread %p releasing lock on Context %p\n", Thread, Context);
+#endif
+*/
KeReleaseMutex(&Context->Mutex, FALSE);
+/*
+#ifndef NDEBUG
+ DPRINT("Thread %p released lock on Context %p\n", Thread, Context);
+#endif
+*/
}
/**
@@ -354,7 +385,7 @@
}
/* We should never go through both lists without finding a match */
- DPRINT1("Cancelling unknow IRP %p\n", Irp);
+ DPRINT1("Cancelling unknown IRP %p for Context %p\n", Irp, Context);
goto FINISH;
FOUND_REQUEST:
@@ -368,6 +399,9 @@
{
tcp_arg(CurrentContext->lwip_tcp_pcb, NULL);
tcp_abort(CurrentContext->lwip_tcp_pcb);
+#ifndef NDEBUG
+ REMOVE_PCB(CurrentContext->lwip_tcp_pcb);
+#endif
CurrentContext->lwip_tcp_pcb = NULL;
}
RELEASE_SERIAL_MUTEX();
@@ -379,6 +413,9 @@
{
tcp_arg(CurrentContext->lwip_tcp_pcb, NULL);
tcp_close(CurrentContext->lwip_tcp_pcb);
+#ifndef NDEBUG
+ REMOVE_PCB(CurrentContext->lwip_tcp_pcb);
+#endif
CurrentContext->lwip_tcp_pcb = NULL;
}
RELEASE_SERIAL_MUTEX();
@@ -386,7 +423,8 @@
case TCP_REQUEST_CANCEL_MODE_PRESERVE :
break;
default :
- DPRINT1("Invalid cancel mode %08x\n", Request->CancelMode);
+ DPRINT1("Invalid cancel mode %08x for Request on Context %p\n",
+ Request->CancelMode, CurrentContext);
break;
}
@@ -452,14 +490,15 @@
PendingIrp->IoStatus.Status = STATUS_CANCELLED;
PendingIrp->IoStatus.Information = 0;
IoCompleteRequest(PendingIrp, IO_NETWORK_INCREMENT);
-#ifndef NDEBUG
- REMOVE_IRP(Irp);
-#endif
case TCP_REQUEST_PAYLOAD_PCB :
tcp_arg(ListWalkRequest->Payload.apcb, NULL);
tcp_close(ListWalkRequest->Payload.apcb);
+#ifndef NDEBUG
+ REMOVE_PCB(ListWalkRequest->Payload.apcb);
+#endif
default :
- DPRINT1("Invalid payload type on Context %p\n",
CurrentContext);
+ DPRINT1("Invalid payload type %08x on Context %p\n",
+ ListWalkRequest->PayloadType, CurrentContext);
break;
}
ExFreePoolWithTag(ListWalkRequest, TAG_TCP_REQUEST);
@@ -490,7 +529,8 @@
break;
default :
ContextMutexRelease(CurrentContext);
- DPRINT1("Invalid pending mode for cancel\n");
+ DPRINT1("Invalid pending mode %08x for cancel on Context %p\n",
+ Request->PendingMode, CurrentContext);
break;
}
ExFreePoolWithTag(Request, TAG_TCP_REQUEST);
@@ -499,9 +539,6 @@
Irp->IoStatus.Status = STATUS_CANCELLED;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
-#ifndef NDEBUG
- REMOVE_IRP(Irp);
-#endif
}
/**
@@ -518,12 +555,10 @@
AddrFileCount = 0;
GlContextCount = 0;
PcbCount = 0;
- IRPCount = 0;
KeInitializeSpinLock(&AddrFileArrayLock);
KeInitializeSpinLock(&ContextArrayLock);
KeInitializeSpinLock(&PCBArrayLock);
- KeInitializeSpinLock(&IRPArrayLock);
#endif
}
@@ -726,7 +761,8 @@
/* Sanity checks */
if ((AddressFile->Protocol != IPPROTO_TCP) || (Context->TcpState !=
TCP_STATE_CREATED))
{
- DPRINT1("We should be associating a new TCP Context with a TCP Address
File\n");
+ DPRINT1("Context %p has wrong state or Addr File %p has wrong protocol, for
association\n",
+ Context, AddressFile);
ObDereferenceObject(FileObject);
return STATUS_INVALID_PARAMETER;
}
@@ -762,28 +798,28 @@
case (ERR_BUF) :
{
RELEASE_SERIAL_MUTEX();
- DPRINT1("lwIP ERR_BUFF\n");
+ DPRINT1("lwIP ERR_BUFF. Context %p, PCB %p\n", Context,
Context->lwip_tcp_pcb);
Status = STATUS_NO_MEMORY;
goto FINISH;
}
case (ERR_VAL) :
{
RELEASE_SERIAL_MUTEX();
- DPRINT1("lwIP ERR_VAL\n");
+ DPRINT1("lwIP ERR_VAL. Context %p, PCB %p\n", Context,
Context->lwip_tcp_pcb);
Status = STATUS_INVALID_PARAMETER;
goto FINISH;
}
case (ERR_USE) :
{
RELEASE_SERIAL_MUTEX();
- DPRINT1("lwIP ERR_USE\n");
+ DPRINT1("lwIP ERR_USE. Context %p, PCB %p\n", Context,
Context->lwip_tcp_pcb);
Status = STATUS_ADDRESS_ALREADY_EXISTS;
goto FINISH;
}
default :
{
RELEASE_SERIAL_MUTEX();
- DPRINT1("lwIP unexpected error\n");
+ DPRINT1("lwIP unexpected error. Context %p, PCB %p\n", Context,
Context->lwip_tcp_pcb);
// TODO: better return code
Status = STATUS_UNSUCCESSFUL;
goto FINISH;
@@ -809,13 +845,14 @@
**/
/* This handler never acquires the mutex for the incoming Context because the IRP sender
should be
- * the only reference holder for that Context */
+ * the only reference holder for that Context. */
NTSTATUS
TcpIpListen(
_Inout_ PIRP Irp
)
{
#ifndef NDEBUG
+ INT i;
KIRQL OldIrql;
#endif
LARGE_INTEGER Timeout;
@@ -840,7 +877,7 @@
Context = IrpSp->FileObject->FsContext;
if (Context->TcpState != TCP_STATE_BOUND)
{
- DPRINT1("Context is not a bound context\n");
+ DPRINT1("Context %p is not a bound context\n", Context);
return STATUS_INVALID_PARAMETER;
}
@@ -893,7 +930,8 @@
/* We walked the entire Request list without finding a connection waiting to be
accepted.
* Now we must enquque a Request and wait for an incomming connection request.
*/
- DPRINT("Walked entire Request list without finding a connection\n");
+ DPRINT("Found no connection for Context %p on Listener %p with PCB
%p\n",
+ Context, ListenContext, ListenContext->lwip_tcp_pcb);
Status = EnqueueIRP(
Irp,
@@ -926,6 +964,7 @@
InterlockedIncrement(&AddressFile->ContextCount);
/* Initialize the Listener */
+ TCP_SET_STATE(TCP_STATE_LISTENING, ListenContext);
ListenContext->AddressFile = AddressFile;
InitializeListHead(&ListenContext->RequestListHead);
ListenContext->ReferencedByUpperLayer = FALSE;
@@ -934,10 +973,13 @@
/* Initiate lwIP listen */
ACQUIRE_SERIAL_MUTEX_NO_TO();
ListenContext->lwip_tcp_pcb = tcp_listen(Context->lwip_tcp_pcb);
+#ifndef NDEBUG
+ REMOVE_PCB(Context->lwip_tcp_pcb);
+#endif
if (ListenContext->lwip_tcp_pcb == NULL)
{
RELEASE_SERIAL_MUTEX();
- DPRINT1("Listen failed\n");
+ DPRINT1("Listen failed on Context %p\n", Context);
return STATUS_INVALID_ADDRESS;
}
#ifndef NDEBUG
@@ -1001,7 +1043,7 @@
Context = IrpSp->FileObject->FsContext;
if (Context->TcpState != TCP_STATE_BOUND)
{
- DPRINT1("Connecting from unbound socket\n");
+ DPRINT1("Connecting from unbound socket context %p\n", Context);
return STATUS_INVALID_PARAMETER;
}
@@ -1032,34 +1074,35 @@
return Status;
case ERR_VAL :
RELEASE_SERIAL_MUTEX();
- DPRINT1("lwip ERR_VAL\n");
+ DPRINT1("lwip ERR_VAL. Context %p, PCB %p\n", Context,
Context->lwip_tcp_pcb);
return STATUS_INVALID_PARAMETER;
case ERR_ISCONN :
RELEASE_SERIAL_MUTEX();
- DPRINT1("lwip ERR_ISCONN\n");
+ DPRINT1("lwip ERR_ISCONN. Context %p, PCB %p\n", Context,
Context->lwip_tcp_pcb);
return STATUS_CONNECTION_ACTIVE;
case ERR_RTE :
RELEASE_SERIAL_MUTEX();
- DPRINT1("lwip ERR_RTE\n");
+ DPRINT1("lwip ERR_RTE. Context %p, PCB %p\n", Context,
Context->lwip_tcp_pcb);
return STATUS_NETWORK_UNREACHABLE;
case ERR_BUF :
/* Use correct error once NDIS errors are included.
* This return value means local port unavailable. */
RELEASE_SERIAL_MUTEX();
- DPRINT1("lwip ERR_BUF\n");
+ DPRINT1("lwip ERR_BUF. Context %p, PCB %p\n", Context,
Context->lwip_tcp_pcb);
return STATUS_ADDRESS_ALREADY_EXISTS;
case ERR_USE :
RELEASE_SERIAL_MUTEX();
- DPRINT1("lwip ERR_USE\n");
+ DPRINT1("lwip ERR_USE. Context %p, PCB %p\n", Context,
Context->lwip_tcp_pcb);
return STATUS_CONNECTION_ACTIVE;
case ERR_MEM :
RELEASE_SERIAL_MUTEX();
- DPRINT1("lwip ERR_MEM\n");
+ DPRINT1("lwip ERR_MEM. Context %p, PCB %p\n", Context,
Context->lwip_tcp_pcb);
return STATUS_NO_MEMORY;
default :
/* unknown return value */
RELEASE_SERIAL_MUTEX();
- DPRINT1("lwip unknown return code\n");
+ DPRINT1("lwip unknown return code. Context %p, PCB %p\n",
+ Context, Context->lwip_tcp_pcb);
return STATUS_NOT_IMPLEMENTED;
}
}
@@ -1148,7 +1191,8 @@
ContextMutexAcquire(Context);
if (!(Context->TcpState & TCP_STATE_CONNECTED))
{
- DPRINT1("Receiving on TCP Context %p in state %08x\n", Context,
Context->TcpState);
+ DPRINT1("Receiving on TCP Context %p in state %08x with PCB %p\n",
+ Context, Context->TcpState, Context->lwip_tcp_pcb);
ContextMutexRelease(Context);
return STATUS_ADDRESS_CLOSED;
}
@@ -1223,6 +1267,9 @@
{
tcp_arg(Context->lwip_tcp_pcb, NULL);
tcp_close(Context->lwip_tcp_pcb);
+#ifndef NDEBUG
+ REMOVE_PCB(Context->lwip_tcp_pcb);
+#endif
Context->lwip_tcp_pcb = NULL;
}
RELEASE_SERIAL_MUTEX();
@@ -1245,9 +1292,6 @@
PendingIrp->IoStatus.Status = STATUS_CANCELLED;
PendingIrp->IoStatus.Information = 0;
IoCompleteRequest(PendingIrp, IO_NETWORK_INCREMENT);
-#ifndef NDEBUG
- REMOVE_IRP(PendingIrp);
-#endif
ExFreePoolWithTag(Request, TAG_TCP_REQUEST);
}
@@ -1263,6 +1307,10 @@
_Inout_ PIRP Irp
)
{
+#ifndef NDEBUG
+ INT i;
+ KIRQL OldIrql;
+#endif
LARGE_INTEGER Timeout;
PIO_STACK_LOCATION IrpSp;
@@ -1288,6 +1336,9 @@
{
tcp_arg(Context->lwip_tcp_pcb, NULL);
tcp_close(Context->lwip_tcp_pcb);
+#ifndef NDEBUG
+ REMOVE_PCB(Context->lwip_tcp_pcb);
+#endif
Context->lwip_tcp_pcb = NULL;
}
@@ -1337,7 +1388,8 @@
ContextMutexAcquire(Context);
if ((Context->AddressFile != NULL) || (Context->lwip_tcp_pcb != NULL)) {
- DPRINT1("Context retains association. AddressFile %p, tcp_pcb %p\n",
+ DPRINT1("Context %p retains association. AddressFile %p, tcp_pcb
%p\n",
+ Context,
Context->AddressFile,
Context->lwip_tcp_pcb);
return STATUS_CONNECTION_ACTIVE;
@@ -1364,9 +1416,6 @@
_Inout_ struct _DEVICE_OBJECT* DeviceObject,
_Inout_ _IRQL_uses_cancel_ struct _IRP *Irp)
{
-#ifndef NDEBUG
- INT i;
-#endif
PIO_STACK_LOCATION IrpSp;
ADDRESS_FILE* AddressFile;
RECEIVE_DATAGRAM_REQUEST* Request;
@@ -1400,9 +1449,6 @@
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
-#ifndef NDEBUG
- REMOVE_IRP(Irp);
-#endif
ExFreePoolWithTag(Request, TAG_DGRAM_REQST);
}
@@ -1411,10 +1457,6 @@
TcpIpReceiveDatagram(
_Inout_ PIRP Irp)
{
-#ifndef NDEBUG
- KIRQL OldIrql;
- INT i;
-#endif
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
ADDRESS_FILE *AddressFile;
RECEIVE_DATAGRAM_REQUEST* Request = NULL;
@@ -1489,9 +1531,6 @@
ExFreePoolWithTag(Request, TAG_DGRAM_REQST);
Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
-#ifndef NDEBUG
- REMOVE_IRP(Irp);
-#endif
return Status;
}
@@ -1499,10 +1538,6 @@
TcpIpSendDatagram(
_Inout_ PIRP Irp)
{
-#ifndef NDEBUG
- KIRQL OldIrql;
- INT i;
-#endif
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
ADDRESS_FILE *AddressFile;
PTDI_REQUEST_KERNEL_SENDDG RequestInfo;
@@ -1638,9 +1673,6 @@
pbuf_free(p);
Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
-#ifndef NDEBUG
- REMOVE_IRP(Irp);
-#endif
return Status;
}
@@ -1867,16 +1899,17 @@
case ERR_OK:
return STATUS_SUCCESS;
case ERR_MEM:
- DPRINT1("lwIP ERR_MEM\n");
+ DPRINT1("lwIP ERR_MEM. Context %p with PCB %p\n", Context,
Context->lwip_tcp_pcb);
return STATUS_NO_MEMORY;
case ERR_ARG:
- DPRINT1("lwIP ERR_ARG\n");
+ DPRINT1("lwIP ERR_ARG. Context %p with PCB %p\n", Context,
Context->lwip_tcp_pcb);
return STATUS_INVALID_PARAMETER;
case ERR_CONN:
- DPRINT1("lwIP ERR_CONN\n");
+ DPRINT1("lwIP ERR_CONN. Context %p with PCB %p\n", Context,
Context->lwip_tcp_pcb);
return STATUS_CONNECTION_ACTIVE;
default:
- DPRINT1("Unknwon lwIP Error: %d\n", lwip_err);
+ DPRINT1("Unknwon lwIP Error: %d. Context %p with PCB %p\n",
+ lwip_err, Context, Context->lwip_tcp_pcb);
return STATUS_NOT_IMPLEMENTED;
}
}
@@ -1899,6 +1932,7 @@
return STATUS_NO_MEMORY;
}
+ IoSetCancelRoutine(Irp, CancelRoutine);
Request->Payload.PendingIrp = Irp;
Request->CancelMode = CancelMode;
Request->PendingMode = PendingMode;
@@ -1950,7 +1984,6 @@
)
{
#ifndef NDEBUG
- INT i;
KIRQL OldIrql;
#endif
@@ -1967,10 +2000,14 @@
ListenContext = (PTCP_CONTEXT)arg;
if (ListenContext == NULL)
{
- DPRINT("No listener\n");
+ DPRINT("No listener.\n");
return ERR_CLSD;
}
+#ifndef NDEBUG
+ ADD_PCB(newpcb);
+#endif
+
/* Do non-dependent PCB setup */
tcp_err(newpcb, lwip_tcp_err_callback);
tcp_recv(newpcb, lwip_tcp_recv_callback);
@@ -2006,9 +2043,6 @@
/* Complete the IRP */
Irp->IoStatus.Status = STATUS_SUCCESS;
IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
-#ifndef NDEBUG
- REMOVE_IRP(Irp);
-#endif
ExFreePoolWithTag(Request, TAG_TCP_REQUEST);
@@ -2045,7 +2079,7 @@
struct tcp_pcb *tpcb,
struct pbuf *p,
err_t err
-)
+)
{
#ifndef NDEBUG
INT i;
@@ -2069,7 +2103,7 @@
Context = (PTCP_CONTEXT)arg;
if (Context == NULL)
{
- DPRINT("No receiving Context\n");
+ DPRINT("No receiving Context for PCB %p\n", tpcb);
return ERR_CLSD;
}
ContextMutexAcquire(Context);
@@ -2077,6 +2111,10 @@
/* A null buffer means the connection has been closed */
if (p == NULL)
{
+#ifndef NDEBUG
+ DPRINT("Context %p closed by lwIP\n", Context);
+ REMOVE_PCB(Context->lwip_tcp_pcb);
+#endif
Context->lwip_tcp_pcb = NULL;
TCP_SET_STATE(TCP_STATE_CLOSED, Context);
ContextMutexRelease(Context);
@@ -2087,13 +2125,14 @@
if (!(Context->TcpState & (TCP_STATE_CONNECTED|TCP_STATE_RECEIVING)))
{
ContextMutexRelease(Context);
- DPRINT("Receiving on unconnected Context %p\n", Context);
+ DPRINT("Receiving on unconnected Context %p from PCB %p\n", Context,
tpcb);
return ERR_ARG;
}
if (Context->lwip_tcp_pcb != tpcb)
{
ContextMutexRelease(Context);
- DPRINT1("Receive PCB mismatch\n");
+ DPRINT1("Receive PCB mismatch. Context %p has %p, callback has %p\n",
+ Context, Context->lwip_tcp_pcb, tpcb);
return ERR_ARG;
}
@@ -2121,7 +2160,8 @@
/* If we did not find a TDI_RECEIVE, simply return an error. lwIP will save the
refused data. */
TCP_RMV_STATE(TCP_STATE_RECEIVING, Context);
ContextMutexRelease(Context);
- DPRINT("Did not find a TDI_RECEIVE on Context %p marked as Receiving\n",
Context);
+ DPRINT("Did not find a TDI_RECEIVE on Context %p marked as Receiving with PCB
%p\n",
+ Context, Context->lwip_tcp_pcb);
return ERR_MEM;
COPY_DATA:
@@ -2186,9 +2226,6 @@
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = CopiedLength;
IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
-#ifndef NDEBUG
- REMOVE_IRP(Irp);
-#endif
return ERR_OK;
}
@@ -2201,10 +2238,6 @@
u16_t len
)
{
-#ifndef NDEBUG
- INT i;
- KIRQL OldIrql;
-#endif
NTSTATUS Status;
PIRP Irp;
@@ -2217,20 +2250,21 @@
Context = (PTCP_CONTEXT)arg;
if (Context == NULL)
{
- DPRINT("Callack on closed Context\n");
+ DPRINT("Callack on closed Context from PCB %p\n", tpcb);
return ERR_CLSD;
}
ContextMutexAcquire(Context);
if (!(Context->TcpState & TCP_STATE_SENDING))
{
ContextMutexRelease(Context);
- DPRINT("Callback on Context %p that is not sending\n", Context);
+ DPRINT("Callback on Context %p that is not sending for PCB %p\n",
Context, tpcb);
return ERR_ARG;
}
if (Context->lwip_tcp_pcb != tpcb)
{
ContextMutexRelease(Context);
- DPRINT("Sent PCB mismatch\n");
+ DPRINT("Sent PCB mismatch. Context %p has %p, callback has %p\n",
+ Context, Context->lwip_tcp_pcb, tpcb);
return ERR_ARG;
}
@@ -2253,9 +2287,6 @@
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = len;
IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
-#ifndef NDEBUG
- REMOVE_IRP(Irp);
-#endif
ExFreePoolWithTag(Request, TAG_TCP_REQUEST);
@@ -2265,7 +2296,8 @@
/* If we didn't find a TDI_SEND, something is wrong. */
ContextMutexRelease(Context);
- DPRINT("No TDI_SEND on Context %p marked as SENDING\n", Context);
+ DPRINT("No TDI_SEND on Context %p marked as SENDING with PCB %p\n",
+ Context, Context->lwip_tcp_pcb);
return ERR_ARG;
CHECK_FOR_NEXT_REQUEST:
@@ -2303,9 +2335,13 @@
err_t err
)
{
+#ifndef NDEBUG
+ INT i;
+ KIRQL OldIrql;
+#endif
PTCP_CONTEXT Context;
- DPRINT("lwIP closed a socket: %d\n", err);
+ DPRINT("lwIP closed a socket with arg %08x: %d\n", arg, err);
Context = (PTCP_CONTEXT)arg;
if (Context == NULL)
@@ -2314,6 +2350,9 @@
}
ContextMutexAcquire(Context);
+#ifndef NDEBUG
+ REMOVE_PCB(Context->lwip_tcp_pcb);
+#endif
Context->lwip_tcp_pcb = NULL;
ContextMutexRelease(Context);
}
@@ -2326,11 +2365,6 @@
err_t err
)
{
-#ifndef NDEBUG
- INT i;
- KIRQL OldIrql;
-#endif
-
PIRP Irp;
PLIST_ENTRY Entry;
PTCP_CONTEXT Context;
@@ -2342,20 +2376,22 @@
Context = (PTCP_CONTEXT)arg;
if (Context == NULL)
{
- DPRINT("No callback Context\n");
+ DPRINT("No callback Context for PCB %p\n", tpcb);
return ERR_CLSD;
}
ContextMutexAcquire(Context);
if (Context->TcpState != TCP_STATE_CONNECTING)
{
ContextMutexRelease(Context);
- DPRINT("Connection established for Context %p in state %08x\n",
Context, Context->TcpState);
+ DPRINT("Connection established for Context %p in state %08x on PCB
%p\n",
+ Context, Context->TcpState, tpcb);
return ERR_ARG;
}
if (Context->lwip_tcp_pcb != tpcb)
{
ContextMutexRelease(Context);
- DPRINT("Connected PCB mismatch\n");
+ DPRINT("Connected PCB mismatch. Context %p has %p, callback has %p\n",
+ Context, Context->lwip_tcp_pcb, tpcb);
return ERR_ARG;
}
@@ -2364,7 +2400,7 @@
if (Entry == &Context->RequestListHead)
{
ContextMutexRelease(Context);
- DPRINT("No Connect request\n");
+ DPRINT("No Connect request on Context %p\n", Context);
return ERR_ARG;
}
@@ -2384,9 +2420,6 @@
Irp->IoStatus.Status = STATUS_CANCELLED;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
-#ifndef NDEBUG
- REMOVE_IRP(Irp);
-#endif
return ERR_ARG;
}
@@ -2401,9 +2434,6 @@
Irp->IoStatus.Status = STATUS_SUCCESS;
IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
-#ifndef NDEBUG
- REMOVE_IRP(Irp);
-#endif
return ERR_OK;
}
Modified: branches/GSoC_2016/lwIP-tcpip/drivers/network/tcpip/address.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2016/lwIP-tcpip/drivers/ne…
==============================================================================
--- branches/GSoC_2016/lwIP-tcpip/drivers/network/tcpip/address.h [iso-8859-1] (original)
+++ branches/GSoC_2016/lwIP-tcpip/drivers/network/tcpip/address.h [iso-8859-1] Tue Aug 16
21:42:21 2016
@@ -10,72 +10,21 @@
#define TCP_REQUEST_PENDING_LISTEN 4
#define TCP_REQUEST_PENDING_ACCEPTED_CONNECTION 5
-#define TCP_REQUEST_PAYLOAD_IRP 1
-#define TCP_REQUEST_PAYLOAD_PCB 2
+#define TCP_REQUEST_PAYLOAD_IRP 1
+#define TCP_REQUEST_PAYLOAD_PCB 2
// TODO: simplify states
-#define TCP_STATE_CREATED 0x1 << 0
-#define TCP_STATE_BOUND 0x1 << 1
-#define TCP_STATE_LISTENING 0x1 << 2
-#define TCP_STATE_RECEIVING 0x1 << 3
-#define TCP_STATE_ABORTED 0x1 << 4
-#define TCP_STATE_CONNECTING 0x1 << 5
-#define TCP_STATE_CONNECTED 0x1 << 6
-#define TCP_STATE_SENDING 0x1 << 7
-#define TCP_STATE_CLOSED 0x1 << 8
+#define TCP_STATE_CREATED 0x1 << 0
+#define TCP_STATE_BOUND 0x1 << 1
+#define TCP_STATE_LISTENING 0x1 << 2
+#define TCP_STATE_RECEIVING 0x1 << 3
+#define TCP_STATE_ABORTED 0x1 << 4
+#define TCP_STATE_CONNECTING 0x1 << 5
+#define TCP_STATE_CONNECTED 0x1 << 6
+#define TCP_STATE_SENDING 0x1 << 7
+#define TCP_STATE_CLOSED 0x1 << 8
//#define TCPIP_NDEBUG
-#ifndef TCPIP_NDEBUG
-KSPIN_LOCK IRPArrayLock;
-PIRP IRPArray[256];
-volatile long int IRPCount;
-
-#define ADD_IRP(Irp) \
- KeAcquireSpinLock(&IRPArrayLock, &OldIrql); \
- IRPArray[IRPCount] = Irp; \
- IRPCount++; \
- KeReleaseSpinLock(&IRPArrayLock, OldIrql)
-
-#define ADD_IRP_DPC(Irp) \
- KeAcquireSpinLockAtDpcLevel(&IRPArrayLock); \
- IRPArray[IRPCount] = Irp; \
- IRPCount++; \
- KeReleaseSpinLockFromDpcLevel(&IRPArrayLock)
-
-#define REMOVE_IRP(Irp) \
- KeAcquireSpinLock(&IRPArrayLock, &OldIrql); \
- for (i = 0; i < IRPCount; i++) \
- { \
- if (Irp == IRPArray[i]) \
- { \
- IRPArray[i] = NULL; \
- } \
- if (IRPArray[i] == NULL) \
- { \
- IRPArray[i] = IRPArray[i+1]; \
- IRPArray[i+1] = NULL; \
- } \
- } \
- IRPCount--; \
- KeReleaseSpinLock(&IRPArrayLock, OldIrql)
-
-#define REMOVE_IRP_DPC(Irp) \
- KeAcquireSpinLockAtDpcLevel(&IRPArrayLock); \
- for (i = 0; i < IRPCount; i++) \
- { \
- if (Irp == IRPArray[i]) \
- { \
- IRPArray[i] = NULL; \
- } \
- if (IRPArray[i] == NULL) \
- { \
- IRPArray[i] = IRPArray[i+1]; \
- IRPArray[i+1] = NULL; \
- } \
- } \
- IRPCount--; \
- KeReleaseSpinLockFromDpcLevel(&IRPArrayLock)
-#endif
#define _IoCompleteRequest(Irp,Mode) \
DPRINT("Complete IRP %p with IO Status %08X\n", Irp,
Irp->IoStatus.Status); \
Modified: branches/GSoC_2016/lwIP-tcpip/drivers/network/tcpip/main.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2016/lwIP-tcpip/drivers/ne…
==============================================================================
--- branches/GSoC_2016/lwIP-tcpip/drivers/network/tcpip/main.c [iso-8859-1] (original)
+++ branches/GSoC_2016/lwIP-tcpip/drivers/network/tcpip/main.c [iso-8859-1] Tue Aug 16
21:42:21 2016
@@ -211,22 +211,11 @@
_Inout_ struct _IRP *Irp
)
{
-#ifndef NDEBUG
- KIRQL OldIrql;
- INT i;
-#endif
NTSTATUS Status;
PFILE_FULL_EA_INFORMATION FileInfo;
IPPROTO Protocol;
-// ADDRESS_FILE *AddressFile;
-
-// ULONG *temp;
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
-
-#ifndef NDEBUG
- ADD_IRP(Irp);
-#endif
/* Grab the info describing the file */
FileInfo = Irp->AssociatedIrp.SystemBuffer;
@@ -276,21 +265,11 @@
goto Quickie;
}
- /* All good. */
-/* temp = (ULONG*)Address;
- DPRINT1("\nPTA_IP_ADDRESS dump before\n %08x %08x %08x %08x\n %08x %08x
%08x %08x\n",
- temp[7], temp[6], temp[5], temp[4],
- temp[3], temp[2], temp[1], temp[0]);*/
- // DPRINT1("Call into TcpIpCreateAddress\n");
Status = TcpIpCreateAddress(Irp, &Address->Address[0].Address[0],
Protocol);
- // DPRINT1("Returned from TcpIpCreateAddress\n");
if (Status != STATUS_SUCCESS)
{
goto Quickie;
}
-/* DPRINT1("\nPTA_IP_ADDRESS dump after\n %08x %08x %08x %08x\n %08x %08x
%08x %08x\n",
- temp[7], temp[6], temp[5], temp[4],
- temp[3], temp[2], temp[1], temp[0]);*/
break;
}
case TDI_CONNECTION_CONTEXT_LENGTH:
@@ -315,19 +294,7 @@
goto Quickie;
}
-/* temp = (ULONG*)Protocol;
- DPRINT1("\n Protocol: %08x\n", temp);
-
- temp = (ULONG*)Address;*/
-
- /* All good. */
-/* DPRINT1("\n PTA_IP_ADDRESS dump before\n %08x %08x %08x %08x\n %08x
%08x %08x %08x\n",
- temp[7], temp[6], temp[5], temp[4],
- temp[3], temp[2], temp[1], temp[0]);*/
Status = TcpIpCreateContext(Irp, &Address->Address[0].Address[0],
Protocol);
-/* DPRINT1("\n PTA_IP_ADDRESS dump after\n %08x %08x %08x %08x\n %08x
%08x %08x %08x\n",
- temp[7], temp[6], temp[5], temp[4],
- temp[3], temp[2], temp[1], temp[0]);*/
break;
}
@@ -345,9 +312,6 @@
else
{
IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
-#ifndef NDEBUG
- REMOVE_IRP(Irp);
-#endif
}
return Status;
@@ -361,20 +325,12 @@
_Inout_ struct _IRP *Irp
)
{
-#ifndef NDEBUG
- KIRQL OldIrql;
- INT i;
-#endif
PIO_STACK_LOCATION IrpSp;
NTSTATUS Status;
ULONG_PTR FileType;
IrpSp = IoGetCurrentIrpStackLocation(Irp);
-#ifndef NDEBUG
- ADD_IRP(Irp);
-#endif
-
FileType = (ULONG_PTR)IrpSp->FileObject->FsContext2;
switch (FileType)
@@ -390,14 +346,13 @@
Status = TcpIpCloseAddress(IrpSp->FileObject->FsContext);
break;
case TDI_CONNECTION_FILE:
- DPRINT1("TCPIP Close Connection File\n");
if (!IrpSp->FileObject->FsContext)
{
DPRINT1("TCPIP: Got a close request without a file to
close!\n");
Status = STATUS_INVALID_PARAMETER;
goto Quickie;
}
- DPRINT1("TCPIP Close Connection Context\n");
+ DPRINT1("TCPIP Close Connection Context %p\n",
IrpSp->FileObject->FsContext);
Status = TcpIpCloseContext(IrpSp->FileObject->FsContext);
break;
case TDI_CONTROL_CHANNEL_FILE:
@@ -414,9 +369,6 @@
Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
-#ifndef NDEBUG
- REMOVE_IRP(Irp);
-#endif
return Status;
}
@@ -429,22 +381,13 @@
_Inout_ struct _IRP *Irp
)
{
-#ifndef NDEBUG
- KIRQL OldIrql;
- INT i;
-#endif
NTSTATUS Status;
PIO_STACK_LOCATION IrpSp;
PTCP_CONTEXT Context;
PADDRESS_FILE AddressFile;
- DPRINT1("TcpIpDispatchInternal\n");
-
IrpSp = IoGetCurrentIrpStackLocation(Irp);
-
-#ifndef NDEBUG
- ADD_IRP(Irp);
-#endif
+ DPRINT("TcpIpDispatchInternal on TDI object %p\n",
IrpSp->FileObject->FsContext);
switch ((ULONG)IrpSp->FileObject->FsContext2)
{
@@ -577,9 +520,6 @@
else
{
IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
-#ifndef NDEBUG
- REMOVE_IRP(Irp);
-#endif
}
return Status;
@@ -595,12 +535,6 @@
{
NTSTATUS Status;
PIO_STACK_LOCATION IrpSp;
-
-#ifndef NDEBUG
- INT i;
- KIRQL OldIrql;
- ADD_IRP(Irp);
-#endif
IrpSp = IoGetCurrentIrpStackLocation(Irp);
@@ -642,9 +576,6 @@
else
{
IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
-#ifndef NDEBUG
- REMOVE_IRP(Irp);
-#endif
}
return Status;
@@ -662,4 +593,4 @@
IoDeleteDevice(UdpDeviceObject);
IoDeleteDevice(TcpDeviceObject);
TcpIpUnregisterNdisProtocol();
-}
+}