RtlInterlockedSetClearRun
NTSTATUS __fastcall RtlInterlockedSetClearRun(INT64 a1, UINT64 a2, UINT64 a3){
UINT64 v3;
volatile signed __int32 *v4;
unsigned int v5;
unsigned __int64 v6;
signed __int32 v7;
int v8;
signed __int32 v9;
int v11;
signed __int32 v12;
int v13;
signed __int32 v14;
signed __int32 v15;
int v16;
signed __int32 v17;
unsigned int v18;
volatile signed __int32 *v19;
unsigned __int64 v20;
unsigned __int64 v21;
v3 = a2 & 0x1F;
v4 = (volatile signed __int32 *)((*(_QWORD *)(a1 + 8) + ((unsigned __int64)(unsigned int)a2 >> 3)) & 0xFFFFFFFFFFFFFFFCui64);
v5 = a3;
v6 = (unsigned int)a2;
if( v3 + (unsigned int)a3 <= 0x20 )
{
v7 = *v4;
if( (_DWORD)a3 == 32 )
v8 = -1;
else
v8 = ((1 << a3) - 1) << v3;
while( (v7 & v8) == 0 )
{
v9 = v7;
v7 = _InterlockedCompareExchange(v4, v8 | v7, v7);
if( v9 == v7 )
return 1;
}
return 0;
}
v11 = a2 & 0x1F;
if( (a2 & 0x1F) == 0 )
goto LABEL_12;
v12 = *v4;
v13 = ((1 << (32 - v11)) - 1) << v3;
do
{
if( (v12 & v13) != 0 )
return 0;
v14 = v12;
v12 = _InterlockedCompareExchange(v4, v13 | v12, v12);
}
while( v14 != v12 );
v5 = a3 - (32 - v11);
for( ++v4; ; ++v4 )
{
LABEL_12:
if( v5 < 0x20 )
{
if( !v5 )
return 1;
v15 = *v4;
v16 = (1 << v5) - 1;
while( (v15 & v16) == 0 )
{
v17 = v15;
v15 = _InterlockedCompareExchange(v4, v16 | v15, v15);
if( v17 == v15 )
return 1;
}
v18 = a3 - v5;
v19 = (volatile signed __int32 *)(*(_QWORD *)(a1 + 8) + 4 * (v6 >> 5));
if( v3 + (unsigned int)a3 - v5 > 0x20 )
{
if( v11 )
{
_InterlockedAnd(v19, ~(((1 << (32 - v11)) - 1) << v3));
v18 -= 32 - v11;
++v19;
}
if( v18 >= 0x20 )
{
v21 = (unsigned __int64)v18 >> 5;
do
{
*v19 = 0;
v18 -= 32;
++v19;
--v21;
}
while( v21 );
}
goto LABEL_36;
}
LABEL_38:
if( v18 == 32 )
*v19 = 0;
else
_InterlockedAnd(v19, ~(((1 << v18) - 1) << v3));
return 0;
}
if( _InterlockedCompareExchange(v4, -1, 0) )
break;
v5 -= 32;
}
if( (_DWORD)a3 == v5 )
return 0;
v18 = a3 - v5;
v19 = (volatile signed __int32 *)(*(_QWORD *)(a1 + 8) + 4 * (v6 >> 5));
if( v3 + (unsigned int)a3 - v5 <= 0x20 )
goto LABEL_38;
if( v11 )
{
_InterlockedAnd(v19, ~(((1 << (32 - v11)) - 1) << v3));
v18 -= 32 - v11;
++v19;
}
if( v18 >= 0x20 )
{
v20 = (unsigned __int64)v18 >> 5;
do
{
*v19 = 0;
v18 -= 32;
++v19;
--v20;
}
while( v20 );
}
LABEL_36:
if( v18 )
_InterlockedAnd(v19, -1 << v18);
return 0;
}Referenced by:
EtwpFindUserBufferSpace
MiDecommitHardwareEnclavePages
MiGetPageFromSlabEntry
MiQueuePinDriverAddressLog
RtlpFcAddDelayedUsageReportToBuffer