HvpDoAllocateCell
UINT64 __stdcall HvpDoAllocateCell(
ULONG_PTR Hive,
UINT64 NewSize,
_HSTORAGE_TYPE Type,
VOID **CellAddress,
_HV_GET_CELL_CONTEXT *CellAddressContext){
VOID **v5;
unsigned int v7;
__int64 v8;
__int64 v9;
_EX_PUSH_LOCK *v10;
_HSTORAGE_TYPE v11;
ULONG_PTR FreeCell;
unsigned int *v13;
char v14;
unsigned int v15;
unsigned int v16;
UINT64 v17;
unsigned int v18;
unsigned int v19;
unsigned int v20;
unsigned int v21;
UINT64 v23;
unsigned int v24;
unsigned int v25;
int v26;
__int64 v27;
UINT8 pCell;
_DWORD Cell[3];
UINT8 CoalesceForward[8];
*(_QWORD *)CoalesceForward = 0i64;
Cell[1] = -1;
v5 = CellAddress;
v7 = ((unsigned int)NewSize >> 3) - 1;
v8 = (unsigned int)NewSize;
Cell[2] = 0;
v9 = *(_QWORD *)&Hive;
if( v7 >= 0x10 )
{
v24 = v7 >> 4;
if( v24 > 0xFF )
{
v7 = 23;
}
else
{
_BitScanReverse(&v25, v24);
v7 = v25 + 16;
}
}
v10 = (_EX_PUSH_LOCK *)(*(_QWORD *)&Hive + 80i64);
ExAcquirePushLockExclusiveEx((_EX_PUSH_LOCK *)(*(_QWORD *)&Hive + 80i64), 0i64);
FreeCell = HvpFindFreeCell(
v9,
v7,
(unsigned int)v8,
Type,
(_HCELL **)CoalesceForward,
(_HV_GET_CELL_CONTEXT *)&Cell[1]);
if( FreeCell != -1 )
{
v13 = *(unsigned int **)CoalesceForward;
v14 = 0;
goto LABEL_4;
}
v26 = HvpAddBin(v9, (unsigned int)v8, Type);
if( v26 != -1 )
{
FreeCell = v26 + 32;
v27 = (*(__int64(__fastcall **)(__int64, _QWORD, _DWORD *))(v9 + 8))(v9, (unsigned int)(v26 + 32), &Cell[1]);
if( v27 )
{
v13 = (unsigned int *)(v27 - 4);
*(_QWORD *)CoalesceForward = v27 - 4;
if( v27 != 4 )
{
v14 = 1;
LABEL_4:
v15 = *v13;
if( (int)v8 + 8 > *v13 )
{
HvpDelistFreeCell(v9, FreeCell, Type, v11);
*v13 = -*v13;
goto LABEL_14;
}
v16 = v15 - v8;
*(unsigned int *)((char *)v13 + v8) = v15 - v8;
*v13 = -(int)v8;
if( v14 )
{
v23 = FreeCell + (unsigned int)v8;
}
else
{
v17 = (v15 >> 3) - 1;
if( (unsigned int)v17 >= 0x10 )
{
v18 = (unsigned int)v17 >> 4;
if( v18 > 0xFF )
{
v17 = 23i64;
}
else
{
_BitScanReverse(&v19, v18);
v17 = v19 + 16;
}
}
v20 = (v16 >> 3) - 1;
if( v20 >= 0x10 )
{
v21 = v20 >> 4;
if( v21 > 0xFF )
{
v20 = 23;
}
else
{
_BitScanReverse(&v21, v21);
v20 = v21 + 16;
}
}
if( (_DWORD)v17 == v20 )
goto LABEL_13;
pCell = 0;
HvpRemoveFreeCellHint((_HHIVE *)v9, FreeCell, v17, Type);
v23 = FreeCell + (unsigned int)v8;
}
HvpEnlistFreeCell((_HHIVE *)v9, v23, v16, Type, pCell);
LABEL_13:
v5 = CellAddress;
LABEL_14:
if( (_InterlockedExchangeAdd64(&v10->_bf_0, 0xFFFFFFFFFFFFFFFFui64) & 6) == 2 )
ExfTryToWakePushLock(v10);
KeAbPostRelease(v10);
if( v5 )
{
*v5 = (VOID *)(*(_QWORD *)CoalesceForward + 4i64);
*CellAddressContext = *(_HV_GET_CELL_CONTEXT *)&Cell[1];
}
else
{
(*(void(__fastcall **)(__int64, _DWORD *))(v9 + 16))(v9, &Cell[1]);
}
return FreeCell;
}
}
}
if( (_InterlockedExchangeAdd64(&v10->_bf_0, 0xFFFFFFFFFFFFFFFFui64) & 6) == 2 )
ExfTryToWakePushLock(v10);
KeAbPostRelease(v10);
return 0xFFFFFFFFi64;
}Referenced by:
HvAllocateCell
HvReallocateCell