ReactOS  0.4.15-dev-1171-gab82533
hivecell.c File Reference
#include "cmlib.h"
#include <debug.h>
Include dependency graph for hivecell.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define CELL_REF_INCREMENT   10
 

Functions

static __inline PHCELL CMAPI HvpGetCellHeader (PHHIVE RegistryHive, HCELL_INDEX CellIndex)
 
BOOLEAN CMAPI HvIsCellAllocated (IN PHHIVE RegistryHive, IN HCELL_INDEX CellIndex)
 
PVOID CMAPI HvGetCell (PHHIVE RegistryHive, HCELL_INDEX CellIndex)
 
static __inline LONG CMAPI HvpGetCellFullSize (PHHIVE RegistryHive, PVOID Cell)
 
LONG CMAPI HvGetCellSize (IN PHHIVE Hive, IN PVOID Address)
 
BOOLEAN CMAPI HvMarkCellDirty (PHHIVE RegistryHive, HCELL_INDEX CellIndex, BOOLEAN HoldingLock)
 
BOOLEAN CMAPI HvIsCellDirty (IN PHHIVE Hive, IN HCELL_INDEX Cell)
 
static __inline ULONG CMAPI HvpComputeFreeListIndex (ULONG Size)
 
static NTSTATUS CMAPI HvpAddFree (PHHIVE RegistryHive, PHCELL FreeBlock, HCELL_INDEX FreeIndex)
 
static VOID CMAPI HvpRemoveFree (PHHIVE RegistryHive, PHCELL CellBlock, HCELL_INDEX CellIndex)
 
static HCELL_INDEX CMAPI HvpFindFree (PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage)
 
NTSTATUS CMAPI HvpCreateHiveFreeCellList (PHHIVE Hive)
 
HCELL_INDEX CMAPI HvAllocateCell (PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage, HCELL_INDEX Vicinity)
 
HCELL_INDEX CMAPI HvReallocateCell (PHHIVE RegistryHive, HCELL_INDEX CellIndex, ULONG Size)
 
VOID CMAPI HvFreeCell (PHHIVE RegistryHive, HCELL_INDEX CellIndex)
 
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)
 

Macro Definition Documentation

◆ CELL_REF_INCREMENT

#define CELL_REF_INCREMENT   10

Definition at line 523 of file hivecell.c.

◆ NDEBUG

#define NDEBUG

Definition at line 9 of file hivecell.c.

Function Documentation

◆ HvAllocateCell()

HCELL_INDEX CMAPI HvAllocateCell ( PHHIVE  RegistryHive,
ULONG  Size,
HSTORAGE_TYPE  Storage,
HCELL_INDEX  Vicinity 
)

Definition at line 330 of file hivecell.c.

335 {
336  PHCELL FreeCell;
337  HCELL_INDEX FreeCellOffset;
338  PHCELL NewCell;
339  PHBIN Bin;
340 
341  ASSERT(RegistryHive->ReadOnly == FALSE);
342 
343  CMLTRACE(CMLIB_HCELL_DEBUG, "%s - Hive %p, Size %x, %s, Vicinity %08lx\n",
344  __FUNCTION__, RegistryHive, Size, (Storage == 0) ? "Stable" : "Volatile", Vicinity);
345 
346  /* Round to 16 bytes multiple. */
347  Size = ROUND_UP(Size + sizeof(HCELL), 16);
348 
349  /* First search in free blocks. */
350  FreeCellOffset = HvpFindFree(RegistryHive, Size, Storage);
351 
352  /* If no free cell was found we need to extend the hive file. */
353  if (FreeCellOffset == HCELL_NIL)
354  {
355  Bin = HvpAddBin(RegistryHive, Size, Storage);
356  if (Bin == NULL)
357  return HCELL_NIL;
358  FreeCellOffset = Bin->FileOffset + sizeof(HBIN);
359  FreeCellOffset |= Storage << HCELL_TYPE_SHIFT;
360  }
361 
362  FreeCell = HvpGetCellHeader(RegistryHive, FreeCellOffset);
363 
364  /* Split the block in two parts */
365 
366  /* The free block that is created has to be at least
367  sizeof(HCELL) + sizeof(HCELL_INDEX) big, so that free
368  cell list code can work. Moreover we round cell sizes
369  to 16 bytes, so creating a smaller block would result in
370  a cell that would never be allocated. */
371  if ((ULONG)FreeCell->Size > Size + 16)
372  {
373  NewCell = (PHCELL)((ULONG_PTR)FreeCell + Size);
374  NewCell->Size = FreeCell->Size - Size;
375  FreeCell->Size = Size;
376  HvpAddFree(RegistryHive, NewCell, FreeCellOffset + Size);
377  if (Storage == Stable)
378  HvMarkCellDirty(RegistryHive, FreeCellOffset + Size, FALSE);
379  }
380 
381  if (Storage == Stable)
382  HvMarkCellDirty(RegistryHive, FreeCellOffset, FALSE);
383 
384  FreeCell->Size = -FreeCell->Size;
385  RtlZeroMemory(FreeCell + 1, Size - sizeof(HCELL));
386 
387  CMLTRACE(CMLIB_HCELL_DEBUG, "%s - CellIndex %08lx\n",
388  __FUNCTION__, FreeCellOffset);
389 
390  return FreeCellOffset;
391 }
PHBIN CMAPI HvpAddBin(PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage)
Definition: hivebin.c:12
#define ROUND_UP(n, align)
Definition: eventvwr.h:31
static HCELL_INDEX CMAPI HvpFindFree(PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage)
Definition: hivecell.c:249
static NTSTATUS CMAPI HvpAddFree(PHHIVE RegistryHive, PHCELL FreeBlock, HCELL_INDEX FreeIndex)
Definition: hivecell.c:175
#define HCELL_NIL
Definition: hivedata.h:85
BOOLEAN ReadOnly
Definition: hivedata.h:310
#define CMLTRACE(x,...)
Definition: cmlib.h:163
struct _HBIN HBIN
#define HCELL_TYPE_SHIFT
Definition: hivedata.h:91
BOOLEAN CMAPI HvMarkCellDirty(PHHIVE RegistryHive, HCELL_INDEX CellIndex, BOOLEAN HoldingLock)
Definition: hivecell.c:100
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define CMLIB_HCELL_DEBUG
Definition: cmlib.h:186
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
Definition: bin.h:43
ULONG HCELL_INDEX
Definition: hivedata.h:80
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
LONG Size
Definition: hivedata.h:190
static __inline PHCELL CMAPI HvpGetCellHeader(PHHIVE RegistryHive, HCELL_INDEX CellIndex)
Definition: hivecell.c:13
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
struct _HCELL * PHCELL
#define __FUNCTION__
Definition: types.h:112
static IStorage Storage
Definition: ole2.c:3548

Referenced by HvReallocateCell().

◆ HvFreeCell()

VOID CMAPI HvFreeCell ( PHHIVE  RegistryHive,
HCELL_INDEX  CellIndex 
)

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:163
#define HvGetCellType(Cell)
Definition: hivedata.h:95
struct _HBIN * PHBIN
_In_opt_ PALLOCATE_FUNCTION _In_opt_ PFREE_FUNCTION Free
Definition: exfuncs.h:814
BOOLEAN CMAPI HvMarkCellDirty(PHHIVE RegistryHive, HCELL_INDEX CellIndex, BOOLEAN HoldingLock)
Definition: hivecell.c:100
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define CMLIB_HCELL_DEBUG
Definition: cmlib.h:186
#define FALSE
Definition: types.h:117
#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  CellIndex 
)

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 ( IN PHHIVE  Hive,
IN PVOID  Address 
)

Definition at line 85 of file hivecell.c.

87 {
88  PHCELL CellHeader;
89  LONG Size;
90 
92 
93  CellHeader = (PHCELL)Address - 1;
94  Size = CellHeader->Size * -1;
95  Size -= sizeof(HCELL);
96  return Size;
97 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
long LONG
Definition: pedump.c:60
static WCHAR Address[46]
Definition: ping.c:68
struct _HCELL HCELL
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
LONG Size
Definition: hivedata.h:190
struct _HCELL * PHCELL

Referenced by HvReallocateCell().

◆ 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
Type
Definition: Type.h:6
#define TRUE
Definition: types.h:120
#define HvGetCellType(Cell)
Definition: hivedata.h:95
#define FALSE
Definition: types.h:117
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 HBLOCK_SIZE
Definition: hivedata.h:41
#define TRUE
Definition: types.h:120
#define RtlCheckBit(BMH, BP)
Definition: rtlfuncs.h:3154
#define HvGetCellType(Cell)
Definition: hivedata.h:95
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
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  CellIndex,
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 HBLOCK_SIZE
Definition: hivedata.h:41
RTL_BITMAP DirtyVector
Definition: hivedata.h:304
#define TRUE
Definition: types.h:120
BOOLEAN ReadOnly
Definition: hivedata.h:310
#define CMLTRACE(x,...)
Definition: cmlib.h:163
#define HvGetCellType(Cell)
Definition: hivedata.h:95
ULONG DirtyCount
Definition: hivedata.h:305
#define CMLIB_HCELL_DEBUG
Definition: cmlib.h:186
#define FALSE
Definition: types.h:117
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSYSAPI void WINAPI RtlSetBits(PRTL_BITMAP, ULONG, ULONG)
unsigned int ULONG
Definition: retypes.h:1
#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().

◆ HvpAddFree()

static NTSTATUS CMAPI HvpAddFree ( PHHIVE  RegistryHive,
PHCELL  FreeBlock,
HCELL_INDEX  FreeIndex 
)
static

Definition at line 175 of file hivecell.c.

179 {
180  PHCELL_INDEX FreeBlockData;
182  ULONG Index;
183 
184  ASSERT(RegistryHive != NULL);
185  ASSERT(FreeBlock != NULL);
186 
187  Storage = HvGetCellType(FreeIndex);
188  Index = HvpComputeFreeListIndex((ULONG)FreeBlock->Size);
189 
190  FreeBlockData = (PHCELL_INDEX)(FreeBlock + 1);
191  *FreeBlockData = RegistryHive->Storage[Storage].FreeDisplay[Index];
192  RegistryHive->Storage[Storage].FreeDisplay[Index] = FreeIndex;
193 
194  /* FIXME: Eventually get rid of free bins. */
195 
196  return STATUS_SUCCESS;
197 }
#define HvGetCellType(Cell)
Definition: hivedata.h:95
smooth NULL
Definition: ftsmooth.c:416
ULONG * PHCELL_INDEX
Definition: hivedata.h:80
DUAL Storage[HTYPE_COUNT]
Definition: hivedata.h:331
static const UCHAR Index[8]
Definition: usbohci.c:18
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
HCELL_INDEX FreeDisplay[24]
Definition: hivedata.h:280
LONG Size
Definition: hivedata.h:190
HSTORAGE_TYPE
Definition: hivedata.h:100
unsigned int ULONG
Definition: retypes.h:1
static __inline ULONG CMAPI HvpComputeFreeListIndex(ULONG Size)
Definition: hivecell.c:147
return STATUS_SUCCESS
Definition: btrfs.c:3014
static IStorage Storage
Definition: ole2.c:3548

Referenced by HvAllocateCell(), HvFreeCell(), and HvpCreateHiveFreeCellList().

◆ HvpComputeFreeListIndex()

static __inline ULONG CMAPI HvpComputeFreeListIndex ( ULONG  Size)
static

Definition at line 147 of file hivecell.c.

149 {
150  ULONG Index;
151  static CCHAR FindFirstSet[128] = {
152  0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
153  4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
154  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
155  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
156  6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
157  6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
158  6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
159  6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6};
160 
161  ASSERT(Size >= (1 << 3));
162  Index = (Size >> 3) - 1;
163  if (Index >= 16)
164  {
165  if (Index > 127)
166  Index = 23;
167  else
168  Index = FindFirstSet[Index] + 16;
169  }
170 
171  return Index;
172 }
char CCHAR
Definition: typedefs.h:51
static const UCHAR Index[8]
Definition: usbohci.c:18
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
unsigned int ULONG
Definition: retypes.h:1

Referenced by HvFreeCell(), HvpAddFree(), HvpFindFree(), and HvpRemoveFree().

◆ 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:65
#define BlockOffset(V, L)
Definition: cdprocs.h:1650
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
Status
Definition: gdiplustypes.h:24
HCELL_INDEX FreeDisplay[24]
Definition: hivedata.h:280
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
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:3014
struct _HCELL * PHCELL
static IStorage Storage
Definition: ole2.c:3548

Referenced by HvpInitializeMemoryHive().

◆ HvpFindFree()

static HCELL_INDEX CMAPI HvpFindFree ( PHHIVE  RegistryHive,
ULONG  Size,
HSTORAGE_TYPE  Storage 
)
static

Definition at line 249 of file hivecell.c.

253 {
254  PHCELL_INDEX FreeCellData;
255  HCELL_INDEX FreeCellOffset;
256  PHCELL_INDEX pFreeCellOffset;
257  ULONG Index;
258 
259  for (Index = HvpComputeFreeListIndex(Size); Index < 24; Index++)
260  {
261  pFreeCellOffset = &RegistryHive->Storage[Storage].FreeDisplay[Index];
262  while (*pFreeCellOffset != HCELL_NIL)
263  {
264  FreeCellData = (PHCELL_INDEX)HvGetCell(RegistryHive, *pFreeCellOffset);
265  if ((ULONG)HvpGetCellFullSize(RegistryHive, FreeCellData) >= Size)
266  {
267  FreeCellOffset = *pFreeCellOffset;
268  *pFreeCellOffset = *FreeCellData;
269  return FreeCellOffset;
270  }
271  pFreeCellOffset = FreeCellData;
272  }
273  }
274 
275  return HCELL_NIL;
276 }
#define HCELL_NIL
Definition: hivedata.h:85
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellIndex)
Definition: hivecell.c:67
ULONG * PHCELL_INDEX
Definition: hivedata.h:80
DUAL Storage[HTYPE_COUNT]
Definition: hivedata.h:331
ULONG HCELL_INDEX
Definition: hivedata.h:80
static const UCHAR Index[8]
Definition: usbohci.c:18
HCELL_INDEX FreeDisplay[24]
Definition: hivedata.h:280
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
static __inline LONG CMAPI HvpGetCellFullSize(PHHIVE RegistryHive, PVOID Cell)
Definition: hivecell.c:76
unsigned int ULONG
Definition: retypes.h:1
static __inline ULONG CMAPI HvpComputeFreeListIndex(ULONG Size)
Definition: hivecell.c:147
static IStorage Storage
Definition: ole2.c:3548

Referenced by HvAllocateCell().

◆ HvpGetCellFullSize()

static __inline LONG CMAPI HvpGetCellFullSize ( PHHIVE  RegistryHive,
PVOID  Cell 
)
static

Definition at line 76 of file hivecell.c.

79 {
80  UNREFERENCED_PARAMETER(RegistryHive);
81  return ((PHCELL)Cell - 1)->Size;
82 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317

Referenced by HvpFindFree().

◆ HvpGetCellHeader()

static __inline PHCELL CMAPI HvpGetCellHeader ( PHHIVE  RegistryHive,
HCELL_INDEX  CellIndex 
)
static

Definition at line 13 of file hivecell.c.

16 {
17  PVOID Block;
18 
19  CMLTRACE(CMLIB_HCELL_DEBUG, "%s - Hive %p, CellIndex %08lx\n",
20  __FUNCTION__, RegistryHive, CellIndex);
21 
22  ASSERT(CellIndex != HCELL_NIL);
23  if (!RegistryHive->Flat)
24  {
25  ULONG CellType = HvGetCellType(CellIndex);
26  ULONG CellBlock = HvGetCellBlock(CellIndex);
27  ULONG CellOffset = (CellIndex & HCELL_OFFSET_MASK) >> HCELL_OFFSET_SHIFT;
28 
29  ASSERT(CellBlock < RegistryHive->Storage[CellType].Length);
30  Block = (PVOID)RegistryHive->Storage[CellType].BlockList[CellBlock].BlockAddress;
31  ASSERT(Block != NULL);
32  return (PVOID)((ULONG_PTR)Block + CellOffset);
33  }
34  else
35  {
36  ASSERT(HvGetCellType(CellIndex) == Stable);
37  return (PVOID)((ULONG_PTR)RegistryHive->BaseBlock + HBLOCK_SIZE +
38  CellIndex);
39  }
40 }
#define HvGetCellBlock(Cell)
Definition: hivedata.h:97
#define HBLOCK_SIZE
Definition: hivedata.h:41
#define HCELL_OFFSET_SHIFT
Definition: hivedata.h:93
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:303
#define HCELL_NIL
Definition: hivedata.h:85
ULONG_PTR BlockAddress
Definition: hivedata.h:258
#define CMLTRACE(x,...)
Definition: cmlib.h:163
#define HvGetCellType(Cell)
Definition: hivedata.h:95
#define CMLIB_HCELL_DEBUG
Definition: cmlib.h:186
smooth NULL
Definition: ftsmooth.c:416
DUAL Storage[HTYPE_COUNT]
Definition: hivedata.h:331
void * PVOID
Definition: retypes.h:9
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PHMAP_ENTRY BlockList
Definition: hivedata.h:278
#define HCELL_OFFSET_MASK
Definition: hivedata.h:90
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
BOOLEAN Flat
Definition: hivedata.h:309
#define __FUNCTION__
Definition: types.h:112
static IStorage Storage
Definition: ole2.c:3548

Referenced by HvAllocateCell(), HvFreeCell(), and HvGetCell().

◆ HvpRemoveFree()

static VOID CMAPI HvpRemoveFree ( PHHIVE  RegistryHive,
PHCELL  CellBlock,
HCELL_INDEX  CellIndex 
)
static

Definition at line 200 of file hivecell.c.

204 {
205  PHCELL_INDEX FreeCellData;
206  PHCELL_INDEX pFreeCellOffset;
208  ULONG Index, FreeListIndex;
209 
210  ASSERT(RegistryHive->ReadOnly == FALSE);
211 
212  Storage = HvGetCellType(CellIndex);
213  Index = HvpComputeFreeListIndex((ULONG)CellBlock->Size);
214 
215  pFreeCellOffset = &RegistryHive->Storage[Storage].FreeDisplay[Index];
216  while (*pFreeCellOffset != HCELL_NIL)
217  {
218  FreeCellData = (PHCELL_INDEX)HvGetCell(RegistryHive, *pFreeCellOffset);
219  if (*pFreeCellOffset == CellIndex)
220  {
221  *pFreeCellOffset = *FreeCellData;
222  return;
223  }
224  pFreeCellOffset = FreeCellData;
225  }
226 
227  /* Something bad happened, print a useful trace info and bugcheck */
228  CMLTRACE(CMLIB_HCELL_DEBUG, "-- beginning of HvpRemoveFree trace --\n");
229  CMLTRACE(CMLIB_HCELL_DEBUG, "block we are about to free: %08x\n", CellIndex);
230  CMLTRACE(CMLIB_HCELL_DEBUG, "chosen free list index: %u\n", Index);
231  for (FreeListIndex = 0; FreeListIndex < 24; FreeListIndex++)
232  {
233  CMLTRACE(CMLIB_HCELL_DEBUG, "free list [%u]: ", FreeListIndex);
234  pFreeCellOffset = &RegistryHive->Storage[Storage].FreeDisplay[FreeListIndex];
235  while (*pFreeCellOffset != HCELL_NIL)
236  {
237  CMLTRACE(CMLIB_HCELL_DEBUG, "%08x ", *pFreeCellOffset);
238  FreeCellData = (PHCELL_INDEX)HvGetCell(RegistryHive, *pFreeCellOffset);
239  pFreeCellOffset = FreeCellData;
240  }
242  }
243  CMLTRACE(CMLIB_HCELL_DEBUG, "-- end of HvpRemoveFree trace --\n");
244 
245  ASSERT(FALSE);
246 }
#define HCELL_NIL
Definition: hivedata.h:85
BOOLEAN ReadOnly
Definition: hivedata.h:310
#define CMLTRACE(x,...)
Definition: cmlib.h:163
#define HvGetCellType(Cell)
Definition: hivedata.h:95
#define CMLIB_HCELL_DEBUG
Definition: cmlib.h:186
#define FALSE
Definition: types.h:117
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellIndex)
Definition: hivecell.c:67
ULONG * PHCELL_INDEX
Definition: hivedata.h:80
DUAL Storage[HTYPE_COUNT]
Definition: hivedata.h:331
static const UCHAR Index[8]
Definition: usbohci.c:18
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
HCELL_INDEX FreeDisplay[24]
Definition: hivedata.h:280
LONG Size
Definition: hivedata.h:190
HSTORAGE_TYPE
Definition: hivedata.h:100
unsigned int ULONG
Definition: retypes.h:1
static __inline ULONG CMAPI HvpComputeFreeListIndex(ULONG Size)
Definition: hivecell.c:147
static IStorage Storage
Definition: ole2.c:3548

Referenced by HvFreeCell().

◆ HvReallocateCell()

HCELL_INDEX CMAPI HvReallocateCell ( PHHIVE  RegistryHive,
HCELL_INDEX  CellIndex,
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:163
#define HvGetCellType(Cell)
Definition: hivedata.h:95
#define CMLIB_HCELL_DEBUG
Definition: cmlib.h:186
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:361
ULONG_PTR SIZE_T
Definition: typedefs.h:80
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:391
#define STATIC_CELL_PAIR_COUNT
Definition: cmlib.h:301
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
#define PAGED_CODE()

Referenced by CmEnumerateKey(), and CmQueryKey().

◆ 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 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define TRUE
Definition: types.h:120
PVOID NTAPI CmpAllocate(_In_ SIZE_T Size, _In_ BOOLEAN Paged, _In_ ULONG Tag)
Definition: bootreg.c:90
#define HvReleaseCell(h, c)
Definition: cmlib.h:391
#define HCELL_NIL
Definition: hivedata.h:85
#define STATIC_CELL_PAIR_COUNT
Definition: cmlib.h:301
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI CmpFree(_In_ PVOID Ptr, _In_ ULONG Quota)
Definition: bootreg.c:105
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define TAG_CM
Definition: cmlib.h:204
#define CELL_REF_INCREMENT
Definition: hivecell.c:523
#define DPRINT1
Definition: precomp.h:8
#define PAGED_CODE()

Referenced by CmEnumerateKey(), and CmQueryKey().