Author: tkreuzer
Date: Wed Aug 16 20:30:45 2017
New Revision: 75580
URL:
http://svn.reactos.org/svn/reactos?rev=75580&view=rev
Log:
[NTOS] Make the GET_HASH_ENTRY() macro return a pointer to the entry instead of the entry
itself.
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
Modified:
trunk/reactos/ntoskrnl/config/cmkcbncb.c
trunk/reactos/ntoskrnl/config/cmsysini.c
trunk/reactos/ntoskrnl/include/internal/cm_x.h
Modified: trunk/reactos/ntoskrnl/config/cmkcbncb.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/cmkcbncb.c…
==============================================================================
--- trunk/reactos/ntoskrnl/config/cmkcbncb.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/config/cmkcbncb.c [iso-8859-1] Wed Aug 16 20:30:45 2017
@@ -82,7 +82,7 @@
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 @@
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 @@
/* 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 @@
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 */
Modified: trunk/reactos/ntoskrnl/config/cmsysini.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/cmsysini.c…
==============================================================================
--- trunk/reactos/ntoskrnl/config/cmsysini.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/config/cmsysini.c [iso-8859-1] Wed Aug 16 20:30:45 2017
@@ -2081,14 +2081,14 @@
/* 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 @@
/* 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);
}
Modified: trunk/reactos/ntoskrnl/include/internal/cm_x.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/cm_x.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/cm_x.h [iso-8859-1] Wed Aug 16 20:30:45 2017
@@ -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))
@@ -81,37 +81,37 @@
//
#define CmpIsKcbLockedExclusive(k) \
(GET_HASH_ENTRY(CmpCacheTable, \
- (k)->ConvKey).Owner == KeGetCurrentThread())
+ (k)->ConvKey)->Owner == KeGetCurrentThread())
+
+//
+// Exclusively acquires a KCB by index
+//
+FORCEINLINE
+VOID
+CmpAcquireKcbLockExclusiveByIndex(ULONG Index)
+{
+ ExAcquirePushLockExclusive(&CmpCacheTable[Index].Lock);
+ CmpCacheTable[Index].Owner = KeGetCurrentThread();
+}
//
// Exclusively acquires a KCB
//
-#define CmpAcquireKcbLockExclusive(k) \
-{ \
- ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpCacheTable, \
- (k)->ConvKey).Lock); \
- GET_HASH_ENTRY(CmpCacheTable, \
- (k)->ConvKey).Owner = KeGetCurrentThread(); \
-}
-
-//
-// Exclusively acquires a KCB by index
-//
-#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));
}
@@ -121,7 +121,7 @@
#define CmpAcquireKcbLockShared(k) \
{ \
ExAcquirePushLockShared(&GET_HASH_ENTRY(CmpCacheTable, \
- (k)->ConvKey).Lock); \
+ (k)->ConvKey)->Lock); \
}
//
@@ -141,42 +141,44 @@
{
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 by index
+//
+FORCEINLINE
+VOID
+CmpReleaseKcbLockByIndex(ULONG Index)
+{
+ CmpCacheTable[Index].Owner = NULL;
+ ExReleasePushLock(&CmpCacheTable[Index].Lock);
+}
+
+//
// Releases an exlusively or shared acquired KCB
//
-#define CmpReleaseKcbLock(k) \
-{ \
- GET_HASH_ENTRY(CmpCacheTable, (k)->ConvKey).Owner = NULL; \
- ExReleasePushLock(&GET_HASH_ENTRY(CmpCacheTable, \
- (k)->ConvKey).Lock); \
-}
-
-//
-// Releases an exlusively or shared acquired KCB by index
-//
-#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 @@
VOID
CmpConvertKcbSharedToExclusive(IN PCM_KEY_CONTROL_BLOCK k)
{
- ASSERT(CmpIsKcbLockedExclusive(k) == FALSE);
+ ASSERT(CmpIsKcbLockedExclusive(k) == FALSE);
CmpReleaseKcbLock(k);
CmpAcquireKcbLockExclusive(k);
}
@@ -197,7 +199,7 @@
#define CmpAcquireNcbLockExclusive(n) \
{ \
ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpNameCacheTable, \
- (n)->ConvKey).Lock); \
+ (n)->ConvKey)->Lock); \
}
//
@@ -206,7 +208,7 @@
#define CmpAcquireNcbLockExclusiveByKey(k) \
{ \
ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpNameCacheTable, \
- (k)).Lock); \
+ (k))->Lock); \
}
//
@@ -215,7 +217,7 @@
#define CmpReleaseNcbLock(k) \
{ \
ExReleasePushLock(&GET_HASH_ENTRY(CmpNameCacheTable, \
- (k)->ConvKey).Lock); \
+ (k)->ConvKey)->Lock); \
}
//
@@ -224,15 +226,15 @@
#define CmpReleaseNcbLockByKey(k) \
{ \
ExReleasePushLock(&GET_HASH_ENTRY(CmpNameCacheTable, \
- (k)).Lock); \
-}
-
-//
-// Asserts that either the registry or the hash entry is locked
+ (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 == \
+ ASSERT(((GET_HASH_ENTRY(CmpCacheTable, k)->Owner == \
KeGetCurrentThread())) || \
(CmpTestRegistryLockExclusive() == TRUE)); \
}