RtlpHpLfhSubsegmentCreate
NTSTATUS __stdcall RtlpHpLfhSubsegmentCreate(INT64 a1, INT64 a2, UINT64 a3){
__int64 v4;
unsigned int v5;
unsigned int v7;
unsigned int v8;
unsigned int v9;
NTSTATUS v10;
unsigned int v11;
unsigned int v12;
unsigned int v13;
int v14;
unsigned int v15;
int v16;
unsigned int v17;
unsigned int v18;
unsigned int v19;
unsigned int v20;
unsigned int v21;
UINT8 v22;
INT64 v23;
unsigned int v24;
NTSTATUS v25;
unsigned int v27;
unsigned int v28;
unsigned int v29;
unsigned int v30;
int v31;
int v32;
unsigned int v33;
int v34;
unsigned int v35;
v4 = *(unsigned __int8 *)(a2 + 1);
v5 = a3;
v31 = 0;
v34 = 0;
v7 = (unsigned __int16)word_140010F30[v4];
v33 = v7;
if( (RtlpHpLfhPerfFlags & 1) != 0 )
{
LOBYTE(v8) = RtlpHpLfhBucketSubsegmentStatsUpdate((INT64 *)(a1 + 64), (unsigned int)v4);
v9 = v8;
}
else
{
v9 = 0;
}
v10 = RtlpHpLfhBucketComputeNewSubsegmentBlockCount(a2, v9);
v11 = 7;
v12 = v7 * v10;
v13 = 18;
v14 = (8 * (((unsigned __int64)(unsigned int)(2 * v10) + 63) >> 6) + 63) & 0xFFFFFFF0;
v15 = v14 + 2 * ((v7 * v10 + v14 + 4095) >> 12);
v16 = v15 + v12;
if( v15 + v12 >= 0xF0000 )
v16 = 983040;
_BitScanReverse(&v17, v16 - 1);
v18 = 7;
v19 = v17 + 1;
if( v19 > 7 )
v18 = v19;
v20 = 18;
if( v18 < 0x12 )
v20 = v18;
if( v20 <= 0xC )
LOBYTE(v20) = 12;
v21 = 1 << v20;
if( (RtlpHpLfhPerfFlags & 8) != 0 && v15 <= v12 >> 6 )
{
if( v12 >= 0xF0000 )
v12 = 983040;
_BitScanReverse(&v29, v12 - 1);
v30 = v29 + 1;
if( v30 > 7 )
v11 = v30;
v35 = v11;
if( v11 < 0x12 )
v13 = v11;
if( v13 <= 0xC )
LOBYTE(v13) = 12;
if( v21 > 1 << v13 )
v21 = 1 << v13;
}
if( (v5 & 1) != 0 )
v22 = -1;
else
v22 = RtlpHpAcquireLockShared((_EX_PUSH_LOCK *)(a1 + 72), *(unsigned __int8 *)(a1 + 57));
v23 = ((__int64(__fastcall *)(_QWORD, _QWORD, _QWORD, int *, int *))(a1 ^ RtlpHpHeapGlobals ^ *(_QWORD *)(a1 + 8)))(
*(_QWORD *)a1,
v21,
v5,
&v34,
&v31);
if( v23 )
{
if( v9 && (RtlpHpLfhPerfFlags & 2) != 0 || (v34 & 1) != 0 )
{
v24 = v21;
}
else
{
v27 = 2 * v33;
v32 = 0;
if( ((2 * v33 - 1) & (2 * v33)) != 0 )
{
_BitScanReverse(&v28, v27);
v32 = v28 + 1;
v27 = 1 << (v28 + 1);
}
if( v27 <= 0x1000 )
v27 = 4096;
v24 = v21;
if( v27 < v21 )
v24 = v27;
}
if( ((int(__fastcall *)(_QWORD, INT64, _QWORD))(a1 ^ RtlpHpHeapGlobals ^ *(_QWORD *)(a1 + 24)))(
*(_QWORD *)a1,
v23,
v24) < 0 )
{
v25 = 0;
}
else
{
RtlpHpLfhSubsegmentInitialize(v23, v21, v24, v33, a1);
_InterlockedIncrement64((volatile signed __int64 *)(a2 + 64));
_InterlockedExchangeAdd64((volatile signed __int64 *)(a2 + 56), *(unsigned __int16 *)(v23 + 34));
v25 = v23;
v23 = 0i64;
}
if( v23 )
((void(__fastcall *)(_QWORD, INT64, _QWORD, _QWORD))(a1 ^ RtlpHpHeapGlobals ^ *(_QWORD *)(a1 + 16)))(
*(_QWORD *)a1,
v23,
v21,
v5);
}
else
{
v25 = 0;
}
if( (v5 & 1) == 0 )
{
if( *(_BYTE *)(a1 + 57) )
{
ExReleaseSpinLockSharedFromDpcLevel((PEX_SPIN_LOCK)(a1 + 72));
__writecr8(v22);
}
else
{
if( _InterlockedCompareExchange64((volatile signed __int64 *)(a1 + 72), 0i64, 17i64) != 17 )
ExfReleasePushLockShared((_EX_PUSH_LOCK *)(a1 + 72));
KeAbPostRelease((VOID *)(a1 + 72));
KiLeaveGuardedRegionUnsafe((__int64)KeGetCurrentThread());
}
}
return v25;
}Referenced by:
RtlpHpLfhSlotAllocate