ReactOS  0.4.14-dev-55-g2da92ac
cmlib.h File Reference
#include <ntdef.h>
#include <ntifs.h>
#include <bugcodes.h>
#include <wine/unicode.h>
#include <wchar.h>
#include "hivedata.h"
#include "cmdata.h"
Include dependency graph for cmlib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _HV_HIVE_CELL_PAIR
 
struct  _HV_TRACK_CELL_REF
 

Macros

#define _CMLIB_DEBUG_   1
 
#define CMLTRACE(x, ...)   if (x & CmlibTraceLevel) DbgPrint(__VA_ARGS__)
 
#define PAGED_CODE()
 
#define _WINDEF_
 
#define _WINBASE_
 
#define _WINNLS_
 
#define CMLIB_HCELL_DEBUG   0x01
 
#define ROUND_UP(a, b)   ((((a)+(b)-1)/(b))*(b))
 
#define ROUND_DOWN(a, b)   (((a)/(b))*(b))
 
#define TAG_CM   ' MC'
 
#define TAG_KCB   'bkMC'
 
#define TAG_CMHIVE   'vHMC'
 
#define TAG_CMSD   'DSMC'
 
#define CMAPI   NTAPI
 
#define STATIC_CELL_PAIR_COUNT   4
 
#define ASSERT_VALUE_BIG(h, s)   ASSERTMSG("Big keys not supported!\n", !CmpIsKeyValueBig(h, s));
 
#define HvReleaseCell(h, c)
 

Typedefs

typedef struct _HV_HIVE_CELL_PAIR HV_HIVE_CELL_PAIR
 
typedef struct _HV_HIVE_CELL_PAIRPHV_HIVE_CELL_PAIR
 
typedef struct _HV_TRACK_CELL_REF HV_TRACK_CELL_REF
 
typedef struct _HV_TRACK_CELL_REFPHV_TRACK_CELL_REF
 

Functions

static BOOLEAN CmpIsKeyValueSmall (OUT PULONG RealLength, IN ULONG Length)
 
static BOOLEAN CmpIsKeyValueBig (IN PHHIVE Hive, IN ULONG Length)
 
NTSTATUS CMAPI HvInitialize (PHHIVE RegistryHive, ULONG OperationType, ULONG HiveFlags, ULONG FileType, PVOID HiveData OPTIONAL, PALLOCATE_ROUTINE Allocate, PFREE_ROUTINE Free, PFILE_SET_SIZE_ROUTINE FileSetSize, PFILE_WRITE_ROUTINE FileWrite, PFILE_READ_ROUTINE FileRead, PFILE_FLUSH_ROUTINE FileFlush, ULONG Cluster OPTIONAL, PCUNICODE_STRING FileName OPTIONAL)
 
VOID CMAPI HvFree (PHHIVE RegistryHive)
 
PVOID CMAPI HvGetCell (PHHIVE RegistryHive, HCELL_INDEX CellOffset)
 
LONG CMAPI HvGetCellSize (PHHIVE RegistryHive, PVOID Cell)
 
HCELL_INDEX CMAPI HvAllocateCell (PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage, IN HCELL_INDEX Vicinity)
 
BOOLEAN CMAPI HvIsCellAllocated (IN PHHIVE RegistryHive, IN HCELL_INDEX CellIndex)
 
HCELL_INDEX CMAPI HvReallocateCell (PHHIVE RegistryHive, HCELL_INDEX CellOffset, ULONG Size)
 
VOID CMAPI HvFreeCell (PHHIVE RegistryHive, HCELL_INDEX CellOffset)
 
BOOLEAN CMAPI HvMarkCellDirty (PHHIVE RegistryHive, HCELL_INDEX CellOffset, BOOLEAN HoldingLock)
 
BOOLEAN CMAPI HvIsCellDirty (IN PHHIVE Hive, IN HCELL_INDEX Cell)
 
BOOLEAN CMAPI HvHiveWillShrink (IN PHHIVE RegistryHive)
 
BOOLEAN CMAPI HvSyncHive (PHHIVE RegistryHive)
 
BOOLEAN CMAPI HvWriteHive (PHHIVE RegistryHive)
 
BOOLEAN CMAPI HvTrackCellRef (IN OUT PHV_TRACK_CELL_REF CellRef, IN PHHIVE Hive, IN HCELL_INDEX Cell)
 
VOID CMAPI HvReleaseFreeCellRefArray (IN OUT PHV_TRACK_CELL_REF CellRef)
 
PHBIN CMAPI HvpAddBin (PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage)
 
NTSTATUS CMAPI HvpCreateHiveFreeCellList (PHHIVE Hive)
 
ULONG CMAPI HvpHiveHeaderChecksum (PHBASE_BLOCK HiveHeader)
 
BOOLEAN CMAPI CmCreateRootNode (PHHIVE Hive, PCWSTR Name)
 
VOID CMAPI CmPrepareHive (PHHIVE RegistryHive)
 
HCELL_INDEX NTAPI CmpFindSubKeyByName (IN PHHIVE Hive, IN PCM_KEY_NODE Parent, IN PCUNICODE_STRING SearchName)
 
HCELL_INDEX NTAPI CmpFindSubKeyByNumber (IN PHHIVE Hive, IN PCM_KEY_NODE Node, IN ULONG Number)
 
ULONG NTAPI CmpComputeHashKey (IN ULONG Hash, IN PCUNICODE_STRING Name, IN BOOLEAN AllowSeparators)
 
BOOLEAN NTAPI CmpAddSubKey (IN PHHIVE Hive, IN HCELL_INDEX Parent, IN HCELL_INDEX Child)
 
BOOLEAN NTAPI CmpRemoveSubKey (IN PHHIVE Hive, IN HCELL_INDEX ParentKey, IN HCELL_INDEX TargetKey)
 
BOOLEAN NTAPI CmpMarkIndexDirty (IN PHHIVE Hive, HCELL_INDEX ParentKey, HCELL_INDEX TargetKey)
 
LONG NTAPI CmpCompareCompressedName (IN PCUNICODE_STRING SearchName, IN PWCHAR CompressedName, IN ULONG NameLength)
 
USHORT NTAPI CmpNameSize (IN PHHIVE Hive, IN PUNICODE_STRING Name)
 
USHORT NTAPI CmpCompressedNameSize (IN PWCHAR Name, IN ULONG Length)
 
USHORT NTAPI CmpCopyName (IN PHHIVE Hive, OUT PWCHAR Destination, IN PUNICODE_STRING Source)
 
VOID NTAPI CmpCopyCompressedName (OUT PWCHAR Destination, IN ULONG DestinationLength, IN PWCHAR Source, IN ULONG SourceLength)
 
BOOLEAN NTAPI CmpFindNameInList (IN PHHIVE Hive, IN PCHILD_LIST ChildList, IN PUNICODE_STRING Name, OUT PULONG ChildIndex OPTIONAL, OUT PHCELL_INDEX CellIndex)
 
HCELL_INDEX NTAPI CmpFindValueByName (IN PHHIVE Hive, IN PCM_KEY_NODE KeyNode, IN PUNICODE_STRING Name)
 
PCELL_DATA NTAPI CmpValueToData (IN PHHIVE Hive, IN PCM_KEY_VALUE Value, OUT PULONG Length)
 
NTSTATUS NTAPI CmpSetValueDataNew (IN PHHIVE Hive, IN PVOID Data, IN ULONG DataSize, IN HSTORAGE_TYPE StorageType, IN HCELL_INDEX ValueCell, OUT PHCELL_INDEX DataCell)
 
NTSTATUS NTAPI CmpAddValueToList (IN PHHIVE Hive, IN HCELL_INDEX ValueCell, IN ULONG Index, IN HSTORAGE_TYPE StorageType, IN OUT PCHILD_LIST ChildList)
 
BOOLEAN NTAPI CmpFreeValue (IN PHHIVE Hive, IN HCELL_INDEX Cell)
 
BOOLEAN NTAPI CmpMarkValueDataDirty (IN PHHIVE Hive, IN PCM_KEY_VALUE Value)
 
BOOLEAN NTAPI CmpFreeValueData (IN PHHIVE Hive, IN HCELL_INDEX DataCell, IN ULONG DataLength)
 
NTSTATUS NTAPI CmpRemoveValueFromList (IN PHHIVE Hive, IN ULONG Index, IN OUT PCHILD_LIST ChildList)
 
BOOLEAN NTAPI CmpGetValueData (IN PHHIVE Hive, IN PCM_KEY_VALUE Value, OUT PULONG Length, OUT PVOID *Buffer, OUT PBOOLEAN BufferAllocated, OUT PHCELL_INDEX CellToRelease)
 
NTSTATUS NTAPI CmpCopyKeyValueList (IN PHHIVE SourceHive, IN PCHILD_LIST SrcValueList, IN PHHIVE DestinationHive, IN OUT PCHILD_LIST DestValueList, IN HSTORAGE_TYPE StorageType)
 
NTSTATUS NTAPI CmpFreeKeyByCell (IN PHHIVE Hive, IN HCELL_INDEX Cell, IN BOOLEAN Unlink)
 
VOID NTAPI CmpRemoveSecurityCellList (IN PHHIVE Hive, IN HCELL_INDEX SecurityCell)
 
VOID NTAPI CmpFreeSecurityDescriptor (IN PHHIVE Hive, IN HCELL_INDEX Cell)
 
PVOID NTAPI CmpAllocate (IN SIZE_T Size, IN BOOLEAN Paged, IN ULONG Tag)
 
VOID NTAPI CmpFree (IN PVOID Ptr, IN ULONG Quota)
 

Variables

ULONG CmlibTraceLevel
 

Macro Definition Documentation

◆ _CMLIB_DEBUG_

#define _CMLIB_DEBUG_   1

Definition at line 14 of file cmlib.h.

◆ _WINBASE_

#define _WINBASE_

Definition at line 177 of file cmlib.h.

◆ _WINDEF_

#define _WINDEF_

Definition at line 176 of file cmlib.h.

◆ _WINNLS_

#define _WINNLS_

Definition at line 178 of file cmlib.h.

◆ ASSERT_VALUE_BIG

#define ASSERT_VALUE_BIG (   h,
  s 
)    ASSERTMSG("Big keys not supported!\n", !CmpIsKeyValueBig(h, s));

Definition at line 315 of file cmlib.h.

◆ CMAPI

#define CMAPI   NTAPI

Definition at line 208 of file cmlib.h.

◆ CMLIB_HCELL_DEBUG

#define CMLIB_HCELL_DEBUG   0x01

Definition at line 185 of file cmlib.h.

◆ CMLTRACE

#define CMLTRACE (   x,
  ... 
)    if (x & CmlibTraceLevel) DbgPrint(__VA_ARGS__)

Definition at line 162 of file cmlib.h.

◆ HvReleaseCell

#define HvReleaseCell (   h,
  c 
)
Value:
do { \
if ((h)->ReleaseCellRoutine) \
(h)->ReleaseCellRoutine(h, c); \
} while(0)
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
const GLubyte * c
Definition: glext.h:8905

Definition at line 390 of file cmlib.h.

◆ PAGED_CODE

#define PAGED_CODE ( )

Definition at line 173 of file cmlib.h.

◆ ROUND_DOWN

#define ROUND_DOWN (   a,
  b 
)    (((a)/(b))*(b))

Definition at line 189 of file cmlib.h.

◆ ROUND_UP

#define ROUND_UP (   a,
  b 
)    ((((a)+(b)-1)/(b))*(b))

Definition at line 188 of file cmlib.h.

◆ STATIC_CELL_PAIR_COUNT

#define STATIC_CELL_PAIR_COUNT   4

Definition at line 300 of file cmlib.h.

◆ TAG_CM

#define TAG_CM   ' MC'

Definition at line 203 of file cmlib.h.

◆ TAG_CMHIVE

#define TAG_CMHIVE   'vHMC'

Definition at line 205 of file cmlib.h.

◆ TAG_CMSD

#define TAG_CMSD   'DSMC'

Definition at line 206 of file cmlib.h.

◆ TAG_KCB

#define TAG_KCB   'bkMC'

Definition at line 204 of file cmlib.h.

Typedef Documentation

◆ HV_HIVE_CELL_PAIR

◆ HV_TRACK_CELL_REF

◆ PHV_HIVE_CELL_PAIR

◆ PHV_TRACK_CELL_REF

Function Documentation

◆ CmCreateRootNode()

BOOLEAN CMAPI CmCreateRootNode ( PHHIVE  Hive,
PCWSTR  Name 
)

Definition at line 17 of file cminit.c.

20 {
22  PCM_KEY_NODE KeyCell;
23  HCELL_INDEX RootCellIndex;
24 
25  /* Initialize the node name and allocate it */
27  RootCellIndex = HvAllocateCell(Hive,
29  CmpNameSize(Hive, &KeyName),
30  Stable,
31  HCELL_NIL);
32  if (RootCellIndex == HCELL_NIL) return FALSE;
33 
34  /* Seutp the base block */
35  Hive->BaseBlock->RootCell = RootCellIndex;
37 
38  /* Get the key cell */
39  KeyCell = (PCM_KEY_NODE)HvGetCell(Hive, RootCellIndex);
40  if (!KeyCell)
41  {
42  HvFreeCell(Hive, RootCellIndex);
43  return FALSE;
44  }
45 
46  /* Setup the cell */
48  KeyCell->Flags = KEY_HIVE_ENTRY | KEY_NO_DELETE;
49  // KeQuerySystemTime(&KeyCell->LastWriteTime);
50  KeyCell->LastWriteTime.QuadPart = 0ULL;
51  KeyCell->Parent = HCELL_NIL;
52  KeyCell->SubKeyCounts[Stable] = 0;
53  KeyCell->SubKeyCounts[Volatile] = 0;
54  KeyCell->SubKeyLists[Stable] = HCELL_NIL;
55  KeyCell->SubKeyLists[Volatile] = HCELL_NIL;
56  KeyCell->ValueList.Count = 0;
57  KeyCell->ValueList.List = HCELL_NIL;
58  KeyCell->Security = HCELL_NIL;
59  KeyCell->Class = HCELL_NIL;
60  KeyCell->ClassLength = 0;
61  KeyCell->MaxNameLen = 0;
62  KeyCell->MaxClassLen = 0;
63  KeyCell->MaxValueNameLen = 0;
64  KeyCell->MaxValueDataLen = 0;
65  KeyCell->NameLength = CmpCopyName(Hive, KeyCell->Name, &KeyName);
66  if (KeyCell->NameLength < KeyName.Length) KeyCell->Flags |= KEY_COMP_NAME;
67 
68  /* Return success */
69  HvReleaseCell(Hive, RootCellIndex);
70  return TRUE;
71 }
#define KEY_COMP_NAME
Definition: cmdata.h:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
WCHAR Name[ANYSIZE_ARRAY]
Definition: cmdata.h:116
#define TRUE
Definition: types.h:120
HCELL_INDEX List
Definition: cmdata.h:75
ULONG CMAPI HvpHiveHeaderChecksum(PHBASE_BLOCK HiveHeader)
Definition: hivesum.c:17
ULONG MaxValueNameLen
Definition: cmdata.h:111
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:303
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
USHORT ClassLength
Definition: cmdata.h:115
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
#define HCELL_NIL
Definition: hivedata.h:85
HCELL_INDEX CMAPI HvAllocateCell(PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage, IN HCELL_INDEX Vicinity)
USHORT NameLength
Definition: cmdata.h:114
ULONG MaxNameLen
Definition: cmdata.h:109
HCELL_INDEX Class
Definition: cmdata.h:108
ULONG CheckSum
Definition: hivedata.h:158
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
HCELL_INDEX SubKeyLists[HTYPE_COUNT]
Definition: cmdata.h:102
struct _CM_KEY_NODE * PCM_KEY_NODE
#define ULL(a, b)
Definition: format_msg.c:27
CHILD_LIST ValueList
Definition: cmdata.h:103
USHORT NTAPI CmpCopyName(IN PHHIVE Hive, OUT PWCHAR Destination, IN PUNICODE_STRING Source)
Definition: cmname.c:21
HCELL_INDEX Parent
Definition: cmdata.h:96
ULONG HCELL_INDEX
Definition: hivedata.h:80
ULONG SubKeyCounts[HTYPE_COUNT]
Definition: cmdata.h:97
USHORT Signature
Definition: cmdata.h:92
VOID CMAPI HvFreeCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:441
USHORT NTAPI CmpNameSize(IN PHHIVE Hive, IN PUNICODE_STRING Name)
Definition: cmname.c:74
LARGE_INTEGER LastWriteTime
Definition: cmdata.h:94
#define KEY_NO_DELETE
Definition: cmdata.h:33
HCELL_INDEX RootCell
Definition: hivedata.h:143
ULONG Count
Definition: cmdata.h:74
HCELL_INDEX Security
Definition: cmdata.h:107
ULONG MaxClassLen
Definition: cmdata.h:110
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
ULONG MaxValueDataLen
Definition: cmdata.h:112
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
USHORT Flags
Definition: cmdata.h:93
LONGLONG QuadPart
Definition: typedefs.h:112
#define KEY_HIVE_ENTRY
Definition: cmdata.h:32

Referenced by CmiInitializeHive().

◆ CmpAddSubKey()

BOOLEAN NTAPI CmpAddSubKey ( IN PHHIVE  Hive,
IN HCELL_INDEX  Parent,
IN HCELL_INDEX  Child 
)

Definition at line 1467 of file cmindex.c.

1470 {
1471  PCM_KEY_NODE KeyNode;
1473  PCM_KEY_FAST_INDEX OldIndex;
1475  HCELL_INDEX IndexCell = HCELL_NIL, CellToRelease = HCELL_NIL, LeafCell;
1476  PHCELL_INDEX RootPointer = NULL;
1477  ULONG Type, i;
1478  BOOLEAN IsCompressed;
1479  PAGED_CODE();
1480 
1481  /* Get the key node */
1482  KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, Child);
1483  if (!KeyNode)
1484  {
1485  /* Shouldn't happen */
1486  ASSERT(FALSE);
1487  return FALSE;
1488  }
1489 
1490  /* Check if the name is compressed */
1491  if (KeyNode->Flags & KEY_COMP_NAME)
1492  {
1493  /* Remember for later */
1494  IsCompressed = TRUE;
1495 
1496  /* Create the compressed name and allocate it */
1497  Name.Length = CmpCompressedNameSize(KeyNode->Name, KeyNode->NameLength);
1498  Name.MaximumLength = Name.Length;
1499  Name.Buffer = Hive->Allocate(Name.Length, TRUE, TAG_CM);
1500  if (!Name.Buffer)
1501  {
1502  /* Release the cell and fail */
1503  HvReleaseCell(Hive, Child);
1504  ASSERT(FALSE);
1505  return FALSE;
1506  }
1507 
1508  /* Copy the compressed name */
1509  CmpCopyCompressedName(Name.Buffer,
1510  Name.MaximumLength,
1511  KeyNode->Name,
1512  KeyNode->NameLength);
1513  }
1514  else
1515  {
1516  /* Remember for later */
1517  IsCompressed = FALSE;
1518 
1519  /* Build the unicode string */
1520  Name.Length = KeyNode->NameLength;
1521  Name.MaximumLength = KeyNode->NameLength;
1522  Name.Buffer = &KeyNode->Name[0];
1523  }
1524 
1525  /* Release the cell */
1526  HvReleaseCell(Hive, Child);
1527 
1528  /* Get the parent node */
1529  KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, Parent);
1530  if (!KeyNode)
1531  {
1532  /* Not handled */
1533  ASSERT(FALSE);
1534  }
1535 
1536  /* Find out the type of the cell, and check if this is the first subkey */
1538  if (!KeyNode->SubKeyCounts[Type])
1539  {
1540  /* Allocate a fast leaf */
1541  IndexCell = HvAllocateCell(Hive, sizeof(CM_KEY_FAST_INDEX), Type, HCELL_NIL);
1542  if (IndexCell == HCELL_NIL)
1543  {
1544  /* Not handled */
1545  ASSERT(FALSE);
1546  }
1547 
1548  /* Get the leaf cell */
1549  Index = (PCM_KEY_INDEX)HvGetCell(Hive, IndexCell);
1550  if (!Index)
1551  {
1552  /* Shouldn't happen */
1553  ASSERT(FALSE);
1554  }
1555 
1556  /* Now check what kind of hive we're dealing with */
1557  if (Hive->Version >= 5)
1558  {
1559  /* XP Hive: Use hash leaf */
1560  Index->Signature = CM_KEY_HASH_LEAF;
1561  }
1562  else if (Hive->Version >= 3)
1563  {
1564  /* Windows 2000 and ReactOS: Use fast leaf */
1565  Index->Signature = CM_KEY_FAST_LEAF;
1566  }
1567  else
1568  {
1569  /* NT 4: Use index leaf */
1570  Index->Signature = CM_KEY_INDEX_LEAF;
1571  }
1572 
1573  /* Setup the index list */
1574  Index->Count = 0;
1575  KeyNode->SubKeyLists[Type] = IndexCell;
1576  }
1577  else
1578  {
1579  /* We already have an index, get it */
1580  Index = (PCM_KEY_INDEX)HvGetCell(Hive, KeyNode->SubKeyLists[Type]);
1581  if (!Index)
1582  {
1583  /* Not handled */
1584  ASSERT(FALSE);
1585  }
1586 
1587  /* Remember to release the cell later */
1588  CellToRelease = KeyNode->SubKeyLists[Type];
1589 
1590  /* Check if this is a fast leaf that's gotten too full */
1591  if ((Index->Signature == CM_KEY_FAST_LEAF) &&
1592  (Index->Count >= CmpMaxFastIndexPerHblock))
1593  {
1594  DPRINT("Doing Fast->Slow Leaf conversion\n");
1595 
1596  /* Mark this cell as dirty */
1597  HvMarkCellDirty(Hive, CellToRelease, FALSE);
1598 
1599  /* Convert */
1600  OldIndex = (PCM_KEY_FAST_INDEX)Index;
1601 
1602  for (i = 0; i < OldIndex->Count; i++)
1603  {
1604  Index->List[i] = OldIndex->List[i].Cell;
1605  }
1606 
1607  /* Set the new type value */
1608  Index->Signature = CM_KEY_INDEX_LEAF;
1609  }
1610  else if (((Index->Signature == CM_KEY_INDEX_LEAF) ||
1611  (Index->Signature == CM_KEY_HASH_LEAF)) &&
1612  (Index->Count >= CmpMaxIndexPerHblock))
1613  {
1614  /* This is an old/hashed leaf that's gotten too large, root it */
1615  IndexCell = HvAllocateCell(Hive,
1616  sizeof(CM_KEY_INDEX) +
1617  sizeof(HCELL_INDEX),
1618  Type,
1619  HCELL_NIL);
1620  if (IndexCell == HCELL_NIL)
1621  {
1622  /* Not handled */
1623  ASSERT(FALSE);
1624  }
1625 
1626  /* Get the index cell */
1627  Index = (PCM_KEY_INDEX)HvGetCell(Hive, IndexCell);
1628  if (!Index)
1629  {
1630  /* Shouldn't happen */
1631  ASSERT(FALSE);
1632  }
1633 
1634  /* Mark the index as a root, and set the index cell */
1635  Index->Signature = CM_KEY_INDEX_ROOT;
1636  Index->Count = 1;
1637  Index->List[0] = KeyNode->SubKeyLists[Type];
1638  KeyNode->SubKeyLists[Type] = IndexCell;
1639  }
1640  }
1641 
1642  /* Now we can choose the leaf cell */
1643  LeafCell = KeyNode->SubKeyLists[Type];
1644 
1645  /* Check if we turned the index into a root */
1646  if (Index->Signature == CM_KEY_INDEX_ROOT)
1647  {
1648  DPRINT("Leaf->Root Index Conversion\n");
1649 
1650  /* Get the leaf where to add the new entry (the routine will do
1651  * the splitting if necessary)
1652  */
1653  LeafCell = CmpSelectLeaf(Hive, KeyNode, &Name, Type, &RootPointer);
1654  if (LeafCell == HCELL_NIL)
1655  {
1656  /* Not handled */
1657  ASSERT(FALSE);
1658  }
1659  }
1660 
1661  /* Add our leaf cell */
1662  LeafCell = CmpAddToLeaf(Hive, LeafCell, Child, &Name);
1663  if (LeafCell == HCELL_NIL)
1664  {
1665  /* Not handled */
1666  ASSERT(FALSE);
1667  }
1668 
1669  /* Update the key counts */
1670  KeyNode->SubKeyCounts[Type]++;
1671 
1672  /* Check if caller wants us to return the leaf */
1673  if (RootPointer)
1674  {
1675  /* Return it */
1676  *RootPointer = LeafCell;
1677  }
1678  else
1679  {
1680  /* Otherwise, mark it as the list index for the cell */
1681  KeyNode->SubKeyLists[Type] = LeafCell;
1682  }
1683 
1684  /* If the name was compressed, free our copy */
1685  if (IsCompressed) Hive->Free(Name.Buffer, 0);
1686 
1687  /* Release all our cells */
1688  if (IndexCell != HCELL_NIL) HvReleaseCell(Hive, IndexCell);
1689  if (CellToRelease != HCELL_NIL) HvReleaseCell(Hive, CellToRelease);
1690  HvReleaseCell(Hive, Parent);
1691  return TRUE;
1692 }
#define KEY_COMP_NAME
Definition: cmdata.h:35
WCHAR Name[ANYSIZE_ARRAY]
Definition: cmdata.h:116
#define TRUE
Definition: types.h:120
struct _CM_KEY_INDEX * PCM_KEY_INDEX
Type
Definition: Type.h:6
HCELL_INDEX Cell
Definition: cmdata.h:165
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
#define HCELL_NIL
Definition: hivedata.h:85
#define HvGetCellType(Cell)
Definition: hivedata.h:95
HCELL_INDEX CMAPI HvAllocateCell(PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage, IN HCELL_INDEX Vicinity)
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
Definition: acpixf.h:722
USHORT NameLength
Definition: cmdata.h:114
#define PAGED_CODE()
Definition: video.h:57
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
VOID NTAPI CmpCopyCompressedName(OUT PWCHAR Destination, IN ULONG DestinationLength, IN PWCHAR Source, IN ULONG SourceLength)
Definition: cmname.c:56
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
struct NameRec_ * Name
Definition: cdprocs.h:464
HCELL_INDEX SubKeyLists[HTYPE_COUNT]
Definition: cmdata.h:102
unsigned char BOOLEAN
#define CM_KEY_HASH_LEAF
Definition: cmdata.h:16
smooth NULL
Definition: ftsmooth.c:416
struct _CM_KEY_NODE * PCM_KEY_NODE
ULONG * PHCELL_INDEX
Definition: hivedata.h:80
CM_INDEX List[ANYSIZE_ARRAY]
Definition: cmdata.h:190
void DPRINT(...)
Definition: polytest.cpp:61
#define CM_KEY_INDEX_ROOT
Definition: cmdata.h:13
struct _CM_KEY_FAST_INDEX * PCM_KEY_FAST_INDEX
ULONG HCELL_INDEX
Definition: hivedata.h:80
ULONG SubKeyCounts[HTYPE_COUNT]
Definition: cmdata.h:97
static const UCHAR Index[8]
Definition: usbohci.c:18
BOOLEAN CMAPI HvMarkCellDirty(PHHIVE RegistryHive, HCELL_INDEX CellOffset, BOOLEAN HoldingLock)
Definition: hivecell.c:100
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define TAG_CM
Definition: cmlib.h:203
HCELL_INDEX NTAPI CmpAddToLeaf(IN PHHIVE Hive, IN HCELL_INDEX LeafCell, IN HCELL_INDEX NewKey, IN PUNICODE_STRING Name)
Definition: cmindex.c:923
HCELL_INDEX NTAPI CmpSelectLeaf(IN PHHIVE Hive, IN PCM_KEY_NODE KeyNode, IN PUNICODE_STRING Name, IN HSTORAGE_TYPE Type, IN PHCELL_INDEX *RootCell)
Definition: cmindex.c:1266
#define CM_KEY_FAST_LEAF
Definition: cmdata.h:15
unsigned int ULONG
Definition: retypes.h:1
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE ACPI_HANDLE Child
Definition: acpixf.h:722
#define CM_KEY_INDEX_LEAF
Definition: cmdata.h:14
#define CmpMaxIndexPerHblock
Definition: cmindex.c:23
USHORT NTAPI CmpCompressedNameSize(IN PWCHAR Name, IN ULONG Length)
Definition: cmname.c:95
#define CmpMaxFastIndexPerHblock
Definition: cmindex.c:19
USHORT Flags
Definition: cmdata.h:93

Referenced by CmiAddSubKey(), CmpCreateLinkNode(), CmpDeepCopyKeyInternal(), and CmpDoCreate().

◆ CmpAddValueToList()

NTSTATUS NTAPI CmpAddValueToList ( IN PHHIVE  Hive,
IN HCELL_INDEX  ValueCell,
IN ULONG  Index,
IN HSTORAGE_TYPE  StorageType,
IN OUT PCHILD_LIST  ChildList 
)

Definition at line 207 of file cmvalue.c.

212 {
213  HCELL_INDEX ListCell;
214  ULONG ChildCount, Length, i;
215  PCELL_DATA CellData;
216  PAGED_CODE();
217 
218  /* Sanity check */
219  ASSERT((((LONG)Index) >= 0) && (Index <= ChildList->Count));
220 
221  /* Get the number of entries in the child list */
222  ChildCount = ChildList->Count;
223  ChildCount++;
224  if (ChildCount > 1)
225  {
226  ASSERT(ChildList->List != HCELL_NIL);
227 
228  /* The cell should be dirty at this point */
229  ASSERT(HvIsCellDirty(Hive, ChildList->List));
230 
231  /* Check if we have less then 100 children */
232  if (ChildCount < 100)
233  {
234  /* Allocate just enough as requested */
235  Length = ChildCount * sizeof(HCELL_INDEX);
236  }
237  else
238  {
239  /* Otherwise, we have quite a few, so allocate a batch */
240  Length = ROUND_UP(ChildCount, 100) * sizeof(HCELL_INDEX);
241  if (Length > HBLOCK_SIZE)
242  {
243  /* But make sure we don't allocate beyond our block size */
245  }
246  }
247 
248  /* Perform the allocation */
249  ListCell = HvReallocateCell(Hive, ChildList->List, Length);
250  }
251  else
252  {
253  /* This is our first child, so allocate a single cell */
254  ASSERT(ChildList->List == HCELL_NIL);
255  ListCell = HvAllocateCell(Hive, sizeof(HCELL_INDEX), StorageType, HCELL_NIL);
256  }
257 
258  /* Fail if we couldn't get a cell */
259  if (ListCell == HCELL_NIL) return STATUS_INSUFFICIENT_RESOURCES;
260 
261  /* Set this cell as the child list's list cell */
262  ChildList->List = ListCell;
263 
264  /* Get the actual key list memory */
265  CellData = HvGetCell(Hive, ListCell);
266  ASSERT(CellData != NULL);
267 
268  /* Loop all the children */
269  for (i = ChildCount - 1; i > Index; i--)
270  {
271  /* Move them all down */
272  CellData->u.KeyList[i] = CellData->u.KeyList[i - 1];
273  }
274 
275  /* Insert us on top now */
276  CellData->u.KeyList[Index] = ValueCell;
277  ChildList->Count = ChildCount;
278 
279  /* Release the list cell and make sure the value cell is dirty */
280  HvReleaseCell(Hive, ListCell);
281  ASSERT(HvIsCellDirty(Hive, ValueCell));
282 
283  /* We're done here */
284  return STATUS_SUCCESS;
285 }
BOOLEAN CMAPI HvIsCellDirty(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: hivecell.c:126
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define HBLOCK_SIZE
Definition: hivedata.h:41
#define ROUND_UP(n, align)
Definition: eventvwr.h:31
HCELL_INDEX CMAPI HvReallocateCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset, ULONG Size)
Definition: hivecell.c:394
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
#define HCELL_NIL
Definition: hivedata.h:85
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
HCELL_INDEX CMAPI HvAllocateCell(PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage, IN HCELL_INDEX Vicinity)
#define PAGED_CODE()
Definition: video.h:57
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
long LONG
Definition: pedump.c:60
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
smooth NULL
Definition: ftsmooth.c:416
ULONG HCELL_INDEX
Definition: hivedata.h:80
static const UCHAR Index[8]
Definition: usbohci.c:18
HCELL_INDEX KeyList[ANYSIZE_ARRAY]
Definition: cmdata.h:205
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
union _CELL_DATA::@3902 u
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by CmiAddValueKey(), CmpCopyKeyValueList(), and CmpSetValueKeyNew().

◆ CmpAllocate()

PVOID NTAPI CmpAllocate ( IN SIZE_T  Size,
IN BOOLEAN  Paged,
IN ULONG  Tag 
)

Definition at line 34 of file registry.c.

38 {
41 
42  return FrLdrTempAlloc(Size, Tag);
43 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:177
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
IN ULONG IN ULONG Tag
Definition: evtlib.h:159

Referenced by CmiInitializeHive(), and RegImportBinaryHive().

◆ CmpCompareCompressedName()

LONG NTAPI CmpCompareCompressedName ( IN PCUNICODE_STRING  SearchName,
IN PWCHAR  CompressedName,
IN ULONG  NameLength 
)

Definition at line 109 of file cmname.c.

112 {
113  WCHAR* p;
114  UCHAR* pp;
115  WCHAR chr1, chr2;
116  USHORT SearchLength;
117  LONG Result;
118 
119  /* Set the pointers and length and then loop */
120  p = SearchName->Buffer;
121  pp = (PUCHAR)CompressedName;
122  SearchLength = (SearchName->Length / sizeof(WCHAR));
123  while (SearchLength > 0 && NameLength > 0)
124  {
125  /* Get the characters */
126  chr1 = *p++;
127  chr2 = (WCHAR)(*pp++);
128 
129  /* Check if we have a direct match */
130  if (chr1 != chr2)
131  {
132  /* See if they match and return result if they don't */
133  Result = (LONG)RtlUpcaseUnicodeChar(chr1) -
134  (LONG)RtlUpcaseUnicodeChar(chr2);
135  if (Result) return Result;
136  }
137 
138  /* Next chars */
139  SearchLength--;
140  NameLength--;
141  }
142 
143  /* Return the difference directly */
144  return SearchLength - NameLength;
145 }
unsigned char * PUCHAR
Definition: retypes.h:3
NTSYSAPI WCHAR NTAPI RtlUpcaseUnicodeChar(WCHAR Source)
long LONG
Definition: pedump.c:60
#define pp
Definition: hlsl.yy.c:978
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned short USHORT
Definition: pedump.c:61
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by CmpDoCompareKeyName(), CmpFindNameInList(), CmpFindValueByNameFromCache(), and CmpGetNameControlBlock().

◆ CmpCompressedNameSize()

USHORT NTAPI CmpCompressedNameSize ( IN PWCHAR  Name,
IN ULONG  Length 
)

Definition at line 95 of file cmname.c.

97 {
98  /*
99  * Don't remove this: compressed names are "opaque" and just because
100  * the current implementation turns them into ansi-names doesn't mean
101  * that it will remain that way forever, so -never- assume this code
102  * below internally!
103  */
104  return (USHORT)Length * sizeof(WCHAR);
105 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned short USHORT
Definition: pedump.c:61

Referenced by BiEnumerateSubKeys(), CmpAddDriverToList(), CmpAddSubKey(), CmpConstructName(), CmpGetHiveName(), CmpIsSafe(), CmpMarkIndexDirty(), CmpQueryKeyData(), CmpQueryKeyDataFromCache(), CmpQueryKeyValueData(), CmpQueryNameInformation(), CmpRemoveSubKey(), and RegEnumKey().

◆ CmpComputeHashKey()

ULONG NTAPI CmpComputeHashKey ( IN ULONG  Hash,
IN PCUNICODE_STRING  Name,
IN BOOLEAN  AllowSeparators 
)

Definition at line 460 of file cmindex.c.

463 {
464  LPWSTR Cp;
465  ULONG Value, i;
466 
467  /* Make some sanity checks on our parameters */
468  ASSERT((Name->Length == 0) ||
469  (AllowSeparators) ||
470  (Name->Buffer[0] != OBJ_NAME_PATH_SEPARATOR));
471 
472  /* If the name is empty, there is nothing to hash! */
473  if (!Name->Length) return Hash;
474 
475  /* Set the buffer and loop every character */
476  Cp = Name->Buffer;
477  for (i = 0; i < Name->Length; i += sizeof(WCHAR), Cp++)
478  {
479  /* Make sure we don't have a separator when we shouldn't */
480  ASSERT(AllowSeparators || (*Cp != OBJ_NAME_PATH_SEPARATOR));
481 
482  /* Check what kind of char we have */
483  if (*Cp >= L'a')
484  {
485  /* In the lower case region... is it truly lower case? */
486  if (*Cp < L'z')
487  {
488  /* Yes! Calculate it ourselves! */
489  Value = *Cp - L'a' + L'A';
490  }
491  else
492  {
493  /* No, use the API */
495  }
496  }
497  else
498  {
499  /* Reuse the char, it's already upcased */
500  Value = *Cp;
501  }
502 
503  /* Multiply by a prime and add our value */
504  Hash *= 37;
505  Hash += Value;
506  }
507 
508  /* Return the hash */
509  return Hash;
510 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
static int Hash(const char *)
Definition: reader.c:2257
NTSYSAPI WCHAR NTAPI RtlUpcaseUnicodeChar(WCHAR Source)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
__wchar_t WCHAR
Definition: xmlstorage.h:180
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
unsigned int ULONG
Definition: retypes.h:1
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by CmpAddToLeaf(), and CmpFindSubKeyByHash().

◆ CmpCopyCompressedName()

VOID NTAPI CmpCopyCompressedName ( OUT PWCHAR  Destination,
IN ULONG  DestinationLength,
IN PWCHAR  Source,
IN ULONG  SourceLength 
)

Definition at line 56 of file cmname.c.

60 {
61  ULONG i, Length;
62 
63  /* Get the actual length to copy */
64  Length = min(DestinationLength / sizeof(WCHAR), SourceLength);
65  for (i = 0; i < Length; i++)
66  {
67  /* Copy each character */
68  Destination[i] = (WCHAR)((PUCHAR)Source)[i];
69  }
70 }
unsigned char * PUCHAR
Definition: retypes.h:3
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2891
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define min(a, b)
Definition: monoChain.cc:55
unsigned int ULONG
Definition: retypes.h:1
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167

Referenced by BiEnumerateSubKeys(), CmpAddDriverToList(), CmpAddSubKey(), CmpGetHiveName(), CmpIsSafe(), CmpMarkIndexDirty(), CmpQueryKeyData(), CmpQueryKeyValueData(), CmpQueryNameInformation(), CmpRemoveSubKey(), and RegEnumKey().

◆ CmpCopyKeyValueList()

NTSTATUS NTAPI CmpCopyKeyValueList ( IN PHHIVE  SourceHive,
IN PCHILD_LIST  SrcValueList,
IN PHHIVE  DestinationHive,
IN OUT PCHILD_LIST  DestValueList,
IN HSTORAGE_TYPE  StorageType 
)

Definition at line 521 of file cmvalue.c.

526 {
528  PCELL_DATA SrcListData = NULL, DestListData = NULL;
529  HCELL_INDEX NewValue;
530  ULONG Index;
531 
532  PAGED_CODE();
533 
534  /* Reset the destination value list */
535  DestValueList->Count = 0;
536  DestValueList->List = HCELL_NIL;
537 
538  /* Check if the list is empty */
539  if (!SrcValueList->Count)
540  return STATUS_SUCCESS;
541 
542  /* Get the source value list */
543  SrcListData = HvGetCell(SourceHive, SrcValueList->List);
544  ASSERT(SrcListData);
545 
546  /* Copy the actual values */
547  for (Index = 0; Index < SrcValueList->Count; Index++)
548  {
549  NewValue = CmpCopyValue(SourceHive,
550  SrcListData->u.KeyList[Index],
551  DestinationHive,
552  StorageType);
553  if (NewValue == HCELL_NIL)
554  {
555  /* Not enough storage space, stop there and cleanup afterwards */
557  break;
558  }
559 
560  /* Add this value cell to the child list */
561  Status = CmpAddValueToList(DestinationHive,
562  NewValue,
563  Index,
564  StorageType,
565  DestValueList);
566  if (!NT_SUCCESS(Status))
567  {
568  /* Not enough storage space, stop there */
569 
570  /* Cleanup the newly-created value here, the other ones will be cleaned up afterwards */
571  if (!CmpFreeValue(DestinationHive, NewValue))
572  HvFreeCell(DestinationHive, NewValue);
573  break;
574  }
575  }
576 
577  /* Revert-cleanup if failure */
578  if (!NT_SUCCESS(Status) && (DestValueList->List != HCELL_NIL))
579  {
580  /* Do not use CmpRemoveValueFromList but directly delete the data */
581 
582  /* Get the destination value list */
583  DestListData = HvGetCell(DestinationHive, DestValueList->List);
584  ASSERT(DestListData);
585 
586  /* Delete each copied value */
587  while (Index--)
588  {
589  NewValue = DestListData->u.KeyList[Index];
590  if (!CmpFreeValue(DestinationHive, NewValue))
591  HvFreeCell(DestinationHive, NewValue);
592  }
593 
594  /* Release and free the list */
595  HvReleaseCell(DestinationHive, DestValueList->List);
596  HvFreeCell(DestinationHive, DestValueList->List);
597 
598  DestValueList->Count = 0;
599  DestValueList->List = HCELL_NIL;
600  }
601 
602  /* Release the cells */
603  HvReleaseCell(SourceHive, SrcValueList->List);
604 
605  return Status;
606 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
LONG NTSTATUS
Definition: precomp.h:26
#define HCELL_NIL
Definition: hivedata.h:85
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS NTAPI CmpAddValueToList(IN PHHIVE Hive, IN HCELL_INDEX ValueCell, IN ULONG Index, IN HSTORAGE_TYPE StorageType, IN OUT PCHILD_LIST ChildList)
Definition: cmvalue.c:207
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG HCELL_INDEX
Definition: hivedata.h:80
static const UCHAR Index[8]
Definition: usbohci.c:18
HCELL_INDEX KeyList[ANYSIZE_ARRAY]
Definition: cmdata.h:205
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID CMAPI HvFreeCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:441
Status
Definition: gdiplustypes.h:24
union _CELL_DATA::@3902 u
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN NTAPI CmpFreeValue(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: cmvalue.c:73
return STATUS_SUCCESS
Definition: btrfs.c:2966
HCELL_INDEX NTAPI CmpCopyValue(IN PHHIVE SourceHive, IN HCELL_INDEX SourceValueCell, IN PHHIVE DestinationHive, IN HSTORAGE_TYPE StorageType)
Definition: cmvalue.c:417

Referenced by CmpDeepCopyKeyInternal().

◆ CmpCopyName()

USHORT NTAPI CmpCopyName ( IN PHHIVE  Hive,
OUT PWCHAR  Destination,
IN PUNICODE_STRING  Source 
)

Definition at line 21 of file cmname.c.

24 {
25  ULONG i;
26 
27  /* Check for old hives */
28  if (Hive->Version == 1)
29  {
30  /* Just copy the source directly */
31  RtlCopyMemory(Destination, Source->Buffer, Source->Length);
32  return Source->Length;
33  }
34 
35  /* For new versions, check for compressed name */
36  for (i = 0; i < (Source->Length / sizeof(WCHAR)); i++)
37  {
38  /* Check if the name is non compressed */
39  if (Source->Buffer[i] > (UCHAR)-1)
40  {
41  /* Do the copy */
42  RtlCopyMemory(Destination, Source->Buffer, Source->Length);
43  return Source->Length;
44  }
45 
46  /* Copy this character */
47  ((PCHAR)Destination)[i] = (CHAR)(Source->Buffer[i]);
48  }
49 
50  /* Compressed name, return length */
51  return Source->Length / sizeof(WCHAR);
52 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define PCHAR
Definition: match.c:90
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2891
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned int ULONG
Definition: retypes.h:1
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
#define CHAR(Char)

Referenced by CmCreateRootNode(), CmiAddValueKey(), CmiCreateSubKey(), CmpCreateLinkNode(), CmpCreateRootNode(), CmpDoCreateChild(), and CmpSetValueKeyNew().

◆ CmpFindNameInList()

BOOLEAN NTAPI CmpFindNameInList ( IN PHHIVE  Hive,
IN PCHILD_LIST  ChildList,
IN PUNICODE_STRING  Name,
OUT PULONG ChildIndex  OPTIONAL,
OUT PHCELL_INDEX  CellIndex 
)

Definition at line 149 of file cmname.c.

154 {
155  PCELL_DATA CellData;
156  HCELL_INDEX CellToRelease = HCELL_NIL;
157  ULONG i;
158  PCM_KEY_VALUE KeyValue;
159  LONG Result;
160  UNICODE_STRING SearchName;
162 
163  /* Make sure there's actually something on the list */
164  if (ChildList->Count != 0)
165  {
166  /* Get the cell data */
167  CellData = (PCELL_DATA)HvGetCell(Hive, ChildList->List);
168  if (!CellData)
169  {
170  /* Couldn't get the cell... tell the caller */
171  *CellIndex = HCELL_NIL;
172  return FALSE;
173  }
174 
175  /* Now loop every entry */
176  for (i = 0; i < ChildList->Count; i++)
177  {
178  /* Check if we have a cell to release */
179  if (CellToRelease != HCELL_NIL)
180  {
181  /* Release it */
182  HvReleaseCell(Hive, CellToRelease);
183  CellToRelease = HCELL_NIL;
184  }
185 
186  /* Get this value */
187  KeyValue = (PCM_KEY_VALUE)HvGetCell(Hive, CellData->u.KeyList[i]);
188  if (!KeyValue)
189  {
190  /* Return with no data found */
191  *CellIndex = HCELL_NIL;
192  Success = FALSE;
193  goto Return;
194  }
195 
196  /* Save the cell to release */
197  CellToRelease = CellData->u.KeyList[i];
198 
199  /* Check if it's a compressed value name */
200  if (KeyValue->Flags & VALUE_COMP_NAME)
201  {
202  /* Compare compressed names */
204  KeyValue->Name,
205  KeyValue->NameLength);
206  }
207  else
208  {
209  /* Compare the Unicode name directly */
210  SearchName.Length = KeyValue->NameLength;
211  SearchName.MaximumLength = SearchName.Length;
212  SearchName.Buffer = KeyValue->Name;
213  Result = RtlCompareUnicodeString(Name, &SearchName, TRUE);
214  }
215 
216  /* Check if we found it */
217  if (!Result)
218  {
219  /* We did... return info to caller */
220  if (ChildIndex) *ChildIndex = i;
221  *CellIndex = CellData->u.KeyList[i];
222 
223  /* Set success state */
224  Success = TRUE;
225  goto Return;
226  }
227  }
228 
229  /* Got to the end of the list */
230  if (ChildIndex) *ChildIndex = i;
231  *CellIndex = HCELL_NIL;
232 
233  /* Nothing found if we got here */
234  Success = TRUE;
235  goto Return;
236  }
237 
238  /* Nothing found... check if the caller wanted more info */
239  ASSERT(ChildList->Count == 0);
240  if (ChildIndex) *ChildIndex = 0;
241  *CellIndex = HCELL_NIL;
242 
243  /* Nothing found if we got here */
244  return TRUE;
245 
246 Return:
247  /* Release the first cell we got */
248  if (CellData) HvReleaseCell(Hive, ChildList->List);
249 
250  /* Release the secondary one, if we have one */
251  if (CellToRelease) HvReleaseCell(Hive, CellToRelease);
252  return Success;
253 }
#define TRUE
Definition: types.h:120
USHORT Flags
Definition: cmdata.h:129
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
#define HCELL_NIL
Definition: hivedata.h:85
LONG NTAPI CmpCompareCompressedName(IN PCUNICODE_STRING SearchName, IN PWCHAR CompressedName, IN ULONG NameLength)
Definition: cmname.c:109
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
struct _CELL_DATA * PCELL_DATA
USHORT NameLength
Definition: cmdata.h:125
long LONG
Definition: pedump.c:60
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
WCHAR Name[ANYSIZE_ARRAY]
Definition: cmdata.h:131
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
ULONG HCELL_INDEX
Definition: hivedata.h:80
#define VALUE_COMP_NAME
Definition: cmdata.h:44
HCELL_INDEX KeyList[ANYSIZE_ARRAY]
Definition: cmdata.h:205
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
struct _CM_KEY_VALUE * PCM_KEY_VALUE
union _CELL_DATA::@3902 u
unsigned int ULONG
Definition: retypes.h:1

Referenced by BiGetRegistryValue(), CmDeleteValueKey(), CmpFindValueByName(), CmSetValueKey(), RegDeleteValueW(), and RegSetValueExW().

◆ CmpFindSubKeyByName()

HCELL_INDEX NTAPI CmpFindSubKeyByName ( IN PHHIVE  Hive,
IN PCM_KEY_NODE  Parent,
IN PCUNICODE_STRING  SearchName 
)

Definition at line 683 of file cmindex.c.

686 {
687  ULONG i;
688  PCM_KEY_INDEX IndexRoot;
689  HCELL_INDEX SubKey, CellToRelease;
690  ULONG Found;
691 
692  /* Loop each storage type */
693  for (i = 0; i < Hive->StorageTypeCount; i++)
694  {
695  /* Make sure the parent node has subkeys */
696  if (Parent->SubKeyCounts[i])
697  {
698  /* Get the Index */
699  IndexRoot = (PCM_KEY_INDEX)HvGetCell(Hive, Parent->SubKeyLists[i]);
700  if (!IndexRoot) return HCELL_NIL;
701 
702  /* Get the cell we'll need to release */
703  CellToRelease = Parent->SubKeyLists[i];
704 
705  /* Check if this is another index root */
706  if (IndexRoot->Signature == CM_KEY_INDEX_ROOT)
707  {
708  /* Lookup the name in the root */
709  Found = CmpFindSubKeyInRoot(Hive,
710  IndexRoot,
711  SearchName,
712  &SubKey);
713 
714  /* Release the previous cell */
715  ASSERT(CellToRelease != HCELL_NIL);
716  HvReleaseCell(Hive, CellToRelease);
717 
718  /* Make sure we found something valid */
719  if (Found & INVALID_INDEX) break;
720 
721  /* Get the new Index Root and set the new cell to be released */
722  if (SubKey == HCELL_NIL) continue;
723  CellToRelease = SubKey;
724  IndexRoot = (PCM_KEY_INDEX)HvGetCell(Hive, SubKey);
725  }
726 
727  /* Make sure the signature is what we expect it to be */
728  ASSERT((IndexRoot->Signature == CM_KEY_INDEX_LEAF) ||
729  (IndexRoot->Signature == CM_KEY_FAST_LEAF) ||
730  (IndexRoot->Signature == CM_KEY_HASH_LEAF));
731 
732  /* Check if this isn't a hashed leaf */
733  if (IndexRoot->Signature != CM_KEY_HASH_LEAF)
734  {
735  /* Find the subkey in the leaf */
736  Found = CmpFindSubKeyInLeaf(Hive,
737  IndexRoot,
738  SearchName,
739  &SubKey);
740 
741  /* Release the previous cell */
742  ASSERT(CellToRelease != HCELL_NIL);
743  HvReleaseCell(Hive, CellToRelease);
744 
745  /* Make sure we found a valid index */
746  if (Found & INVALID_INDEX) break;
747  }
748  else
749  {
750  /* Find the subkey in the hash */
751  SubKey = CmpFindSubKeyByHash(Hive,
752  (PCM_KEY_FAST_INDEX)IndexRoot,
753  SearchName);
754 
755  /* Release the previous cell */
756  ASSERT(CellToRelease != HCELL_NIL);
757  HvReleaseCell(Hive, CellToRelease);
758  }
759 
760  /* Make sure we got a valid subkey and return it */
761  if (SubKey != HCELL_NIL) return SubKey;
762  }
763  }
764 
765  /* If we got here, then we failed */
766  return HCELL_NIL;
767 }
ULONG NTAPI CmpFindSubKeyInLeaf(IN PHHIVE Hive, IN PCM_KEY_INDEX Index, IN PCUNICODE_STRING SearchName, IN PHCELL_INDEX SubKey)
Definition: cmindex.c:358
struct _CM_KEY_INDEX * PCM_KEY_INDEX
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
#define HCELL_NIL
Definition: hivedata.h:85
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
Definition: acpixf.h:722
ULONG NTAPI CmpFindSubKeyInRoot(IN PHHIVE Hive, IN PCM_KEY_INDEX Index, IN PCUNICODE_STRING SearchName, IN PHCELL_INDEX SubKey)
Definition: cmindex.c:143
#define INVALID_INDEX
Definition: cmindex.c:17
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
USHORT Signature
Definition: cmdata.h:178
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
#define CM_KEY_HASH_LEAF
Definition: cmdata.h:16
return Found
Definition: dirsup.c:1270
#define CM_KEY_INDEX_ROOT
Definition: cmdata.h:13
ULONG HCELL_INDEX
Definition: hivedata.h:80
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static HCELL_INDEX NTAPI CmpFindSubKeyByHash(IN PHHIVE Hive, IN PCM_KEY_FAST_INDEX FastIndex, IN PCUNICODE_STRING SearchName)
Definition: cmindex.c:646
#define CM_KEY_FAST_LEAF
Definition: cmdata.h:15
unsigned int ULONG
Definition: retypes.h:1
#define CM_KEY_INDEX_LEAF
Definition: cmdata.h:14

Referenced by BiLoadHive(), BiOpenKey(), CmGetSystemControlValues(), CmpDoCreate(), CmpFindControlSet(), CmpFindDrivers(), CmpIsSafe(), CmpParseKey(), CmpSortDriverList(), CmpWalkPath(), RegOpenKey(), and RegpCreateOrOpenKey().

◆ CmpFindSubKeyByNumber()

HCELL_INDEX NTAPI CmpFindSubKeyByNumber ( IN PHHIVE  Hive,
IN PCM_KEY_NODE  Node,
IN ULONG  Number 
)

Definition at line 600 of file cmindex.c.

603 {
606 
607  /* Check if it's in the stable list */
608  if (Number < Node->SubKeyCounts[Stable])
609  {
610  /* Get the actual key index */
611  Index = (PCM_KEY_INDEX)HvGetCell(Hive, Node->SubKeyLists[Stable]);
612  if (!Index) return HCELL_NIL;
613 
614  /* Do a search inside it */
616 
617  /* Release the cell and return the result */
618  HvReleaseCell(Hive, Node->SubKeyLists[Stable]);
619  return Result;
620  }
621  else if (Hive->StorageTypeCount > Volatile)
622  {
623  /* It's in the volatile list */
624  Number = Number - Node->SubKeyCounts[Stable];
625  if (Number < Node->SubKeyCounts[Volatile])
626  {
627  /* Get the actual key index */
628  Index = (PCM_KEY_INDEX)HvGetCell(Hive, Node->SubKeyLists[Volatile]);
629  if (!Index) return HCELL_NIL;
630 
631  /* Do a search inside it */
633 
634  /* Release the cell and return the result */
635  HvReleaseCell(Hive, Node->SubKeyLists[Volatile]);
636  return Result;
637  }
638  }
639 
640  /* Nothing was found */
641  return HCELL_NIL;
642 }
struct _CM_KEY_INDEX * PCM_KEY_INDEX
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
#define HCELL_NIL
Definition: hivedata.h:85
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
HCELL_INDEX NTAPI CmpDoFindSubKeyByNumber(IN PHHIVE Hive, IN PCM_KEY_INDEX Index, IN ULONG Number)
Definition: cmindex.c:514
ULONG HCELL_INDEX
Definition: hivedata.h:80
static const UCHAR Index[8]
Definition: usbohci.c:18
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:204
Definition: dlist.c:348

Referenced by BiEnumerateSubKeys(), CmEnumerateKey(), CmpDeepCopyKeyInternal(), CmpFindDrivers(), and RegEnumKey().

◆ CmpFindValueByName()

HCELL_INDEX NTAPI CmpFindValueByName ( IN PHHIVE  Hive,
IN PCM_KEY_NODE  KeyNode,
IN PUNICODE_STRING  Name 
)

Definition at line 99 of file cmvalue.c.

102 {
103  HCELL_INDEX CellIndex;
104 
105  /* Call the main function */
106  if (!CmpFindNameInList(Hive,
107  &KeyNode->ValueList,
108  Name,
109  NULL,
110  &CellIndex))
111  {
112  /* Sanity check */
113  ASSERT(CellIndex == HCELL_NIL);
114  }
115 
116  /* Return the index */
117  return CellIndex;
118 }
#define HCELL_NIL
Definition: hivedata.h:85
BOOLEAN NTAPI CmpFindNameInList(IN PHHIVE Hive, IN PCHILD_LIST ChildList, IN PUNICODE_STRING Name, OUT PULONG ChildIndex OPTIONAL, OUT PHCELL_INDEX CellIndex)
Definition: cmname.c:149
smooth NULL
Definition: ftsmooth.c:416
ULONG HCELL_INDEX
Definition: hivedata.h:80
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by CmGetSystemControlValues(), CmpAddDriverToList(), CmpFindControlSet(), CmpFindTagIndex(), CmpGetSymbolicLink(), CmpIsLoadType(), CmpIsSafe(), CmpSortDriverList(), RegQueryValue(), and RegQueryValueExW().

◆ CmpFree()

VOID NTAPI CmpFree ( IN PVOID  Ptr,
IN ULONG  Quota 
)

Definition at line 47 of file registry.c.

50 {
52  FrLdrTempFree(Ptr, 0);
53 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:186

Referenced by CmiInitializeHive(), and RegImportBinaryHive().

◆ CmpFreeKeyByCell()

NTSTATUS NTAPI CmpFreeKeyByCell ( IN PHHIVE  Hive,
IN HCELL_INDEX  Cell,
IN BOOLEAN  Unlink 
)

Definition at line 159 of file cmkeydel.c.

162 {
163  PCM_KEY_NODE CellData, ParentData;
164  PCELL_DATA ListData;
165  ULONG i;
166  BOOLEAN Result;
167 
168  /* Mark the entire key dirty */
169  CmpMarkKeyDirty(Hive, Cell, TRUE);
170 
171  /* Get the target node and release it */
172  CellData = HvGetCell(Hive, Cell);
173  if (!CellData) ASSERT(FALSE);
174  HvReleaseCell(Hive, Cell);
175 
176  /* Make sure we don't have subkeys */
177  ASSERT(CellData->SubKeyCounts[Stable] + CellData->SubKeyCounts[Volatile] == 0);
178 
179  /* Check if we have to unlink */
180  if (Unlink)
181  {
182  /* Remove the subkey */
183  Result = CmpRemoveSubKey(Hive, CellData->Parent, Cell);
185 
186  /* Get the parent node and release it */
187  ParentData = HvGetCell(Hive, CellData->Parent);
188  if (!ParentData) ASSERT(FALSE);
189  HvReleaseCell(Hive, CellData->Parent);
190 
191  /* Check if the parent node has no more subkeys */
192  if (ParentData->SubKeyCounts[Stable] + ParentData->SubKeyCounts[Volatile] == 0)
193  {
194  /* Then free the cached name/class lengths */
195  ParentData->MaxNameLen = 0;
196  ParentData->MaxClassLen = 0;
197  }
198  }
199 
200  // TODO: Handle predefined keys (Flags: KEY_PREDEF_HANDLE)
201  /* If this is an exit node, we don't have values */
202  if (!(CellData->Flags & KEY_HIVE_EXIT))
203  {
204  /* Check if we have any values */
205  if (CellData->ValueList.Count > 0)
206  {
207  /* Get the value list and release it */
208  ListData = HvGetCell(Hive, CellData->ValueList.List);
209  if (!ListData) ASSERT(FALSE);
210  HvReleaseCell(Hive, CellData->ValueList.List);
211 
212  /* Loop every value */
213  for (i = 0; i < CellData->ValueList.Count; i++)
214  {
215  /* Free it */
216  if (!CmpFreeValue(Hive, ListData->u.KeyList[i])) ASSERT(FALSE);
217  }
218 
219  /* Free the value list */
220  HvFreeCell(Hive, CellData->ValueList.List);
221  }
222 
223  /* Free the key security descriptor */
225  }
226 
227  /* Free the key body itself, and then return our status */
229  return STATUS_SUCCESS;
230 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
HCELL_INDEX List
Definition: cmdata.h:75
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
VOID NTAPI CmpFreeSecurityDescriptor(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: cmse.c:65
static int Unlink(const char **args)
Definition: vfdcmd.c:2549
ULONG MaxNameLen
Definition: cmdata.h:109
BOOLEAN NTAPI CmpFreeValue(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: cmvalue.c:73
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
CHILD_LIST ValueList
Definition: cmdata.h:103
#define KEY_HIVE_EXIT
Definition: cmdata.h:31
HCELL_INDEX Parent
Definition: cmdata.h:96
ULONG SubKeyCounts[HTYPE_COUNT]
Definition: cmdata.h:97
Definition: bzip2.c:1694
HCELL_INDEX KeyList[ANYSIZE_ARRAY]
Definition: cmdata.h:205
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID CMAPI HvFreeCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:441
BOOLEAN NTAPI CmpFreeKeyBody(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: cmkeydel.c:124
ULONG Count
Definition: cmdata.h:74
ULONG MaxClassLen
Definition: cmdata.h:110
BOOLEAN NTAPI CmpRemoveSubKey(IN PHHIVE Hive, IN HCELL_INDEX ParentKey, IN HCELL_INDEX TargetKey)
Definition: cmindex.c:1696
union _CELL_DATA::@3902 u
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN NTAPI CmpMarkKeyDirty(IN PHHIVE Hive, IN HCELL_INDEX Cell, IN BOOLEAN CheckNoSubkeys)
Definition: cmkeydel.c:19
return STATUS_SUCCESS
Definition: btrfs.c:2966
USHORT Flags
Definition: cmdata.h:93

Referenced by BiDeleteKey(), CmDeleteKey(), CmpUnlinkHiveFromMaster(), and RegDeleteKeyW().

◆ CmpFreeSecurityDescriptor()

VOID NTAPI CmpFreeSecurityDescriptor ( IN PHHIVE  Hive,
IN HCELL_INDEX  Cell 
)

Definition at line 65 of file cmse.c.

67 {
68  PCM_KEY_NODE CellData;
69  PCM_KEY_SECURITY SecurityData;
70 
71  PAGED_CODE();
72 
73  // ASSERT( (((PCMHIVE)Hive)->HiveSecurityLockOwner == KeGetCurrentThread()) || (CmpTestRegistryLockExclusive() == TRUE) );
74 
75  CellData = HvGetCell(Hive, Cell);
76  if (!CellData) return;
77 
79 
80  // FIXME: ReactOS-specific: check whether this key has a security block.
81  // On Windows there is no such check, all keys seem to have a valid
82  // security block.
83  // If we remove this check on ReactOS (and continue running) then we get
84  // a BSOD at the end...
85  if (CellData->Security == HCELL_NIL)
86  {
87  DPRINT("Cell 0x%08x (data 0x%p) has no security block!\n", Cell, CellData);
88  HvReleaseCell(Hive, Cell);
89  return;
90  }
91 
92  SecurityData = HvGetCell(Hive, CellData->Security);
93  if (!SecurityData)
94  {
95  HvReleaseCell(Hive, Cell);
96  return;
97  }
98 
99  ASSERT(SecurityData->Signature == CM_KEY_SECURITY_SIGNATURE);
100 
101  if (SecurityData->ReferenceCount > 1)
102  {
103  SecurityData->ReferenceCount--;
104  }
105  else // if (SecurityData->ReferenceCount <= 1)
106  {
107  CmpRemoveSecurityCellList(Hive, CellData->Security);
108  HvFreeCell(Hive, CellData->Security);
109  }
110 
111  CellData->Security = HCELL_NIL;
112  HvReleaseCell(Hive, CellData->Security);
113  HvReleaseCell(Hive, Cell);
114 }
#define CM_KEY_SECURITY_SIGNATURE
Definition: cmdata.h:23
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
#define HCELL_NIL
Definition: hivedata.h:85
#define PAGED_CODE()
Definition: video.h:57
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
void DPRINT(...)
Definition: polytest.cpp:61
ULONG ReferenceCount
Definition: cmdata.h:143
USHORT Signature
Definition: cmdata.h:92
Definition: bzip2.c:1694
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID CMAPI HvFreeCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:441
HCELL_INDEX Security
Definition: cmdata.h:107
VOID NTAPI CmpRemoveSecurityCellList(IN PHHIVE Hive, IN HCELL_INDEX SecurityCell)
Definition: cmse.c:19
USHORT Signature
Definition: cmdata.h:139

Referenced by CmpFreeKeyByCell().

◆ CmpFreeValue()

BOOLEAN NTAPI CmpFreeValue ( IN PHHIVE  Hive,
IN HCELL_INDEX  Cell 
)

Definition at line 73 of file cmvalue.c.

75 {
77  PAGED_CODE();
78 
79  /* Get the cell data */
81  if (!Value) ASSERT(FALSE);
82 
83  /* Free it */
84  if (!CmpFreeValueData(Hive, Value->Data, Value->DataLength))
85  {
86  /* We failed to free the data, return failure */
87  HvReleaseCell(Hive, Cell);
88  return FALSE;
89  }
90 
91  /* Release the cell and free it */
92  HvReleaseCell(Hive, Cell);
93  HvFreeCell(Hive, Cell);
94  return TRUE;
95 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define TRUE
Definition: types.h:120
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
#define PAGED_CODE()
Definition: video.h:57
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
Definition: bzip2.c:1694
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID CMAPI HvFreeCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:441
BOOLEAN NTAPI CmpFreeValueData(IN PHHIVE Hive, IN HCELL_INDEX DataCell, IN ULONG DataLength)
Definition: cmvalue.c:44
struct _CM_KEY_VALUE * PCM_KEY_VALUE

Referenced by CmDeleteValueKey(), CmiAddValueKey(), CmpCopyKeyValueList(), CmpFreeKeyByCell(), CmpSetValueKeyNew(), and RegDeleteValueW().

◆ CmpFreeValueData()

BOOLEAN NTAPI CmpFreeValueData ( IN PHHIVE  Hive,
IN HCELL_INDEX  DataCell,
IN ULONG  DataLength 
)

Definition at line 44 of file cmvalue.c.

47 {
48  ULONG KeySize;
49  PAGED_CODE();
50 
51  /* If this is a small key, the data is built-in */
52  if (!CmpIsKeyValueSmall(&KeySize, DataLength))
53  {
54  /* If there's no data cell, there's nothing to do */
55  if (DataCell == HCELL_NIL) return TRUE;
56 
57  /* Make sure the data cell is allocated */
58  //ASSERT(HvIsCellAllocated(Hive, DataCell));
59 
60  /* Unsupported value type */
61  ASSERT_VALUE_BIG(Hive, KeySize);
62 
63  /* Normal value, just free the data cell */
64  HvFreeCell(Hive, DataCell);
65  }
66 
67  /* Operation complete */
68  return TRUE;
69 }
#define TRUE
Definition: types.h:120
#define HCELL_NIL
Definition: hivedata.h:85
#define PAGED_CODE()
Definition: video.h:57
static BOOLEAN CmpIsKeyValueSmall(OUT PULONG RealLength, IN ULONG Length)
Definition: cmlib.h:323
VOID CMAPI HvFreeCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:441
unsigned int ULONG
Definition: retypes.h:1
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA _Inout_ PULONG DataLength
Definition: hidpi.h:333
#define ASSERT_VALUE_BIG(h, s)
Definition: cm.h:42

Referenced by CmpFreeValue(), and CmpSetValueKeyExisting().

◆ CmpGetValueData()

BOOLEAN NTAPI CmpGetValueData ( IN PHHIVE  Hive,
IN PCM_KEY_VALUE  Value,
OUT PULONG  Length,
OUT PVOID Buffer,
OUT PBOOLEAN  BufferAllocated,
OUT PHCELL_INDEX  CellToRelease 
)

Definition at line 125 of file cmvalue.c.

131 {
132  PAGED_CODE();
133 
134  /* Sanity check */
135  ASSERT(Value->Signature == CM_KEY_VALUE_SIGNATURE);
136 
137  /* Set failure defaults */
138  *BufferAllocated = FALSE;
139  *Buffer = NULL;
140  *CellToRelease = HCELL_NIL;
141 
142  /* Check if this is a small key */
143  if (CmpIsKeyValueSmall(Length, Value->DataLength))
144  {
145  /* Return the data immediately */
146  *Buffer = &Value->Data;
147  return TRUE;
148  }
149 
150  /* Unsupported at the moment */
151  ASSERT_VALUE_BIG(Hive, *Length);
152 
153  /* Get the data from the cell */
154  *Buffer = HvGetCell(Hive, Value->Data);
155  if (!(*Buffer)) return FALSE;
156 
157  /* Return success and the cell to be released */
158  *CellToRelease = Value->Data;
159  return TRUE;
160 }
#define CM_KEY_VALUE_SIGNATURE
Definition: cmdata.h:24
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define TRUE
Definition: types.h:120
#define HCELL_NIL
Definition: hivedata.h:85
#define PAGED_CODE()
Definition: video.h:57
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
static BOOLEAN CmpIsKeyValueSmall(OUT PULONG RealLength, IN ULONG Length)
Definition: cmlib.h:323
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ASSERT_VALUE_BIG(h, s)
Definition: cm.h:42

Referenced by CmpFindTagIndex(), CmpGetSymbolicLink(), CmpGetValueDataFromCache(), and CmpValueToData().

◆ CmpIsKeyValueBig()

static BOOLEAN CmpIsKeyValueBig ( IN PHHIVE  Hive,
IN ULONG  Length 
)
inlinestatic

Definition at line 344 of file cmlib.h.

346 {
347  /* Check if the hive is XP Beta 1 or newer */
348  if (Hive->Version >= HSYS_WHISTLER_BETA1)
349  {
350  /* Check if the key length is valid for a big value key */
352  {
353  /* Yes, this value is big */
354  return TRUE;
355  }
356  }
357 
358  /* Not a big value key */
359  return FALSE;
360 }
#define TRUE
Definition: types.h:120
#define CM_KEY_VALUE_SPECIAL_SIZE
Definition: cm.h:73
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define CM_KEY_VALUE_BIG
Definition: cm.h:72
#define HSYS_WHISTLER_BETA1
Definition: hivedata.h:59

◆ CmpIsKeyValueSmall()

static BOOLEAN CmpIsKeyValueSmall ( OUT PULONG  RealLength,
IN ULONG  Length 
)
inlinestatic

Definition at line 323 of file cmlib.h.

325 {
326  /* Check if the length has the special size value */
328  {
329  /* It does, so this is a small key: return the real length */
330  *RealLength = Length - CM_KEY_VALUE_SPECIAL_SIZE;
331  return TRUE;
332  }
333 
334  /* This is not a small key, return the length we read */
335  *RealLength = Length;
336  return FALSE;
337 }
#define TRUE
Definition: types.h:120
#define CM_KEY_VALUE_SPECIAL_SIZE
Definition: cm.h:73
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101

Referenced by CmGetSystemControlValues(), CmpCopyValue(), CmpFreeValueData(), CmpGetValueData(), CmpMarkValueDataDirty(), CmpQueryKeyValueData(), and CmpSetValueKeyExisting().

◆ CmpMarkIndexDirty()

BOOLEAN NTAPI CmpMarkIndexDirty ( IN PHHIVE  Hive,
HCELL_INDEX  ParentKey,
HCELL_INDEX  TargetKey 
)

◆ CmpMarkValueDataDirty()

BOOLEAN NTAPI CmpMarkValueDataDirty ( IN PHHIVE  Hive,
IN PCM_KEY_VALUE  Value 
)

Definition at line 19 of file cmvalue.c.

21 {
22  ULONG KeySize;
23  PAGED_CODE();
24 
25  /* Make sure there's actually any data */
26  if (Value->Data != HCELL_NIL)
27  {
28  /* If this is a small key, there's no need to have it dirty */
29  if (CmpIsKeyValueSmall(&KeySize, Value->DataLength)) return TRUE;
30 
31  /* Check if this is a big key */
32  ASSERT_VALUE_BIG(Hive, KeySize);
33 
34  /* Normal value, just mark it dirty */
35  HvMarkCellDirty(Hive, Value->Data, FALSE);
36  }
37 
38  /* Operation complete */
39  return TRUE;
40 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define TRUE
Definition: types.h:120
#define HCELL_NIL
Definition: hivedata.h:85
#define PAGED_CODE()
Definition: video.h:57
static BOOLEAN CmpIsKeyValueSmall(OUT PULONG RealLength, IN ULONG Length)
Definition: cmlib.h:323
BOOLEAN CMAPI HvMarkCellDirty(PHHIVE RegistryHive, HCELL_INDEX CellOffset, BOOLEAN HoldingLock)
Definition: hivecell.c:100
unsigned int ULONG
Definition: retypes.h:1
#define ASSERT_VALUE_BIG(h, s)
Definition: cm.h:42

Referenced by CmDeleteValueKey(), CmpMarkKeyDirty(), CmpSetValueKeyExisting(), and RegDeleteValueW().

◆ CmpNameSize()

USHORT NTAPI CmpNameSize ( IN PHHIVE  Hive,
IN PUNICODE_STRING  Name 
)

Definition at line 74 of file cmname.c.

76 {
77  ULONG i;
78 
79  /* For old hives, just return the length */
80  if (Hive->Version == 1) return Name->Length;
81 
82  /* For new versions, check for compressed name */
83  for (i = 0; i < (Name->Length / sizeof(WCHAR)); i++)
84  {
85  /* Check if the name is non compressed */
86  if (Name->Buffer[i] > (UCHAR)-1) return Name->Length;
87  }
88 
89  /* Compressed name, return length */
90  return Name->Length / sizeof(WCHAR);
91 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned int ULONG
Definition: retypes.h:1

Referenced by CmCreateRootNode(), CmiAddValueKey(), CmiCreateSubKey(), CmpCreateLinkNode(), CmpCreateRootNode(), CmpDoCreateChild(), and CmpSetValueKeyNew().

◆ CmpRemoveSecurityCellList()

VOID NTAPI CmpRemoveSecurityCellList ( IN PHHIVE  Hive,
IN HCELL_INDEX  SecurityCell 
)

Definition at line 19 of file cmse.c.

21 {
22  PCM_KEY_SECURITY SecurityData, FlinkCell, BlinkCell;
23 
24  PAGED_CODE();
25 
26  // ASSERT( (((PCMHIVE)Hive)->HiveSecurityLockOwner == KeGetCurrentThread()) || (CmpTestRegistryLockExclusive() == TRUE) );
27 
28  SecurityData = HvGetCell(Hive, SecurityCell);
29  if (!SecurityData) return;
30 
31  FlinkCell = HvGetCell(Hive, SecurityData->Flink);
32  if (!FlinkCell)
33  {
34  HvReleaseCell(Hive, SecurityCell);
35  return;
36  }
37 
38  BlinkCell = HvGetCell(Hive, SecurityData->Blink);
39  if (!BlinkCell)
40  {
41  HvReleaseCell(Hive, SecurityData->Flink);
42  HvReleaseCell(Hive, SecurityCell);
43  return;
44  }
45 
46  /* Sanity checks */
47  ASSERT(FlinkCell->Blink == SecurityCell);
48  ASSERT(BlinkCell->Flink == SecurityCell);
49 
50  /* Unlink the security block and free it */
51  FlinkCell->Blink = SecurityData->Blink;
52  BlinkCell->Flink = SecurityData->Flink;
53 #ifdef USE_CM_CACHE
54  CmpRemoveFromSecurityCache(Hive, SecurityCell);
55 #endif
56 
57  /* Release the cells */
58  HvReleaseCell(Hive, SecurityData->Blink);
59  HvReleaseCell(Hive, SecurityData->Flink);
60  HvReleaseCell(Hive, SecurityCell);
61 }
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
HCELL_INDEX Flink
Definition: cmdata.h:141
#define PAGED_CODE()
Definition: video.h:57
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
HCELL_INDEX Blink
Definition: cmdata.h:142

Referenced by CmpFreeSecurityDescriptor().

◆ CmpRemoveSubKey()

BOOLEAN NTAPI CmpRemoveSubKey ( IN PHHIVE  Hive,
IN HCELL_INDEX  ParentKey,
IN HCELL_INDEX  TargetKey 
)

Definition at line 1696 of file cmindex.c.

1699 {
1701  UNICODE_STRING SearchName;
1702  BOOLEAN IsCompressed;
1703  WCHAR Buffer[50];
1704  HCELL_INDEX RootCell = HCELL_NIL, LeafCell, ChildCell;
1705  PCM_KEY_INDEX Root = NULL, Leaf;
1707  ULONG Storage, RootIndex = INVALID_INDEX, LeafIndex;
1708  BOOLEAN Result = FALSE;
1709  HCELL_INDEX CellToRelease1 = HCELL_NIL, CellToRelease2 = HCELL_NIL;
1710 
1711  /* Get the target key node */
1712  Node = (PCM_KEY_NODE)HvGetCell(Hive, TargetKey);
1713  if (!Node) return FALSE;
1714 
1715  /* Make sure it's dirty, then release it */
1716  ASSERT(HvIsCellDirty(Hive, TargetKey));
1717  HvReleaseCell(Hive, TargetKey);
1718 
1719  /* Check if the name is compressed */
1720  if (Node->Flags & KEY_COMP_NAME)
1721  {
1722  /* Remember for later */
1723  IsCompressed = TRUE;
1724 
1725  /* Build the search name */
1726  SearchName.Length = CmpCompressedNameSize(Node->Name,
1727  Node->NameLength);
1728  SearchName.MaximumLength = SearchName.Length;
1729 
1730  /* Do we need an extra bufer? */
1731  if (SearchName.MaximumLength > sizeof(Buffer))
1732  {
1733  /* Allocate one */
1734  SearchName.Buffer = CmpAllocate(SearchName.Length,
1735  TRUE,
1736  TAG_CM);
1737  if (!SearchName.Buffer) return FALSE;
1738  }
1739  else
1740  {
1741  /* Otherwise, use our local stack buffer */
1742  SearchName.Buffer = Buffer;
1743  }
1744 
1745  /* Copy the compressed name */
1746  CmpCopyCompressedName(SearchName.Buffer,
1747  SearchName.MaximumLength,
1748  Node->Name,
1749  Node->NameLength);
1750  }
1751  else
1752  {
1753  /* It's not compressed, build the name directly from the node */
1754  IsCompressed = FALSE;
1755  SearchName.Length = Node->NameLength;
1756  SearchName.MaximumLength = Node->NameLength;
1757  SearchName.Buffer = Node->Name;
1758  }
1759 
1760  /* Now get the parent node */
1761  Node = (PCM_KEY_NODE)HvGetCell(Hive, ParentKey);
1762  if (!Node) goto Exit;
1763 
1764  /* Make sure it's dirty, then release it */
1765  ASSERT(HvIsCellDirty(Hive, ParentKey));
1766  HvReleaseCell(Hive, ParentKey);
1767 
1768  /* Get the storage type and make sure it's not empty */
1769  Storage = HvGetCellType(TargetKey);
1770  ASSERT(Node->SubKeyCounts[Storage] != 0);
1771  //ASSERT(HvIsCellAllocated(Hive, Node->SubKeyLists[Storage]));
1772 
1773  /* Get the leaf cell now */
1774  LeafCell = Node->SubKeyLists[Storage];
1775  Leaf = (PCM_KEY_INDEX)HvGetCell(Hive, LeafCell);
1776  if (!Leaf) goto Exit;
1777 
1778  /* Remember to release it later */
1779  CellToRelease1 = LeafCell;
1780 
1781  /* Check if the leaf is a root */
1782  if (Leaf->Signature == CM_KEY_INDEX_ROOT)
1783  {
1784  /* Find the child inside the root */
1785  RootIndex = CmpFindSubKeyInRoot(Hive, Leaf, &SearchName, &ChildCell);
1786  if (RootIndex & INVALID_INDEX) goto Exit;
1787  ASSERT(ChildCell != FALSE);
1788 
1789  /* The root cell is now this leaf */
1790  Root = Leaf;
1791  RootCell = LeafCell;
1792 
1793  /* And the new leaf is now this child */
1794  LeafCell = ChildCell;
1795  Leaf = (PCM_KEY_INDEX)HvGetCell(Hive, LeafCell);
1796  if (!Leaf) goto Exit;
1797 
1798  /* Remember to release it later */
1799  CellToRelease2 = LeafCell;
1800  }
1801 
1802  /* Make sure the leaf is valid */
1803  ASSERT((Leaf->Signature == CM_KEY_INDEX_LEAF) ||
1804  (Leaf->Signature == CM_KEY_FAST_LEAF) ||
1805  (Leaf->Signature == CM_KEY_HASH_LEAF));
1806 
1807  /* Now get the child in the leaf */
1808  LeafIndex = CmpFindSubKeyInLeaf(Hive, Leaf, &SearchName, &ChildCell);
1809  if (LeafIndex & INVALID_INDEX) goto Exit;
1810  ASSERT(ChildCell != HCELL_NIL);
1811 
1812  /* Decrement key counts and check if this was the last leaf entry */
1813  Node->SubKeyCounts[Storage]--;
1814  if (!(--Leaf->Count))
1815  {
1816  /* Free the leaf */
1817  HvFreeCell(Hive, LeafCell);
1818 
1819  /* Check if we were inside a root */
1820  if (Root)
1821  {
1822  /* Decrease the root count too, since the leaf is going away */
1823  if (!(--Root->Count))
1824  {
1825  /* The root is gone too,n ow */
1826  HvFreeCell(Hive, RootCell);
1827  Node->SubKeyLists[Storage] = HCELL_NIL;
1828  }
1829  else if (RootIndex < Root->Count)
1830  {
1831  /* Bring everything up by one */
1832  RtlMoveMemory(&Root->List[RootIndex],
1833  &Root->List[RootIndex + 1],
1834  (Root->Count - RootIndex) * sizeof(HCELL_INDEX));
1835  }
1836  }
1837  else
1838  {
1839  /* Otherwise, just clear the cell */
1840  Node->SubKeyLists[Storage] = HCELL_NIL;
1841  }
1842  }
1843  else if (LeafIndex < Leaf->Count)
1844  {
1845  /* Was the leaf a normal index? */
1846  if (Leaf->Signature == CM_KEY_INDEX_LEAF)
1847  {
1848  /* Bring everything up by one */
1849  RtlMoveMemory(&Leaf->List[LeafIndex],
1850  &Leaf->List[LeafIndex + 1],
1851  (Leaf->Count - LeafIndex) * sizeof(HCELL_INDEX));
1852  }
1853  else
1854  {
1855  /* This is a fast index, bring everything up by one */
1856  Child = (PCM_KEY_FAST_INDEX)Leaf;
1857  RtlMoveMemory(&Child->List[LeafIndex],
1858  &Child->List[LeafIndex+1],
1859  (Child->Count - LeafIndex) * sizeof(CM_INDEX));
1860  }
1861  }
1862 
1863  /* If we got here, now we're done */
1864  Result = TRUE;
1865 
1866 Exit:
1867  /* Release any cells we may have been holding */
1868  if (CellToRelease1 != HCELL_NIL) HvReleaseCell(Hive, CellToRelease1);
1869  if (CellToRelease2 != HCELL_NIL) HvReleaseCell(Hive, CellToRelease2);
1870 
1871  /* Check if the name was compressed and not inside our local buffer */
1872  if ((IsCompressed) && (SearchName.MaximumLength > sizeof(Buffer)))
1873  {
1874  /* Free the buffer we allocated */
1875  CmpFree(SearchName.Buffer, 0);
1876  }
1877 
1878  /* Return the result */
1879  return Result;
1880 }
#define KEY_COMP_NAME
Definition: cmdata.h:35
BOOLEAN CMAPI HvIsCellDirty(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: hivecell.c:126
#define TRUE
Definition: types.h:120
ULONG NTAPI CmpFindSubKeyInLeaf(IN PHHIVE Hive, IN PCM_KEY_INDEX Index, IN PCUNICODE_STRING SearchName, IN PHCELL_INDEX SubKey)
Definition: cmindex.c:358
struct _CM_KEY_INDEX * PCM_KEY_INDEX
USHORT MaximumLength
Definition: env_spec_w32.h:370
PVOID NTAPI CmpAllocate(_In_ SIZE_T Size, _In_ BOOLEAN Paged, _In_ ULONG Tag)
Definition: bootreg.c:90
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
#define HCELL_NIL
Definition: hivedata.h:85
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define HvGetCellType(Cell)
Definition: hivedata.h:95
ULONG NTAPI CmpFindSubKeyInRoot(IN PHHIVE Hive, IN PCM_KEY_INDEX Index, IN PCUNICODE_STRING SearchName, IN PHCELL_INDEX SubKey)
Definition: cmindex.c:143
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define INVALID_INDEX
Definition: cmindex.c:17
union node Node
Definition: types.h:1255
VOID NTAPI CmpCopyCompressedName(OUT PWCHAR Destination, IN ULONG DestinationLength, IN PWCHAR Source, IN ULONG SourceLength)
Definition: cmname.c:56
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
unsigned char BOOLEAN
#define CM_KEY_HASH_LEAF
Definition: cmdata.h:16
smooth NULL
Definition: ftsmooth.c:416
struct _CM_KEY_NODE * PCM_KEY_NODE
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
Definition: bufpool.h:45
#define CM_KEY_INDEX_ROOT
Definition: cmdata.h:13
struct _CM_KEY_FAST_INDEX * PCM_KEY_FAST_INDEX
root entry for file system trees
Definition: entries.h:148
__wchar_t WCHAR
Definition: xmlstorage.h:180
VOID NTAPI CmpFree(_In_ PVOID Ptr, _In_ ULONG Quota)
Definition: bootreg.c:105
ULONG HCELL_INDEX
Definition: hivedata.h:80
static void Exit(void)
Definition: sock.c:1331
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID CMAPI HvFreeCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:441
#define TAG_CM
Definition: cmlib.h:203
#define CM_KEY_FAST_LEAF
Definition: cmdata.h:15
unsigned int ULONG
Definition: retypes.h:1
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE ACPI_HANDLE Child
Definition: acpixf.h:722
#define CM_KEY_INDEX_LEAF
Definition: cmdata.h:14
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
USHORT NTAPI CmpCompressedNameSize(IN PWCHAR Name, IN ULONG Length)
Definition: cmname.c:95
static IStorage Storage
Definition: ole2.c:3548
Definition: dlist.c:348

Referenced by CmpFreeKeyByCell().

◆ CmpRemoveValueFromList()

NTSTATUS NTAPI CmpRemoveValueFromList ( IN PHHIVE  Hive,
IN ULONG  Index,
IN OUT PCHILD_LIST  ChildList 
)

Definition at line 320 of file cmvalue.c.

323 {
324  ULONG Count;
325  PCELL_DATA CellData;
326  HCELL_INDEX NewCell;
327  PAGED_CODE();
328 
329  /* Sanity check */
330  ASSERT((((LONG)Index) >= 0) && (Index <= ChildList->Count));
331 
332  /* Get the new count after removal */
333  Count = ChildList->Count - 1;
334  if (Count > 0)
335  {
336  /* Get the actual list array */
337  CellData = HvGetCell(Hive, ChildList->List);
338  if (!CellData) return STATUS_INSUFFICIENT_RESOURCES;
339 
340  /* Make sure cells data have been made dirty */
341  ASSERT(HvIsCellDirty(Hive, ChildList->List));
342  ASSERT(HvIsCellDirty(Hive, CellData->u.KeyList[Index]));
343 
344  /* Loop the list */
345  while (Index < Count)
346  {
347  /* Move everything up */
348  CellData->u.KeyList[Index] = CellData->u.KeyList[Index + 1];
349  Index++;
350  }
351 
352  /* Re-allocate the cell for the list by decreasing the count */
353  NewCell = HvReallocateCell(Hive,
354  ChildList->List,
355  Count * sizeof(HCELL_INDEX));
356  ASSERT(NewCell != HCELL_NIL);
357  HvReleaseCell(Hive,ChildList->List);
358 
359  /* Update the list cell */
360  ChildList->List = NewCell;
361  }
362  else
363  {
364  /* Otherwise, we were the last entry, so free the list entirely */
365  HvFreeCell(Hive, ChildList->List);
366  ChildList->List = HCELL_NIL;
367  }
368 
369  /* Update the child list with the new count */
370  ChildList->Count = Count;
371  return STATUS_SUCCESS;
372 }
BOOLEAN CMAPI HvIsCellDirty(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: hivecell.c:126
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
HCELL_INDEX CMAPI HvReallocateCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset, ULONG Size)
Definition: hivecell.c:394
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
#define HCELL_NIL
Definition: hivedata.h:85
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define PAGED_CODE()
Definition: video.h:57
long LONG
Definition: pedump.c:60
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
ULONG HCELL_INDEX
Definition: hivedata.h:80
static const UCHAR Index[8]
Definition: usbohci.c:18
HCELL_INDEX KeyList[ANYSIZE_ARRAY]
Definition: cmdata.h:205
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID CMAPI HvFreeCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:441
union _CELL_DATA::@3902 u
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by CmDeleteValueKey(), and RegDeleteValueW().

◆ CmPrepareHive()

VOID CMAPI CmPrepareHive ( PHHIVE  RegistryHive)

Definition at line 135 of file cminit.c.

137 {
138  PCM_KEY_NODE RootCell;
139 
140  RootCell = HvGetCell(RegistryHive, RegistryHive->BaseBlock->RootCell);
141  CmpPrepareKey(RegistryHive, RootCell);
142 }
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:303
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
static VOID CMAPI CmpPrepareKey(PHHIVE RegistryHive, PCM_KEY_NODE KeyCell)
Definition: cminit.c:115
HCELL_INDEX RootCell
Definition: hivedata.h:143

Referenced by BiInitializeAndValidateHive(), and HvInitialize().

◆ CmpSetValueDataNew()

NTSTATUS NTAPI CmpSetValueDataNew ( IN PHHIVE  Hive,
IN PVOID  Data,
IN ULONG  DataSize,
IN HSTORAGE_TYPE  StorageType,
IN HCELL_INDEX  ValueCell,
OUT PHCELL_INDEX  DataCell 
)

Definition at line 289 of file cmvalue.c.

295 {
296  PCELL_DATA CellData;
297  PAGED_CODE();
299 
300  /* Check if this is a big key */
301  ASSERT_VALUE_BIG(Hive, DataSize);
302 
303  /* Allocate a data cell */
304  *DataCell = HvAllocateCell(Hive, DataSize, StorageType, HCELL_NIL);
305  if (*DataCell == HCELL_NIL) return STATUS_INSUFFICIENT_RESOURCES;
306 
307  /* Get the actual data */
308  CellData = HvGetCell(Hive, *DataCell);
309  if (!CellData) ASSERT(FALSE);
310 
311  /* Copy our buffer into it */
312  RtlCopyMemory(CellData, Data, DataSize);
313 
314  /* All done */
315  return STATUS_SUCCESS;
316 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define HCELL_NIL
Definition: hivedata.h:85
HCELL_INDEX CMAPI HvAllocateCell(PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage, IN HCELL_INDEX Vicinity)
#define PAGED_CODE()
Definition: video.h:57
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CM_KEY_VALUE_SMALL
Definition: cm.h:71
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define ASSERT_VALUE_BIG(h, s)
Definition: cm.h:42
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751

Referenced by CmpSetValueKeyNew().

◆ CmpValueToData()

PCELL_DATA NTAPI CmpValueToData ( IN PHHIVE  Hive,
IN PCM_KEY_VALUE  Value,
OUT PULONG  Length 
)

Definition at line 167 of file cmvalue.c.

170 {
172  BOOLEAN BufferAllocated;
173  HCELL_INDEX CellToRelease;
174  PAGED_CODE();
175 
176  /* Sanity check */
177  ASSERT(Hive->ReleaseCellRoutine == NULL);
178 
179  /* Get the actual data */
180  if (!CmpGetValueData(Hive,
181  Value,
182  Length,
183  (PVOID*)&Buffer,
184  &BufferAllocated,
185  &CellToRelease))
186  {
187  /* We failed */
188  ASSERT(BufferAllocated == FALSE);
189  ASSERT(Buffer == NULL);
190  return NULL;
191  }
192 
193  /* This should never happen! */
194  if (BufferAllocated)
195  {
196  /* Free the buffer and bugcheck */
197  CmpFree(Buffer, 0);
198  KeBugCheckEx(REGISTRY_ERROR, 8, 0, (ULONG_PTR)Hive, (ULONG_PTR)Value);
199  }
200 
201  /* Otherwise, return the cell data */
202  return Buffer;
203 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define PAGED_CODE()
Definition: video.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:63
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
VOID NTAPI CmpFree(_In_ PVOID Ptr, _In_ ULONG Quota)
Definition: bootreg.c:105
ULONG HCELL_INDEX
Definition: hivedata.h:80
BOOLEAN NTAPI CmpGetValueData(IN PHHIVE Hive, IN PCM_KEY_VALUE Value, OUT PULONG Length, OUT PVOID *Buffer, OUT PBOOLEAN BufferAllocated, OUT PHCELL_INDEX CellToRelease)
Definition: cmvalue.c:125
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:107

Referenced by BiGetRegistryValue(), CmpAddDriverToList(), CmpFindControlSet(), CmpFindTagIndex(), CmpIsLoadType(), CmpIsSafe(), CmpSortDriverList(), and RepGetValueData().

◆ HvAllocateCell()

◆ HvFree()

VOID CMAPI HvFree ( PHHIVE  RegistryHive)

Definition at line 623 of file hiveinit.c.

625 {
626  if (!RegistryHive->ReadOnly)
627  {
628  /* Release hive bitmap */
629  if (RegistryHive->DirtyVector.Buffer)
630  {
631  RegistryHive->Free(RegistryHive->DirtyVector.Buffer, 0);
632  }
633 
634  HvpFreeHiveBins(RegistryHive);
635 
636  /* Free the BaseBlock */
637  if (RegistryHive->BaseBlock)
638  {
639  RegistryHive->Free(RegistryHive->BaseBlock, RegistryHive->BaseBlockAlloc);
640  RegistryHive->BaseBlock = NULL;
641  }
642  }
643 }
PULONG Buffer
Definition: typedefs.h:89
RTL_BITMAP DirtyVector
Definition: hivedata.h:304
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:303
BOOLEAN ReadOnly
Definition: hivedata.h:310
PFREE_ROUTINE Free
Definition: hivedata.h:294
smooth NULL
Definition: ftsmooth.c:416
ULONG BaseBlockAlloc
Definition: hivedata.h:307
VOID CMAPI HvpFreeHiveBins(PHHIVE Hive)
Definition: hiveinit.c:53

Referenced by CmiInitializeHive(), CmpDestroyHive(), and CmUnloadKey().

◆ HvFreeCell()

VOID CMAPI HvFreeCell ( PHHIVE  RegistryHive,
HCELL_INDEX  CellOffset 
)

Definition at line 441 of file hivecell.c.

444 {
445  PHCELL Free;
446  PHCELL Neighbor;
447  PHBIN Bin;
448  ULONG CellType;
449  ULONG CellBlock;
450 
451  ASSERT(RegistryHive->ReadOnly == FALSE);
452 
453  CMLTRACE(CMLIB_HCELL_DEBUG, "%s - Hive %p, CellIndex %08lx\n",
454  __FUNCTION__, RegistryHive, CellIndex);
455 
456  Free = HvpGetCellHeader(RegistryHive, CellIndex);
457 
458  ASSERT(Free->Size < 0);
459 
460  Free->Size = -Free->Size;
461 
462  CellType = HvGetCellType(CellIndex);
463  CellBlock = HvGetCellBlock(CellIndex);
464 
465  /* FIXME: Merge free blocks */
466  Bin = (PHBIN)RegistryHive->Storage[CellType].BlockList[CellBlock].BinAddress;
467 
468  if ((CellIndex & ~HCELL_TYPE_MASK) + Free->Size <
469  Bin->FileOffset + Bin->Size)
470  {
471  Neighbor = (PHCELL)((ULONG_PTR)Free + Free->Size);
472  if (Neighbor->Size > 0)
473  {
474  HvpRemoveFree(RegistryHive, Neighbor,
475  ((HCELL_INDEX)((ULONG_PTR)Neighbor - (ULONG_PTR)Bin +
476  Bin->FileOffset)) | (CellIndex & HCELL_TYPE_MASK));
477  Free->Size += Neighbor->Size;
478  }
479  }
480 
481  Neighbor = (PHCELL)(Bin + 1);
482  while (Neighbor < Free)
483  {
484  if (Neighbor->Size > 0)
485  {
486  if ((ULONG_PTR)Neighbor + Neighbor->Size == (ULONG_PTR)Free)
487  {
488  HCELL_INDEX NeighborCellIndex =
489  ((HCELL_INDEX)((ULONG_PTR)Neighbor - (ULONG_PTR)Bin +
490  Bin->FileOffset)) | (CellIndex & HCELL_TYPE_MASK);
491 
492  if (HvpComputeFreeListIndex(Neighbor->Size) !=
493  HvpComputeFreeListIndex(Neighbor->Size + Free->Size))
494  {
495  HvpRemoveFree(RegistryHive, Neighbor, NeighborCellIndex);
496  Neighbor->Size += Free->Size;
497  HvpAddFree(RegistryHive, Neighbor, NeighborCellIndex);
498  }
499  else
500  Neighbor->Size += Free->Size;
501 
502  if (CellType == Stable)
503  HvMarkCellDirty(RegistryHive, NeighborCellIndex, FALSE);
504 
505  return;
506  }
507  Neighbor = (PHCELL)((ULONG_PTR)Neighbor + Neighbor->Size);
508  }
509  else
510  {
511  Neighbor = (PHCELL)((ULONG_PTR)Neighbor - Neighbor->Size);
512  }
513  }
514 
515  /* Add block to the list of free blocks */
516  HvpAddFree(RegistryHive, Free, CellIndex);
517 
518  if (CellType == Stable)
519  HvMarkCellDirty(RegistryHive, CellIndex, FALSE);
520 }
#define HvGetCellBlock(Cell)
Definition: hivedata.h:97
static NTSTATUS CMAPI HvpAddFree(PHHIVE RegistryHive, PHCELL FreeBlock, HCELL_INDEX FreeIndex)
Definition: hivecell.c:175
BOOLEAN ReadOnly
Definition: hivedata.h:310
#define CMLTRACE(x,...)
Definition: cmlib.h:162
#define HvGetCellType(Cell)
Definition: hivedata.h:95
struct _HBIN * PHBIN
_In_opt_ PALLOCATE_FUNCTION _In_opt_ PFREE_FUNCTION Free
Definition: exfuncs.h:656
BOOLEAN CMAPI HvMarkCellDirty(PHHIVE RegistryHive, HCELL_INDEX CellIndex, BOOLEAN HoldingLock)
Definition: hivecell.c:100
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define CMLIB_HCELL_DEBUG
Definition: cmlib.h:185
#define HCELL_TYPE_MASK
Definition: hivedata.h:88
Definition: bin.h:43
DUAL Storage[HTYPE_COUNT]
Definition: hivedata.h:331
if(!(yy_init))
Definition: macro.lex.yy.c:714
ULONG HCELL_INDEX
Definition: hivedata.h:80
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PHMAP_ENTRY BlockList
Definition: hivedata.h:278
LONG Size
Definition: hivedata.h:190
static VOID CMAPI HvpRemoveFree(PHHIVE RegistryHive, PHCELL CellBlock, HCELL_INDEX CellIndex)
Definition: hivecell.c:200
ULONG_PTR BinAddress
Definition: hivedata.h:259
static __inline PHCELL CMAPI HvpGetCellHeader(PHHIVE RegistryHive, HCELL_INDEX CellIndex)
Definition: hivecell.c:13
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
static __inline ULONG CMAPI HvpComputeFreeListIndex(ULONG Size)
Definition: hivecell.c:147
struct _HCELL * PHCELL
#define __FUNCTION__
Definition: types.h:112

Referenced by CmCreateRootNode(), CmiAddValueKey(), CmiCreateSubKey(), CmpCopyKeyValueList(), CmpCopyValue(), CmpDeepCopyKeyInternal(), CmpDoCreateChild(), CmpFreeKeyBody(), CmpFreeKeyByCell(), CmpFreeSecurityDescriptor(), CmpFreeValue(), CmpFreeValueData(), CmpRemoveSubKey(), CmpRemoveValueFromList(), CmpSetValueKeyNew(), CmpSplitLeaf(), HvReallocateCell(), and RegSetValueExW().

◆ HvGetCell()

PVOID CMAPI HvGetCell ( PHHIVE  RegistryHive,
HCELL_INDEX  CellOffset 
)

Definition at line 67 of file hivecell.c.

70 {
71  ASSERT(CellIndex != HCELL_NIL);
72  return (PVOID)(HvpGetCellHeader(RegistryHive, CellIndex) + 1);
73 }
#define HCELL_NIL
Definition: hivedata.h:85
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static __inline PHCELL CMAPI HvpGetCellHeader(PHHIVE RegistryHive, HCELL_INDEX CellIndex)
Definition: hivecell.c:13

Referenced by BiEnumerateSubKeys(), BiGetRegistryValue(), BiLoadHive(), BiOpenKey(), CmCreateRootNode(), CmDeleteKey(), CmDeleteValueKey(), CmEnumerateKey(), CmEnumerateValueKey(), CmGetSystemControlValues(), CmiAddSubKey(), CmiAddValueKey(), CmiCreateSecurityKey(), CmiCreateSubKey(), CmpAddDriverToList(), CmpAddSubKey(), CmpAddToLeaf(), CmpAddValueToList(), CmpCleanUpSubKeyInfo(), CmpCompareNewValueDataAgainstKCBCache(), CmpConstructName(), CmpCopyCell(), CmpCopyKeyValueList(), CmpCopyValue(), CmpCreateLinkNode(), CmpCreateRegistryRoot(), CmpCreateRootNode(), CmpDeepCopyKeyInternal(), CmpDoCompareKeyName(), CmpDoCreate(), CmpDoCreateChild(), CmpDoFindSubKeyByNumber(), CmpFindControlSet(), CmpFindDrivers(), CmpFindNameInList(), CmpFindSubKeyByName(), CmpFindSubKeyByNumber(), CmpFindSubKeyInRoot(), CmpFindTagIndex(), CmpFreeKeyBody(), CmpFreeKeyByCell(), CmpFreeSecurityDescriptor(), CmpFreeValue(), CmpGetHiveName(), CmpGetSymbolicLink(), CmpGetValueData(), CmpGetValueKeyFromCache(), CmpGetValueListFromCache(), CmpHandleExitNode(), CmpIsLoadType(), CmpIsSafe(), CmpMarkIndexDirty(), CmpMarkKeyDirty(), CmpParseKey(), CmpPrepareIndexOfKeys(), CmpPrepareKey(), CmpQueryKeyData(), CmpQueryKeyDataFromCache(), CmpRemoveSecurityCellList(), CmpRemoveSubKey(), CmpRemoveValueFromList(), CmPrepareHive(), CmpSelectLeaf(), CmpSetValueDataNew(), CmpSetValueKeyExisting(), CmpSetValueKeyNew(), CmpSortDriverList(), CmpSplitLeaf(), CmpUnlinkHiveFromMaster(), CmpWalkPath(), CmQueryKey(), CmSetValueKey(), HvpFindFree(), HvpRemoveFree(), HvReallocateCell(), RegDeleteKeyW(), RegDeleteValueW(), RegEnumKey(), RegImportBinaryHive(), RegOpenKey(), RegpCreateOrOpenKey(), RegQueryValue(), RegQueryValueExW(), and RegSetValueExW().

◆ HvGetCellSize()

LONG CMAPI HvGetCellSize ( PHHIVE  RegistryHive,
PVOID  Cell 
)

◆ HvHiveWillShrink()

BOOLEAN CMAPI HvHiveWillShrink ( IN PHHIVE  RegistryHive)

Definition at line 277 of file hivewrt.c.

278 {
279  /* No shrinking yet */
281  return FALSE;
282 }
#define UNIMPLEMENTED
Definition: debug.h:114

Referenced by CmFlushKey(), and CmpDoFlushAll().

◆ HvInitialize()

NTSTATUS CMAPI HvInitialize ( PHHIVE  RegistryHive,
ULONG  OperationType,
ULONG  HiveFlags,
ULONG  FileType,
PVOID HiveData  OPTIONAL,
PALLOCATE_ROUTINE  Allocate,
PFREE_ROUTINE  Free,
PFILE_SET_SIZE_ROUTINE  FileSetSize,
PFILE_WRITE_ROUTINE  FileWrite,
PFILE_READ_ROUTINE  FileRead,
PFILE_FLUSH_ROUTINE  FileFlush,
ULONG Cluster  OPTIONAL,
PCUNICODE_STRING FileName  OPTIONAL 
)

Definition at line 522 of file hiveinit.c.

536 {
538  PHHIVE Hive = RegistryHive;
539 
540  /*
541  * Create a new hive structure that will hold all the maintenance data.
542  */
543 
544  RtlZeroMemory(Hive, sizeof(HHIVE));
546 
547  Hive->Allocate = Allocate;
548  Hive->Free = Free;
549  Hive->FileSetSize = FileSetSize;
550  Hive->FileWrite = FileWrite;
551  Hive->FileRead = FileRead;
552  Hive->FileFlush = FileFlush;
553 
554  Hive->RefreshCount = 0;
556  Hive->Cluster = Cluster;
557  Hive->BaseBlockAlloc = sizeof(HBASE_BLOCK); // == HBLOCK_SIZE
558 
559  Hive->Version = HSYS_MINOR;
560 #if (NTDDI_VERSION < NTDDI_VISTA)
561  Hive->Log = (FileType == HFILE_TYPE_LOG);
562 #endif
563  Hive->HiveFlags = HiveFlags & ~HIVE_NOLAZYFLUSH;
564 
565  switch (OperationType)
566  {
567  case HINIT_CREATE:
568  Status = HvpCreateHive(Hive, FileName);
569  break;
570 
571  case HINIT_MEMORY:
572  Status = HvpInitializeMemoryHive(Hive, HiveData, FileName);
573  break;
574 
575  case HINIT_FLAT:
576  Status = HvpInitializeFlatHive(Hive, HiveData);
577  break;
578 
579  case HINIT_FILE:
580  {
581  Status = HvLoadHive(Hive, FileName);
582  if ((Status != STATUS_SUCCESS) &&
584  {
585  /* Unrecoverable failure */
586  return Status;
587  }
588 
589  /* Check for previous damage */
591  break;
592  }
593 
595  // Status = HvpInitializeMemoryInplaceHive(Hive, HiveData);
596  // break;
597 
598  case HINIT_MAPFILE:
599 
600  default:
601  /* FIXME: A better return status value is needed */
603  ASSERT(FALSE);
604  }
605 
606  if (!NT_SUCCESS(Status)) return Status;
607 
608  /* HACK: ROS: Init root key cell and prepare the hive */
609  // r31253
610  // if (OperationType == HINIT_CREATE) CmCreateRootNode(Hive, L"");
611  if (OperationType != HINIT_CREATE) CmPrepareHive(Hive);
612 
613  return Status;
614 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define HSYS_MINOR
Definition: hivedata.h:58
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_REGISTRY_RECOVERED
Definition: ntstatus.h:123
NTSTATUS CMAPI HvpInitializeMemoryHive(PHHIVE Hive, PHBASE_BLOCK ChunkBase, IN PCUNICODE_STRING FileName OPTIONAL)
Definition: hiveinit.c:221
#define HTYPE_COUNT
Definition: hivedata.h:71
#define HV_HHIVE_SIGNATURE
Definition: hivedata.h:50
PFREE_ROUTINE Free
Definition: hivedata.h:294
#define HINIT_MAPFILE
Definition: hivedata.h:18
#define HINIT_MEMORY_INPLACE
Definition: hivedata.h:16
PALLOCATE_ROUTINE Allocate
Definition: hivedata.h:293
_In_opt_ PALLOCATE_FUNCTION Allocate
Definition: exfuncs.h:656
_In_opt_ PALLOCATE_FUNCTION _In_opt_ PFREE_FUNCTION Free
Definition: exfuncs.h:656
ULONG StorageTypeCount
Definition: hivedata.h:329
ULONG RefreshCount
Definition: hivedata.h:328
#define HINIT_FILE
Definition: hivedata.h:15
#define HINIT_FLAT
Definition: hivedata.h:17
NTSTATUS CMAPI HvpCreateHive(IN OUT PHHIVE RegistryHive, IN PCUNICODE_STRING FileName OPTIONAL)
Definition: hiveinit.c:160
PFILE_SET_SIZE_ROUTINE FileSetSize
Definition: hivedata.h:295
ULONG Signature
Definition: hivedata.h:288
ULONG Version
Definition: hivedata.h:330
#define HINIT_CREATE
Definition: hivedata.h:13
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define HFILE_TYPE_LOG
Definition: hivedata.h:34
ULONG Cluster
Definition: hivedata.h:308
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSTATUS CMAPI HvpInitializeFlatHive(PHHIVE Hive, PHBASE_BLOCK ChunkBase)
Definition: hiveinit.c:344
PFILE_WRITE_ROUTINE FileWrite
Definition: hivedata.h:296
VOID CMAPI CmPrepareHive(PHHIVE RegistryHive)
Definition: cminit.c:135
#define HINIT_MEMORY
Definition: hivedata.h:14
Status
Definition: gdiplustypes.h:24
ULONG HiveFlags
Definition: hivedata.h:321
PFILE_FLUSH_ROUTINE FileFlush
Definition: hivedata.h:298
ULONG BaseBlockAlloc
Definition: hivedata.h:307
#define HIVE_NOLAZYFLUSH
Definition: hivedata.h:24
NTSTATUS CMAPI HvLoadHive(IN PHHIVE Hive, IN PCUNICODE_STRING FileName OPTIONAL)
Definition: hiveinit.c:415
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
struct _HBASE_BLOCK HBASE_BLOCK
return STATUS_SUCCESS
Definition: btrfs.c:2966
PFILE_READ_ROUTINE FileRead
Definition: hivedata.h:297

Referenced by BiInitializeAndValidateHive(), CmGetSystemControlValues(), CmiInitializeHive(), CmpInitializeHive(), and RegImportBinaryHive().

◆ HvIsCellAllocated()

BOOLEAN CMAPI HvIsCellAllocated ( IN PHHIVE  RegistryHive,
IN HCELL_INDEX  CellIndex 
)

Definition at line 43 of file hivecell.c.

45 {
46  ULONG Type, Block;
47 
48  /* If it's a flat hive, the cell is always allocated */
49  if (RegistryHive->Flat)
50  return TRUE;
51 
52  /* Otherwise, get the type and make sure it's valid */
53  Type = HvGetCellType(CellIndex);
54  Block = HvGetCellBlock(CellIndex);
55  if (Block >= RegistryHive->Storage[Type].Length)
56  return FALSE;
57 
58  /* Try to get the cell block */
59  if (RegistryHive->Storage[Type].BlockList[Block].BlockAddress)
60  return TRUE;
61 
62  /* No valid block, fail */
63  return FALSE;
64 }
#define HvGetCellBlock(Cell)
Definition: hivedata.h:97
#define TRUE
Definition: types.h:120
Type
Definition: Type.h:6
#define HvGetCellType(Cell)
Definition: hivedata.h:95
unsigned int ULONG
Definition: retypes.h:1

◆ HvIsCellDirty()

BOOLEAN CMAPI HvIsCellDirty ( IN PHHIVE  Hive,
IN HCELL_INDEX  Cell 
)

Definition at line 126 of file hivecell.c.

128 {
129  BOOLEAN IsDirty = FALSE;
130 
131  /* Sanity checks */
132  ASSERT(Hive->ReadOnly == FALSE);
133 
134  /* Volatile cells are always "dirty" */
135  if (HvGetCellType(Cell) == Volatile)
136  return TRUE;
137 
138  /* Check if the dirty bit is set */
139  if (RtlCheckBit(&Hive->DirtyVector, Cell / HBLOCK_SIZE))
140  IsDirty = TRUE;
141 
142  /* Return result as boolean*/
143  return IsDirty;
144 }
#define TRUE
Definition: types.h:120
#define HBLOCK_SIZE
Definition: hivedata.h:41
#define RtlCheckBit(BMH, BP)
Definition: rtlfuncs.h:3154
#define HvGetCellType(Cell)
Definition: hivedata.h:95
unsigned char BOOLEAN
Definition: bzip2.c:1694
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by CmDeleteKey(), CmDeleteValueKey(), CmpAddValueToList(), CmpRemoveSubKey(), CmpRemoveValueFromList(), CmpSetValueKeyExisting(), CmpSetValueKeyNew(), RegDeleteKeyW(), and RegDeleteValueW().

◆ HvMarkCellDirty()

BOOLEAN CMAPI HvMarkCellDirty ( PHHIVE  RegistryHive,
HCELL_INDEX  CellOffset,
BOOLEAN  HoldingLock 
)

Definition at line 100 of file hivecell.c.

104 {
105  ULONG CellBlock;
106  ULONG CellLastBlock;
107 
108  ASSERT(RegistryHive->ReadOnly == FALSE);
109 
110  CMLTRACE(CMLIB_HCELL_DEBUG, "%s - Hive %p, CellIndex %08lx, HoldingLock %u\n",
111  __FUNCTION__, RegistryHive, CellIndex, HoldingLock);
112 
113  if (HvGetCellType(CellIndex) != Stable)
114  return TRUE;
115 
116  CellBlock = HvGetCellBlock(CellIndex);
117  CellLastBlock = HvGetCellBlock(CellIndex + HBLOCK_SIZE - 1);
118 
119  RtlSetBits(&RegistryHive->DirtyVector,
120  CellBlock, CellLastBlock - CellBlock);
121  RegistryHive->DirtyCount++;
122  return TRUE;
123 }
#define HvGetCellBlock(Cell)
Definition: hivedata.h:97
#define TRUE
Definition: types.h:120
#define HBLOCK_SIZE
Definition: hivedata.h:41
RTL_BITMAP DirtyVector
Definition: hivedata.h:304
BOOLEAN ReadOnly
Definition: hivedata.h:310
#define CMLTRACE(x,...)
Definition: cmlib.h:162
#define HvGetCellType(Cell)
Definition: hivedata.h:95
ULONG DirtyCount
Definition: hivedata.h:305
#define CMLIB_HCELL_DEBUG
Definition: cmlib.h:185
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI void WINAPI RtlSetBits(PRTL_BITMAP, ULONG, ULONG)
#define __FUNCTION__
Definition: types.h:112

Referenced by CmDeleteValueKey(), CmiAddSubKey(), CmiAddValueKey(), CmpAddSubKey(), CmpAddToLeaf(), CmpCreateLinkNode(), CmpDoCreate(), CmpMarkIndexDirty(), CmpMarkKeyDirty(), CmpMarkValueDataDirty(), CmpSelectLeaf(), CmpSetValueKeyExisting(), CmpSetValueKeyNew(), CmpSplitLeaf(), CmSetValueKey(), HvAllocateCell(), HvFreeCell(), RegDeleteValueW(), and RegSetValueExW().

◆ HvpAddBin()

PHBIN CMAPI HvpAddBin ( PHHIVE  RegistryHive,
ULONG  Size,
HSTORAGE_TYPE  Storage 
)

Definition at line 12 of file hivebin.c.

16 {
17  PHMAP_ENTRY BlockList;
18  PHBIN Bin;
19  ULONG BinSize;
20  ULONG i;
21  ULONG BitmapSize;
22  ULONG BlockCount;
23  ULONG OldBlockListSize;
24  PHCELL Block;
25 
26  BinSize = ROUND_UP(Size + sizeof(HBIN), HBLOCK_SIZE);
27  BlockCount = BinSize / HBLOCK_SIZE;
28 
29  Bin = RegistryHive->Allocate(BinSize, TRUE, TAG_CM);
30  if (Bin == NULL)
31  return NULL;
32  RtlZeroMemory(Bin, BinSize);
33 
34  Bin->Signature = HV_HBIN_SIGNATURE;
35  Bin->FileOffset = RegistryHive->Storage[Storage].Length *
37  Bin->Size = BinSize;
38 
39  /* Allocate new block list */
40  OldBlockListSize = RegistryHive->Storage[Storage].Length;
41  BlockList = RegistryHive->Allocate(sizeof(HMAP_ENTRY) *
42  (OldBlockListSize + BlockCount),
43  TRUE,
44  TAG_CM);
45  if (BlockList == NULL)
46  {
47  RegistryHive->Free(Bin, 0);
48  return NULL;
49  }
50 
51  if (OldBlockListSize > 0)
52  {
53  RtlCopyMemory(BlockList, RegistryHive->Storage[Storage].BlockList,
54  OldBlockListSize * sizeof(HMAP_ENTRY));
55  RegistryHive->Free(RegistryHive->Storage[Storage].BlockList, 0);
56  }
57 
58  RegistryHive->Storage[Storage].BlockList = BlockList;
59  RegistryHive->Storage[Storage].Length += BlockCount;
60 
61  for (i = 0; i < BlockCount; i++)
62  {
63  RegistryHive->Storage[Storage].BlockList[OldBlockListSize + i].BlockAddress =
64  ((ULONG_PTR)Bin + (i * HBLOCK_SIZE));
65  RegistryHive->Storage[Storage].BlockList[OldBlockListSize + i].BinAddress = (ULONG_PTR)Bin;
66  }
67 
68  /* Initialize a free block in this heap. */
69  Block = (PHCELL)(Bin + 1);
70  Block->Size = (LONG)(BinSize - sizeof(HBIN));
71 
72  if (Storage == Stable)
73  {
74  /* Calculate bitmap size in bytes (always a multiple of 32 bits). */
75  BitmapSize = ROUND_UP(RegistryHive->Storage[Stable].Length,
76  sizeof(ULONG) * 8) / 8;
77 
78  /* Grow bitmap if necessary. */
79  if (BitmapSize > RegistryHive->DirtyVector.SizeOfBitMap / 8)
80  {
82 
83  BitmapBuffer = RegistryHive->Allocate(BitmapSize, TRUE, TAG_CM);
84  RtlZeroMemory(BitmapBuffer, BitmapSize);
85  if (RegistryHive->DirtyVector.SizeOfBitMap > 0)
86  {
87  ASSERT(RegistryHive->DirtyVector.Buffer);
89  RegistryHive->DirtyVector.Buffer,
90  RegistryHive->DirtyVector.SizeOfBitMap / 8);
91  RegistryHive->Free(RegistryHive->DirtyVector.Buffer, 0);
92  }
94  BitmapSize * 8);
95  }
96 
97  /* Mark new bin dirty. */
98  RtlSetBits(&RegistryHive->DirtyVector,
99  Bin->FileOffset / HBLOCK_SIZE,
100  BlockCount);
101 
102  /* Update size in the base block */
103  RegistryHive->BaseBlock->Length += BinSize;
104  }
105 
106  return Bin;
107 }
PULONG Buffer
Definition: typedefs.h:89
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
NTSYSAPI void WINAPI RtlInitializeBitMap(PRTL_BITMAP, PULONG, ULONG)
#define HBLOCK_SIZE
Definition: hivedata.h:41
#define ROUND_UP(n, align)
Definition: eventvwr.h:31
RTL_BITMAP DirtyVector
Definition: hivedata.h:304
Definition: hivedata.h:256
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:303
ULONG_PTR BlockAddress
Definition: hivedata.h:258
PFREE_ROUTINE Free
Definition: hivedata.h:294
PALLOCATE_ROUTINE Allocate
Definition: hivedata.h:293
ULONG Length
Definition: hivedata.h:146
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
Definition: bin.h:43
DUAL Storage[HTYPE_COUNT]
Definition: hivedata.h:331
#define HV_HBIN_SIGNATURE
Definition: hivedata.h:52
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static ULONG BitmapBuffer[(XMS_BLOCKS+31)/32]
Definition: himem.c:86
#define TAG_CM
Definition: cmlib.h:203
ULONG SizeOfBitMap
Definition: typedefs.h:88
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
PHMAP_ENTRY BlockList
Definition: hivedata.h:278
LONG Size
Definition: hivedata.h:190
ULONG_PTR BinAddress
Definition: hivedata.h:259
unsigned int * PULONG
Definition: retypes.h:1
ULONG Length
Definition: hivedata.h:276
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ULONG_PTR
Definition: config.h:101
NTSYSAPI void WINAPI RtlSetBits(PRTL_BITMAP, ULONG, ULONG)
struct _HCELL * PHCELL
static IStorage Storage
Definition: ole2.c:3548

Referenced by HvAllocateCell().

◆ HvpCreateHiveFreeCellList()

NTSTATUS CMAPI HvpCreateHiveFreeCellList ( PHHIVE  Hive)

Definition at line 279 of file hivecell.c.

281 {
283  PHCELL FreeBlock;
284  ULONG BlockIndex;
285  ULONG FreeOffset;
286  PHBIN Bin;
288  ULONG Index;
289 
290  /* Initialize the free cell list */
291  for (Index = 0; Index < 24; Index++)
292  {
295  }
296 
297  BlockOffset = 0;
298  BlockIndex = 0;
299  while (BlockIndex < Hive->Storage[Stable].Length)
300  {
301  Bin = (PHBIN)Hive->Storage[Stable].BlockList[BlockIndex].BinAddress;
302 
303  /* Search free blocks and add to list */
304  FreeOffset = sizeof(HBIN);
305  while (FreeOffset < Bin->Size)
306  {
307  FreeBlock = (PHCELL)((ULONG_PTR)Bin + FreeOffset);
308  if (FreeBlock->Size > 0)
309  {
310  Status = HvpAddFree(Hive, FreeBlock, Bin->FileOffset + FreeOffset);
311  if (!NT_SUCCESS(Status))
312  return Status;
313 
314  FreeOffset += FreeBlock->Size;
315  }
316  else
317  {
318  FreeOffset -= FreeBlock->Size;
319  }
320  }
321 
322  BlockIndex += Bin->Size / HBLOCK_SIZE;
323  BlockOffset += Bin->Size;
324  }
325 
326  return STATUS_SUCCESS;
327 }
#define HBLOCK_SIZE
Definition: hivedata.h:41
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS CMAPI HvpAddFree(PHHIVE RegistryHive, PHCELL FreeBlock, HCELL_INDEX FreeIndex)
Definition: hivecell.c:175
#define HCELL_NIL
Definition: hivedata.h:85
struct _HBIN * PHBIN
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define BlockOffset(V, L)
Definition: cdprocs.h:1660
Definition: bin.h:43
DUAL Storage[HTYPE_COUNT]
Definition: hivedata.h:331
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG HCELL_INDEX
Definition: hivedata.h:80
static const UCHAR Index[8]
Definition: usbohci.c:18
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
HCELL_INDEX FreeDisplay[24]
Definition: hivedata.h:280
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
PHMAP_ENTRY BlockList
Definition: hivedata.h:278
LONG Size
Definition: hivedata.h:190
ULONG_PTR BinAddress
Definition: hivedata.h:259
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966
struct _HCELL * PHCELL
static IStorage Storage
Definition: ole2.c:3548

Referenced by HvpInitializeMemoryHive().

◆ HvpHiveHeaderChecksum()

ULONG CMAPI HvpHiveHeaderChecksum ( PHBASE_BLOCK  HiveHeader)

Definition at line 17 of file hivesum.c.

19 {
20  PULONG Buffer = (PULONG)HiveHeader;
21  ULONG Sum = 0;
22  ULONG i;
23 
24  for (i = 0; i < 127; i++)
25  Sum ^= Buffer[i];
26  if (Sum == (ULONG)-1)
27  Sum = (ULONG)-2;
28  if (Sum == 0)
29  Sum = 1;
30 
31  return Sum;
32 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
Definition: bufpool.h:45
unsigned int * PULONG
Definition: retypes.h:1
unsigned int ULONG
Definition: retypes.h:1

Referenced by CmCreateRootNode(), HvIsInPlaceBaseBlockValid(), HvpVerifyHiveHeader(), HvpWriteHive(), and HvpWriteLog().

◆ HvReallocateCell()

HCELL_INDEX CMAPI HvReallocateCell ( PHHIVE  RegistryHive,
HCELL_INDEX  CellOffset,
ULONG  Size 
)

Definition at line 394 of file hivecell.c.

398 {
399  PVOID OldCell;
400  PVOID NewCell;
401  LONG OldCellSize;
402  HCELL_INDEX NewCellIndex;
404 
405  ASSERT(CellIndex != HCELL_NIL);
406 
407  CMLTRACE(CMLIB_HCELL_DEBUG, "%s - Hive %p, CellIndex %08lx, Size %x\n",
408  __FUNCTION__, RegistryHive, CellIndex, Size);
409 
410  Storage = HvGetCellType(CellIndex);
411 
412  OldCell = HvGetCell(RegistryHive, CellIndex);
413  OldCellSize = HvGetCellSize(RegistryHive, OldCell);
414  ASSERT(OldCellSize > 0);
415 
416  /*
417  * If new data size is larger than the current, destroy current
418  * data block and allocate a new one.
419  *
420  * FIXME: Merge with adjacent free cell if possible.
421  * FIXME: Implement shrinking.
422  */
423  if (Size > (ULONG)OldCellSize)
424  {
425  NewCellIndex = HvAllocateCell(RegistryHive, Size, Storage, HCELL_NIL);
426  if (NewCellIndex == HCELL_NIL)
427  return HCELL_NIL;
428 
429  NewCell = HvGetCell(RegistryHive, NewCellIndex);
430  RtlCopyMemory(NewCell, OldCell, (SIZE_T)OldCellSize);
431 
432  HvFreeCell(RegistryHive, CellIndex);
433 
434  return NewCellIndex;
435  }
436 
437  return CellIndex;
438 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define HCELL_NIL
Definition: hivedata.h:85
#define CMLTRACE(x,...)
Definition: cmlib.h:162
#define HvGetCellType(Cell)
Definition: hivedata.h:95
#define CMLIB_HCELL_DEBUG
Definition: cmlib.h:185
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellIndex)
Definition: hivecell.c:67
long LONG
Definition: pedump.c:60
ULONG HCELL_INDEX
Definition: hivedata.h:80
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID CMAPI HvFreeCell(PHHIVE RegistryHive, HCELL_INDEX CellIndex)
Definition: hivecell.c:441
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
ULONG_PTR SIZE_T
Definition: typedefs.h:78
LONG CMAPI HvGetCellSize(IN PHHIVE Hive, IN PVOID Address)
Definition: hivecell.c:85
HSTORAGE_TYPE
Definition: hivedata.h:100
HCELL_INDEX CMAPI HvAllocateCell(PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage, HCELL_INDEX Vicinity)
Definition: hivecell.c:330
unsigned int ULONG
Definition: retypes.h:1
#define __FUNCTION__
Definition: types.h:112
static IStorage Storage
Definition: ole2.c:3548

Referenced by CmpAddToLeaf(), CmpAddValueToList(), CmpRemoveValueFromList(), CmpSetValueKeyExisting(), and CmpSplitLeaf().

◆ HvReleaseFreeCellRefArray()

VOID CMAPI HvReleaseFreeCellRefArray ( IN OUT PHV_TRACK_CELL_REF  CellRef)

Definition at line 607 of file hivecell.c.

609 {
610  ULONG i;
611 
612  PAGED_CODE();
613 
614  ASSERT(CellRef);
615 
616  /* Any references in the static array? */
617  if (CellRef->StaticCount > 0)
618  {
619  /* Sanity check */
620  ASSERT(CellRef->StaticCount <= STATIC_CELL_PAIR_COUNT);
621 
622  /* Loop over them and release them */
623  for (i = 0; i < CellRef->StaticCount; i++)
624  {
625  HvReleaseCell(CellRef->StaticArray[i].Hive,
626  CellRef->StaticArray[i].Cell);
627  }
628 
629  /* We can reuse the static array */
630  CellRef->StaticCount = 0;
631  }
632 
633  /* Any references in the dynamic array? */
634  if (CellRef->Count > 0)
635  {
636  /* Sanity checks */
637  ASSERT(CellRef->Count <= CellRef->Max);
638  ASSERT(CellRef->CellArray);
639 
640  /* Loop over them and release them */
641  for (i = 0; i < CellRef->Count; i++)
642  {
643  HvReleaseCell(CellRef->CellArray[i].Hive,
644  CellRef->CellArray[i].Cell);
645  }
646 
647  /* We can reuse the dynamic array */
648  CmpFree(CellRef->CellArray, 0); // TAG_CM
649  CellRef->CellArray = NULL;
650  CellRef->Count = CellRef->Max = 0;
651  }
652 }
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
#define STATIC_CELL_PAIR_COUNT
Definition: cmlib.h:300
#define PAGED_CODE()
Definition: video.h:57
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI CmpFree(_In_ PVOID Ptr, _In_ ULONG Quota)
Definition: bootreg.c:105
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned int ULONG
Definition: retypes.h:1

Referenced by CmEnumerateKey(), and CmQueryKey().

◆ HvSyncHive()

BOOLEAN CMAPI HvSyncHive ( PHHIVE  RegistryHive)

Definition at line 243 of file hivewrt.c.

245 {
246  ASSERT(RegistryHive->ReadOnly == FALSE);
247 
248  if (RtlFindSetBits(&RegistryHive->DirtyVector, 1, 0) == ~0U)
249  {
250  return TRUE;
251  }
252 
253  /* Update hive header modification time */
254  KeQuerySystemTime(&RegistryHive->BaseBlock->TimeStamp);
255 
256  /* Update log file */
257  if (!HvpWriteLog(RegistryHive))
258  {
259  return FALSE;
260  }
261 
262  /* Update hive file */
263  if (!HvpWriteHive(RegistryHive, TRUE))
264  {
265  return FALSE;
266  }
267 
268  /* Clear dirty bitmap. */
269  RtlClearAllBits(&RegistryHive->DirtyVector);
270  RegistryHive->DirtyCount = 0;
271 
272  return TRUE;
273 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define TRUE
Definition: types.h:120
RTL_BITMAP DirtyVector
Definition: hivedata.h:304
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:303
#define U(x)
Definition: wordpad.c:44
BOOLEAN ReadOnly
Definition: hivedata.h:310
ULONG DirtyCount
Definition: hivedata.h:305
LARGE_INTEGER TimeStamp
Definition: hivedata.h:126
NTSYSAPI void WINAPI RtlClearAllBits(PRTL_BITMAP)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSYSAPI ULONG WINAPI RtlFindSetBits(PCRTL_BITMAP, ULONG, ULONG)
static BOOLEAN CMAPI HvpWriteHive(PHHIVE RegistryHive, BOOLEAN OnlyDirty)
Definition: hivewrt.c:147
static BOOLEAN CMAPI HvpWriteLog(PHHIVE RegistryHive)
Definition: hivewrt.c:13

Referenced by CmFlushKey(), CmLoadKey(), CmpDoFlushAll(), and CmpDoFlushNextHive().

◆ HvTrackCellRef()

BOOLEAN CMAPI HvTrackCellRef ( IN OUT PHV_TRACK_CELL_REF  CellRef,
IN PHHIVE  Hive,
IN HCELL_INDEX  Cell 
)

Definition at line 527 of file hivecell.c.

531 {
532  PHV_HIVE_CELL_PAIR NewCellArray;
533 
534  PAGED_CODE();
535 
536  /* Sanity checks */
537  ASSERT(CellRef);
538  ASSERT(Hive);
539  ASSERT(Cell != HCELL_NIL);
540 
541  /* NOTE: The hive cell is already referenced! */
542 
543  /* Less than 4? Use the static array */
544  if (CellRef->StaticCount < STATIC_CELL_PAIR_COUNT)
545  {
546  /* Add the reference */
547  CellRef->StaticArray[CellRef->StaticCount].Hive = Hive;
548  CellRef->StaticArray[CellRef->StaticCount].Cell = Cell;
549  CellRef->StaticCount++;
550  return TRUE;
551  }
552 
553  DPRINT("HvTrackCellRef: Static array full, use dynamic array.\n");
554 
555  /* Sanity checks */
556  if (CellRef->Max == 0)
557  {
558  /* The dynamic array must not have been allocated already */
559  ASSERT(CellRef->CellArray == NULL);
560  ASSERT(CellRef->Count == 0);
561  }
562  else
563  {
564  /* The dynamic array must be allocated */
565  ASSERT(CellRef->CellArray);
566  }
567  ASSERT(CellRef->Count <= CellRef->Max);
568 
569  if (CellRef->Count == CellRef->Max)
570  {
571  /* Allocate a new reference table */
572  NewCellArray = CmpAllocate((CellRef->Max + CELL_REF_INCREMENT) * sizeof(HV_HIVE_CELL_PAIR),
573  TRUE,
574  TAG_CM);
575  if (!NewCellArray)
576  {
577  DPRINT1("HvTrackCellRef: Cannot reallocate the reference table.\n");
578  /* We failed, dereference the hive cell */
579  HvReleaseCell(Hive, Cell);
580  return FALSE;
581  }
582 
583  /* Free the old reference table and use the new one */
584  if (CellRef->CellArray)
585  {
586  /* Copy the handles from the old table to the new one */
587  RtlCopyMemory(NewCellArray,
588  CellRef->CellArray,
589  CellRef->Max * sizeof(HV_HIVE_CELL_PAIR));
590  CmpFree(CellRef->CellArray, 0); // TAG_CM
591  }
592  CellRef->CellArray = NewCellArray;
593  CellRef->Max += CELL_REF_INCREMENT;
594  }
595 
596  // ASSERT(CellRef->Count < CellRef->Max);
597 
598  /* Add the reference */
599  CellRef->CellArray[CellRef->Count].Hive = Hive;
600  CellRef->CellArray[CellRef->Count].Cell = Cell;
601  CellRef->Count++;
602  return TRUE;
603 }
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
PVOID NTAPI CmpAllocate(_In_ SIZE_T Size, _In_ BOOLEAN Paged, _In_ ULONG Tag)
Definition: bootreg.c:90
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
#define HCELL_NIL
Definition: hivedata.h:85
#define STATIC_CELL_PAIR_COUNT
Definition: cmlib.h:300
#define PAGED_CODE()
Definition: video.h:57
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
struct zzzz Cell
VOID NTAPI CmpFree(_In_ PVOID Ptr, _In_ ULONG Quota)
Definition: bootreg.c:105
Definition: bzip2.c:1694
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define TAG_CM
Definition: cmlib.h:203
#define CELL_REF_INCREMENT
Definition: hivecell.c:523
#define DPRINT1
Definition: precomp.h:8

Referenced by CmEnumerateKey(), and CmQueryKey().

◆ HvWriteHive()

BOOLEAN CMAPI HvWriteHive ( PHHIVE  RegistryHive)

Definition at line 285 of file hivewrt.c.

287 {
288  ASSERT(RegistryHive->ReadOnly == FALSE);
289 
290  /* Update hive header modification time */
291  KeQuerySystemTime(&RegistryHive->BaseBlock->TimeStamp);
292 
293  /* Update hive file */
294  if (!HvpWriteHive(RegistryHive, FALSE))
295  {
296  return FALSE;
297  }
298 
299  return TRUE;
300 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define TRUE
Definition: types.h:120
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:303
BOOLEAN ReadOnly
Definition: hivedata.h:310
LARGE_INTEGER TimeStamp
Definition: hivedata.h:126
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static BOOLEAN CMAPI HvpWriteHive(PHHIVE RegistryHive, BOOLEAN OnlyDirty)
Definition: hivewrt.c:147

Referenced by CmSaveKey(), CmSaveMergedKeys(), and ExportBinaryHive().

Variable Documentation

◆ CmlibTraceLevel

ULONG CmlibTraceLevel

Definition at line 12 of file cminit.c.