#include <ntoskrnl.h>
#define NDEBUG
#include <debug.h>
-#include "cm.h"
/* GLOBALS *******************************************************************/
PAGED_CODE();
/* Sanity checks */
- ASSERT(IsListEmpty(&(Kcb->KeyBodyListHead)) == TRUE);
+ ASSERT(IsListEmpty(&Kcb->KeyBodyListHead) == TRUE);
for (i = 0; i < 4; i++) ASSERT(Kcb->KeyBodyArray[i] == NULL);
/* Check if it wasn't privately allocated */
if (!Kcb->PrivateAlloc)
{
/* Free it from the pool */
- ExFreePool(Kcb);
+ CmpFree(Kcb, 0);
return;
}
KeAcquireGuardedMutex(&CmpAllocBucketLock);
/* Sanity check on lock ownership */
- ASSERT((GET_HASH_ENTRY(CmpCacheTable, Kcb->ConvKey).Owner ==
- KeGetCurrentThread()) ||
- (CmpTestRegistryLockExclusive() == TRUE));
+ //ASSERT((CmpIsKcbLockedExclusive(Kcb) == TRUE) ||
+ // (CmpTestRegistryLockExclusive() == TRUE));
/* Add us to the free list */
InsertTailList(&CmpFreeKCBListHead, &Kcb->FreeListEntry);
if (++AllocPage->FreeCount == CM_KCBS_PER_PAGE)
{
/* Loop all the entries */
- for (i = CM_KCBS_PER_PAGE; i; i--)
+ for (i = 0; i < CM_KCBS_PER_PAGE; i++)
{
/* Get the KCB */
Kcb = (PVOID)((ULONG_PTR)AllocPage +
FIELD_OFFSET(CM_ALLOC_PAGE, AllocPage) +
- (i - 1) * sizeof(CM_KEY_CONTROL_BLOCK));
+ i * sizeof(CM_KEY_CONTROL_BLOCK));
/* Remove the entry */
RemoveEntryList(&Kcb->FreeListEntry);
}
/* Free the page */
- ExFreePool(AllocPage);
+ CmpFree(AllocPage, 0);
}
/* Release the lock */
PCM_ALLOC_PAGE AllocPage;
ULONG i;
PAGED_CODE();
-
+
/* Check if private allocations are initialized */
if (CmpAllocInited)
{
}
/* Allocate an allocation page */
- AllocPage = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, TAG_CM);
+ AllocPage = CmpAllocate(PAGE_SIZE, TRUE, TAG_CM);
if (AllocPage)
{
/* Set default entries */
goto 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 */
/* Look for an item on the free list */
SearchList:
- if (!IsListEmpty(&CmpFreeDelayItemsListHead))
- {
- /* Get the current entry in the list */
- NextEntry = RemoveHeadList(&CmpFreeDelayItemsListHead);
-
- /* Grab the item */
- Entry = CONTAINING_RECORD(NextEntry, CM_DELAY_ALLOC, ListEntry);
-
- /* Clear the list */
- Entry->ListEntry.Flink = Entry->ListEntry.Blink = NULL;
-
- /* Grab the alloc page */
- AllocPage = (PCM_ALLOC_PAGE)((ULONG_PTR)Entry & 0xFFFFF000);
-
- /* Decrease free entries */
- ASSERT(AllocPage->FreeCount != 0);
- AllocPage->FreeCount--;
-
- /* Release the lock */
- KeReleaseGuardedMutex(&CmpDelayAllocBucketLock);
- return Entry;
- }
+ if (!IsListEmpty(&CmpFreeDelayItemsListHead))
+ {
+ /* Get the current entry in the list */
+ NextEntry = RemoveHeadList(&CmpFreeDelayItemsListHead);
+
+ /* Grab the item */
+ Entry = CONTAINING_RECORD(NextEntry, CM_DELAY_ALLOC, ListEntry);
+
+ /* Clear the list */
+ Entry->ListEntry.Flink = Entry->ListEntry.Blink = NULL;
+
+ /* Grab the alloc page */
+ AllocPage = (PCM_ALLOC_PAGE)((ULONG_PTR)Entry & 0xFFFFF000);
+
+ /* Decrease free entries */
+ ASSERT(AllocPage->FreeCount != 0);
+ AllocPage->FreeCount--;
+
+ /* Release the lock */
+ KeReleaseGuardedMutex(&CmpDelayAllocBucketLock);
+ return Entry;
+ }
/* Allocate an allocation page */
- AllocPage = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, TAG_CM);
+ AllocPage = CmpAllocate(PAGE_SIZE, TRUE, TAG_CM);
if (AllocPage)
{
/* Set default entries */
}
/* Now free the page */
- ExFreePool(AllocPage);
+ CmpFree(AllocPage, 0);
}
/* Release the lock */