[NTOS] Make the GET_HASH_ENTRY() macro return a pointer to the entry instead of the...
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Wed, 16 Aug 2017 20:30:45 +0000 (20:30 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Wed, 16 Aug 2017 20:30:45 +0000 (20:30 +0000)
Implicitly it was already returning a pointer, which was then referenced using a "." instead of "->", giving the impression we were working on the returned object instead of the original data. - Convert some macros to inline functions

svn path=/trunk/; revision=75580

reactos/ntoskrnl/config/cmkcbncb.c
reactos/ntoskrnl/config/cmsysini.c
reactos/ntoskrnl/include/internal/cm_x.h

index ca60d4e..8751357 100644 (file)
@@ -82,7 +82,7 @@ CmpRemoveKeyHash(IN PCM_KEY_HASH KeyHash)
     ASSERT_VALID_HASH(KeyHash);
 
     /* Lookup all the keys in this index entry */
-    Prev = &GET_HASH_ENTRY(CmpCacheTable, KeyHash->ConvKey).Entry;
+    Prev = &GET_HASH_ENTRY(CmpCacheTable, KeyHash->ConvKey)->Entry;
     while (TRUE)
     {
         /* Save the current one and make sure it's valid */
@@ -189,7 +189,7 @@ CmpGetNameControlBlock(IN PUNICODE_STRING NodeName)
     CmpAcquireNcbLockExclusiveByKey(ConvKey);
 
     /* Get the hash entry */
-    HashEntry = GET_HASH_ENTRY(CmpNameCacheTable, ConvKey).Entry;
+    HashEntry = GET_HASH_ENTRY(CmpNameCacheTable, ConvKey)->Entry;
     while (HashEntry)
     {
         /* Get the current NCB */
@@ -290,8 +290,8 @@ CmpGetNameControlBlock(IN PUNICODE_STRING NodeName)
 
         /* Insert the name in the hash table */
         HashEntry = &Ncb->NameHash;
-        HashEntry->NextHash = GET_HASH_ENTRY(CmpNameCacheTable, ConvKey).Entry;
-        GET_HASH_ENTRY(CmpNameCacheTable, ConvKey).Entry = HashEntry;
+        HashEntry->NextHash = GET_HASH_ENTRY(CmpNameCacheTable, ConvKey)->Entry;
+        GET_HASH_ENTRY(CmpNameCacheTable, ConvKey)->Entry = HashEntry;
     }
 
     /* Release NCB lock */
@@ -327,7 +327,7 @@ CmpDereferenceNameControlBlockWithLock(IN PCM_NAME_CONTROL_BLOCK Ncb)
     if (!(--Ncb->RefCount))
     {
         /* Find the NCB in the table */
-        Next = &GET_HASH_ENTRY(CmpNameCacheTable, Ncb->ConvKey).Entry;
+        Next = &GET_HASH_ENTRY(CmpNameCacheTable, Ncb->ConvKey)->Entry;
         while (TRUE)
         {
             /* Check the current entry */
index 2785f40..6b079ce 100644 (file)
@@ -2081,14 +2081,14 @@ CmpReleaseTwoKcbLockByKey(IN ULONG ConvKey1,
     /* Get hash indexes */
     Index1 = GET_HASH_INDEX(ConvKey1);
     Index2 = GET_HASH_INDEX(ConvKey2);
-    ASSERT((GET_HASH_ENTRY(CmpCacheTable, ConvKey2).Owner == KeGetCurrentThread()) ||
+    ASSERT((GET_HASH_ENTRY(CmpCacheTable, ConvKey2)->Owner == KeGetCurrentThread()) ||
            (CmpTestRegistryLockExclusive()));
 
     /* See which one is highest */
     if (Index1 < Index2)
     {
         /* Grab them in the proper order */
-        ASSERT((GET_HASH_ENTRY(CmpCacheTable, ConvKey1).Owner == KeGetCurrentThread()) ||
+        ASSERT((GET_HASH_ENTRY(CmpCacheTable, ConvKey1)->Owner == KeGetCurrentThread()) ||
                (CmpTestRegistryLockExclusive()));
         CmpReleaseKcbLockByKey(ConvKey2);
         CmpReleaseKcbLockByKey(ConvKey1);
@@ -2098,7 +2098,7 @@ CmpReleaseTwoKcbLockByKey(IN ULONG ConvKey1,
         /* Release the first one first, then the second */
         if (Index1 != Index2)
         {
-            ASSERT((GET_HASH_ENTRY(CmpCacheTable, ConvKey1).Owner == KeGetCurrentThread()) ||
+            ASSERT((GET_HASH_ENTRY(CmpCacheTable, ConvKey1)->Owner == KeGetCurrentThread()) ||
                    (CmpTestRegistryLockExclusive()));
             CmpReleaseKcbLockByKey(ConvKey1);
         }
index a6b2742..373700b 100644 (file)
@@ -18,7 +18,7 @@
 #define GET_HASH_INDEX(ConvKey)                                     \
     GET_HASH_KEY(ConvKey) % CmpHashTableSize
 #define GET_HASH_ENTRY(Table, ConvKey)                              \
-    (Table[GET_HASH_INDEX(ConvKey)])
+    (&Table[GET_HASH_INDEX(ConvKey)])
 #define ASSERT_VALID_HASH(h)                                        \
     ASSERT_KCB_VALID(CONTAINING_RECORD((h), CM_KEY_CONTROL_BLOCK, KeyHash))
 
 //
 #define CmpIsKcbLockedExclusive(k)                                  \
     (GET_HASH_ENTRY(CmpCacheTable,                                  \
-                    (k)->ConvKey).Owner == KeGetCurrentThread())
+                    (k)->ConvKey)->Owner == KeGetCurrentThread())
 
 //
-// Exclusively acquires a KCB
+// Exclusively acquires a KCB by index
 //
-#define CmpAcquireKcbLockExclusive(k)                               \
-{                                                                   \
-    ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpCacheTable,       \
-                                              (k)->ConvKey).Lock);  \
-    GET_HASH_ENTRY(CmpCacheTable,                                   \
-                   (k)->ConvKey).Owner = KeGetCurrentThread();      \
+FORCEINLINE
+VOID
+CmpAcquireKcbLockExclusiveByIndex(ULONG Index)
+{
+    ExAcquirePushLockExclusive(&CmpCacheTable[Index].Lock);
+    CmpCacheTable[Index].Owner = KeGetCurrentThread();
 }
 
 //
-// Exclusively acquires a KCB by index
+// Exclusively acquires a KCB
 //
-#define CmpAcquireKcbLockExclusiveByIndex(i)                        \
-{                                                                   \
-    ExAcquirePushLockExclusive(&CmpCacheTable[(i)].Lock);           \
-    CmpCacheTable[(i)].Owner = KeGetCurrentThread();                \
+FORCEINLINE
+VOID
+CmpAcquireKcbLockExclusive(PCM_KEY_CONTROL_BLOCK Kcb)
+{
+    CmpAcquireKcbLockExclusiveByIndex(GET_HASH_INDEX(Kcb->ConvKey));
 }
 
 //
 // Exclusively acquires a KCB by key
 //
-#define CmpAcquireKcbLockExclusiveByKey(k)                          \
-{                                                                   \
-    ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpCacheTable,       \
-                                              (k)).Lock);           \
-    GET_HASH_ENTRY(CmpCacheTable,                                   \
-                   (k)).Owner = KeGetCurrentThread();               \
+FORCEINLINE
+VOID
+CmpAcquireKcbLockExclusiveByKey(IN ULONG ConvKey)
+{
+    CmpAcquireKcbLockExclusiveByIndex(GET_HASH_INDEX(ConvKey));
 }
 
 
 #define CmpAcquireKcbLockShared(k)                                  \
 {                                                                   \
     ExAcquirePushLockShared(&GET_HASH_ENTRY(CmpCacheTable,          \
-                                            (k)->ConvKey).Lock);    \
+                                            (k)->ConvKey)->Lock);    \
 }
 
 //
@@ -141,42 +141,44 @@ CmpTryToConvertKcbSharedToExclusive(IN PCM_KEY_CONTROL_BLOCK k)
 {
     ASSERT(CmpIsKcbLockedExclusive(k) == FALSE);
     if (ExConvertPushLockSharedToExclusive(
-            &GET_HASH_ENTRY(CmpCacheTable, k->ConvKey).Lock))
+            &GET_HASH_ENTRY(CmpCacheTable, k->ConvKey)->Lock))
     {
         GET_HASH_ENTRY(CmpCacheTable,
-                       k->ConvKey).Owner = KeGetCurrentThread();
+                       k->ConvKey)->Owner = KeGetCurrentThread();
         return TRUE;
     }
     return FALSE;
 }
 
 //
-// Releases an exlusively or shared acquired KCB
+// Releases an exlusively or shared acquired KCB by index
 //
-#define CmpReleaseKcbLock(k)                                        \
-{                                                                   \
-    GET_HASH_ENTRY(CmpCacheTable, (k)->ConvKey).Owner = NULL;       \
-    ExReleasePushLock(&GET_HASH_ENTRY(CmpCacheTable,                \
-                                      (k)->ConvKey).Lock);          \
+FORCEINLINE
+VOID
+CmpReleaseKcbLockByIndex(ULONG Index)
+{
+    CmpCacheTable[Index].Owner = NULL;
+    ExReleasePushLock(&CmpCacheTable[Index].Lock);
 }
 
 //
-// Releases an exlusively or shared acquired KCB by index
+// Releases an exlusively or shared acquired KCB
 //
-#define CmpReleaseKcbLockByIndex(i)                                 \
-{                                                                   \
-    CmpCacheTable[(i)].Owner = NULL;                                \
-    ExReleasePushLock(&CmpCacheTable[(i)].Lock);                    \
+FORCEINLINE
+VOID
+CmpReleaseKcbLock(PCM_KEY_CONTROL_BLOCK Kcb)
+{
+    CmpReleaseKcbLockByIndex(GET_HASH_INDEX(Kcb->ConvKey));
 }
 
 //
 // Releases an exlusively or shared acquired KCB by key
 //
-#define CmpReleaseKcbLockByKey(k)                                   \
-{                                                                   \
-    GET_HASH_ENTRY(CmpCacheTable, (k)).Owner = NULL;                \
-    ExReleasePushLock(&GET_HASH_ENTRY(CmpCacheTable,                \
-                                      (k)).Lock);                   \
+FORCEINLINE
+VOID
+CmpReleaseKcbLockByKey(ULONG ConvKey)
+{
+    CmpReleaseKcbLockByIndex(GET_HASH_INDEX(ConvKey));
 }
 
 //
@@ -186,7 +188,7 @@ FORCEINLINE
 VOID
 CmpConvertKcbSharedToExclusive(IN PCM_KEY_CONTROL_BLOCK k)
 {
-    ASSERT(CmpIsKcbLockedExclusive(k) == FALSE);  
+    ASSERT(CmpIsKcbLockedExclusive(k) == FALSE);
     CmpReleaseKcbLock(k);
     CmpAcquireKcbLockExclusive(k);
 }
@@ -197,7 +199,7 @@ CmpConvertKcbSharedToExclusive(IN PCM_KEY_CONTROL_BLOCK k)
 #define CmpAcquireNcbLockExclusive(n)                               \
 {                                                                   \
     ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpNameCacheTable,   \
-                                              (n)->ConvKey).Lock);  \
+                                              (n)->ConvKey)->Lock);  \
 }
 
 //
@@ -206,7 +208,7 @@ CmpConvertKcbSharedToExclusive(IN PCM_KEY_CONTROL_BLOCK k)
 #define CmpAcquireNcbLockExclusiveByKey(k)                          \
 {                                                                   \
     ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpNameCacheTable,   \
-                                               (k)).Lock);          \
+                                               (k))->Lock);          \
 }
 
 //
@@ -215,7 +217,7 @@ CmpConvertKcbSharedToExclusive(IN PCM_KEY_CONTROL_BLOCK k)
 #define CmpReleaseNcbLock(k)                                        \
 {                                                                   \
     ExReleasePushLock(&GET_HASH_ENTRY(CmpNameCacheTable,            \
-                                     (k)->ConvKey).Lock);           \
+                                     (k)->ConvKey)->Lock);           \
 }
 
 //
@@ -224,15 +226,15 @@ CmpConvertKcbSharedToExclusive(IN PCM_KEY_CONTROL_BLOCK k)
 #define CmpReleaseNcbLockByKey(k)                                   \
 {                                                                   \
     ExReleasePushLock(&GET_HASH_ENTRY(CmpNameCacheTable,            \
-                                      (k)).Lock);                   \
+                                      (k))->Lock);                   \
 }
 
 //
-// Asserts that either the registry or the hash entry is locked
+// Asserts that either the registry or the KCB is locked
 //
 #define CMP_ASSERT_HASH_ENTRY_LOCK(k)                               \
 {                                                                   \
-    ASSERT(((GET_HASH_ENTRY(CmpCacheTable, k).Owner ==              \
+    ASSERT(((GET_HASH_ENTRY(CmpCacheTable, k)->Owner ==              \
             KeGetCurrentThread())) ||                               \
            (CmpTestRegistryLockExclusive() == TRUE));               \
 }