HalpTimerClockPowerChange

INT64 __stdcall HalpTimerClockPowerChange(PVOID BugCheckParameter3, INT8 a2){
  struct _KPRCB *CurrentPrcb; 
  char v3; 
  ULONG_PTR v4; 
  INT64 result; 
  CHAR v6; 
  INT64 v7; 
  void *v8; 
  void *v9; 
  ULONG_PTR v10; 
  ULONG_PTR v11; 
  signed __int64 v12; 
  unsigned __int64 v13; 
  __int64 v14; 
  int v15; 
  __int64 v16; 
  ULONG_PTR BugCheckParameter4; 
  unsigned __int64 v18; 
  CurrentPrcb = KeGetCurrentPrcb();
  v3 = *((_BYTE *)BugCheckParameter3 + 224) & 1;
  if( a2 )
  {
    result = HalpTimerClockInitialize();
    if( !v3 )
      ++KiClockStats;
  }
  else
  {
    v4 = HalpAlwaysOnTimer;
    if( !HalpAlwaysOnTimer )
      KeBugCheckEx(
        HalpAlwaysOnTimer + 92,
        0x113ui64,
        (unsigned int)(HalpAlwaysOnTimer + 33),
        (ULONG_PTR)BugCheckParameter3,
        HalpAlwaysOnTimer & BugCheckParameter4);
    if( v3 )
    {
      result = (unsigned int)KiClockTimerOwner;
      if( *((_DWORD *)KeGetCurrentPrcb() + 9) != (_DWORD)KiClockTimerOwner )
        return result;
    }
    else
    {
      ++KiClockStats;
    }
    HalpTimerClockStop();
    KeGetNextClockTickDuration(v7, v6);
    v11 = v10;
    v12 = 0x989680ui64 / *(_QWORD *)(v4 + 192);
    v13 = 0x989680ui64 % *(_QWORD *)(v4 + 192);
    if( v12 < 5000 )
      v12 = 5000i64;
    if( (__int64)v11 < v12 )
    {
      ++HalpTimerClockSwapViolationCount;
      v11 = v12;
    }
    if( v11 > HalpTimerMaxIncrement )
      KeBugCheckEx(0x5Cu, 0x113ui64, 0x25ui64, v11, 0i64);
    HalpTimerGetInternalData((KDPC *)v4, (PVOID)v13, v8, v9);
    v15 = (*(__int64(__fastcall **)(__int64))(v4 + 104))(v14);
    if( v15 < 0 )
      KeBugCheckEx(0x5Cu, 0x113ui64, 0xFui64, v4, v15);
    result = HalpSetTimerAnyMode(v4, (unsigned int)v11, v16, &v18);
    if( (int)result < 0 )
      KeBugCheckEx(0x5Cu, 0x113ui64, 0x23ui64, v4, (int)result);
    *((_BYTE *)CurrentPrcb + 34) |= 2u;
  }
  return result;
}

Referenced by:

HalpTimerPowerChange