Author: ion
Date: Thu Aug 17 05:54:33 2006
New Revision: 23594
URL:
http://svn.reactos.org/svn/reactos?rev=23594&view=rev
Log:
- Fix CMP_ASSERT_EXCLUSIVE_REGISTRY_LOCK and CMP_ASSERT_REGISTRY_LOCK
- Create cmutil.c and add registry lock routines in it, as well as CmpAllocateDelayItem
and CmpFreeDelayItem (move them out from cmkcbncb.c)
- Implement CmpCompareCompressedName.
Added:
branches/alex-cm-branch/reactos/ntoskrnl/cm/cmutil.c
Modified:
branches/alex-cm-branch/reactos/ntoskrnl/cm/cm.h
branches/alex-cm-branch/reactos/ntoskrnl/cm/cm_x.h
branches/alex-cm-branch/reactos/ntoskrnl/cm/cminfo.txt
branches/alex-cm-branch/reactos/ntoskrnl/cm/cmkcbncb.c
branches/alex-cm-branch/reactos/ntoskrnl/cm/cmname.c
Modified: branches/alex-cm-branch/reactos/ntoskrnl/cm/cm.h
URL:
http://svn.reactos.org/svn/reactos/branches/alex-cm-branch/reactos/ntoskrnl…
==============================================================================
--- branches/alex-cm-branch/reactos/ntoskrnl/cm/cm.h (original)
+++ branches/alex-cm-branch/reactos/ntoskrnl/cm/cm.h Thu Aug 17 05:54:33 2006
@@ -569,12 +569,24 @@
);
//
-// Registry Locking Functions
+// Registry Utility Functions
//
BOOLEAN
NTAPI
CmpTestRegistryLockExclusive(
VOID
+);
+
+PVOID
+NTAPI
+CmpAllocateDelayItem(
+ VOID
+);
+
+VOID
+NTAPI
+CmpFreeDelayItem(
+ PVOID Entry
);
//
@@ -588,8 +600,22 @@
);
//
+// Name Functions
+//
+LONG
+NTAPI
+CmpCompareCompressedName(
+ IN PUNICODE_STRING SearchName,
+ IN PWCHAR CompressedName,
+ IN ULONG NameLength
+);
+
+//
// Global variables accessible from all of Cm
//
+extern BOOLEAN CmpSpecialBootCondition;
+extern BOOLEAN CmpFlushOnLockRelease;
+
//
// Inlined functions
Modified: branches/alex-cm-branch/reactos/ntoskrnl/cm/cm_x.h
URL:
http://svn.reactos.org/svn/reactos/branches/alex-cm-branch/reactos/ntoskrnl…
==============================================================================
--- branches/alex-cm-branch/reactos/ntoskrnl/cm/cm_x.h (original)
+++ branches/alex-cm-branch/reactos/ntoskrnl/cm/cm_x.h Thu Aug 17 05:54:33 2006
@@ -41,14 +41,14 @@
//
// Makes sure that the registry is locked
//
-#define CMP_ASSERT_REGISTRY_LOCK \
+#define CMP_ASSERT_REGISTRY_LOCK() \
ASSERT((CmpSpecialBootCondition == TRUE) || \
(CmpTestRegistryLock() == TRUE))
//
// Makes sure that the registry is exclusively locked
//
-#define CMP_ASSERT_EXCLUSIVE_REGISTRY_LOCK \
+#define CMP_ASSERT_EXCLUSIVE_REGISTRY_LOCK() \
ASSERT((CmpSpecialBootCondition == TRUE) || \
(CmpTestRegistryLockExclusive() == TRUE))
Modified: branches/alex-cm-branch/reactos/ntoskrnl/cm/cminfo.txt
URL:
http://svn.reactos.org/svn/reactos/branches/alex-cm-branch/reactos/ntoskrnl…
==============================================================================
--- branches/alex-cm-branch/reactos/ntoskrnl/cm/cminfo.txt (original)
+++ branches/alex-cm-branch/reactos/ntoskrnl/cm/cminfo.txt Thu Aug 17 05:54:33 2006
@@ -107,6 +107,8 @@
paths.
cmobject.c - Contains the implementation of the key object that is exported to
the Object Manager.
+cmutil.c - Contains utility functions such as the registry lock and delayed
+ item allocation and de-allocation routines.
ntapi.c - Contains the Nt APIs exported to drivers and user-mode, which wrap
around other internal APIs in this module (mostly cmapi.c).
Modified: branches/alex-cm-branch/reactos/ntoskrnl/cm/cmkcbncb.c
URL:
http://svn.reactos.org/svn/reactos/branches/alex-cm-branch/reactos/ntoskrnl…
==============================================================================
--- branches/alex-cm-branch/reactos/ntoskrnl/cm/cmkcbncb.c (original)
+++ branches/alex-cm-branch/reactos/ntoskrnl/cm/cmkcbncb.c Thu Aug 17 05:54:33 2006
@@ -17,15 +17,14 @@
ULONG CmpHashTableSize;
PCM_KEY_HASH_TABLE_ENTRY *CmpCacheTable;
PCM_NAME_HASH_TABLE_ENTRY *CmpNameCacheTable;
+LIST_ENTRY CmpFreeKCBListHead;
BOOLEAN CmpAllocInited;
-KGUARDED_MUTEX CmpAllocBucketLock, CmpDelayAllocBucketLock;
-LIST_ENTRY CmpFreeKCBListHead;
+KGUARDED_MUTEX CmpAllocBucketLock;
ULONG CmpDelayedCloseSize;
ULONG CmpDelayedCloseElements;
KGUARDED_MUTEX CmpDelayedCloseTableLock;
BOOLEAN CmpDelayCloseWorkItemActive;
LIST_ENTRY CmpDelayedLRUListHead;
-LIST_ENTRY CmpFreeDelayItemsListHead;
ULONG CmpDelayCloseIntervalInSeconds = 5;
KDPC CmpDelayCloseDpc;
KTIMER CmpDelayCloseTimer;
@@ -201,6 +200,9 @@
/* Go to the next hash */
HashEntry = HashEntry->NextHash;
}
+
+ /* Return the NCB found */
+ return Ncb;
}
BOOLEAN
@@ -320,46 +322,6 @@
/* Release the lock */
CmpReleaseNcbLock(Ncb);
-}
-
-VOID
-NTAPI
-CmpFreeDelayItem(PVOID Entry)
-{
- PCM_DELAYED_CLOSE_ENTRY AllocEntry = (PCM_DELAYED_CLOSE_ENTRY)Entry;
- PCM_DELAYED_CLOSE_ENTRY *AllocTable;
- PCM_ALLOC_PAGE AllocPage;
- ULONG i;
- PAGED_CODE();
-
- /* Lock the table */
- KeAcquireGuardedMutex(&CmpDelayAllocBucketLock);
-
- /* Add the entry at the end */
- InsertTailList(&CmpFreeDelayItemsListHead, &AllocEntry->DelayedLRUList);
-
- /* Get the alloc page */
- AllocPage = (PCM_ALLOC_PAGE)((ULONG_PTR)Entry & 0xFFFFF000);
- ASSERT(AllocPage->FreeCount != CM_DELAYS_PER_PAGE);
-
- /* Increase the number of free items */
- if (++AllocPage->FreeCount == CM_DELAYS_PER_PAGE)
- {
- /* Page is totally free now, loop each entry */
- AllocTable = (PCM_DELAYED_CLOSE_ENTRY*)&AllocPage->AllocPage;
- for (i = CM_DELAYS_PER_PAGE; i; i--)
- {
- /* Get the entry and unlink it */
- AllocEntry = AllocTable[i];
- RemoveEntryList(&AllocEntry->DelayedLRUList);
- }
-
- /* Now free the page */
- ExFreePool(AllocPage);
- }
-
- /* Release the lock */
- KeReleaseGuardedMutex(&CmpDelayAllocBucketLock);
}
VOID
@@ -487,58 +449,6 @@
/* Return success */
return TRUE;
-}
-
-// FIXME: THIS FUNCTION IS PARTIALLY FUCKED
-PVOID
-NTAPI
-CmpAllocateDelayItem(VOID)
-{
- PCM_DELAYED_CLOSE_ENTRY Entry;
- PCM_ALLOC_PAGE AllocPage;
- ULONG i;
- PLIST_ENTRY NextEntry;
- PAGED_CODE();
-
- /* Lock the allocation buckets */
- KeAcquireGuardedMutex(&CmpDelayAllocBucketLock);
- if (TRUE)
- {
- /* Allocate an allocation page */
- AllocPage = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, TAG_CM);
- if (AllocPage)
- {
- /* Set default entries */
- AllocPage->FreeCount = CM_DELAYS_PER_PAGE;
-
- /* Loop each entry */
- for (i = 0; i < CM_DELAYS_PER_PAGE; i++)
- {
- /* Get this entry and link it */
- Entry = (PCM_DELAYED_CLOSE_ENTRY)(&AllocPage[i]);
- InsertHeadList(&Entry->DelayedLRUList,
- &CmpFreeDelayItemsListHead);
- }
- }
-
- /* Get the entry and the alloc page */
- Entry = CONTAINING_RECORD(NextEntry,
- CM_DELAYED_CLOSE_ENTRY,
- DelayedLRUList);
- AllocPage = (PCM_ALLOC_PAGE)((ULONG_PTR)Entry & 0xFFFFF000);
-
- /* Decrease free entries */
- ASSERT(AllocPage->FreeCount != 0);
- AllocPage->FreeCount--;
-
- /* Release the lock */
- KeReleaseGuardedMutex(&CmpDelayAllocBucketLock);
- return Entry;
- }
-
- /* Release the lock */
- KeReleaseGuardedMutex(&CmpDelayAllocBucketLock);
- return Entry;
}
VOID
Modified: branches/alex-cm-branch/reactos/ntoskrnl/cm/cmname.c
URL:
http://svn.reactos.org/svn/reactos/branches/alex-cm-branch/reactos/ntoskrnl…
==============================================================================
--- branches/alex-cm-branch/reactos/ntoskrnl/cm/cmname.c (original)
+++ branches/alex-cm-branch/reactos/ntoskrnl/cm/cmname.c Thu Aug 17 05:54:33 2006
@@ -14,3 +14,37 @@
/* FUNCTIONS *****************************************************************/
+LONG
+NTAPI
+CmpCompareCompressedName(IN PUNICODE_STRING SearchName,
+ IN PWCHAR CompressedName,
+ IN ULONG NameLength)
+{
+ WCHAR *p, *pp;
+ WCHAR p1, p2;
+ USHORT SearchLength;
+ LONG Result;
+
+ /* Set the pointers and length and then loop */
+ p = SearchName->Buffer;
+ pp = CompressedName;
+ SearchLength = (SearchName->Length / sizeof(WCHAR));
+ while (SearchLength && NameLength)
+ {
+ /* Get the characters */
+ p1 = *p++;
+ p2 = *pp++;
+
+ /* See if they match and return result if they don't */
+ Result = (LONG)RtlUpcaseUnicodeChar(p1) -
+ (LONG)RtlUpcaseUnicodeChar(p2);
+ if (Result) return Result;
+
+ /* Next chars */
+ SearchLength--;
+ NameLength--;
+ }
+
+ /* Return the difference directly */
+ return SearchLength - NameLength;
+}
Added: branches/alex-cm-branch/reactos/ntoskrnl/cm/cmutil.c
URL:
http://svn.reactos.org/svn/reactos/branches/alex-cm-branch/reactos/ntoskrnl…
==============================================================================
--- branches/alex-cm-branch/reactos/ntoskrnl/cm/cmutil.c (added)
+++ branches/alex-cm-branch/reactos/ntoskrnl/cm/cmutil.c Thu Aug 17 05:54:33 2006
@@ -1,0 +1,167 @@
+/*
+ * PROJECT: ReactOS Kernel
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: ntoskrnl/cm/cmapi.c
+ * PURPOSE: Internal routines that implement Nt* API functionality
+ * PROGRAMMERS: Alex Ionescu (alex.ionescu(a)reactos.org)
+ */
+
+/* INCLUDES ******************************************************************/
+
+#include <ntoskrnl.h>
+#define NDEBUG
+#include <debug.h>
+
+ERESOURCE CmpRegistryLock;
+PVOID CmpRegistryLockCallerCaller, CmpRegistryLockCaller;
+BOOLEAN CmpFlushStarveWriters;
+
+KGUARDED_MUTEX CmpDelayAllocBucketLock;
+LIST_ENTRY CmpFreeDelayItemsListHead;
+
+/* FUNCTIONS *****************************************************************/
+
+VOID
+NTAPI
+CmpLockRegistryExclusive(VOID)
+{
+ /* Enter a critical region and lock the registry */
+ KeEnterCriticalRegion();
+ ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE);
+
+ /* Sanity check */
+ ASSERT(CmpFlushStarveWriters == 0);
+ RtlGetCallersAddress(&CmpRegistryLockCaller, &CmpRegistryLockCallerCaller);
+}
+
+BOOLEAN
+NTAPI
+CmpTestRegistryLock(VOID)
+{
+ /* Test the lock */
+ return (BOOLEAN)ExIsResourceAcquiredSharedLite(&CmpRegistryLock);
+}
+
+BOOLEAN
+NTAPI
+CmpTestRegistryLockExclusive(VOID)
+{
+ /* Test the lock */
+ return ExIsResourceAcquiredExclusiveLite(&CmpRegistryLock);
+}
+
+// FIXME: THIS FUNCTION IS PARTIALLY FUCKED
+PVOID
+NTAPI
+CmpAllocateDelayItem(VOID)
+{
+ PCM_DELAYED_CLOSE_ENTRY Entry;
+ PCM_ALLOC_PAGE AllocPage;
+ ULONG i;
+ PLIST_ENTRY NextEntry;
+ PAGED_CODE();
+
+ /* Lock the allocation buckets */
+ KeAcquireGuardedMutex(&CmpDelayAllocBucketLock);
+ if (TRUE)
+ {
+ /* Allocate an allocation page */
+ AllocPage = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, TAG_CM);
+ if (AllocPage)
+ {
+ /* Set default entries */
+ AllocPage->FreeCount = CM_DELAYS_PER_PAGE;
+
+ /* Loop each entry */
+ for (i = 0; i < CM_DELAYS_PER_PAGE; i++)
+ {
+ /* Get this entry and link it */
+ Entry = (PCM_DELAYED_CLOSE_ENTRY)(&AllocPage[i]);
+ InsertHeadList(&Entry->DelayedLRUList,
+ &CmpFreeDelayItemsListHead);
+ }
+ }
+
+ /* Get the entry and the alloc page */
+ Entry = CONTAINING_RECORD(NextEntry,
+ CM_DELAYED_CLOSE_ENTRY,
+ DelayedLRUList);
+ AllocPage = (PCM_ALLOC_PAGE)((ULONG_PTR)Entry & 0xFFFFF000);
+
+ /* Decrease free entries */
+ ASSERT(AllocPage->FreeCount != 0);
+ AllocPage->FreeCount--;
+
+ /* Release the lock */
+ KeReleaseGuardedMutex(&CmpDelayAllocBucketLock);
+ return Entry;
+ }
+
+ /* Release the lock */
+ KeReleaseGuardedMutex(&CmpDelayAllocBucketLock);
+ return Entry;
+}
+
+
+VOID
+NTAPI
+CmpFreeDelayItem(PVOID Entry)
+{
+ PCM_DELAYED_CLOSE_ENTRY AllocEntry = (PCM_DELAYED_CLOSE_ENTRY)Entry;
+ PCM_DELAYED_CLOSE_ENTRY *AllocTable;
+ PCM_ALLOC_PAGE AllocPage;
+ ULONG i;
+ PAGED_CODE();
+
+ /* Lock the table */
+ KeAcquireGuardedMutex(&CmpDelayAllocBucketLock);
+
+ /* Add the entry at the end */
+ InsertTailList(&CmpFreeDelayItemsListHead, &AllocEntry->DelayedLRUList);
+
+ /* Get the alloc page */
+ AllocPage = (PCM_ALLOC_PAGE)((ULONG_PTR)Entry & 0xFFFFF000);
+ ASSERT(AllocPage->FreeCount != CM_DELAYS_PER_PAGE);
+
+ /* Increase the number of free items */
+ if (++AllocPage->FreeCount == CM_DELAYS_PER_PAGE)
+ {
+ /* Page is totally free now, loop each entry */
+ AllocTable = (PCM_DELAYED_CLOSE_ENTRY*)&AllocPage->AllocPage;
+ for (i = CM_DELAYS_PER_PAGE; i; i--)
+ {
+ /* Get the entry and unlink it */
+ AllocEntry = AllocTable[i];
+ RemoveEntryList(&AllocEntry->DelayedLRUList);
+ }
+
+ /* Now free the page */
+ ExFreePool(AllocPage);
+ }
+
+ /* Release the lock */
+ KeReleaseGuardedMutex(&CmpDelayAllocBucketLock);
+}
+
+VOID
+NTAPI
+CmpUnlockRegistry(VOID)
+{
+ /* Sanity check */
+ CMP_ASSERT_REGISTRY_LOCK();
+
+ /* Check if we should flush the registry */
+ if (CmpFlushOnLockRelease)
+ {
+ /* The registry should be exclusively locked for this */
+ CMP_ASSERT_EXCLUSIVE_REGISTRY_LOCK();
+
+ /* Flush the registry */
+ CmpFlushEntireRegistry(TRUE);
+ CmpFlushOnLockRelease = FALSE;
+ }
+
+ /* Release the lock and leave the critical region */
+ ExReleaseResourceLite(&CmpRegistryLock);
+ KeLeaveCriticalRegion();
+}