]> xenbits.xensource.com Git - pvdrivers/win/xennet.git/commitdiff
Update util.h
authorPaul Durrant <paul.durrant@citrix.com>
Thu, 25 Jan 2018 12:51:06 +0000 (12:51 +0000)
committerPaul Durrant <paul.durrant@citrix.com>
Thu, 25 Jan 2018 12:51:06 +0000 (12:51 +0000)
XENNET does not use much of the functionality in util.h, including the
__AllocatePages()/__FreePages() functions modified by this change, however
it is good to keep the header in-sync with the other drivers.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
src/xennet/util.h

index d6340332a7321833efb0cca380ac566a9df66c9a..83008ad64020e78aacd1c40eb9200eee17f3a1fb 100644 (file)
@@ -170,8 +170,8 @@ __FreePoolWithTag(
 }
 
 static FORCEINLINE PMDL
-__AllocatePage(
-    VOID
+__AllocatePages(
+    IN  ULONG           Count
     )
 {
     PHYSICAL_ADDRESS    LowAddress;
@@ -185,7 +185,7 @@ __AllocatePage(
     LowAddress.QuadPart = 0ull;
     HighAddress.QuadPart = ~0ull;
     SkipBytes.QuadPart = 0ull;
-    TotalBytes = (SIZE_T)PAGE_SIZE;
+    TotalBytes = (SIZE_T)PAGE_SIZE * Count;
 
     Mdl = MmAllocatePagesForMdlEx(LowAddress,
                                   HighAddress,
@@ -198,7 +198,7 @@ __AllocatePage(
     if (Mdl == NULL)
         goto fail1;
 
-    if (Mdl->ByteCount < PAGE_SIZE)
+    if (Mdl->ByteCount < TotalBytes)
         goto fail2;
 
     ASSERT((Mdl->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA |
@@ -219,9 +219,13 @@ __AllocatePage(
     if (MdlMappedSystemVa == NULL)
         goto fail3;
 
-    ASSERT3P(MdlMappedSystemVa, ==, Mdl->MappedSystemVa);
+    Mdl->StartVa = PAGE_ALIGN(MdlMappedSystemVa);
 
-    RtlZeroMemory(MdlMappedSystemVa, PAGE_SIZE);
+    ASSERT3U(Mdl->ByteOffset, ==, 0);
+    ASSERT3P(Mdl->StartVa, ==, MdlMappedSystemVa);
+    ASSERT3P(Mdl->MappedSystemVa, ==, MdlMappedSystemVa);
+
+    RtlZeroMemory(MdlMappedSystemVa, Mdl->ByteCount);
 
     return Mdl;
 
@@ -240,8 +244,10 @@ fail1:
     return NULL;
 }
 
+#define __AllocatePage()    __AllocatePages(1)
+
 static FORCEINLINE VOID
-__FreePage(
+__FreePages(
     IN PMDL    Mdl
     )
 {
@@ -250,13 +256,14 @@ __FreePage(
     ASSERT(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA);
     MdlMappedSystemVa = Mdl->MappedSystemVa;
 
-    RtlFillMemory(MdlMappedSystemVa, PAGE_SIZE, 0xAA);
-
     MmUnmapLockedPages(MdlMappedSystemVa, Mdl);
 
     MmFreePagesFromMdl(Mdl);
+    ExFreePool(Mdl);
 }
 
+#define __FreePage(_Mdl)    __FreePages(_Mdl)
+
 static FORCEINLINE PCHAR
 __strtok_r(
     IN      PCHAR   Buffer,