From 938600f750ed33a13f75762e75c89936a9140608 Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Fri, 26 Mar 2010 08:39:27 +0000 Subject: [PATCH] [NTOSKRNL/CONFIG] - Add a macro for asserting hash lock ownership. - Add a macro for getting an alloc page from KCB / delay alloc item. - Add a newly allocated KCB to the tail of CmpFreeKCBList, not to its head. svn path=/trunk/; revision=46459 --- reactos/ntoskrnl/config/cmalloc.c | 17 +++++++---------- reactos/ntoskrnl/include/internal/cm_x.h | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/reactos/ntoskrnl/config/cmalloc.c b/reactos/ntoskrnl/config/cmalloc.c index 37da97ea44b..97dfc1a6e26 100644 --- a/reactos/ntoskrnl/config/cmalloc.c +++ b/reactos/ntoskrnl/config/cmalloc.c @@ -70,14 +70,13 @@ CmpFreeKeyControlBlock(IN PCM_KEY_CONTROL_BLOCK Kcb) KeAcquireGuardedMutex(&CmpAllocBucketLock); /* Sanity check on lock ownership */ - //ASSERT((CmpIsKcbLockedExclusive(Kcb) == TRUE) || - // (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); @@ -134,7 +133,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); @@ -168,7 +167,7 @@ SearchKcbList: /* Set it up */ CurrentKcb->PrivateAlloc = TRUE; CurrentKcb->DelayCloseEntry = NULL; - InsertHeadList(&CmpFreeKCBListHead, + InsertTailList(&CmpFreeKCBListHead, &CurrentKcb->FreeListEntry); } @@ -178,9 +177,7 @@ SearchKcbList: } /* Allocate a KCB only */ - CurrentKcb = CmpAllocate(sizeof(CM_KEY_CONTROL_BLOCK), - TRUE, - TAG_CM); + CurrentKcb = CmpAllocate(sizeof(CM_KEY_CONTROL_BLOCK), TRUE, TAG_CM); if (CurrentKcb) { /* Set it up */ @@ -219,7 +216,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); @@ -278,7 +275,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 */ diff --git a/reactos/ntoskrnl/include/internal/cm_x.h b/reactos/ntoskrnl/include/internal/cm_x.h index ed3f3bff629..581a336d636 100644 --- a/reactos/ntoskrnl/include/internal/cm_x.h +++ b/reactos/ntoskrnl/include/internal/cm_x.h @@ -254,3 +254,25 @@ CmpConvertKcbSharedToExclusive(IN PCM_KEY_CONTROL_BLOCK k) ExReleasePushLock(&GET_HASH_ENTRY(CmpNameCacheTable, \ (k)).Lock); \ } + +// +// Asserts that either the registry or the KCB is locked +// +#define CMP_ASSERT_HASH_ENTRY_LOCK(k) \ +{ \ + ASSERT(((GET_HASH_ENTRY(CmpCacheTable, k).Owner == \ + KeGetCurrentThread())) || \ + (CmpTestRegistryLockExclusive() == TRUE)); \ +} + +// +// Gets the page attached to the KCB +// +#define CmpGetAllocPageFromKcb(k) \ + (PCM_ALLOC_PAGE)(((ULONG_PTR)(k)) & ~(PAGE_SIZE - 1)) + +// +// Gets the page attached to the delayed allocation +// +#define CmpGetAllocPageFromDelayAlloc(a) \ + (PCM_ALLOC_PAGE)(((ULONG_PTR)(a)) & ~(PAGE_SIZE - 1))