- Fix handling of nonpaged contiguous memory in NdisAllocateMemory and NdisFreeMemory
authorCameron Gutman <aicommander@gmail.com>
Sat, 30 May 2009 17:12:45 +0000 (17:12 +0000)
committerCameron Gutman <aicommander@gmail.com>
Sat, 30 May 2009 17:12:45 +0000 (17:12 +0000)
svn path=/trunk/; revision=41207

reactos/drivers/network/ndis/ndis/memory.c

index 194bfe5..9dd0771 100644 (file)
@@ -74,26 +74,26 @@ NdisAllocateMemory(
 {
   NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
 
-  if (MemoryFlags & NDIS_MEMORY_NONCACHED)
-    {
-      *VirtualAddress = MmAllocateNonCachedMemory(Length);
-      if(!*VirtualAddress)
-        return NDIS_STATUS_FAILURE;
-
-      return NDIS_STATUS_SUCCESS;
-    }
-
   if (MemoryFlags & NDIS_MEMORY_CONTIGUOUS)
-    {
-      *VirtualAddress = MmAllocateContiguousMemory(Length, HighestAcceptableAddress);
-      if(!*VirtualAddress)
-        return NDIS_STATUS_FAILURE;
-
-      return NDIS_STATUS_SUCCESS;
-    }
+  {
+      /* Allocate contiguous memory (possibly noncached) */
+      *VirtualAddress = MmAllocateContiguousMemorySpecifyCache(Length,
+                                                               RtlConvertUlongToLargeInteger(0),
+                                                               HighestAcceptableAddress,
+                                                               RtlConvertUlongToLargeInteger(0),
+                                                               (MemoryFlags & NDIS_MEMORY_NONCACHED) ? MmNonCached : MmCached);
+  }
+  else if (MemoryFlags & NDIS_MEMORY_NONCACHED)
+  {
+      /* Allocate noncached noncontiguous memory */
+      *VirtualAddress = MmAllocateNonCachedMemory(Length);
+  }
+  else
+  {
+      /* Allocate plain nonpaged memory */
+      *VirtualAddress = ExAllocatePool(NonPagedPool, Length);
+  }
 
-  /* Plain nonpaged memory */
-  *VirtualAddress = ExAllocatePool(NonPagedPool, Length);
   if (!*VirtualAddress)
     return NDIS_STATUS_FAILURE;
 
@@ -120,19 +120,23 @@ NdisFreeMemory(
 {
   NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
 
-  if (MemoryFlags & NDIS_MEMORY_NONCACHED)
-    {
-      MmFreeNonCachedMemory(VirtualAddress, Length);
-      return;
-    }
-
   if (MemoryFlags & NDIS_MEMORY_CONTIGUOUS)
-    {
-      MmFreeContiguousMemory(VirtualAddress);
-      return;
-    }
-
-  ExFreePool(VirtualAddress);
+  {
+      /* Free contiguous memory (possibly noncached) */
+      MmFreeContiguousMemorySpecifyCache(VirtualAddress,
+                                         Length,
+                                         (MemoryFlags & NDIS_MEMORY_NONCACHED) ? MmNonCached : MmCached);
+  }
+  else if (MemoryFlags & NDIS_MEMORY_NONCACHED)
+  {
+      /* Free noncached noncontiguous memory */
+      MmFreeNonCachedMemory(VirtualAddress, Length);
+  }
+  else
+  {
+      /* Free nonpaged pool */
+      ExFreePool(VirtualAddress);
+  }
 }
 
 \f