[NTOS:CM] Set and reset the CMHIVE HiveIsLoading flag adequately. Fix an assertion in CmFlushKey() and reset the CMHIVE ViewLockOwner when releasing the view lock.

This commit is contained in:
Hermès Bélusca-Maïto 2019-02-17 00:54:59 +01:00
parent 86800fc498
commit 83fdb9a6d9
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
2 changed files with 21 additions and 4 deletions

View file

@ -1959,6 +1959,7 @@ CmFlushKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
{ {
/* Don't touch the hive */ /* Don't touch the hive */
CmpLockHiveFlusherExclusive(CmHive); CmpLockHiveFlusherExclusive(CmHive);
ASSERT(CmHive->ViewLock); ASSERT(CmHive->ViewLock);
KeAcquireGuardedMutex(CmHive->ViewLock); KeAcquireGuardedMutex(CmHive->ViewLock);
CmHive->ViewLockOwner = KeGetCurrentThread(); CmHive->ViewLockOwner = KeGetCurrentThread();
@ -1968,13 +1969,18 @@ CmFlushKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
{ {
/* I don't believe the current Hv does shrinking */ /* I don't believe the current Hv does shrinking */
ASSERT(FALSE); ASSERT(FALSE);
// CMP_ASSERT_EXCLUSIVE_REGISTRY_LOCK_OR_LOADING(CmHive);
} }
else else
{ {
/* Now we can release views */ /* Now we can release views */
ASSERT(CmHive->ViewLock); ASSERT(CmHive->ViewLock);
CMP_ASSERT_EXCLUSIVE_REGISTRY_LOCK_OR_LOADING(CmHive); // CMP_ASSERT_VIEW_LOCK_OWNED(CmHive);
ASSERT(KeGetCurrentThread() == CmHive->ViewLockOwner); ASSERT((CmpSpecialBootCondition == TRUE) ||
(CmHive->HiveIsLoading == TRUE) ||
(CmHive->ViewLockOwner == KeGetCurrentThread()) ||
(CmpTestRegistryLockExclusive() == TRUE));
CmHive->ViewLockOwner = NULL;
KeReleaseGuardedMutex(CmHive->ViewLock); KeReleaseGuardedMutex(CmHive->ViewLock);
} }
@ -2240,6 +2246,9 @@ CmUnloadKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
} }
} }
/* Set the loading flag */
CmHive->HiveIsLoading = TRUE;
/* Flush the hive */ /* Flush the hive */
CmFlushKey(Kcb, TRUE); CmFlushKey(Kcb, TRUE);
@ -2248,8 +2257,13 @@ CmUnloadKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
{ {
DPRINT("CmpUnlinkHiveFromMaster() failed!\n"); DPRINT("CmpUnlinkHiveFromMaster() failed!\n");
/* Remove the unloading flag and return failure */ /* Remove the unloading flag */
Hive->HiveFlags &= ~HIVE_IS_UNLOADING; Hive->HiveFlags &= ~HIVE_IS_UNLOADING;
/* Reset the loading flag */
CmHive->HiveIsLoading = FALSE;
/* Return failure */
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
} }

View file

@ -102,7 +102,7 @@ CmpInitializeHive(OUT PCMHIVE *CmHive,
Hive->NotifyList.Flink = NULL; Hive->NotifyList.Flink = NULL;
Hive->NotifyList.Blink = NULL; Hive->NotifyList.Blink = NULL;
/* Set loading flag */ /* Set the loading flag */
Hive->HiveIsLoading = TRUE; Hive->HiveIsLoading = TRUE;
/* Set the current thread as creator */ /* Set the current thread as creator */
@ -213,6 +213,9 @@ CmpInitializeHive(OUT PCMHIVE *CmHive,
} }
} }
/* Reset the loading flag */
Hive->HiveIsLoading = FALSE;
/* Lock the hive list */ /* Lock the hive list */
ExAcquirePushLockExclusive(&CmpHiveListHeadLock); ExAcquirePushLockExclusive(&CmpHiveListHeadLock);