MiDeleteNonPagedPoolPte

NTSTATUS __stdcall MiDeleteNonPagedPoolPte(PVOID BugCheckParameter2){
  INT64 v1; 
  int v2; 
  int v4; 
  UINT64 v5; 
  UINT64 v6; 
  __int64 v7; 
  int i; 
  INT64 v9; 
  __int64 v10; 
  char *v11; 
  int v12; 
  bool v13; 
  UINT64 v14; 
  void *LeafVa; 
  ULONG_PTR BugCheckParameter4; 
  UINT64 v18[7]; 
  UINT64 SpinCount; 
  v4 = v2;
  v5 = v1;
  v18[0] = MI_READ_PTE_LOCK_FREE(v1);
  v6 = v18[0];
  if( (v18[0] & 1) != 0 && v4 <= 1 )
  {
    v7 = 1i64;
    for( i = v4; i; --i )
      v7 <<= 9;
    v9 = *((_QWORD *)BugCheckParameter2 + 21);
    if( SLOBYTE(v18[0]) < 0 )
    {
      if( (*(_DWORD *)(v9 + 204) & 1) != 0 )
      {
        LeafVa = (void *)MiGetLeafVa(v5);
        if( (unsigned __int64)LeafVa < *((_QWORD *)BugCheckParameter2 + 4)
          || (unsigned __int64)LeafVa + 4096 * BugCheckParameter4 - 1 > *((_QWORD *)BugCheckParameter2 + 5) )
        {
          KeBugCheckEx(0x1Au, 0x5306ui64, (ULONG_PTR)BugCheckParameter2, (ULONG_PTR)LeafVa, BugCheckParameter4);
        }
        MiDecommitLargePoolVa(LeafVa, (MMPTE *)v5, BugCheckParameter4);
        *(_DWORD *)(v9 + 212) += 512;
      }
    }
    else
    {
      MiPteInShadowRange((UINT64)v18);
      v10 = 48 * ((v6 >> 12) & 0xFFFFFFFFFi64);
      v11 = (char *)MmGetPfnDb() + v10;
      if( v4 == 1 )
      {
        if( (*((_QWORD *)v11 + 3) & 0x3FFFFFFFFFFFFFFFi64) != 1
          || !(unsigned int)MiEvictPageTableLock((INT64)&qword_140C4F380, (volatile UINT64 *)v5, ZeroPte, 2) )
        {
          return 0;
        }
      }
      else
      {
        if( (*(_DWORD *)(v9 + 204) & 1) == 0 )
          return 0;
        *(_QWORD *)v5 = ZeroPte;
        if( (v11[35] & 0x10) == 0 )
          ++*(_DWORD *)(v9 + 212);
      }
      v12 = *(_DWORD *)(v9 + 208);
      if( !v12 )
        *(_QWORD *)(v9 + 216) = MiGetContainingPageTable(v5);
      *(_DWORD *)(v9 + 208) = v12 + 1;
      LODWORD(SpinCount) = 0;
      while( _interlockedbittestandset64((volatile signed __int32 *)v11 + 6, 0x3Fui64) )
      {
        do
          KeYieldProcessorEx(&SpinCount);
        while( *((__int64 *)v11 + 3) < 0 );
      }
      if( (*(_DWORD *)(v9 + 204) & 2) == 0 )
      {
        if( *((_WORD *)v11 + 16) != 1 )
          KeBugCheckEx(0x4Eu, 0x9Aui64, v10 / 48, v11[34] & 7, *((unsigned __int16 *)v11 + 16));
        v11[34] = v11[34] & 0xF8 | 5;
      }
      if( v4 )
      {
        *(_QWORD *)v11 = *(_QWORD *)(v9 + 192);
        *(_QWORD *)(v9 + 192) = v11;
        _InterlockedAnd64((volatile signed __int64 *)v11 + 3, 0x7FFFFFFFFFFFFFFFui64);
        MiInsertRecursiveTbFlushEntries(v9, (unsigned int)v4, v5);
      }
      else
      {
        if( (*(_DWORD *)(v9 + 204) & 2) == 0 )
        {
          *(_QWORD *)v11 = *(_QWORD *)(v9 + 184);
          *(_QWORD *)(v9 + 184) = v11;
        }
        _InterlockedAnd64((volatile signed __int64 *)v11 + 3, 0x7FFFFFFFFFFFFFFFui64);
        v13 = (*(_DWORD *)(v9 + 200) & 0x40000000) == 0;
        v18[0] = 0i64;
        if( v13 )
        {
          MiInitializeTbFlushStamps(v18);
          *(_QWORD *)v5 = v18[0];
        }
        v14 = v18[0];
        if( qword_140C4DC80 && (v18[0] & 0x10) == 0 )
          v14 = v18[0] & ~qword_140C4DC80;
        if( (v14 & 0xFFFFFFFF00000000ui64) == 0 )
          MiInsertTbFlushEntry(v9, (__int64)((v5 << 25) - ((_QWORD)MmGetPteBase() << 25)) >> 16, 1i64, 0i64);
      }
    }
  }
  return 0;
}

Referenced by:

MiClearNonPagedPtes