KeSetTimer2
NTSTATUS __fastcall KeSetTimer2(INT64 a1, INT64 a2, INT64 a3, INT64 a4){
INT64 v5;
INT64 v6;
char v8;
char v9;
unsigned __int64 v10;
UINT64 v11;
__int64 v12;
__int64 v13;
unsigned __int8 v14;
int v15;
char v16;
bool v17;
char v18;
signed __int32 v19;
signed __int32 v20;
CHAR v21;
INT64 v22;
INT64 v24;
INT64 v25;
char v26;
INT64 v27;
signed __int32 v28;
UINT8 WasLate;
__int64 CurrentIrql;
INT64 CurrentQpc;
CurrentQpc = 0i64;
v5 = a3;
v6 = a2;
if( a3 && a3 < (unsigned int)KeMinimumIncrement )
v5 = (unsigned int)KeMinimumIncrement;
v8 = *(_BYTE *)(a1 + 129);
CurrentIrql = KeGetCurrentIrql();
__writecr8(2ui64);
v9 = 0;
if( a2 > 0 )
{
v9 = 1;
if( (v8 & 4) != 0 )
{
LODWORD(v27) = RtlGetSystemTimePrecise();
v24 = v27;
}
else
{
v24 = *(_QWORD *)&KUSER_SHARED_DATA.SystemTime.LowPart;
}
v25 = 0i64;
if( v6 > v24 )
v25 = v24 - v6;
v6 = v25;
}
if( (v8 & 4) != 0 )
LODWORD(v10) = RtlGetInterruptTimePrecise(&CurrentQpc);
else
v10 = *(_QWORD *)&KUSER_SHARED_DATA.InterruptTime.LowPart;
v11 = v10 - v6;
if( v10 - v6 < v10 || v11 == -1i64 )
v11 = -2i64;
v12 = v11;
if( a4 && *(_BYTE *)(a1 + 130) != 21 )
{
v13 = *(_QWORD *)(a4 + 8);
if( v13 == -1 )
{
v12 = -1i64;
}
else
{
v12 = v13 + v11;
if( v13 + v11 < v11 || v12 == -1 )
v12 = -2i64;
}
}
v14 = 0;
WasLate = 0;
v15 = 1;
if( !KiAcquireTimer2LockUnlessDisabled((_KTIMER2 *)a1) )
{
if( KiAcquireTimer2CollectionLockIfInserted((_KTIMER2 *)a1) )
{
KiRemoveTimer2((_KTIMER2 *)a1);
KxReleaseSpinLock(&KiTimer2CollectionLock);
v14 = 1;
}
else
{
v16 = *(_BYTE *)(a1 + 1);
if( (v16 & 0xF) != 0 )
{
v15 = 8;
if( (v16 & 4) == 0 )
v14 = 1;
}
}
v17 = (KiVelocityFlags & 0x2000) == 0;
*(_QWORD *)(a1 + 72) = v11;
*(_QWORD *)(a1 + 80) = v12;
v18 = *(_BYTE *)(a1 + 129);
*(_DWORD *)(a1 + 4) = 0;
*(_QWORD *)(a1 + 88) = v5;
*(_BYTE *)(a1 + 128) = v9;
if( v17 )
{
if( (v18 & 0x10) == 0 )
{
LABEL_43:
*(_BYTE *)(a1 + 129) = v18 | 0x10;
KiUpdateTimer2Collections((_BYTE *)a1);
}
}
else if( (v18 & 0xE) == 0 )
{
if( !PsTimerResolutionActive((INT64)KeGetCurrentThread()->ApcState.Process) )
{
if( v26 )
{
*(_BYTE *)(a1 + 129) = v18 & 0xEF;
KiUpdateTimer2Collections((_BYTE *)a1);
}
goto LABEL_17;
}
if( !v26 )
goto LABEL_43;
}
LABEL_17:
if( v15 == 1 )
{
KxAcquireSpinLock(&KiTimer2CollectionLock);
KiInsertTimer2WithCollectionLockHeld((_KTIMER2 *)a1, 1u, &WasLate);
}
v19 = *(_DWORD *)a1;
v20 = _InterlockedCompareExchange(
(volatile signed __int32 *)a1,
(v15 << 8) | *(_DWORD *)a1 & 0xFFFFF07F,
*(_DWORD *)a1);
if( v19 != v20 )
{
do
{
v28 = v20;
v20 = _InterlockedCompareExchange((volatile signed __int32 *)a1, (v15 << 8) | v20 & 0xFFFFF07F, v20);
}
while( v28 != v20 );
}
if( v15 == 1 )
KxReleaseSpinLock(&KiTimer2CollectionLock);
if( !KeIsForceIdleEngaged() )
{
if( WasLate )
{
KiRequestTimer2Expiration(v22, v21);
}
else if( (v8 & 4) != 0 && KiShouldActivateHRTimerClock(*(UINT64 *)&KUSER_SHARED_DATA.InterruptTime.LowPart, v11) )
{
KiSendClockInterruptToClockOwner();
}
}
}
__writecr8((unsigned __int8)CurrentIrql);
return v14;
}Referenced by:
EtwpCoverageEnsureContext
EtwpCoverageRecord
ExInitializeTimeRefresh
ExSetTimer
ExpSetTimerObject2
ExpTimeRefreshWork
ExpWorkQueueManagerThread
HalpBlkInitSystem
KiTriggerForegroundBoostDpc
MiStoreEvictThread
NtCreateWorkerFactory
NtSetInformationWorkerFactory
PopCheckPowerSourceAfterRtcWakeSet
PopDirectedDripsStartDisengageTimer
PopDripsWatchdogScheduleNextTimer
PopIdleArmAoAcDozeS4Timer
PopNetArmDsEvaluationTimer
PopNetArmRefreshTimer
PopPowerAggregatorSessionSwitchWorker
PopPowerButtonWorkCallback
PopSleepstudyStartNextSession
PopThermalUpdateTelemetryClientCount
PopThermalWorker
PpmRegisterPerfStates
SMKM_STORE_MGR::SmHighMemPriorityTimerStart