KeSetPriorityAndQuantumProcess
NTSTATUS __stdcall KeSetPriorityAndQuantumProcess(
_EPROCESS *Process,
INT64 NewBase,
CHAR QuantumReset,
UINT64 ResetForegroundBoost,
UINT64 ApplyForegroundBoost){
NTSTATUS result;
NTSTATUS v6;
int v7;
unsigned int v8;
int v10;
int v11;
char v12;
char v13;
_EPROCESS *v14;
INT64 v15;
int v16;
int v17;
char v18;
int v19;
UINT64 updated;
UINT64 v21;
unsigned int v22;
char v23;
UINT8 v24;
volatile INT32 *v25;
NTSTATUS v26;
__int64 v27;
int v28;
INT64 v29;
int v30;
int v31;
char v32;
bool v33;
UINT64 v34;
UINT64 v35;
volatile INT32 *v36;
int v37;
unsigned int v38;
int v39;
int v40;
_EPROCESS **v41;
int v42;
int v43;
struct _KPRCB *CurrentPrcb;
_SINGLE_LIST_ENTRY ReadyList;
UINT64 SpinCount;
__int64 v47;
_EPROCESS *v48;
PEX_SPIN_LOCK SpinLock;
__int64 CurrentIrql;
INT64 NewBasea;
char v52;
CHAR v53;
v53 = QuantumReset;
result = *((char *)Process + 640);
v6 = NewBase;
v7 = ApplyForegroundBoost;
LODWORD(NewBasea) = 0;
v8 = ResetForegroundBoost;
if( result == (_DWORD)NewBase && ((_DWORD)ResetForegroundBoost == (_DWORD)ApplyForegroundBoost || (int)NewBase >= 16) )
{
if( QuantumReset )
KeSetQuantumProcess((__int64)Process, QuantumReset);
return v6;
}
else if( Process != (_EPROCESS *)KiInitialProcess )
{
v37 = 0;
v10 = 1;
v39 = 0;
if( (_DWORD)NewBase )
v10 = NewBase;
v52 = 0;
ReadyList.Next = 0i64;
v43 = WORD2(PerfGlobalGroupMask) & 0x2000;
v11 = 0;
v12 = 0;
CurrentIrql = KeGetCurrentIrql();
__writecr8(2ui64);
CurrentPrcb = KeGetCurrentPrcb();
v47 = *((_QWORD *)CurrentPrcb + 1);
SpinLock = (PEX_SPIN_LOCK)((char *)Process + 64);
ExAcquireSpinLockExclusiveAtDpcLevel((INT64 *)Process + 8);
v13 = v53;
if( v53 )
*((_BYTE *)Process + 641) = v53;
v40 = *((char *)Process + 640);
v42 = v10 - v40;
*((_BYTE *)Process + 640) = v10;
KeFlushProcessWriteBuffers(1u);
v14 = (_EPROCESS *)*((_QWORD *)Process + 6);
v48 = (_EPROCESS *)((char *)Process + 48);
v41 = (_EPROCESS **)v14;
if( v14 != (_EPROCESS *)((char *)Process + 48) )
{
if( v10 < 16 )
{
while( 1 )
{
v15 = (INT64)v14 - 760;
if( v13 )
*(_BYTE *)(v15 + 651) = v13;
HIDWORD(SpinCount) = 0;
while( _interlockedbittestandset64((volatile signed __int32 *)(v15 + 64), 0i64) )
{
do
KeYieldProcessorEx((UINT64 *)((char *)&SpinCount + 4));
while( *(_QWORD *)(v15 + 64) );
}
v16 = *(char *)(v15 + 563);
if( v16 <= v40 || v16 < 16 )
break;
KiReleaseThreadLockSafe(v15);
LABEL_43:
v13 = v53;
v14 = *v41;
v41 = (_EPROCESS **)v14;
if( v14 == v48 )
goto LABEL_44;
}
v17 = v16 + v42;
if( v16 + v42 >= 16 )
{
LODWORD(NewBasea) = 15;
}
else
{
if( v17 <= 0 )
v17 = 1;
LODWORD(NewBasea) = v17;
}
v18 = *(_BYTE *)(v15 + 645);
if( !v18 )
goto LABEL_25;
if( v40 < 16 )
{
KiReleaseThreadLockSafe(v15);
v23 = 0;
LABEL_42:
if( v43 )
{
if( v52 )
{
v52 = 0;
EtwTracePriority(v15, 0x530u, v39, v37, 0i64);
}
if( v23 && v16 != (_DWORD)NewBasea )
EtwTracePriority(v15, 0x531u, v16, NewBasea, &NewBasea);
}
goto LABEL_43;
}
if( v18 > 0 )
{
LODWORD(NewBasea) = 15;
}
else
{
LABEL_25:
v19 = NewBasea;
if( v18 < 0 )
v19 = 1;
LODWORD(NewBasea) = v19;
}
if( v15 != v47 || *((_BYTE *)CurrentPrcb + 32) )
{
updated = *(_QWORD *)(v15 + 72);
}
else
{
_disable();
updated = KiUpdateTotalCyclesCurrentThread((__int64)CurrentPrcb, v15, 0i64);
_enable();
}
v21 = updated + KiCyclesPerClockQuantum * (unsigned int)*(unsigned __int8 *)(v15 + 651);
if( (*(_DWORD *)(v15 + 120) & 0x20) != 0 )
_interlockedbittestandreset((volatile signed __int32 *)(v15 + 120), 5u);
*(_QWORD *)(v15 + 32) = v21;
if( v7 && (v23 = 0, (_DWORD)NewBasea == v16) )
{
v22 = v37;
}
else
{
v22 = KiSetBasePriorityAndClearDecrement((_KTHREAD *)v15, &NewBasea, v8);
v37 = v22;
v23 = 1;
}
v24 = 0;
if( v7 )
v24 = KiApplyForegroundBoostThread((_KTHREAD *)v15, &ReadyList);
if( !v23 )
goto LABEL_41;
if( !v24 )
{
v39 = *(char *)(v15 + 195);
if( KiSetPriorityThread((_KTHREAD *)v15, &ReadyList, v22) )
{
v37 = *(char *)(v15 + 195);
v52 = 1;
}
}
v25 = *(volatile INT32 **)(v15 + 232);
if( v25 && (*(_BYTE *)v25 & 0x7F) == 21 )
KiPriQueueThreadPriorityChanged(v25, v15);
else
LABEL_41:
KiReleaseThreadLockSafe(v15);
goto LABEL_42;
}
v26 = v40;
v28 = 0;
while( 1 )
{
v29 = (INT64)v14 - 760;
if( v13 )
*(_BYTE *)(v29 + 651) = v13;
LODWORD(SpinCount) = 0;
while( _interlockedbittestandset64((volatile signed __int32 *)(v29 + 64), 0i64) )
{
do
KeYieldProcessorEx(&SpinCount);
while( *(_QWORD *)(v29 + 64) );
}
v30 = *(char *)(v29 + 563);
v31 = v30 + v42;
if( v30 + v42 >= 16 )
{
if( v31 > 31 )
v31 = 31;
LODWORD(NewBasea) = v31;
}
else
{
v31 = 16;
LODWORD(NewBasea) = 16;
}
v32 = *(_BYTE *)(v29 + 645);
v27 = (__int64)CurrentPrcb;
v33 = v32 < 0;
if( !v32 )
goto LABEL_75;
if( v40 < 16 )
break;
KiReleaseThreadLockSafe(v29);
LABEL_91:
if( v43 )
{
if( v52 )
{
v52 = 0;
EtwTracePriority(v29, 0x530u, v39, v28, 0i64);
}
if( v12 )
{
v12 = 0;
if( v11 != v31 )
EtwTracePriority(v29, 0x531u, v11, v31, &NewBasea);
}
}
v13 = v53;
v14 = *v41;
v41 = (_EPROCESS **)v14;
if( v14 == v48 )
goto LABEL_45;
}
v33 = v32 < 0;
if( v32 <= 0 )
{
LABEL_75:
if( v33 )
v31 = 16;
LODWORD(NewBasea) = v31;
}
else
{
LODWORD(NewBasea) = 31;
}
v11 = v30;
if( v29 != v47 || *((_BYTE *)CurrentPrcb + 32) )
{
v34 = *(_QWORD *)(v29 + 72);
}
else
{
_disable();
v34 = KiUpdateTotalCyclesCurrentThread((__int64)CurrentPrcb, v29, 0i64);
_enable();
}
v35 = v34 + KiCyclesPerClockQuantum * (unsigned int)*(unsigned __int8 *)(v29 + 651);
if( (*(_DWORD *)(v29 + 120) & 0x20) != 0 )
_interlockedbittestandreset((volatile signed __int32 *)(v29 + 120), 5u);
*(_QWORD *)(v29 + 32) = v35;
v38 = KiSetBasePriorityAndClearDecrement((_KTHREAD *)v29, &NewBasea, 0i64);
v39 = *(char *)(v29 + 195);
v12 = 1;
if( KiSetPriorityThread((_KTHREAD *)v29, &ReadyList, v38) )
{
v38 = *(char *)(v29 + 195);
v52 = 1;
}
v36 = *(volatile INT32 **)(v29 + 232);
if( v36 && (*(_BYTE *)v36 & 0x7F) == 21 )
KiPriQueueThreadPriorityChanged(v36, v29);
else
KiReleaseThreadLockSafe(v29);
v28 = v38;
v31 = NewBasea;
goto LABEL_91;
}
LABEL_44:
v26 = v40;
v27 = (__int64)CurrentPrcb;
LABEL_45:
ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)SpinLock);
KiProcessDeferredReadyList(v27, &ReadyList, CurrentIrql);
return v26;
}
return result;
}Referenced by:
NtSetInformationProcess
PspSetProcessPriorityByClass