[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

svn path=/trunk/; revision=75580
This commit is contained in:
Timo Kreuzer 2017-08-16 20:30:45 +00:00
parent 3c64b4cbe9
commit 7462d87d28
3 changed files with 59 additions and 57 deletions

View file

@ -82,7 +82,7 @@ CmpRemoveKeyHash(IN PCM_KEY_HASH KeyHash)
ASSERT_VALID_HASH(KeyHash); ASSERT_VALID_HASH(KeyHash);
/* Lookup all the keys in this index entry */ /* 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) while (TRUE)
{ {
/* Save the current one and make sure it's valid */ /* Save the current one and make sure it's valid */
@ -189,7 +189,7 @@ CmpGetNameControlBlock(IN PUNICODE_STRING NodeName)
CmpAcquireNcbLockExclusiveByKey(ConvKey); CmpAcquireNcbLockExclusiveByKey(ConvKey);
/* Get the hash entry */ /* Get the hash entry */
HashEntry = GET_HASH_ENTRY(CmpNameCacheTable, ConvKey).Entry; HashEntry = GET_HASH_ENTRY(CmpNameCacheTable, ConvKey)->Entry;
while (HashEntry) while (HashEntry)
{ {
/* Get the current NCB */ /* Get the current NCB */
@ -290,8 +290,8 @@ CmpGetNameControlBlock(IN PUNICODE_STRING NodeName)
/* Insert the name in the hash table */ /* Insert the name in the hash table */
HashEntry = &Ncb->NameHash; HashEntry = &Ncb->NameHash;
HashEntry->NextHash = GET_HASH_ENTRY(CmpNameCacheTable, ConvKey).Entry; HashEntry->NextHash = GET_HASH_ENTRY(CmpNameCacheTable, ConvKey)->Entry;
GET_HASH_ENTRY(CmpNameCacheTable, ConvKey).Entry = HashEntry; GET_HASH_ENTRY(CmpNameCacheTable, ConvKey)->Entry = HashEntry;
} }
/* Release NCB lock */ /* Release NCB lock */
@ -327,7 +327,7 @@ CmpDereferenceNameControlBlockWithLock(IN PCM_NAME_CONTROL_BLOCK Ncb)
if (!(--Ncb->RefCount)) if (!(--Ncb->RefCount))
{ {
/* Find the NCB in the table */ /* Find the NCB in the table */
Next = &GET_HASH_ENTRY(CmpNameCacheTable, Ncb->ConvKey).Entry; Next = &GET_HASH_ENTRY(CmpNameCacheTable, Ncb->ConvKey)->Entry;
while (TRUE) while (TRUE)
{ {
/* Check the current entry */ /* Check the current entry */

View file

@ -2081,14 +2081,14 @@ CmpReleaseTwoKcbLockByKey(IN ULONG ConvKey1,
/* Get hash indexes */ /* Get hash indexes */
Index1 = GET_HASH_INDEX(ConvKey1); Index1 = GET_HASH_INDEX(ConvKey1);
Index2 = GET_HASH_INDEX(ConvKey2); Index2 = GET_HASH_INDEX(ConvKey2);
ASSERT((GET_HASH_ENTRY(CmpCacheTable, ConvKey2).Owner == KeGetCurrentThread()) || ASSERT((GET_HASH_ENTRY(CmpCacheTable, ConvKey2)->Owner == KeGetCurrentThread()) ||
(CmpTestRegistryLockExclusive())); (CmpTestRegistryLockExclusive()));
/* See which one is highest */ /* See which one is highest */
if (Index1 < Index2) if (Index1 < Index2)
{ {
/* Grab them in the proper order */ /* Grab them in the proper order */
ASSERT((GET_HASH_ENTRY(CmpCacheTable, ConvKey1).Owner == KeGetCurrentThread()) || ASSERT((GET_HASH_ENTRY(CmpCacheTable, ConvKey1)->Owner == KeGetCurrentThread()) ||
(CmpTestRegistryLockExclusive())); (CmpTestRegistryLockExclusive()));
CmpReleaseKcbLockByKey(ConvKey2); CmpReleaseKcbLockByKey(ConvKey2);
CmpReleaseKcbLockByKey(ConvKey1); CmpReleaseKcbLockByKey(ConvKey1);
@ -2098,7 +2098,7 @@ CmpReleaseTwoKcbLockByKey(IN ULONG ConvKey1,
/* Release the first one first, then the second */ /* Release the first one first, then the second */
if (Index1 != Index2) if (Index1 != Index2)
{ {
ASSERT((GET_HASH_ENTRY(CmpCacheTable, ConvKey1).Owner == KeGetCurrentThread()) || ASSERT((GET_HASH_ENTRY(CmpCacheTable, ConvKey1)->Owner == KeGetCurrentThread()) ||
(CmpTestRegistryLockExclusive())); (CmpTestRegistryLockExclusive()));
CmpReleaseKcbLockByKey(ConvKey1); CmpReleaseKcbLockByKey(ConvKey1);
} }

View file

@ -18,7 +18,7 @@
#define GET_HASH_INDEX(ConvKey) \ #define GET_HASH_INDEX(ConvKey) \
GET_HASH_KEY(ConvKey) % CmpHashTableSize GET_HASH_KEY(ConvKey) % CmpHashTableSize
#define GET_HASH_ENTRY(Table, ConvKey) \ #define GET_HASH_ENTRY(Table, ConvKey) \
(Table[GET_HASH_INDEX(ConvKey)]) (&Table[GET_HASH_INDEX(ConvKey)])
#define ASSERT_VALID_HASH(h) \ #define ASSERT_VALID_HASH(h) \
ASSERT_KCB_VALID(CONTAINING_RECORD((h), CM_KEY_CONTROL_BLOCK, KeyHash)) ASSERT_KCB_VALID(CONTAINING_RECORD((h), CM_KEY_CONTROL_BLOCK, KeyHash))
@ -81,37 +81,37 @@
// //
#define CmpIsKcbLockedExclusive(k) \ #define CmpIsKcbLockedExclusive(k) \
(GET_HASH_ENTRY(CmpCacheTable, \ (GET_HASH_ENTRY(CmpCacheTable, \
(k)->ConvKey).Owner == KeGetCurrentThread()) (k)->ConvKey)->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 // Exclusively acquires a KCB by index
// //
#define CmpAcquireKcbLockExclusiveByIndex(i) \ FORCEINLINE
{ \ VOID
ExAcquirePushLockExclusive(&CmpCacheTable[(i)].Lock); \ CmpAcquireKcbLockExclusiveByIndex(ULONG Index)
CmpCacheTable[(i)].Owner = KeGetCurrentThread(); \ {
ExAcquirePushLockExclusive(&CmpCacheTable[Index].Lock);
CmpCacheTable[Index].Owner = KeGetCurrentThread();
}
//
// Exclusively acquires a KCB
//
FORCEINLINE
VOID
CmpAcquireKcbLockExclusive(PCM_KEY_CONTROL_BLOCK Kcb)
{
CmpAcquireKcbLockExclusiveByIndex(GET_HASH_INDEX(Kcb->ConvKey));
} }
// //
// Exclusively acquires a KCB by key // Exclusively acquires a KCB by key
// //
#define CmpAcquireKcbLockExclusiveByKey(k) \ FORCEINLINE
{ \ VOID
ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpCacheTable, \ CmpAcquireKcbLockExclusiveByKey(IN ULONG ConvKey)
(k)).Lock); \ {
GET_HASH_ENTRY(CmpCacheTable, \ CmpAcquireKcbLockExclusiveByIndex(GET_HASH_INDEX(ConvKey));
(k)).Owner = KeGetCurrentThread(); \
} }
@ -121,7 +121,7 @@
#define CmpAcquireKcbLockShared(k) \ #define CmpAcquireKcbLockShared(k) \
{ \ { \
ExAcquirePushLockShared(&GET_HASH_ENTRY(CmpCacheTable, \ 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); ASSERT(CmpIsKcbLockedExclusive(k) == FALSE);
if (ExConvertPushLockSharedToExclusive( if (ExConvertPushLockSharedToExclusive(
&GET_HASH_ENTRY(CmpCacheTable, k->ConvKey).Lock)) &GET_HASH_ENTRY(CmpCacheTable, k->ConvKey)->Lock))
{ {
GET_HASH_ENTRY(CmpCacheTable, GET_HASH_ENTRY(CmpCacheTable,
k->ConvKey).Owner = KeGetCurrentThread(); k->ConvKey)->Owner = KeGetCurrentThread();
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
// //
// Releases an exlusively or shared acquired KCB // Releases an exlusively or shared acquired KCB by index
// //
#define CmpReleaseKcbLock(k) \ FORCEINLINE
{ \ VOID
GET_HASH_ENTRY(CmpCacheTable, (k)->ConvKey).Owner = NULL; \ CmpReleaseKcbLockByIndex(ULONG Index)
ExReleasePushLock(&GET_HASH_ENTRY(CmpCacheTable, \ {
(k)->ConvKey).Lock); \ 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) \ FORCEINLINE
{ \ VOID
CmpCacheTable[(i)].Owner = NULL; \ CmpReleaseKcbLock(PCM_KEY_CONTROL_BLOCK Kcb)
ExReleasePushLock(&CmpCacheTable[(i)].Lock); \ {
CmpReleaseKcbLockByIndex(GET_HASH_INDEX(Kcb->ConvKey));
} }
// //
// Releases an exlusively or shared acquired KCB by key // Releases an exlusively or shared acquired KCB by key
// //
#define CmpReleaseKcbLockByKey(k) \ FORCEINLINE
{ \ VOID
GET_HASH_ENTRY(CmpCacheTable, (k)).Owner = NULL; \ CmpReleaseKcbLockByKey(ULONG ConvKey)
ExReleasePushLock(&GET_HASH_ENTRY(CmpCacheTable, \ {
(k)).Lock); \ CmpReleaseKcbLockByIndex(GET_HASH_INDEX(ConvKey));
} }
// //
@ -197,7 +199,7 @@ CmpConvertKcbSharedToExclusive(IN PCM_KEY_CONTROL_BLOCK k)
#define CmpAcquireNcbLockExclusive(n) \ #define CmpAcquireNcbLockExclusive(n) \
{ \ { \
ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpNameCacheTable, \ 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) \ #define CmpAcquireNcbLockExclusiveByKey(k) \
{ \ { \
ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpNameCacheTable, \ ExAcquirePushLockExclusive(&GET_HASH_ENTRY(CmpNameCacheTable, \
(k)).Lock); \ (k))->Lock); \
} }
// //
@ -215,7 +217,7 @@ CmpConvertKcbSharedToExclusive(IN PCM_KEY_CONTROL_BLOCK k)
#define CmpReleaseNcbLock(k) \ #define CmpReleaseNcbLock(k) \
{ \ { \
ExReleasePushLock(&GET_HASH_ENTRY(CmpNameCacheTable, \ 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) \ #define CmpReleaseNcbLockByKey(k) \
{ \ { \
ExReleasePushLock(&GET_HASH_ENTRY(CmpNameCacheTable, \ 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) \ #define CMP_ASSERT_HASH_ENTRY_LOCK(k) \
{ \ { \
ASSERT(((GET_HASH_ENTRY(CmpCacheTable, k).Owner == \ ASSERT(((GET_HASH_ENTRY(CmpCacheTable, k)->Owner == \
KeGetCurrentThread())) || \ KeGetCurrentThread())) || \
(CmpTestRegistryLockExclusive() == TRUE)); \ (CmpTestRegistryLockExclusive() == TRUE)); \
} }