MiUpdatePfnPriorityByPte

VOID __stdcall MiUpdatePfnPriorityByPte(_MMPTE *PointerPte, INT64 DesiredPriority, CHAR a3){
  unsigned int v3; 
  unsigned __int64 PteBase; 
  INT64 v6; 
  wchar_t *v7; 
  unsigned __int64 v8; 
  int v9; 
  int v10; 
  __int64 v11; 
  UINT8 v12; 
  _MMPFN *v13; 
  unsigned __int8 CurrentIrql; 
  int v15; 
  char v16; 
  char v17; 
  _MMPTE *PteLimit; 
  unsigned __int64 v19; 
  __int64 v20; 
  UINT8 *v21; 
  char v22; 
  unsigned int v23; 
  UINT64 SpinCount; 
  INT64 v25; 

  v3 = DesiredPriority;
  while( 2 )
  {
    PteBase = (unsigned __int64)MmGetPteBase();
    while( 1 )
    {
      LODWORD(v6) = MI_READ_PTE_LOCK_FREE((INT64)PointerPte);
      v25 = v6;
      v8 = v6;
      if( (v6 & 1) != 0 )
      {
        v9 = 6;
      }
      else
      {
        if( (v6 & 0x400) != 0 )
          return;
        if( (v6 & 0x800) == 0 )
          return;
        LOBYTE(v10) = MiInvalidPteConforms(v6, (INT64 *)v6);
        if( !v10 )
          return;
        if( *(&stru_140C4DB30 + 42) )
        {
          if( (v8 & 0x10) != 0 )
            v8 &= ~0x10ui64;
          else
            v8 &= ~*(&stru_140C4DB30 + 42);
        }
        v9 = 2;
      }
      v11 = (v8 >> 12) & 0xFFFFFFFFFi64;
      v12 = 6 * v11;
      if( (MmGetPfnDb()[v11].u4._bf_0 & 0x4000000000000i64) == 0 )
        return;
      v13 = &MmGetPfnDb()[v11];
      CurrentIrql = KeGetCurrentIrql();
      __writecr8(2ui64);
      LODWORD(SpinCount) = 0;
      while( _interlockedbittestandset64((volatile signed __int32 *)&v13->u2, 0x3Fui64) )
      {
        do
          KeYieldProcessorEx(&SpinCount);
        while( v13->u2._bf_0 < 0 );
      }
      if( (_MMPTE *)(v13->PteLong | 0x8000000000000000ui64) != PointerPte )
      {
        LOBYTE(v15) = MI_PFN_IS_PROTO((_UNICODE_STRING *)v13, (_UNICODE_STRING *)v11, v12, v7);
        if( !v15 || (unsigned __int64)PointerPte < PteBase || PointerPte > MmGetPteLimit() )
          goto LABEL_44;
      }
      v16 = *((_BYTE *)&v13->u3 + 2);
      v17 = v16 & 7;
      if( v9 != 6 )
        break;
      if( v17 == 6 )
        goto LABEL_31;
      _InterlockedAnd64(&v13->u2.Lock, 0x7FFFFFFFFFFFFFFFui64);
      __writecr8(CurrentIrql);
      PteBase = (unsigned __int64)MmGetPteBase();
      if( (unsigned __int64)PointerPte >= PteBase )
      {
        PteLimit = MmGetPteLimit();
        if( PointerPte <= PteLimit )
        {
          v19 = (__int64)(((_QWORD)PointerPte << 25) - (PteBase << 25)) >> 16;
          if( (v19 < PteBase || v19 > (unsigned __int64)PteLimit) && MiGetSystemRegionType(v19) == 9 )
            return;
        }
      }
    }
    if( (unsigned __int8)(v17 - 2) > 2u || (v13->u2._bf_0 & 0x4000000000000000i64) != 0 )
    {
LABEL_32:
      _InterlockedAnd64(&v13->u2.Lock, 0x7FFFFFFFFFFFFFFFui64);
      __writecr8(CurrentIrql);
      continue;
    }
    break;
  }
LABEL_31:
  LODWORD(v20) = MI_READ_PTE_LOCK_FREE((INT64)PointerPte);
  if( v25 != v20 )
    goto LABEL_32;
  v22 = *((_BYTE *)&v13->u3 + 3);
  if( (v22 & 8) != 0 )
    v23 = 5;
  else
    v23 = v22 & 7;
  if( v3 != v23 && v3 >= v23 )
  {
    if( (v16 & 7) == 2 )
    {
      if( v23
        || (*(_DWORD *)(&v13->3 + 1) & 0x400i64) != 0
        || !MiIsPteInStore(
              *(_MI_PARTITION **)(*(&stru_140C4DB30 + 267) + 8 * (((unsigned __int64)v13->u4._bf_0 >> 39) & 0x3FF)),
              v13->OriginalPte) )
      {
        MiRelinkStandbyPage((ULONG_PTR)v13, v3, v21);
      }
    }
    else
    {
      *((_BYTE *)&v13->u3 + 3) = v22 ^ (v3 ^ v22) & 7;
    }
  }
LABEL_44:
  _InterlockedAnd64(&v13->u2.Lock, 0x7FFFFFFFFFFFFFFFui64);
  __writecr8(CurrentIrql);
}

Referenced by:

MiPfPrepareReadList
MiPfPrepareSequentialReadList
MiSystemFault