[AFD] Introduce and use pool tags. Thanks go to Arty for assisting me with this. CORE-14048

This commit is contained in:
Amine Khaldi 2017-12-02 00:20:14 +01:00
parent a2cc76af84
commit b8309397b5
14 changed files with 269 additions and 123 deletions

View file

@ -43,7 +43,10 @@ NTSTATUS WarmSocketForBind( PAFD_FCB FCB, ULONG ShareType ) {
if (NT_SUCCESS(Status) && !FCB->Recv.Window)
{
FCB->Recv.Window = ExAllocatePool(PagedPool, FCB->Recv.Size);
FCB->Recv.Window = ExAllocatePoolWithTag(PagedPool,
FCB->Recv.Size,
TAG_AFD_DATA_BUFFER);
if (!FCB->Recv.Window)
Status = STATUS_NO_MEMORY;
}
@ -87,7 +90,11 @@ AfdBindSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY,
Irp, 0 );
if( FCB->LocalAddress ) ExFreePool( FCB->LocalAddress );
if (FCB->LocalAddress)
{
ExFreePoolWithTag(FCB->LocalAddress, TAG_AFD_TRANSPORT_ADDRESS);
}
FCB->LocalAddress = TaCopyTransportAddress( &BindReq->Address );
if( FCB->LocalAddress )

View file

@ -59,13 +59,16 @@ AfdSetConnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp,
if (FCB->ConnectOptions)
{
ExFreePool(FCB->ConnectOptions);
ExFreePoolWithTag(FCB->ConnectOptions, TAG_AFD_CONNECT_OPTIONS);
FCB->ConnectOptions = NULL;
FCB->ConnectOptionsSize = 0;
FCB->FilledConnectOptions = 0;
}
FCB->ConnectOptions = ExAllocatePool(PagedPool, ConnectOptionsSize);
FCB->ConnectOptions = ExAllocatePoolWithTag(PagedPool,
ConnectOptionsSize,
TAG_AFD_CONNECT_OPTIONS);
if (!FCB->ConnectOptions)
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
@ -103,12 +106,15 @@ AfdSetConnectOptionsSize(PDEVICE_OBJECT DeviceObject, PIRP Irp,
if (FCB->ConnectOptions)
{
ExFreePool(FCB->ConnectOptions);
ExFreePoolWithTag(FCB->ConnectOptions, TAG_AFD_CONNECT_OPTIONS);
FCB->ConnectOptionsSize = 0;
FCB->FilledConnectOptions = 0;
}
FCB->ConnectOptions = ExAllocatePool(PagedPool, *ConnectOptionsSize);
FCB->ConnectOptions = ExAllocatePoolWithTag(PagedPool,
*ConnectOptionsSize,
TAG_AFD_CONNECT_OPTIONS);
if (!FCB->ConnectOptions) return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
FCB->ConnectOptionsSize = *ConnectOptionsSize;
@ -165,13 +171,16 @@ AfdSetConnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
if (FCB->ConnectData)
{
ExFreePool(FCB->ConnectData);
ExFreePoolWithTag(FCB->ConnectData, TAG_AFD_CONNECT_DATA);
FCB->ConnectData = NULL;
FCB->ConnectDataSize = 0;
FCB->FilledConnectData = 0;
}
FCB->ConnectData = ExAllocatePool(PagedPool, ConnectDataSize);
FCB->ConnectData = ExAllocatePoolWithTag(PagedPool,
ConnectDataSize,
TAG_AFD_CONNECT_DATA);
if (!FCB->ConnectData) return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
RtlCopyMemory(FCB->ConnectData,
@ -208,12 +217,15 @@ AfdSetConnectDataSize(PDEVICE_OBJECT DeviceObject, PIRP Irp,
if (FCB->ConnectData)
{
ExFreePool(FCB->ConnectData);
ExFreePoolWithTag(FCB->ConnectData, TAG_AFD_CONNECT_DATA);
FCB->ConnectDataSize = 0;
FCB->FilledConnectData = 0;
}
FCB->ConnectData = ExAllocatePool(PagedPool, *ConnectDataSize);
FCB->ConnectData = ExAllocatePoolWithTag(PagedPool,
*ConnectDataSize,
TAG_AFD_CONNECT_DATA);
if (!FCB->ConnectData) return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
FCB->ConnectDataSize = *ConnectDataSize;
@ -269,13 +281,19 @@ MakeSocketIntoConnection(PAFD_FCB FCB) {
/* Allocate the receive area and start receiving */
if (!FCB->Recv.Window)
{
FCB->Recv.Window = ExAllocatePool( PagedPool, FCB->Recv.Size );
FCB->Recv.Window = ExAllocatePoolWithTag(PagedPool,
FCB->Recv.Size,
TAG_AFD_DATA_BUFFER);
if( !FCB->Recv.Window ) return STATUS_NO_MEMORY;
}
if (!FCB->Send.Window)
{
FCB->Send.Window = ExAllocatePool( PagedPool, FCB->Send.Size );
FCB->Send.Window = ExAllocatePoolWithTag(PagedPool,
FCB->Send.Size,
TAG_AFD_DATA_BUFFER);
if( !FCB->Send.Window ) return STATUS_NO_MEMORY;
}
@ -434,7 +452,11 @@ AfdStreamSocketConnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
if( FCB->Flags & AFD_ENDPOINT_CONNECTIONLESS )
{
if( FCB->RemoteAddress ) ExFreePool( FCB->RemoteAddress );
if (FCB->RemoteAddress)
{
ExFreePoolWithTag(FCB->RemoteAddress, TAG_AFD_TRANSPORT_ADDRESS);
}
FCB->RemoteAddress =
TaCopyTransportAddress( &ConnectReq->RemoteAddress );
@ -455,7 +477,11 @@ AfdStreamSocketConnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
return LeaveIrpUntilLater( FCB, Irp, FUNCTION_CONNECT );
case SOCKET_STATE_CREATED:
if( FCB->LocalAddress ) ExFreePool( FCB->LocalAddress );
if (FCB->LocalAddress)
{
ExFreePoolWithTag(FCB->LocalAddress, TAG_AFD_TRANSPORT_ADDRESS);
}
FCB->LocalAddress =
TaBuildNullTransportAddress( ConnectReq->RemoteAddress.Address[0].AddressType );
@ -473,7 +499,11 @@ AfdStreamSocketConnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
/* Drop through to SOCKET_STATE_BOUND */
case SOCKET_STATE_BOUND:
if( FCB->RemoteAddress ) ExFreePool( FCB->RemoteAddress );
if (FCB->RemoteAddress)
{
ExFreePoolWithTag(FCB->RemoteAddress, TAG_AFD_TRANSPORT_ADDRESS);
}
FCB->RemoteAddress =
TaCopyTransportAddress( &ConnectReq->RemoteAddress );
@ -487,14 +517,22 @@ AfdStreamSocketConnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
if( !NT_SUCCESS(Status) )
break;
if (FCB->ConnectReturnInfo) ExFreePool(FCB->ConnectReturnInfo);
if (FCB->ConnectReturnInfo)
{
ExFreePoolWithTag(FCB->ConnectReturnInfo, TAG_AFD_TDI_CONNECTION_INFORMATION);
}
Status = TdiBuildConnectionInfo
( &FCB->ConnectReturnInfo,
&ConnectReq->RemoteAddress );
if( NT_SUCCESS(Status) )
{
if (FCB->ConnectCallInfo) ExFreePool(FCB->ConnectCallInfo);
if (FCB->ConnectCallInfo)
{
ExFreePoolWithTag(FCB->ConnectCallInfo, TAG_AFD_TDI_CONNECTION_INFORMATION);
}
Status = TdiBuildConnectionInfo(&FCB->ConnectCallInfo,
&ConnectReq->RemoteAddress);
}

View file

@ -75,12 +75,13 @@ AfdSetContext( PDEVICE_OBJECT DeviceObject, PIRP Irp,
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
if( FCB->Context ) {
ExFreePool( FCB->Context );
ExFreePoolWithTag(FCB->Context, TAG_AFD_SOCKET_CONTEXT);
FCB->ContextSize = 0;
}
FCB->Context = ExAllocatePool( PagedPool,
IrpSp->Parameters.DeviceIoControl.InputBufferLength );
FCB->Context = ExAllocatePoolWithTag(PagedPool,
IrpSp->Parameters.DeviceIoControl.InputBufferLength,
TAG_AFD_SOCKET_CONTEXT);
if( !FCB->Context ) return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY, Irp, 0 );

View file

@ -55,15 +55,21 @@ NTSTATUS AfdEventReceive(
AFD_DbgPrint(MID_TRACE, ("Receiving (%d) bytes on socket\n",
BytesAvailable));
ReceiveBuffer = ExAllocatePool(NonPagedPool, BytesAvailable);
ReceiveBuffer = ExAllocatePoolWithTag(NonPagedPool,
BytesAvailable,
TAG_AFD_DATA_BUFFER);
if (!ReceiveBuffer)
return STATUS_INSUFFICIENT_RESOURCES;
/*Buffer = (PAFD_BUFFER)ExAllocateFromNPagedLookasideList(
&BufferLookasideList);*/
Buffer = (PAFD_BUFFER)ExAllocatePool(NonPagedPool, sizeof(AFD_BUFFER));
Buffer = (PAFD_BUFFER)ExAllocatePoolWithTag(NonPagedPool,
sizeof(AFD_BUFFER),
TAG_AFD_DATA_BUFFER);
if (!Buffer) {
ExFreePool(ReceiveBuffer);
ExFreePoolWithTag(ReceiveBuffer, TAG_AFD_DATA_BUFFER);
return STATUS_INSUFFICIENT_RESOURCES;
}
@ -149,15 +155,21 @@ NTSTATUS AfdEventReceiveDatagramHandler(
AFD_DbgPrint(MID_TRACE, ("Receiving (%d) bytes from (0x%X).\n",
BytesAvailable, *(PULONG)SourceAddress));
ReceiveBuffer = ExAllocatePool(NonPagedPool, BytesAvailable);
ReceiveBuffer = ExAllocatePoolWithTag(NonPagedPool,
BytesAvailable,
TAG_AFD_DATA_BUFFER);
if (!ReceiveBuffer)
return STATUS_INSUFFICIENT_RESOURCES;
/*Buffer = (PAFD_BUFFER)ExAllocateFromNPagedLookasideList(
&BufferLookasideList);*/
Buffer = (PAFD_BUFFER)ExAllocatePool(NonPagedPool, sizeof(AFD_BUFFER));
Buffer = (PAFD_BUFFER)ExAllocatePoolWithTag(NonPagedPool,
sizeof(AFD_BUFFER),
TAG_AFD_DATA_BUFFER);
if (!Buffer) {
ExFreePool(ReceiveBuffer);
ExFreePoolWithTag(ReceiveBuffer, TAG_AFD_DATA_BUFFER);
return STATUS_INSUFFICIENT_RESOURCES;
}

View file

@ -124,7 +124,10 @@ AfdSetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp,
FCB->OobInline = InfoReq->Information.Boolean;
break;
case AFD_INFO_RECEIVE_WINDOW_SIZE:
NewBuffer = ExAllocatePool(PagedPool, InfoReq->Information.Ulong);
NewBuffer = ExAllocatePoolWithTag(PagedPool,
InfoReq->Information.Ulong,
TAG_AFD_DATA_BUFFER);
if (NewBuffer)
{
if (FCB->Recv.Content > InfoReq->Information.Ulong)
@ -136,7 +139,7 @@ AfdSetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp,
FCB->Recv.Window,
FCB->Recv.Content);
ExFreePool(FCB->Recv.Window);
ExFreePoolWithTag(FCB->Recv.Window, TAG_AFD_DATA_BUFFER);
}
FCB->Recv.Size = InfoReq->Information.Ulong;
@ -150,7 +153,10 @@ AfdSetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp,
}
break;
case AFD_INFO_SEND_WINDOW_SIZE:
NewBuffer = ExAllocatePool(PagedPool, InfoReq->Information.Ulong);
NewBuffer = ExAllocatePoolWithTag(PagedPool,
InfoReq->Information.Ulong,
TAG_AFD_DATA_BUFFER);
if (NewBuffer)
{
if (FCB->Send.BytesUsed > InfoReq->Information.Ulong)
@ -162,7 +168,7 @@ AfdSetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp,
FCB->Send.Window,
FCB->Send.BytesUsed);
ExFreePool(FCB->Send.Window);
ExFreePoolWithTag(FCB->Send.Window, TAG_AFD_DATA_BUFFER);
}
FCB->Send.Size = InfoReq->Information.Ulong;

View file

@ -27,7 +27,11 @@ static NTSTATUS SatisfyAccept( PAFD_DEVICE_EXTENSION DeviceExt,
FCB->Connection = Qelt->Object;
if( FCB->RemoteAddress ) ExFreePool( FCB->RemoteAddress );
if (FCB->RemoteAddress)
{
ExFreePoolWithTag(FCB->RemoteAddress, TAG_AFD_TRANSPORT_ADDRESS);
}
FCB->RemoteAddress =
TaCopyTransportAddress( Qelt->ConnInfo->RemoteAddress );
@ -115,13 +119,17 @@ static NTSTATUS NTAPI ListenComplete( PDEVICE_OBJECT DeviceObject,
/* Free ConnectionReturnInfo and ConnectionCallInfo */
if (FCB->ListenIrp.ConnectionReturnInfo)
{
ExFreePool(FCB->ListenIrp.ConnectionReturnInfo);
ExFreePoolWithTag(FCB->ListenIrp.ConnectionReturnInfo,
TAG_AFD_TDI_CONNECTION_INFORMATION);
FCB->ListenIrp.ConnectionReturnInfo = NULL;
}
if (FCB->ListenIrp.ConnectionCallInfo)
{
ExFreePool(FCB->ListenIrp.ConnectionCallInfo);
ExFreePoolWithTag(FCB->ListenIrp.ConnectionCallInfo,
TAG_AFD_TDI_CONNECTION_INFORMATION);
FCB->ListenIrp.ConnectionCallInfo = NULL;
}
@ -138,7 +146,10 @@ static NTSTATUS NTAPI ListenComplete( PDEVICE_OBJECT DeviceObject,
return Irp->IoStatus.Status;
}
Qelt = ExAllocatePool( NonPagedPool, sizeof(*Qelt) );
Qelt = ExAllocatePoolWithTag(NonPagedPool,
sizeof(*Qelt),
TAG_AFD_ACCEPT_QUEUE);
if( !Qelt ) {
Status = STATUS_NO_MEMORY;
} else {
@ -256,7 +267,9 @@ NTSTATUS AfdListenSocket( PDEVICE_OBJECT DeviceObject, PIRP Irp,
if (!NT_SUCCESS(Status))
{
ExFreePool(FCB->ListenIrp.ConnectionCallInfo);
ExFreePoolWithTag(FCB->ListenIrp.ConnectionCallInfo,
TAG_AFD_TDI_CONNECTION_INFORMATION);
FCB->ListenIrp.ConnectionCallInfo = NULL;
return UnlockAndMaybeComplete(FCB, Status, Irp, 0);
}
@ -372,7 +385,7 @@ NTSTATUS AfdAccept( PDEVICE_OBJECT DeviceObject, PIRP Irp,
AFD_DbgPrint(MID_TRACE,("Completed a wait for accept\n"));
ExFreePool( PendingConnObj );
ExFreePoolWithTag(PendingConnObj, TAG_AFD_ACCEPT_QUEUE);
if( !IsListEmpty( &FCB->PendingConnections ) )
{

View file

@ -69,7 +69,10 @@ PVOID LockRequest( PIRP Irp,
}
/* The allocated address goes in index 0 */
Irp->Tail.Overlay.DriverContext[0] = ExAllocatePool(NonPagedPool, MmGetMdlByteCount(Irp->MdlAddress));
Irp->Tail.Overlay.DriverContext[0] = ExAllocatePoolWithTag(NonPagedPool,
MmGetMdlByteCount(Irp->MdlAddress),
TAG_AFD_DATA_BUFFER);
if (!Irp->Tail.Overlay.DriverContext[0])
{
AFD_DbgPrint(MIN_TRACE,("Failed to allocate memory\n"));
@ -126,7 +129,10 @@ PVOID LockRequest( PIRP Irp,
}
/* We need to create the info struct that AFD expects for all send/recv requests */
AfdInfo = ExAllocatePool(NonPagedPool, sizeof(AFD_RECV_INFO) + sizeof(AFD_WSABUF));
AfdInfo = ExAllocatePoolWithTag(NonPagedPool,
sizeof(AFD_RECV_INFO) + sizeof(AFD_WSABUF),
TAG_AFD_DATA_BUFFER);
if (!AfdInfo)
{
AFD_DbgPrint(MIN_TRACE,("Failed to allocate memory\n"));
@ -186,7 +192,7 @@ VOID UnlockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp )
MmGetMdlByteCount(Irp->MdlAddress));
}
ExFreePool(Irp->Tail.Overlay.DriverContext[0]);
ExFreePoolWithTag(Irp->Tail.Overlay.DriverContext[0], TAG_AFD_DATA_BUFFER);
MmUnlockPages( Irp->MdlAddress );
IoFreeMdl( Irp->MdlAddress );
Irp->MdlAddress = NULL;
@ -204,7 +210,7 @@ PAFD_WSABUF LockBuffers( PAFD_WSABUF Buf, UINT Count,
/* Copy the buffer array so we don't lose it */
UINT Lock = LockAddress ? 2 : 0;
UINT Size = (sizeof(AFD_WSABUF) + sizeof(AFD_MAPBUF)) * (Count + Lock);
PAFD_WSABUF NewBuf = ExAllocatePool( PagedPool, Size );
PAFD_WSABUF NewBuf = ExAllocatePoolWithTag(PagedPool, Size, TAG_AFD_WSA_BUFFER);
BOOLEAN LockFailed = FALSE;
PAFD_MAPBUF MapBuf;
@ -230,7 +236,7 @@ PAFD_WSABUF LockBuffers( PAFD_WSABUF Buf, UINT Count,
AFD_DbgPrint(MIN_TRACE,("Access violation copying buffer info "
"from userland (%p %p)\n",
Buf, AddressLen));
ExFreePool( NewBuf );
ExFreePoolWithTag(NewBuf, TAG_AFD_WSA_BUFFER);
_SEH2_YIELD(return NULL);
} _SEH2_END;
@ -265,11 +271,11 @@ PAFD_WSABUF LockBuffers( PAFD_WSABUF Buf, UINT Count,
AFD_DbgPrint(MIN_TRACE,("Failed to lock pages\n"));
IoFreeMdl( MapBuf[i].Mdl );
MapBuf[i].Mdl = NULL;
ExFreePool( NewBuf );
ExFreePoolWithTag(NewBuf, TAG_AFD_WSA_BUFFER);
return NULL;
}
} else {
ExFreePool( NewBuf );
ExFreePoolWithTag(NewBuf, TAG_AFD_WSA_BUFFER);
return NULL;
}
}
@ -295,7 +301,7 @@ VOID UnlockBuffers( PAFD_WSABUF Buf, UINT Count, BOOL Address ) {
}
}
ExFreePool( Buf );
ExFreePoolWithTag(Buf, TAG_AFD_WSA_BUFFER);
Buf = NULL;
}
@ -305,8 +311,9 @@ PAFD_HANDLE LockHandles( PAFD_HANDLE HandleArray, UINT HandleCount ) {
UINT i;
NTSTATUS Status = STATUS_SUCCESS;
PAFD_HANDLE FileObjects = ExAllocatePool
( NonPagedPool, HandleCount * sizeof(AFD_HANDLE) );
PAFD_HANDLE FileObjects = ExAllocatePoolWithTag(NonPagedPool,
HandleCount * sizeof(AFD_HANDLE),
TAG_AFD_POLL_HANDLE);
for( i = 0; FileObjects && i < HandleCount; i++ ) {
FileObjects[i].Status = 0;
@ -346,7 +353,7 @@ VOID UnlockHandles( PAFD_HANDLE HandleArray, UINT HandleCount ) {
ObDereferenceObject( (PVOID)HandleArray[i].Handle );
}
ExFreePool( HandleArray );
ExFreePoolWithTag(HandleArray, TAG_AFD_POLL_HANDLE);
HandleArray = NULL;
}

View file

@ -86,13 +86,16 @@ AfdSetDisconnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp,
if (FCB->DisconnectOptions)
{
ExFreePool(FCB->DisconnectOptions);
ExFreePoolWithTag(FCB->DisconnectOptions, TAG_AFD_DISCONNECT_OPTIONS);
FCB->DisconnectOptions = NULL;
FCB->DisconnectOptionsSize = 0;
FCB->FilledDisconnectOptions = 0;
}
FCB->DisconnectOptions = ExAllocatePool(PagedPool, DisconnectOptionsSize);
FCB->DisconnectOptions = ExAllocatePoolWithTag(PagedPool,
DisconnectOptionsSize,
TAG_AFD_DISCONNECT_OPTIONS);
if (!FCB->DisconnectOptions)
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
@ -130,12 +133,15 @@ AfdSetDisconnectOptionsSize(PDEVICE_OBJECT DeviceObject, PIRP Irp,
if (FCB->DisconnectOptions)
{
ExFreePool(FCB->DisconnectOptions);
ExFreePoolWithTag(FCB->DisconnectOptions, TAG_AFD_DISCONNECT_OPTIONS);
FCB->DisconnectOptionsSize = 0;
FCB->FilledDisconnectOptions = 0;
}
FCB->DisconnectOptions = ExAllocatePool(PagedPool, *DisconnectOptionsSize);
FCB->DisconnectOptions = ExAllocatePoolWithTag(PagedPool,
*DisconnectOptionsSize,
TAG_AFD_DISCONNECT_OPTIONS);
if (!FCB->DisconnectOptions) return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
FCB->DisconnectOptionsSize = *DisconnectOptionsSize;
@ -192,13 +198,16 @@ AfdSetDisconnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
if (FCB->DisconnectData)
{
ExFreePool(FCB->DisconnectData);
ExFreePoolWithTag(FCB->DisconnectData, TAG_AFD_DISCONNECT_DATA);
FCB->DisconnectData = NULL;
FCB->DisconnectDataSize = 0;
FCB->FilledDisconnectData = 0;
}
FCB->DisconnectData = ExAllocatePool(PagedPool, DisconnectDataSize);
FCB->DisconnectData = ExAllocatePoolWithTag(PagedPool,
DisconnectDataSize,
TAG_AFD_DISCONNECT_DATA);
if (!FCB->DisconnectData)
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
@ -236,12 +245,15 @@ AfdSetDisconnectDataSize(PDEVICE_OBJECT DeviceObject, PIRP Irp,
if (FCB->DisconnectData)
{
ExFreePool(FCB->DisconnectData);
ExFreePoolWithTag(FCB->DisconnectData, TAG_AFD_DISCONNECT_DATA);
FCB->DisconnectDataSize = 0;
FCB->FilledDisconnectData = 0;
}
FCB->DisconnectData = ExAllocatePool(PagedPool, *DisconnectDataSize);
FCB->DisconnectData = ExAllocatePoolWithTag(PagedPool,
*DisconnectDataSize,
TAG_AFD_DISCONNECT_DATA);
if (!FCB->DisconnectData)
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
@ -319,7 +331,7 @@ AfdCreateSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
AFD_DbgPrint(MID_TRACE,("About to allocate the new FCB\n"));
FCB = ExAllocatePool(NonPagedPool, sizeof(AFD_FCB));
FCB = ExAllocatePoolWithTag(NonPagedPool, sizeof(AFD_FCB), TAG_AFD_FCB);
if( FCB == NULL ) {
Irp->IoStatus.Status = STATUS_NO_MEMORY;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
@ -354,11 +366,12 @@ AfdCreateSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
if( ConnectInfo ) {
FCB->TdiDeviceName.Length = ConnectInfo->SizeOfTransportName;
FCB->TdiDeviceName.MaximumLength = FCB->TdiDeviceName.Length;
FCB->TdiDeviceName.Buffer =
ExAllocatePool( NonPagedPool, FCB->TdiDeviceName.Length );
FCB->TdiDeviceName.Buffer = ExAllocatePoolWithTag(NonPagedPool,
FCB->TdiDeviceName.Length,
TAG_AFD_TRANSPORT_ADDRESS);
if( !FCB->TdiDeviceName.Buffer ) {
ExFreePool(FCB);
ExFreePoolWithTag(FCB, TAG_AFD_FCB);
AFD_DbgPrint(MID_TRACE,("Could not copy target string\n"));
Irp->IoStatus.Status = STATUS_NO_MEMORY;
IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
@ -388,8 +401,11 @@ AfdCreateSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
}
if( !NT_SUCCESS(Status) ) {
if( FCB->TdiDeviceName.Buffer ) ExFreePool( FCB->TdiDeviceName.Buffer );
ExFreePool( FCB );
if (FCB->TdiDeviceName.Buffer)
{
ExFreePoolWithTag(FCB->TdiDeviceName.Buffer, TAG_AFD_TRANSPORT_ADDRESS);
}
ExFreePoolWithTag(FCB, TAG_AFD_FCB);
FileObject->FsContext = NULL;
}
@ -485,7 +501,7 @@ AfdCloseSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
ObDereferenceObject(Qelt->Object.Object);
ZwClose(Qelt->Object.Handle);
ExFreePool(Qelt);
ExFreePoolWithTag(Qelt, TAG_AFD_ACCEPT_QUEUE);
}
SocketStateUnlock( FCB );
@ -493,41 +509,41 @@ AfdCloseSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
if( FCB->EventSelect )
ObDereferenceObject( FCB->EventSelect );
if( FCB->Context )
ExFreePool( FCB->Context );
if (FCB->Context)
ExFreePoolWithTag(FCB->Context, TAG_AFD_SOCKET_CONTEXT);
if( FCB->Recv.Window )
ExFreePool( FCB->Recv.Window );
if (FCB->Recv.Window)
ExFreePoolWithTag(FCB->Recv.Window, TAG_AFD_DATA_BUFFER);
if( FCB->Send.Window )
ExFreePool( FCB->Send.Window );
if (FCB->Send.Window)
ExFreePoolWithTag(FCB->Send.Window, TAG_AFD_DATA_BUFFER);
if( FCB->AddressFrom )
ExFreePool( FCB->AddressFrom );
if (FCB->AddressFrom)
ExFreePoolWithTag(FCB->AddressFrom, TAG_AFD_TDI_CONNECTION_INFORMATION);
if( FCB->ConnectCallInfo )
ExFreePool( FCB->ConnectCallInfo );
if (FCB->ConnectCallInfo)
ExFreePoolWithTag(FCB->ConnectCallInfo, TAG_AFD_TDI_CONNECTION_INFORMATION);
if( FCB->ConnectReturnInfo )
ExFreePool( FCB->ConnectReturnInfo );
if (FCB->ConnectReturnInfo)
ExFreePoolWithTag(FCB->ConnectReturnInfo, TAG_AFD_TDI_CONNECTION_INFORMATION);
if( FCB->ConnectData )
ExFreePool( FCB->ConnectData );
if (FCB->ConnectData)
ExFreePoolWithTag(FCB->ConnectData, TAG_AFD_CONNECT_DATA);
if( FCB->DisconnectData )
ExFreePool( FCB->DisconnectData );
if (FCB->DisconnectData)
ExFreePoolWithTag(FCB->DisconnectData, TAG_AFD_DISCONNECT_DATA);
if( FCB->ConnectOptions )
ExFreePool( FCB->ConnectOptions );
if (FCB->ConnectOptions)
ExFreePoolWithTag(FCB->ConnectOptions, TAG_AFD_CONNECT_OPTIONS);
if( FCB->DisconnectOptions )
ExFreePool( FCB->DisconnectOptions );
if (FCB->DisconnectOptions)
ExFreePoolWithTag(FCB->DisconnectOptions, TAG_AFD_DISCONNECT_OPTIONS);
if( FCB->LocalAddress )
ExFreePool( FCB->LocalAddress );
if (FCB->LocalAddress)
ExFreePoolWithTag(FCB->LocalAddress, TAG_AFD_TRANSPORT_ADDRESS);
if( FCB->RemoteAddress )
ExFreePool( FCB->RemoteAddress );
if (FCB->RemoteAddress)
ExFreePoolWithTag(FCB->RemoteAddress, TAG_AFD_TRANSPORT_ADDRESS);
if( FCB->Connection.Object )
{
@ -554,10 +570,12 @@ AfdCloseSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
}
}
if( FCB->TdiDeviceName.Buffer )
ExFreePool(FCB->TdiDeviceName.Buffer);
if (FCB->TdiDeviceName.Buffer)
{
ExFreePoolWithTag(FCB->TdiDeviceName.Buffer, TAG_AFD_TRANSPORT_ADDRESS);
}
ExFreePool(FCB);
ExFreePoolWithTag(FCB, TAG_AFD_FCB);
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
@ -817,7 +835,7 @@ AfdDisconnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
return UnlockAndMaybeComplete(FCB, STATUS_INVALID_PARAMETER, Irp, 0);
}
ExFreePool(FCB->RemoteAddress);
ExFreePoolWithTag(FCB->RemoteAddress, TAG_AFD_TRANSPORT_ADDRESS);
FCB->RemoteAddress = NULL;
}

View file

@ -409,8 +409,8 @@ SatisfyPacketRecvRequest( PAFD_FCB FCB, PIRP Irp,
if (!(RecvReq->TdiFlags & TDI_RECEIVE_PEEK))
{
FCB->Recv.Content -= DatagramRecv->Len;
ExFreePool( DatagramRecv->Address );
ExFreePool( DatagramRecv );
ExFreePoolWithTag(DatagramRecv->Address, TAG_AFD_TRANSPORT_ADDRESS);
ExFreePoolWithTag(DatagramRecv, TAG_AFD_STORED_DATAGRAM);
}
AFD_DbgPrint(MID_TRACE,("Done\n"));
@ -584,8 +584,8 @@ PacketSocketRecvComplete(
while( !IsListEmpty( &FCB->DatagramList ) ) {
DatagramRecvEntry = RemoveHeadList(&FCB->DatagramList);
DatagramRecv = CONTAINING_RECORD(DatagramRecvEntry, AFD_STORED_DATAGRAM, ListEntry);
ExFreePool( DatagramRecv->Address );
ExFreePool( DatagramRecv );
ExFreePoolWithTag(DatagramRecv->Address, TAG_AFD_TRANSPORT_ADDRESS);
ExFreePoolWithTag(DatagramRecv, TAG_AFD_STORED_DATAGRAM);
}
SocketStateUnlock( FCB );
@ -604,7 +604,9 @@ PacketSocketRecvComplete(
return STATUS_FILE_CLOSED;
}
DatagramRecv = ExAllocatePool( NonPagedPool, DGSize );
DatagramRecv = ExAllocatePoolWithTag(NonPagedPool,
DGSize,
TAG_AFD_STORED_DATAGRAM);
if( DatagramRecv ) {
DatagramRecv->Len = Irp->IoStatus.Information;
@ -620,7 +622,12 @@ PacketSocketRecvComplete(
} else Status = STATUS_NO_MEMORY;
if( !NT_SUCCESS( Status ) ) {
if( DatagramRecv ) ExFreePool( DatagramRecv );
if (DatagramRecv)
{
ExFreePoolWithTag(DatagramRecv, TAG_AFD_STORED_DATAGRAM);
}
SocketStateUnlock( FCB );
return Status;
} else {

View file

@ -68,7 +68,7 @@ VOID SignalSocket(
{
KeCancelTimer( &Poll->Timer );
RemoveEntryList( &Poll->ListEntry );
ExFreePool( Poll );
ExFreePoolWithTag(Poll, TAG_AFD_ACTIVE_POLL);
}
Irp->IoStatus.Status = Status;
@ -228,7 +228,9 @@ AfdSelect( PDEVICE_OBJECT DeviceObject, PIRP Irp,
PAFD_ACTIVE_POLL Poll = NULL;
Poll = ExAllocatePool( NonPagedPool, sizeof(AFD_ACTIVE_POLL) );
Poll = ExAllocatePoolWithTag(NonPagedPool,
sizeof(AFD_ACTIVE_POLL),
TAG_AFD_ACTIVE_POLL);
if (Poll){
Poll->Irp = Irp;

View file

@ -196,7 +196,9 @@ NTSTATUS TdiOpenAddressFile(
EaLength = sizeof(FILE_FULL_EA_INFORMATION) +
TDI_TRANSPORT_ADDRESS_LENGTH +
TaLengthOfTransportAddress( Name ) + 1;
EaInfo = (PFILE_FULL_EA_INFORMATION)ExAllocatePool(NonPagedPool, EaLength);
EaInfo = (PFILE_FULL_EA_INFORMATION)ExAllocatePoolWithTag(NonPagedPool,
EaLength,
TAG_AFD_EA_INFO);
if (!EaInfo)
return STATUS_INSUFFICIENT_RESOURCES;
@ -217,7 +219,7 @@ NTSTATUS TdiOpenAddressFile(
ShareType,
AddressHandle,
AddressObject);
ExFreePool(EaInfo);
ExFreePoolWithTag(EaInfo, TAG_AFD_EA_INFO);
return Status;
}
@ -229,13 +231,16 @@ NTSTATUS TdiQueryMaxDatagramLength(
PTDI_MAX_DATAGRAM_INFO Buffer;
NTSTATUS Status = STATUS_SUCCESS;
Buffer = ExAllocatePool(NonPagedPool, sizeof(TDI_MAX_DATAGRAM_INFO));
Buffer = ExAllocatePoolWithTag(NonPagedPool,
sizeof(TDI_MAX_DATAGRAM_INFO),
TAG_AFD_DATA_BUFFER);
if (!Buffer) return STATUS_NO_MEMORY;
Mdl = IoAllocateMdl(Buffer, sizeof(TDI_MAX_DATAGRAM_INFO), FALSE, FALSE, NULL);
if (!Mdl)
{
ExFreePool(Buffer);
ExFreePoolWithTag(Buffer, TAG_AFD_DATA_BUFFER);
return STATUS_NO_MEMORY;
}
@ -253,7 +258,7 @@ NTSTATUS TdiQueryMaxDatagramLength(
{
AFD_DbgPrint(MIN_TRACE,("Failed to lock pages\n"));
IoFreeMdl(Mdl);
ExFreePool(Buffer);
ExFreePoolWithTag(Buffer, TAG_AFD_DATA_BUFFER);
return Status;
}
@ -262,13 +267,13 @@ NTSTATUS TdiQueryMaxDatagramLength(
Mdl);
if (!NT_SUCCESS(Status))
{
ExFreePool(Buffer);
ExFreePoolWithTag(Buffer, TAG_AFD_DATA_BUFFER);
return Status;
}
*MaxDatagramLength = Buffer->MaxDatagramSize;
ExFreePool(Buffer);
ExFreePoolWithTag(Buffer, TAG_AFD_DATA_BUFFER);
return STATUS_SUCCESS;
}
@ -299,7 +304,9 @@ NTSTATUS TdiOpenConnectionEndpointFile(
TDI_CONNECTION_CONTEXT_LENGTH +
sizeof(PVOID) + 1;
EaInfo = (PFILE_FULL_EA_INFORMATION)ExAllocatePool(NonPagedPool, EaLength);
EaInfo = (PFILE_FULL_EA_INFORMATION)ExAllocatePoolWithTag(NonPagedPool,
EaLength,
TAG_AFD_EA_INFO);
if (!EaInfo)
return STATUS_INSUFFICIENT_RESOURCES;
@ -319,7 +326,7 @@ NTSTATUS TdiOpenConnectionEndpointFile(
AFD_SHARE_UNIQUE,
ConnectionHandle,
ConnectionObject);
ExFreePool(EaInfo);
ExFreePoolWithTag(EaInfo, TAG_AFD_EA_INFO);
return Status;
}
@ -776,7 +783,9 @@ NTSTATUS TdiQueryAddress(
AFD_DbgPrint(MAX_TRACE, ("Called\n"));
BufferSize = sizeof(TDIEntityID) * 20;
Entities = (TDIEntityID*)ExAllocatePool(NonPagedPool, BufferSize);
Entities = (TDIEntityID*)ExAllocatePoolWithTag(NonPagedPool,
BufferSize,
TAG_AFD_TRANSPORT_ADDRESS);
if (!Entities) {
AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
return STATUS_INSUFFICIENT_RESOURCES;
@ -794,7 +803,7 @@ NTSTATUS TdiQueryAddress(
&BufferSize); /* Output buffer size */
if (!NT_SUCCESS(Status)) {
AFD_DbgPrint(MIN_TRACE, ("Unable to get list of supported entities (Status = 0x%X).\n", Status));
ExFreePool(Entities);
ExFreePoolWithTag(Entities, TAG_AFD_TRANSPORT_ADDRESS);
return Status;
}
@ -841,7 +850,9 @@ NTSTATUS TdiQueryAddress(
if (SnmpInfo.ipsi_numaddr != 0) {
BufferSize = SnmpInfo.ipsi_numaddr * sizeof(IPADDR_ENTRY);
IpAddress = (PIPADDR_ENTRY)ExAllocatePool(NonPagedPool, BufferSize);
IpAddress = (PIPADDR_ENTRY)ExAllocatePoolWithTag(NonPagedPool,
BufferSize,
TAG_AFD_SNMP_ADDRESS_INFO);
if (!IpAddress) {
AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
break;
@ -857,7 +868,7 @@ NTSTATUS TdiQueryAddress(
&BufferSize); /* Output buffer size */
if (!NT_SUCCESS(Status)) {
AFD_DbgPrint(MIN_TRACE, ("Unable to get IP address (Status = 0x%X).\n", Status));
ExFreePool(IpAddress);
ExFreePoolWithTag(IpAddress, TAG_AFD_SNMP_ADDRESS_INFO);
break;
}
@ -869,7 +880,7 @@ NTSTATUS TdiQueryAddress(
*Address = DN2H(IpAddress->Addr);
}
ExFreePool(IpAddress);
ExFreePoolWithTag(IpAddress, TAG_AFD_SNMP_ADDRESS_INFO);
} else {
Status = STATUS_UNSUCCESSFUL;
break;
@ -877,7 +888,7 @@ NTSTATUS TdiQueryAddress(
}
}
ExFreePool(Entities);
ExFreePoolWithTag(Entities, TAG_AFD_TRANSPORT_ADDRESS);
AFD_DbgPrint(MAX_TRACE, ("Leaving\n"));

View file

@ -85,7 +85,9 @@ PTRANSPORT_ADDRESS TaCopyTransportAddress( PTRANSPORT_ADDRESS OtherAddress ) {
if (!AddrLen)
return NULL;
A = ExAllocatePool( NonPagedPool, AddrLen );
A = ExAllocatePoolWithTag(NonPagedPool,
AddrLen,
TAG_AFD_TRANSPORT_ADDRESS);
if( A )
TaCopyTransportAddressInPlace( A, OtherAddress );
@ -117,13 +119,13 @@ PTRANSPORT_ADDRESS TaBuildNullTransportAddress(UINT AddressType)
if (!AddrLen)
return NULL;
A = ExAllocatePool(NonPagedPool, AddrLen);
A = ExAllocatePoolWithTag(NonPagedPool, AddrLen, TAG_AFD_TRANSPORT_ADDRESS);
if (A)
{
if (TdiBuildNullTransportAddressInPlace(A, AddressType) != STATUS_SUCCESS)
{
ExFreePool(A);
ExFreePoolWithTag(A, TAG_AFD_TRANSPORT_ADDRESS);
return NULL;
}
}
@ -190,9 +192,9 @@ NTSTATUS TdiBuildNullConnectionInfo
}
ConnInfo = (PTDI_CONNECTION_INFORMATION)
ExAllocatePool(NonPagedPool,
sizeof(TDI_CONNECTION_INFORMATION) +
TdiAddressSize);
ExAllocatePoolWithTag(NonPagedPool,
sizeof(TDI_CONNECTION_INFORMATION) + TdiAddressSize,
TAG_AFD_TDI_CONNECTION_INFORMATION);
if (!ConnInfo) {
*ConnectionInfo = NULL;
return STATUS_INSUFFICIENT_RESOURCES;
@ -202,7 +204,7 @@ NTSTATUS TdiBuildNullConnectionInfo
if (!NT_SUCCESS(Status))
{
ExFreePool( ConnInfo );
ExFreePoolWithTag(ConnInfo, TAG_AFD_TDI_CONNECTION_INFORMATION);
ConnInfo = NULL;
}

View file

@ -398,7 +398,7 @@ AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
}
}
ExFreePool( TargetAddress );
ExFreePoolWithTag(TargetAddress, TAG_AFD_TDI_CONNECTION_INFORMATION);
SocketStateUnlock(FCB);
@ -597,7 +597,11 @@ AfdPacketSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
if (FCB->State == SOCKET_STATE_CREATED)
{
if( FCB->LocalAddress ) ExFreePool( FCB->LocalAddress );
if (FCB->LocalAddress)
{
ExFreePoolWithTag(FCB->LocalAddress, TAG_AFD_TRANSPORT_ADDRESS);
}
FCB->LocalAddress =
TaBuildNullTransportAddress( ((PTRANSPORT_ADDRESS)SendReq->TdiConnection.RemoteAddress)->
Address[0].AddressType );
@ -660,7 +664,7 @@ AfdPacketSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
}
}
ExFreePool(TargetAddress);
ExFreePoolWithTag(TargetAddress, TAG_AFD_TDI_CONNECTION_INFORMATION);
SocketStateUnlock(FCB);

View file

@ -35,6 +35,24 @@
#define IP_MIB_STATS_ID 1
#define IP_MIB_ADDRTABLE_ENTRY_ID 0x102
#define TAG_AFD_DATA_BUFFER 'BdfA'
#define TAG_AFD_TRANSPORT_ADDRESS 'tdfA'
#define TAG_AFD_SOCKET_CONTEXT 'XdfA'
#define TAG_AFD_CONNECT_DATA 'cdfA'
#define TAG_AFD_DISCONNECT_DATA 'ddfA'
#define TAG_AFD_CONNECT_OPTIONS 'ocfA'
#define TAG_AFD_DISCONNECT_OPTIONS 'odfA'
#define TAG_AFD_ACCEPT_QUEUE 'qafA'
#define TAG_AFD_POLL_HANDLE 'hpfA'
#define TAG_AFD_FCB 'cffA'
#define TAG_AFD_ACTIVE_POLL 'pafA'
#define TAG_AFD_EA_INFO 'aefA'
#define TAG_AFD_STORED_DATAGRAM 'gsfA'
#define TAG_AFD_SNMP_ADDRESS_INFO 'asfA'
#define TAG_AFD_TDI_CONNECTION_INFORMATION 'cTfA'
#define TAG_AFD_WSA_BUFFER 'bWfA'
typedef struct IPADDR_ENTRY {
ULONG Addr;
ULONG Index;