[CMAKE]
[reactos.git] / ntoskrnl / config / cmalloc.c
index 3c8cdbb..6502883 100644 (file)
@@ -25,6 +25,7 @@ LIST_ENTRY CmpFreeDelayItemsListHead;
 
 VOID
 NTAPI
+INIT_FUNCTION
 CmpInitCmPrivateAlloc(VOID)
 {
     /* Make sure we didn't already do this */
@@ -39,6 +40,7 @@ CmpInitCmPrivateAlloc(VOID)
 
 VOID
 NTAPI
+INIT_FUNCTION
 CmpInitCmPrivateDelayAlloc(VOID)
 {
     /* Initialize the delay allocation list and lock */
@@ -62,7 +64,7 @@ CmpFreeKeyControlBlock(IN PCM_KEY_CONTROL_BLOCK Kcb)
     if (!Kcb->PrivateAlloc)
     {
         /* Free it from the pool */
-        ExFreePool(Kcb);
+        CmpFree(Kcb, 0);
         return;
     }
     
@@ -70,15 +72,13 @@ CmpFreeKeyControlBlock(IN PCM_KEY_CONTROL_BLOCK Kcb)
     KeAcquireGuardedMutex(&CmpAllocBucketLock);
     
     /* Sanity check on lock ownership */
-    ASSERT((GET_HASH_ENTRY(CmpCacheTable, Kcb->ConvKey).Owner ==
-            KeGetCurrentThread()) ||
-           (CmpTestRegistryLockExclusive() == TRUE));
+    CMP_ASSERT_HASH_ENTRY_LOCK(Kcb->ConvKey);
     
     /* Add us to the free list */
     InsertTailList(&CmpFreeKCBListHead, &Kcb->FreeListEntry);
     
     /* Get the allocation page */
-    AllocPage = (PCM_ALLOC_PAGE)((ULONG_PTR)Kcb & 0xFFFFF000);
+    AllocPage = CmpGetAllocPageFromKcb(Kcb);
     
     /* Sanity check */
     ASSERT(AllocPage->FreeCount != CM_KCBS_PER_PAGE);
@@ -99,7 +99,7 @@ CmpFreeKeyControlBlock(IN PCM_KEY_CONTROL_BLOCK Kcb)
         }
         
         /* Free the page */
-        ExFreePool(AllocPage);
+        CmpFree(AllocPage, 0);
     }
     
     /* Release the lock */
@@ -135,7 +135,7 @@ SearchKcbList:
                                            FreeListEntry);
             
             /* Get the allocation page */
-            AllocPage = (PCM_ALLOC_PAGE)((ULONG_PTR)CurrentKcb & 0xFFFFF000);
+            AllocPage = CmpGetAllocPageFromKcb(CurrentKcb);
             
             /* Decrease the free count */
             ASSERT(AllocPage->FreeCount != 0);
@@ -152,7 +152,7 @@ SearchKcbList:
         }
         
         /* Allocate an allocation page */
-        AllocPage = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, TAG_CM);
+        AllocPage = CmpAllocate(PAGE_SIZE, TRUE, TAG_CM);
         if (AllocPage)
         {
             /* Set default entries */
@@ -169,7 +169,7 @@ SearchKcbList:
                 /* Set it up */
                 CurrentKcb->PrivateAlloc = TRUE;
                 CurrentKcb->DelayCloseEntry = NULL;
-                InsertHeadList(&CmpFreeKCBListHead,
+                InsertTailList(&CmpFreeKCBListHead,
                                &CurrentKcb->FreeListEntry);
             }
             
@@ -179,9 +179,7 @@ SearchKcbList:
     }
 
     /* Allocate a KCB only */
-    CurrentKcb = ExAllocatePoolWithTag(PagedPool,
-                                       sizeof(CM_KEY_CONTROL_BLOCK),
-                                       TAG_CM);
+    CurrentKcb = CmpAllocate(sizeof(CM_KEY_CONTROL_BLOCK), TRUE, TAG_CM);
     if (CurrentKcb)
     {
         /* Set it up */
@@ -220,7 +218,7 @@ SearchList:
         Entry->ListEntry.Flink = Entry->ListEntry.Blink = NULL;
         
         /* Grab the alloc page */
-        AllocPage = (PCM_ALLOC_PAGE)((ULONG_PTR)Entry & 0xFFFFF000);
+        AllocPage = CmpGetAllocPageFromDelayAlloc(Entry);
         
         /* Decrease free entries */
         ASSERT(AllocPage->FreeCount != 0);
@@ -232,7 +230,7 @@ SearchList:
     }
     
     /* Allocate an allocation page */
-    AllocPage = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, TAG_CM);
+    AllocPage = CmpAllocate(PAGE_SIZE, TRUE, TAG_CM);
     if (AllocPage)
     {
         /* Set default entries */
@@ -279,7 +277,7 @@ CmpFreeDelayItem(PVOID Entry)
     InsertTailList(&CmpFreeDelayItemsListHead, &AllocEntry->ListEntry);
     
     /* Get the alloc page */
-    AllocPage = (PCM_ALLOC_PAGE)((ULONG_PTR)Entry & 0xFFFFF000);
+    AllocPage = CmpGetAllocPageFromDelayAlloc(Entry);
     ASSERT(AllocPage->FreeCount != CM_DELAYS_PER_PAGE);
     
     /* Increase the number of free items */
@@ -296,7 +294,7 @@ CmpFreeDelayItem(PVOID Entry)
         }
         
         /* Now free the page */
-        ExFreePool(AllocPage);
+        CmpFree(AllocPage, 0);
     }
     
     /* Release the lock */