https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c6230ba2553fad585a096dc8c24ca8c7c1573163
commit c6230ba2553fad585a096dc8c24ca8c7c1573163 Author: George Bișoc <george.bi...@reactos.org> AuthorDate: Thu Feb 16 20:25:10 2023 +0100 Commit: George Bișoc <george.bi...@reactos.org> CommitDate: Sun Oct 1 20:06:01 2023 +0200 [NTOS:CM] Add KCB array lock function prototypes & Other Stuff Implement CmpBuildAndLockKcbArray and CmpUnLockKcbArray prototypes, we'll gonna need these to do the locking/unlocking of KCBs stacked up in an array. In addition implement some CM constructs specifically for cache lookup implementation (more at documentation remarks). === DOCUMENTATION REMARKS === CMP_SUBKEY_LEVELS_DEPTH_LIMIT -- This is the limit of up to 32 subkey levels that the registry can permit. This is used in CmpComputeHashValue to ensure that we don't compute more than the limit of subkeys we're allowed to. CMP_KCBS_IN_ARRAY_LIMIT -- This is equal to CMP_SUBKEY_LEVELS_DEPTH_LIMIT plus the addition by 2. This construct is used as a limit of KCB elements the array can hold. 2 serves as an additional space for the array (one for the root object and another one as extra space so we don't blow up the stack array). CMP_LOCK_KCB_ARRAY_EXCLUSIVE & CMP_LOCK_KCB_ARRAY_SHARED -- These flags are used exclusively for CmpBuildAndLockKcbArray and CmpLockKcbArray. Their meaning are obvious. CM_HASH_CACHE_STACK -- A structure used to store the hashes of KCBs for locking. It is named "stack" because the way we store the hashes of KCBs is within an auxilliary "outer stack array". --- ntoskrnl/include/internal/cm.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/ntoskrnl/include/internal/cm.h b/ntoskrnl/include/internal/cm.h index 423c65b9a8d..da8bad2dbd0 100644 --- a/ntoskrnl/include/internal/cm.h +++ b/ntoskrnl/include/internal/cm.h @@ -95,6 +95,12 @@ #define CMP_ENLIST_KCB_LOCKED_SHARED 0x1 #define CMP_ENLIST_KCB_LOCKED_EXCLUSIVE 0x2 +// +// CmpBuildAndLockKcbArray & CmpLockKcbArray Flags +// +#define CMP_LOCK_KCB_ARRAY_EXCLUSIVE 0x1 +#define CMP_LOCK_KCB_ARRAY_SHARED 0x2 + // // Unload Flags // @@ -119,6 +125,12 @@ #define CM_DELAYS_PER_PAGE \ ((PAGE_SIZE - FIELD_OFFSET(CM_ALLOC_PAGE, AllocPage)) / sizeof(CM_DELAY_ALLOC)) +// +// Cache Lookup & KCB Array constructs +// +#define CMP_SUBKEY_LEVELS_DEPTH_LIMIT 32 +#define CMP_KCBS_IN_ARRAY_LIMIT (CMP_SUBKEY_LEVELS_DEPTH_LIMIT + 2) + // // Value Search Results // @@ -402,6 +414,15 @@ typedef struct _HIVE_LIST_ENTRY BOOLEAN Allocate; } HIVE_LIST_ENTRY, *PHIVE_LIST_ENTRY; +// +// Hash Cache Stack +// +typedef struct _CM_HASH_CACHE_STACK +{ + UNICODE_STRING NameOfKey; + ULONG ConvKey; +} CM_HASH_CACHE_STACK, *PCM_HASH_CACHE_STACK; + // // Parse context for Key Object // @@ -993,6 +1014,23 @@ DelistKeyBodyFromKCB( IN BOOLEAN LockHeld ); +VOID +NTAPI +CmpUnLockKcbArray( + _In_ PULONG LockedKcbs +); + +PULONG +NTAPI +CmpBuildAndLockKcbArray( + _In_ PCM_HASH_CACHE_STACK HashCacheStack, + _In_ ULONG KcbLockFlags, + _In_ PCM_KEY_CONTROL_BLOCK Kcb, + _Inout_ PULONG OuterStackArray, + _In_ ULONG TotalRemainingSubkeys, + _In_ ULONG MatchRemainSubkeyLevel +); + VOID NTAPI CmpAcquireTwoKcbLocksExclusiveByKey( @@ -1084,6 +1122,7 @@ CmpCreateLinkNode( IN PHHIVE Hive, IN HCELL_INDEX Cell, IN PACCESS_STATE AccessState, + IN PULONG KcbsLocked, IN UNICODE_STRING Name, IN KPROCESSOR_MODE AccessMode, IN ULONG CreateOptions,