[AFD] Introduce and use pool tags. Thanks go to Arty for assisting me with this....
[reactos.git] / drivers / network / afd / afd / lock.c
index d26fbf2..aed7b81 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id$
+/*
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
  * FILE:             drivers/net/afd/afd/lock.c
@@ -7,6 +7,7 @@
  * UPDATE HISTORY:
  * 20040708 Created
  */
+
 #include "afd.h"
 
 PVOID GetLockedData(PIRP Irp, PIO_STACK_LOCATION IrpSp)
@@ -14,6 +15,8 @@ PVOID GetLockedData(PIRP Irp, PIO_STACK_LOCATION IrpSp)
     ASSERT(Irp->MdlAddress);
     ASSERT(Irp->Tail.Overlay.DriverContext[0]);
 
+    UNREFERENCED_PARAMETER(IrpSp);
+
     return Irp->Tail.Overlay.DriverContext[0];
 }
 
@@ -66,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"));
@@ -123,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"));
@@ -173,6 +182,8 @@ VOID UnlockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp )
     ASSERT(Irp->MdlAddress);
     ASSERT(Irp->Tail.Overlay.DriverContext[0]);
 
+    UNREFERENCED_PARAMETER(IrpSp);
+
     /* Check if we need to copy stuff back */
     if (Irp->Tail.Overlay.DriverContext[1] != NULL)
     {
@@ -181,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;
@@ -199,11 +210,11 @@ 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;
 
-    AFD_DbgPrint(MID_TRACE,("Called(%08x)\n", NewBuf));
+    AFD_DbgPrint(MID_TRACE,("Called(%p)\n", NewBuf));
 
     if( NewBuf ) {
         RtlZeroMemory(NewBuf, Size);
@@ -223,14 +234,14 @@ PAFD_WSABUF LockBuffers( PAFD_WSABUF Buf, UINT Count,
             }
         } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
             AFD_DbgPrint(MIN_TRACE,("Access violation copying buffer info "
-                                    "from userland (%x %x)\n",
+                                    "from userland (%p %p)\n",
                                     Buf, AddressLen));
-            ExFreePool( NewBuf );
+            ExFreePoolWithTag(NewBuf, TAG_AFD_WSA_BUFFER);
             _SEH2_YIELD(return NULL);
         } _SEH2_END;
 
         for( i = 0; i < Count; i++ ) {
-            AFD_DbgPrint(MID_TRACE,("Locking buffer %d (%x:%d)\n",
+            AFD_DbgPrint(MID_TRACE,("Locking buffer %u (%p:%u)\n",
                                     i, NewBuf[i].buf, NewBuf[i].len));
 
             if( NewBuf[i].buf && NewBuf[i].len ) {
@@ -244,7 +255,7 @@ PAFD_WSABUF LockBuffers( PAFD_WSABUF Buf, UINT Count,
                 continue;
             }
 
-            AFD_DbgPrint(MID_TRACE,("NewMdl @ %x\n", MapBuf[i].Mdl));
+            AFD_DbgPrint(MID_TRACE,("NewMdl @ %p\n", MapBuf[i].Mdl));
 
             if( MapBuf[i].Mdl ) {
                 AFD_DbgPrint(MID_TRACE,("Probe and lock pages\n"));
@@ -260,17 +271,17 @@ 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;
             }
         }
     }
 
-    AFD_DbgPrint(MID_TRACE,("Leaving %x\n", NewBuf));
+    AFD_DbgPrint(MID_TRACE,("Leaving %p\n", NewBuf));
 
     return NewBuf;
 }
@@ -290,7 +301,7 @@ VOID UnlockBuffers( PAFD_WSABUF Buf, UINT Count, BOOL Address ) {
         }
     }
 
-    ExFreePool( Buf );
+    ExFreePoolWithTag(Buf, TAG_AFD_WSA_BUFFER);
     Buf = NULL;
 }
 
@@ -300,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;
@@ -341,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;
 }