- Define LIST_ENTRY functions as part of host headers, instead of mkhive-specific defines.

- Use CM_KEY_CONTROL_BLOCK when communicating with new CM implementation ("config"). CM now builds a dummy KCB so that the functions in "config" can go around their business with KCB without needing to know what a ros-specific PKEY_OBJECT is.

svn path=/trunk/; revision=29902
This commit is contained in:
Aleksey Bragin 2007-10-26 20:59:42 +00:00
parent dbb8fcae7b
commit ec2b9a0991
7 changed files with 269 additions and 206 deletions

View file

@ -120,6 +120,102 @@ typedef struct _UNICODE_STRING
} UNICODE_STRING, *PUNICODE_STRING; } UNICODE_STRING, *PUNICODE_STRING;
#include <host/poppack.h> #include <host/poppack.h>
//
// List Functions
//
static inline
VOID
InitializeListHead(
IN PLIST_ENTRY ListHead
)
{
ListHead->Flink = ListHead->Blink = ListHead;
}
static inline
VOID
InsertHeadList(
IN PLIST_ENTRY ListHead,
IN PLIST_ENTRY Entry
)
{
PLIST_ENTRY OldFlink;
OldFlink = ListHead->Flink;
Entry->Flink = OldFlink;
Entry->Blink = ListHead;
OldFlink->Blink = Entry;
ListHead->Flink = Entry;
}
static inline
VOID
InsertTailList(
IN PLIST_ENTRY ListHead,
IN PLIST_ENTRY Entry
)
{
PLIST_ENTRY OldBlink;
OldBlink = ListHead->Blink;
Entry->Flink = ListHead;
Entry->Blink = OldBlink;
OldBlink->Flink = Entry;
ListHead->Blink = Entry;
}
BOOLEAN
static inline
IsListEmpty(
IN const LIST_ENTRY * ListHead
)
{
return (BOOLEAN)(ListHead->Flink == ListHead);
}
static inline
BOOLEAN
RemoveEntryList(
IN PLIST_ENTRY Entry)
{
PLIST_ENTRY OldFlink;
PLIST_ENTRY OldBlink;
OldFlink = Entry->Flink;
OldBlink = Entry->Blink;
OldFlink->Blink = OldBlink;
OldBlink->Flink = OldFlink;
return (BOOLEAN)(OldFlink == OldBlink);
}
static inline
PLIST_ENTRY
RemoveHeadList(
IN PLIST_ENTRY ListHead)
{
PLIST_ENTRY Flink;
PLIST_ENTRY Entry;
Entry = ListHead->Flink;
Flink = Entry->Flink;
ListHead->Flink = Flink;
Flink->Blink = ListHead;
return Entry;
}
static inline
PLIST_ENTRY
RemoveTailList(
IN PLIST_ENTRY ListHead)
{
PLIST_ENTRY Blink;
PLIST_ENTRY Entry;
Entry = ListHead->Blink;
Blink = Entry->Blink;
ListHead->Blink = Blink;
Blink->Flink = ListHead;
return Entry;
}
typedef const UNICODE_STRING *PCUNICODE_STRING; typedef const UNICODE_STRING *PCUNICODE_STRING;
#define NT_SUCCESS(x) ((x)>=0) #define NT_SUCCESS(x) ((x)>=0)

View file

@ -114,6 +114,51 @@ typedef struct _KEY_OBJECT
CACHED_CHILD_LIST ValueCache; CACHED_CHILD_LIST ValueCache;
} KEY_OBJECT, *PKEY_OBJECT; } KEY_OBJECT, *PKEY_OBJECT;
//
// Key Control Block (KCB) for old Cm (just so it can talk to New CM)
//
typedef struct _CM_KEY_CONTROL_BLOCK
{
USHORT RefCount;
USHORT Flags;
ULONG ExtFlags:8;
ULONG PrivateAlloc:1;
ULONG Delete:1;
ULONG DelayedCloseIndex:12;
ULONG TotalLevels:10;
union
{
//CM_KEY_HASH KeyHash;
struct
{
ULONG ConvKey;
PVOID NextHash;
PHHIVE KeyHive;
HCELL_INDEX KeyCell;
};
};
struct _CM_KEY_CONTROL_BLOCK *ParentKcb;
PVOID NameBlock;
PVOID CachedSecurity;
CACHED_CHILD_LIST ValueCache;
PVOID IndexHint;
ULONG HashKey;
ULONG SubKeyCount;
union
{
LIST_ENTRY KeyBodyListHead;
LIST_ENTRY FreeListEntry;
};
PVOID KeyBodyArray[4];
PVOID DelayCloseEntry;
LARGE_INTEGER KcbLastWriteTime;
USHORT KcbMaxNameLen;
USHORT KcbMaxValueNameLen;
ULONG KcbMaxValueDataLen;
ULONG InDelayClose;
} CM_KEY_CONTROL_BLOCK, *PCM_KEY_CONTROL_BLOCK;
/* Bits 31-22 (top 10 bits) of the cell index is the directory index */ /* Bits 31-22 (top 10 bits) of the cell index is the directory index */
#define CmiDirectoryIndex(CellIndex)(CellIndex & 0xffc000000) #define CmiDirectoryIndex(CellIndex)(CellIndex & 0xffc000000)
/* Bits 21-12 (middle 10 bits) of the cell index is the table index */ /* Bits 21-12 (middle 10 bits) of the cell index is the table index */
@ -222,12 +267,12 @@ CmiScanKeyForValue(IN PEREGISTRY_HIVE RegistryHive,
NTSTATUS NTSTATUS
NTAPI NTAPI
CmDeleteValueKey(IN PKEY_OBJECT KeyControlBlock, CmDeleteValueKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
IN UNICODE_STRING ValueName); IN UNICODE_STRING ValueName);
NTSTATUS NTSTATUS
NTAPI NTAPI
CmQueryValueKey(IN PKEY_OBJECT KeyObject, CmQueryValueKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
IN UNICODE_STRING ValueName, IN UNICODE_STRING ValueName,
IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
IN PVOID KeyValueInformation, IN PVOID KeyValueInformation,
@ -236,7 +281,7 @@ CmQueryValueKey(IN PKEY_OBJECT KeyObject,
NTSTATUS NTSTATUS
NTAPI NTAPI
CmEnumerateValueKey(IN PKEY_OBJECT KeyObject, CmEnumerateValueKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
IN ULONG Index, IN ULONG Index,
IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
IN PVOID KeyValueInformation, IN PVOID KeyValueInformation,
@ -245,7 +290,7 @@ CmEnumerateValueKey(IN PKEY_OBJECT KeyObject,
NTSTATUS NTSTATUS
NTAPI NTAPI
CmSetValueKey(IN PKEY_OBJECT KeyObject, CmSetValueKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
IN PUNICODE_STRING ValueName, IN PUNICODE_STRING ValueName,
IN ULONG Type, IN ULONG Type,
IN PVOID Data, IN PVOID Data,
@ -253,7 +298,7 @@ CmSetValueKey(IN PKEY_OBJECT KeyObject,
NTSTATUS NTSTATUS
NTAPI NTAPI
CmQueryKey(IN PKEY_OBJECT KeyObject, CmQueryKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
IN KEY_INFORMATION_CLASS KeyInformationClass, IN KEY_INFORMATION_CLASS KeyInformationClass,
IN PVOID KeyInformation, IN PVOID KeyInformation,
IN ULONG Length, IN ULONG Length,
@ -261,7 +306,7 @@ CmQueryKey(IN PKEY_OBJECT KeyObject,
NTSTATUS NTSTATUS
NTAPI NTAPI
CmEnumerateKey(IN PKEY_OBJECT KeyObject, CmEnumerateKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
IN ULONG Index, IN ULONG Index,
IN KEY_INFORMATION_CLASS KeyInformationClass, IN KEY_INFORMATION_CLASS KeyInformationClass,
IN PVOID KeyInformation, IN PVOID KeyInformation,
@ -270,7 +315,7 @@ CmEnumerateKey(IN PKEY_OBJECT KeyObject,
NTSTATUS NTSTATUS
NTAPI NTAPI
CmDeleteKey(IN PKEY_OBJECT KeyObject); CmDeleteKey(IN PCM_KEY_CONTROL_BLOCK Kcb);
NTSTATUS NTSTATUS
CmiAllocateHashTableCell(IN PEREGISTRY_HIVE RegistryHive, CmiAllocateHashTableCell(IN PEREGISTRY_HIVE RegistryHive,
@ -317,8 +362,6 @@ CmpFindValueByName(
IN PUNICODE_STRING Name IN PUNICODE_STRING Name
); );
/* NOTE: This function declaration is currently duplicated in both */
/* cm/cm.h and config/cm.h. TODO: Pick one single place to declare it. */
HCELL_INDEX HCELL_INDEX
NTAPI NTAPI
CmpFindSubKeyByName( CmpFindSubKeyByName(
@ -342,8 +385,6 @@ CmFindObject(
IN PVOID ParseContext IN PVOID ParseContext
); );
/* NOTE: This function declaration is currently duplicated in both */
/* cm/cm.h and config/cm.h. TODO: Pick one single place to declare it. */
NTSTATUS NTSTATUS
NTAPI NTAPI
CmpOpenHiveFiles(IN PCUNICODE_STRING BaseName, CmpOpenHiveFiles(IN PCUNICODE_STRING BaseName,

View file

@ -24,7 +24,6 @@
/* GLOBALS ******************************************************************/ /* GLOBALS ******************************************************************/
extern POBJECT_TYPE CmpKeyObjectType; extern POBJECT_TYPE CmpKeyObjectType;
static BOOLEAN CmiRegistryInitialized = FALSE; static BOOLEAN CmiRegistryInitialized = FALSE;
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
@ -709,8 +708,13 @@ NtDeleteKey(IN HANDLE KeyHandle)
Status = CmiCallRegisteredCallbacks(RegNtPreDeleteKey, &DeleteKeyInfo); Status = CmiCallRegisteredCallbacks(RegNtPreDeleteKey, &DeleteKeyInfo);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
/* HACK: Setup the Dummy KCB */
CM_KEY_CONTROL_BLOCK DummyKcb = {0};
DummyKcb.KeyHive = &KeyObject->RegistryHive->Hive;
DummyKcb.KeyCell = KeyObject->KeyCellOffset;
/* Call the internal API */ /* Call the internal API */
Status = CmDeleteKey(KeyObject); Status = CmDeleteKey(&DummyKcb);
/* Remove the keep-alive reference */ /* Remove the keep-alive reference */
ObDereferenceObject(KeyObject); ObDereferenceObject(KeyObject);
@ -773,8 +777,13 @@ NtEnumerateKey(IN HANDLE KeyHandle,
Status = CmiCallRegisteredCallbacks(RegNtPreEnumerateKey, &EnumerateKeyInfo); Status = CmiCallRegisteredCallbacks(RegNtPreEnumerateKey, &EnumerateKeyInfo);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
/* HACK: Setup the Dummy KCB */
CM_KEY_CONTROL_BLOCK DummyKcb = {0};
DummyKcb.KeyHive = &KeyObject->RegistryHive->Hive;
DummyKcb.KeyCell = KeyObject->KeyCellOffset;
/* Call the internal API */ /* Call the internal API */
Status = CmEnumerateKey(KeyObject, Status = CmEnumerateKey(&DummyKcb,
Index, Index,
KeyInformationClass, KeyInformationClass,
KeyInformation, KeyInformation,
@ -836,8 +845,13 @@ NtEnumerateValueKey(IN HANDLE KeyHandle,
&EnumerateValueKeyInfo); &EnumerateValueKeyInfo);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
/* HACK: Setup the Dummy KCB */
CM_KEY_CONTROL_BLOCK DummyKcb = {0};
DummyKcb.KeyHive = &KeyObject->RegistryHive->Hive;
DummyKcb.KeyCell = KeyObject->KeyCellOffset;
/* Call the internal API */ /* Call the internal API */
Status = CmEnumerateValueKey(KeyObject, Status = CmEnumerateValueKey(&DummyKcb,
Index, Index,
KeyValueInformationClass, KeyValueInformationClass,
KeyValueInformation, KeyValueInformation,
@ -897,8 +911,13 @@ NtQueryKey(IN HANDLE KeyHandle,
Status = CmiCallRegisteredCallbacks(RegNtPreQueryKey, &QueryKeyInfo); Status = CmiCallRegisteredCallbacks(RegNtPreQueryKey, &QueryKeyInfo);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
/* HACK: Setup the Dummy KCB */
CM_KEY_CONTROL_BLOCK DummyKcb = {0};
DummyKcb.KeyHive = &KeyObject->RegistryHive->Hive;
DummyKcb.KeyCell = KeyObject->KeyCellOffset;
/* Call the internal API */ /* Call the internal API */
Status = CmQueryKey(KeyObject, Status = CmQueryKey(&DummyKcb,
KeyInformationClass, KeyInformationClass,
KeyInformation, KeyInformation,
Length, Length,
@ -957,8 +976,13 @@ NtQueryValueKey(IN HANDLE KeyHandle,
Status = CmiCallRegisteredCallbacks(RegNtPreQueryValueKey, &QueryValueKeyInfo); Status = CmiCallRegisteredCallbacks(RegNtPreQueryValueKey, &QueryValueKeyInfo);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
/* HACK: Setup the Dummy KCB */
CM_KEY_CONTROL_BLOCK DummyKcb = {0};
DummyKcb.KeyHive = &KeyObject->RegistryHive->Hive;
DummyKcb.KeyCell = KeyObject->KeyCellOffset;
/* Call the internal API */ /* Call the internal API */
Status = CmQueryValueKey(KeyObject, Status = CmQueryValueKey(&DummyKcb,
*ValueName, *ValueName,
KeyValueInformationClass, KeyValueInformationClass,
KeyValueInformation, KeyValueInformation,
@ -1021,8 +1045,13 @@ NtSetValueKey(IN HANDLE KeyHandle,
Status = CmiCallRegisteredCallbacks(RegNtPreSetValueKey, &SetValueKeyInfo); Status = CmiCallRegisteredCallbacks(RegNtPreSetValueKey, &SetValueKeyInfo);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
/* HACK: Setup the Dummy KCB */
CM_KEY_CONTROL_BLOCK DummyKcb = {0};
DummyKcb.KeyHive = &KeyObject->RegistryHive->Hive;
DummyKcb.KeyCell = KeyObject->KeyCellOffset;
/* Call the internal API */ /* Call the internal API */
Status = CmSetValueKey(KeyObject, Status = CmSetValueKey(&DummyKcb,
ValueName, ValueName,
Type, Type,
Data, Data,
@ -1071,8 +1100,13 @@ NtDeleteValueKey(IN HANDLE KeyHandle,
&DeleteValueKeyInfo); &DeleteValueKeyInfo);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
/* HACK: Setup the Dummy KCB */
CM_KEY_CONTROL_BLOCK DummyKcb = {0};
DummyKcb.KeyHive = &KeyObject->RegistryHive->Hive;
DummyKcb.KeyCell = KeyObject->KeyCellOffset;
/* Call the internal API */ /* Call the internal API */
Status = CmDeleteValueKey(KeyObject, *ValueName); Status = CmDeleteValueKey(&DummyKcb, *ValueName);
/* Do the post callback */ /* Do the post callback */
PostOperationInfo.Object = (PVOID)KeyObject; PostOperationInfo.Object = (PVOID)KeyObject;

View file

@ -710,7 +710,7 @@ CmpInitSecurityCache(
VALUE_SEARCH_RETURN_TYPE VALUE_SEARCH_RETURN_TYPE
NTAPI NTAPI
CmpFindValueByNameFromCache( CmpFindValueByNameFromCache(
IN PKEY_OBJECT KeyObject, IN PCM_KEY_CONTROL_BLOCK Kcb,
IN PCUNICODE_STRING Name, IN PCUNICODE_STRING Name,
OUT PCM_CACHED_VALUE **CachedValue, OUT PCM_CACHED_VALUE **CachedValue,
OUT ULONG *Index, OUT ULONG *Index,
@ -722,7 +722,7 @@ CmpFindValueByNameFromCache(
VALUE_SEARCH_RETURN_TYPE VALUE_SEARCH_RETURN_TYPE
NTAPI NTAPI
CmpQueryKeyValueData( CmpQueryKeyValueData(
IN PKEY_OBJECT KeyObject, IN PCM_KEY_CONTROL_BLOCK Kcb,
IN PCM_CACHED_VALUE *CachedValue, IN PCM_CACHED_VALUE *CachedValue,
IN PCM_KEY_VALUE ValueKey, IN PCM_KEY_VALUE ValueKey,
IN BOOLEAN ValueIsCached, IN BOOLEAN ValueIsCached,
@ -736,7 +736,7 @@ CmpQueryKeyValueData(
VALUE_SEARCH_RETURN_TYPE VALUE_SEARCH_RETURN_TYPE
NTAPI NTAPI
CmpGetValueListFromCache( CmpGetValueListFromCache(
IN PKEY_OBJECT KeyObject, IN PCM_KEY_CONTROL_BLOCK Kcb,
OUT PCELL_DATA *CellData, OUT PCELL_DATA *CellData,
OUT BOOLEAN *IndexIsCached, OUT BOOLEAN *IndexIsCached,
OUT PHCELL_INDEX ValueListToRelease OUT PHCELL_INDEX ValueListToRelease
@ -745,7 +745,7 @@ CmpGetValueListFromCache(
VALUE_SEARCH_RETURN_TYPE VALUE_SEARCH_RETURN_TYPE
NTAPI NTAPI
CmpGetValueKeyFromCache( CmpGetValueKeyFromCache(
IN PKEY_OBJECT KeyObject, IN PCM_KEY_CONTROL_BLOCK Kcb,
IN PCELL_DATA CellData, IN PCELL_DATA CellData,
IN ULONG Index, IN ULONG Index,
OUT PCM_CACHED_VALUE **CachedValue, OUT PCM_CACHED_VALUE **CachedValue,
@ -979,7 +979,7 @@ EnlistKeyBodyWithKCB(
#if 0 #if 0
IN PCM_KEY_BODY KeyObject, IN PCM_KEY_BODY KeyObject,
#else #else
IN PKEY_OBJECT KeyObject, IN PVOID KeyObject,
#endif #endif
IN ULONG Flags IN ULONG Flags
); );

View file

@ -216,7 +216,7 @@ CmpSetValueKeyExisting(IN PHHIVE Hive,
NTSTATUS NTSTATUS
NTAPI NTAPI
CmSetValueKey(IN PKEY_OBJECT KeyObject, CmSetValueKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
IN PUNICODE_STRING ValueName, IN PUNICODE_STRING ValueName,
IN ULONG Type, IN ULONG Type,
IN PVOID Data, IN PVOID Data,
@ -235,11 +235,11 @@ CmSetValueKey(IN PKEY_OBJECT KeyObject,
ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE);
/* Get pointer to key cell */ /* Get pointer to key cell */
Parent = KeyObject->KeyCell; Hive = Kcb->KeyHive;
Hive = &KeyObject->RegistryHive->Hive; Cell = Kcb->KeyCell;
Cell = KeyObject->KeyCellOffset;
/* Prepare to scan the key node */ /* Prepare to scan the key node */
Parent = (PCM_KEY_NODE)HvGetCell(Hive, Cell);
Count = Parent->ValueList.Count; Count = Parent->ValueList.Count;
Found = FALSE; Found = FALSE;
if (Count > 0) if (Count > 0)
@ -343,7 +343,7 @@ Quickie:
NTSTATUS NTSTATUS
NTAPI NTAPI
CmDeleteValueKey(IN PKEY_OBJECT KeyObject, CmDeleteValueKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
IN UNICODE_STRING ValueName) IN UNICODE_STRING ValueName)
{ {
NTSTATUS Status = STATUS_OBJECT_NAME_NOT_FOUND; NTSTATUS Status = STATUS_OBJECT_NAME_NOT_FOUND;
@ -360,8 +360,8 @@ CmDeleteValueKey(IN PKEY_OBJECT KeyObject,
ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE);
/* Get the hive and the cell index */ /* Get the hive and the cell index */
Hive = &KeyObject->RegistryHive->Hive; Hive = Kcb->KeyHive;
Cell = KeyObject->KeyCellOffset; Cell = Kcb->KeyCell;
/* Get the parent key node */ /* Get the parent key node */
Parent = (PCM_KEY_NODE)HvGetCell(Hive, Cell); Parent = (PCM_KEY_NODE)HvGetCell(Hive, Cell);
@ -458,7 +458,7 @@ Quickie:
NTSTATUS NTSTATUS
NTAPI NTAPI
CmQueryValueKey(IN PKEY_OBJECT KeyObject, CmQueryValueKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
IN UNICODE_STRING ValueName, IN UNICODE_STRING ValueName,
IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
IN PVOID KeyValueInformation, IN PVOID KeyValueInformation,
@ -480,10 +480,10 @@ CmQueryValueKey(IN PKEY_OBJECT KeyObject,
ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE);
/* Get the hive */ /* Get the hive */
Hive = &KeyObject->RegistryHive->Hive; Hive = Kcb->KeyHive;
/* Find the key value */ /* Find the key value */
Result = CmpFindValueByNameFromCache(KeyObject, Result = CmpFindValueByNameFromCache(Kcb,
&ValueName, &ValueName,
&CachedValue, &CachedValue,
&Index, &Index,
@ -496,7 +496,7 @@ CmQueryValueKey(IN PKEY_OBJECT KeyObject,
ASSERT(ValueData != NULL); ASSERT(ValueData != NULL);
/* Query the information requested */ /* Query the information requested */
Result = CmpQueryKeyValueData(KeyObject, Result = CmpQueryKeyValueData(Kcb,
CachedValue, CachedValue,
ValueData, ValueData,
ValueCached, ValueCached,
@ -523,7 +523,7 @@ CmQueryValueKey(IN PKEY_OBJECT KeyObject,
NTSTATUS NTSTATUS
NTAPI NTAPI
CmEnumerateValueKey(IN PKEY_OBJECT KeyObject, CmEnumerateValueKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
IN ULONG Index, IN ULONG Index,
IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
IN PVOID KeyValueInformation, IN PVOID KeyValueInformation,
@ -546,8 +546,8 @@ CmEnumerateValueKey(IN PKEY_OBJECT KeyObject,
ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE);
/* Get the hive and parent */ /* Get the hive and parent */
Hive = &KeyObject->RegistryHive->Hive; Hive = Kcb->KeyHive;
Parent = (PCM_KEY_NODE)HvGetCell(Hive, KeyObject->KeyCellOffset); Parent = (PCM_KEY_NODE)HvGetCell(Hive, Kcb->KeyCell);
if (!Parent) if (!Parent)
{ {
/* Fail */ /* Fail */
@ -556,17 +556,17 @@ CmEnumerateValueKey(IN PKEY_OBJECT KeyObject,
} }
/* Make sure the index is valid */ /* Make sure the index is valid */
//if (Index >= KeyObject->ValueCache.Count) //if (Index >= Kcb->ValueCache.Count)
if (Index >= KeyObject->KeyCell->ValueList.Count) if (Index >= Parent->ValueList.Count)
{ {
/* Release the cell and fail */ /* Release the cell and fail */
HvReleaseCell(Hive, KeyObject->KeyCellOffset); HvReleaseCell(Hive, Kcb->KeyCell);
Status = STATUS_NO_MORE_ENTRIES; Status = STATUS_NO_MORE_ENTRIES;
goto Quickie; goto Quickie;
} }
/* Find the value list */ /* Find the value list */
Result = CmpGetValueListFromCache(KeyObject, Result = CmpGetValueListFromCache(Kcb,
&CellData, &CellData,
&IndexIsCached, &IndexIsCached,
&CellToRelease); &CellToRelease);
@ -581,7 +581,7 @@ CmEnumerateValueKey(IN PKEY_OBJECT KeyObject,
} }
/* Now get the key value */ /* Now get the key value */
Result = CmpGetValueKeyFromCache(KeyObject, Result = CmpGetValueKeyFromCache(Kcb,
CellData, CellData,
Index, Index,
&CachedValue, &CachedValue,
@ -600,7 +600,7 @@ CmEnumerateValueKey(IN PKEY_OBJECT KeyObject,
} }
/* Query the information requested */ /* Query the information requested */
Result = CmpQueryKeyValueData(KeyObject, Result = CmpQueryKeyValueData(Kcb,
CachedValue, CachedValue,
ValueData, ValueData,
ValueIsCached, ValueIsCached,
@ -615,7 +615,7 @@ Quickie:
if (CellToRelease != HCELL_NIL) HvReleaseCell(Hive, CellToRelease); if (CellToRelease != HCELL_NIL) HvReleaseCell(Hive, CellToRelease);
/* Release the parent cell */ /* Release the parent cell */
HvReleaseCell(Hive, KeyObject->KeyCellOffset); HvReleaseCell(Hive, Kcb->KeyCell);
/* If we have a cell to release, do so */ /* If we have a cell to release, do so */
if (CellToRelease2 != HCELL_NIL) HvReleaseCell(Hive, CellToRelease2); if (CellToRelease2 != HCELL_NIL) HvReleaseCell(Hive, CellToRelease2);
@ -852,7 +852,7 @@ CmpQueryKeyData(IN PHHIVE Hive,
NTSTATUS NTSTATUS
NTAPI NTAPI
CmQueryKey(IN PKEY_OBJECT KeyObject, CmQueryKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
IN KEY_INFORMATION_CLASS KeyInformationClass, IN KEY_INFORMATION_CLASS KeyInformationClass,
IN PVOID KeyInformation, IN PVOID KeyInformation,
IN ULONG Length, IN ULONG Length,
@ -867,8 +867,8 @@ CmQueryKey(IN PKEY_OBJECT KeyObject,
ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE);
/* Get the hive and parent */ /* Get the hive and parent */
Hive = &KeyObject->RegistryHive->Hive; Hive = Kcb->KeyHive;
Parent = (PCM_KEY_NODE)HvGetCell(Hive, KeyObject->KeyCellOffset); Parent = (PCM_KEY_NODE)HvGetCell(Hive, Kcb->KeyCell);
if (!Parent) if (!Parent)
{ {
/* Fail */ /* Fail */
@ -921,7 +921,7 @@ Quickie:
NTSTATUS NTSTATUS
NTAPI NTAPI
CmEnumerateKey(IN PKEY_OBJECT KeyObject, CmEnumerateKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
IN ULONG Index, IN ULONG Index,
IN KEY_INFORMATION_CLASS KeyInformationClass, IN KEY_INFORMATION_CLASS KeyInformationClass,
IN PVOID KeyInformation, IN PVOID KeyInformation,
@ -938,8 +938,8 @@ CmEnumerateKey(IN PKEY_OBJECT KeyObject,
ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE);
/* Get the hive and parent */ /* Get the hive and parent */
Hive = &KeyObject->RegistryHive->Hive; Hive = Kcb->KeyHive;
Parent = (PCM_KEY_NODE)HvGetCell(Hive, KeyObject->KeyCellOffset); Parent = (PCM_KEY_NODE)HvGetCell(Hive, Kcb->KeyCell);
if (!Parent) if (!Parent)
{ {
/* Fail */ /* Fail */
@ -951,7 +951,7 @@ CmEnumerateKey(IN PKEY_OBJECT KeyObject,
ChildCell = CmpFindSubKeyByNumber(Hive, Parent, Index); ChildCell = CmpFindSubKeyByNumber(Hive, Parent, Index);
/* Release the parent cell */ /* Release the parent cell */
HvReleaseCell(Hive, KeyObject->KeyCellOffset); HvReleaseCell(Hive, Kcb->KeyCell);
/* Check if we found the child */ /* Check if we found the child */
if (ChildCell == HCELL_NIL) if (ChildCell == HCELL_NIL)
@ -987,7 +987,7 @@ Quickie:
NTSTATUS NTSTATUS
NTAPI NTAPI
CmDeleteKey(IN PKEY_OBJECT KeyObject) CmDeleteKey(IN PCM_KEY_CONTROL_BLOCK Kcb)
{ {
NTSTATUS Status; NTSTATUS Status;
PHHIVE Hive; PHHIVE Hive;
@ -999,17 +999,9 @@ CmDeleteKey(IN PKEY_OBJECT KeyObject)
ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE);
/* Get the hive and node */ /* Get the hive and node */
Hive = &KeyObject->RegistryHive->Hive; Hive = Kcb->KeyHive;
Cell = KeyObject->KeyCellOffset; Cell = Kcb->KeyCell;
/* Check if we have no parent */
if (!KeyObject->ParentKey)
{
/* This is an attempt to delete \Registry itself! */
Status = STATUS_CANNOT_DELETE;
goto Quickie;
}
/* Get the key node */ /* Get the key node */
Node = (PCM_KEY_NODE)HvGetCell(Hive, Cell); Node = (PCM_KEY_NODE)HvGetCell(Hive, Cell);
if (!Node) if (!Node)
@ -1019,6 +1011,14 @@ CmDeleteKey(IN PKEY_OBJECT KeyObject)
goto Quickie; goto Quickie;
} }
/* Check if we have no parent */
if (!Node->Parent)
{
/* This is an attempt to delete \Registry itself! */
Status = STATUS_CANNOT_DELETE;
goto Quickie;
}
/* Check if we don't have any children */ /* Check if we don't have any children */
if (!(Node->SubKeyCounts[Stable] + Node->SubKeyCounts[Volatile])) if (!(Node->SubKeyCounts[Stable] + Node->SubKeyCounts[Volatile]))
{ {
@ -1042,7 +1042,7 @@ CmDeleteKey(IN PKEY_OBJECT KeyObject)
} }
/* Clear the cell */ /* Clear the cell */
KeyObject->KeyCellOffset = HCELL_NIL; Kcb->KeyCell = HCELL_NIL;
} }
} }
else else
@ -1050,19 +1050,19 @@ CmDeleteKey(IN PKEY_OBJECT KeyObject)
/* Fail */ /* Fail */
Status = STATUS_CANNOT_DELETE; Status = STATUS_CANNOT_DELETE;
} }
Quickie:
/* Release the cell */
HvReleaseCell(Hive, Cell);
/* Make sure we're file-backed */ /* Make sure we're file-backed */
if (!(IsNoFileHive(KeyObject->RegistryHive)) || if (!(IsNoFileHive((PEREGISTRY_HIVE)Kcb->KeyHive)) ||
!(IsNoFileHive(KeyObject->ParentKey->RegistryHive))) !(IsNoFileHive((PEREGISTRY_HIVE)Kcb->ParentKcb->KeyHive)))
{ {
/* Sync up the hives */ /* Sync up the hives */
CmiSyncHives(); CmiSyncHives();
} }
Quickie:
/* Release the cell */
HvReleaseCell(Hive, Cell);
/* Release hive lock */ /* Release hive lock */
ExReleaseResourceLite(&CmpRegistryLock); ExReleaseResourceLite(&CmpRegistryLock);
KeLeaveCriticalRegion(); KeLeaveCriticalRegion();

View file

@ -42,7 +42,7 @@ CmpSetValueCached(IN PHCELL_INDEX CellIndex)
VALUE_SEARCH_RETURN_TYPE VALUE_SEARCH_RETURN_TYPE
NTAPI NTAPI
CmpGetValueListFromCache(IN PKEY_OBJECT KeyObject, CmpGetValueListFromCache(IN PCM_KEY_CONTROL_BLOCK Kcb,
OUT PCELL_DATA *CellData, OUT PCELL_DATA *CellData,
OUT BOOLEAN *IndexIsCached, OUT BOOLEAN *IndexIsCached,
OUT PHCELL_INDEX ValueListToRelease) OUT PHCELL_INDEX ValueListToRelease)
@ -50,17 +50,19 @@ CmpGetValueListFromCache(IN PKEY_OBJECT KeyObject,
PHHIVE Hive; PHHIVE Hive;
PCACHED_CHILD_LIST ChildList; PCACHED_CHILD_LIST ChildList;
HCELL_INDEX CellToRelease; HCELL_INDEX CellToRelease;
PCM_KEY_NODE KeyNode;
/* Set defaults */ /* Set defaults */
*ValueListToRelease = HCELL_NIL; *ValueListToRelease = HCELL_NIL;
*IndexIsCached = FALSE; *IndexIsCached = FALSE;
/* Get the hive */ /* Get the hive */
Hive = &KeyObject->RegistryHive->Hive; Hive = Kcb->KeyHive;
KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, Kcb->KeyCell);
/* Get the child value cache */ /* Get the child value cache */
//ChildList = &KeyObject->ValueCache; //ChildList = &Kcb->ValueCache;
ChildList = (PCACHED_CHILD_LIST)&KeyObject->KeyCell->ValueList; ChildList = (PCACHED_CHILD_LIST)&KeyNode->ValueList;
/* Check if the value is cached */ /* Check if the value is cached */
if (CmpIsValueCached(ChildList->ValueList)) if (CmpIsValueCached(ChildList->ValueList))
@ -87,7 +89,7 @@ CmpGetValueListFromCache(IN PKEY_OBJECT KeyObject,
VALUE_SEARCH_RETURN_TYPE VALUE_SEARCH_RETURN_TYPE
NTAPI NTAPI
CmpGetValueKeyFromCache(IN PKEY_OBJECT KeyObject, CmpGetValueKeyFromCache(IN PCM_KEY_CONTROL_BLOCK Kcb,
IN PCELL_DATA CellData, IN PCELL_DATA CellData,
IN ULONG Index, IN ULONG Index,
OUT PCM_CACHED_VALUE **CachedValue, OUT PCM_CACHED_VALUE **CachedValue,
@ -106,7 +108,7 @@ CmpGetValueKeyFromCache(IN PKEY_OBJECT KeyObject,
*ValueIsCached = FALSE; *ValueIsCached = FALSE;
/* Get the hive */ /* Get the hive */
Hive = &KeyObject->RegistryHive->Hive; Hive = Kcb->KeyHive;
/* Check if the index was cached */ /* Check if the index was cached */
if (IndexIsCached) if (IndexIsCached)
@ -133,7 +135,7 @@ CmpGetValueKeyFromCache(IN PKEY_OBJECT KeyObject,
VALUE_SEARCH_RETURN_TYPE VALUE_SEARCH_RETURN_TYPE
NTAPI NTAPI
CmpGetValueDataFromCache(IN PKEY_OBJECT KeyObject, CmpGetValueDataFromCache(IN PCM_KEY_CONTROL_BLOCK Kcb,
IN PCM_CACHED_VALUE *CachedValue, IN PCM_CACHED_VALUE *CachedValue,
IN PCELL_DATA ValueKey, IN PCELL_DATA ValueKey,
IN BOOLEAN ValueIsCached, IN BOOLEAN ValueIsCached,
@ -154,7 +156,7 @@ CmpGetValueDataFromCache(IN PKEY_OBJECT KeyObject,
*CellToRelease = HCELL_NIL; *CellToRelease = HCELL_NIL;
/* Get the hive */ /* Get the hive */
Hive = &KeyObject->RegistryHive->Hive; Hive = Kcb->KeyHive;
/* Check it the value is cached */ /* Check it the value is cached */
if (ValueIsCached) if (ValueIsCached)
@ -185,7 +187,7 @@ CmpGetValueDataFromCache(IN PKEY_OBJECT KeyObject,
VALUE_SEARCH_RETURN_TYPE VALUE_SEARCH_RETURN_TYPE
NTAPI NTAPI
CmpFindValueByNameFromCache(IN PKEY_OBJECT KeyObject, CmpFindValueByNameFromCache(IN PCM_KEY_CONTROL_BLOCK Kcb,
IN PCUNICODE_STRING Name, IN PCUNICODE_STRING Name,
OUT PCM_CACHED_VALUE **CachedValue, OUT PCM_CACHED_VALUE **CachedValue,
OUT ULONG *Index, OUT ULONG *Index,
@ -203,21 +205,25 @@ CmpFindValueByNameFromCache(IN PKEY_OBJECT KeyObject,
BOOLEAN IndexIsCached; BOOLEAN IndexIsCached;
ULONG i = 0; ULONG i = 0;
HCELL_INDEX Cell = HCELL_NIL; HCELL_INDEX Cell = HCELL_NIL;
PCM_KEY_NODE KeyNode;
/* Set defaults */ /* Set defaults */
*CellToRelease = HCELL_NIL; *CellToRelease = HCELL_NIL;
*Value = NULL; *Value = NULL;
/* Get the hive and child list */ /* Get the hive */
Hive = &KeyObject->RegistryHive->Hive; Hive = Kcb->KeyHive;
//ChildList = &KeyObject->ValueCache; KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, Kcb->KeyCell);
ChildList = (PCACHED_CHILD_LIST)&KeyObject->KeyCell->ValueList;
/* Get the child value cache */
//ChildList = &Kcb->ValueCache;
ChildList = (PCACHED_CHILD_LIST)&KeyNode->ValueList;
/* Check if the child list has any entries */ /* Check if the child list has any entries */
if (ChildList->Count != 0) if (ChildList->Count != 0)
{ {
/* Get the value list associated to this child list */ /* Get the value list associated to this child list */
SearchResult = CmpGetValueListFromCache(KeyObject, SearchResult = CmpGetValueListFromCache(Kcb,
&CellData, &CellData,
&IndexIsCached, &IndexIsCached,
&Cell); &Cell);
@ -238,7 +244,7 @@ CmpFindValueByNameFromCache(IN PKEY_OBJECT KeyObject,
} }
/* Get the key value for this index */ /* Get the key value for this index */
SearchResult = CmpGetValueKeyFromCache(KeyObject, SearchResult = CmpGetValueKeyFromCache(Kcb,
CellData, CellData,
i, i,
CachedValue, CachedValue,
@ -307,7 +313,7 @@ Quickie:
VALUE_SEARCH_RETURN_TYPE VALUE_SEARCH_RETURN_TYPE
NTAPI NTAPI
CmpQueryKeyValueData(IN PKEY_OBJECT KeyObject, CmpQueryKeyValueData(IN PCM_KEY_CONTROL_BLOCK Kcb,
IN PCM_CACHED_VALUE *CachedValue, IN PCM_CACHED_VALUE *CachedValue,
IN PCM_KEY_VALUE ValueKey, IN PCM_KEY_VALUE ValueKey,
IN BOOLEAN ValueIsCached, IN BOOLEAN ValueIsCached,
@ -328,7 +334,7 @@ CmpQueryKeyValueData(IN PKEY_OBJECT KeyObject,
VALUE_SEARCH_RETURN_TYPE Result = SearchSuccess; VALUE_SEARCH_RETURN_TYPE Result = SearchSuccess;
/* Get the hive and cell data */ /* Get the hive and cell data */
Hive = &KeyObject->RegistryHive->Hive; Hive = Kcb->KeyHive;
CellData = (PCELL_DATA)ValueKey; CellData = (PCELL_DATA)ValueKey;
/* Check if the value is compressed */ /* Check if the value is compressed */
@ -492,7 +498,7 @@ CmpQueryKeyValueData(IN PKEY_OBJECT KeyObject,
else else
{ {
/* Otherwise, we must retrieve it from the value cache */ /* Otherwise, we must retrieve it from the value cache */
Result = CmpGetValueDataFromCache(KeyObject, Result = CmpGetValueDataFromCache(Kcb,
CachedValue, CachedValue,
CellData, CellData,
ValueIsCached, ValueIsCached,
@ -587,7 +593,7 @@ CmpQueryKeyValueData(IN PKEY_OBJECT KeyObject,
else else
{ {
/* Otherwise, we must retrieve it from the value cache */ /* Otherwise, we must retrieve it from the value cache */
Result = CmpGetValueDataFromCache(KeyObject, Result = CmpGetValueDataFromCache(Kcb,
CachedValue, CachedValue,
CellData, CellData,
ValueIsCached, ValueIsCached,

View file

@ -63,121 +63,6 @@ extern EREGISTRY_HIVE SystemHive; /* \Registry\Machine\SYSTEM */
#define ERROR_MORE_DATA 234L #define ERROR_MORE_DATA 234L
#define ERROR_NO_MORE_ITEMS 259L #define ERROR_NO_MORE_ITEMS 259L
/*
* VOID
* InitializeListHead (
* PLIST_ENTRY ListHead
* );
*
* FUNCTION: Initializes a double linked list
* ARGUMENTS:
* ListHead = Caller supplied storage for the head of the list
*/
#define InitializeListHead(ListHead) \
{ \
(ListHead)->Flink = (ListHead); \
(ListHead)->Blink = (ListHead); \
}
/*
* VOID
* InsertHeadList (
* PLIST_ENTRY ListHead,
* PLIST_ENTRY Entry
* );
*
* FUNCTION: Inserts an entry in a double linked list
* ARGUMENTS:
* ListHead = Head of the list
* Entry = Entry to insert
*/
#define InsertHeadList(ListHead, ListEntry) \
{ \
PLIST_ENTRY OldFlink; \
OldFlink = (ListHead)->Flink; \
(ListEntry)->Flink = OldFlink; \
(ListEntry)->Blink = (ListHead); \
OldFlink->Blink = (ListEntry); \
(ListHead)->Flink = (ListEntry); \
assert((ListEntry) != NULL); \
assert((ListEntry)->Blink!=NULL); \
assert((ListEntry)->Blink->Flink == (ListEntry)); \
assert((ListEntry)->Flink != NULL); \
assert((ListEntry)->Flink->Blink == (ListEntry)); \
}
/*
* VOID
* InsertTailList (
* PLIST_ENTRY ListHead,
* PLIST_ENTRY Entry
* );
*
* FUNCTION:
* Inserts an entry in a double linked list
*
* ARGUMENTS:
* ListHead = Head of the list
* Entry = Entry to insert
*/
#define InsertTailList(ListHead, ListEntry) \
{ \
PLIST_ENTRY OldBlink; \
OldBlink = (ListHead)->Blink; \
(ListEntry)->Flink = (ListHead); \
(ListEntry)->Blink = OldBlink; \
OldBlink->Flink = (ListEntry); \
(ListHead)->Blink = (ListEntry); \
assert((ListEntry) != NULL); \
assert((ListEntry)->Blink != NULL); \
assert((ListEntry)->Blink->Flink == (ListEntry)); \
assert((ListEntry)->Flink != NULL); \
assert((ListEntry)->Flink->Blink == (ListEntry)); \
}
/*
*VOID
*RemoveEntryList (
* PLIST_ENTRY Entry
* );
*
* FUNCTION:
* Removes an entry from a double linked list
*
* ARGUMENTS:
* ListEntry = Entry to remove
*/
#define RemoveEntryList(ListEntry) \
{ \
PLIST_ENTRY OldFlink; \
PLIST_ENTRY OldBlink; \
assert((ListEntry) != NULL); \
assert((ListEntry)->Blink!=NULL); \
assert((ListEntry)->Blink->Flink == (ListEntry)); \
assert((ListEntry)->Flink != NULL); \
assert((ListEntry)->Flink->Blink == (ListEntry)); \
OldFlink = (ListEntry)->Flink; \
OldBlink = (ListEntry)->Blink; \
OldFlink->Blink = OldBlink; \
OldBlink->Flink = OldFlink; \
(ListEntry)->Flink = NULL; \
(ListEntry)->Blink = NULL; \
}
/*
* PURPOSE: Returns the base address structure if the caller knows the
* address of a field within the structure
* ARGUMENTS:
* Address = address of the field
* Type = Type of the whole structure
* Field = Name of the field whose address is none
*/
#define CONTAINING_RECORD(address, type, field) \
((type *)(((ULONG_PTR)address) - (ULONG_PTR)(&(((type *)0)->field))))
#define REG_NONE 0 #define REG_NONE 0
#define REG_SZ 1 #define REG_SZ 1
#define REG_EXPAND_SZ 2 #define REG_EXPAND_SZ 2
@ -241,3 +126,4 @@ RegInitializeRegistry(VOID);
/* EOF */ /* EOF */