MiIsExtentDangling

UINT64 __fastcall MiIsExtentDangling(UINT64 PageFrameIndex, UINT64 a2, CHAR a3){
  UINT64 v4; 
  UINT64 v5; 
  _MMPFN *PfnDb; 
  UINT64 v8; 
  _QWORD *v9; 
  _ETHREAD *CurrentThread; 
  _QWORD *v11; 
  UINT64 v12; 
  _QWORD *v13; 
  _QWORD *v14; 
  __int64 i; 
  _ETHREAD *v16; 
  v4 = PageFrameIndex + a2;
  v5 = a2;
  PfnDb = MmGetPfnDb();
  v8 = PageFrameIndex;
  if( PageFrameIndex < PageFrameIndex + a2 )
  {
    v9 = (_QWORD *)((char *)PfnDb + 48 * PageFrameIndex + 40);
    while( !(unsigned int)MiIsPfn(v8) || (*v9 & 0x2000000000000i64) == 0 )
    {
      ++v8;
      v9 += 6;
      if( v8 >= v4 )
        goto LABEL_8;
    }
    v4 = v8;
    v5 = v8 - PageFrameIndex;
  }
LABEL_8:
  if( (a3 & 2) == 0 )
  {
    CurrentThread = (_ETHREAD *)KeGetCurrentThread();
    --*((_WORD *)CurrentThread + 243);
    ExAcquirePushLockSharedEx((UINT64)&qword_140C4C9E8, 0i64);
    v11 = (_QWORD *)qword_140C4C9E0;
    if( qword_140C4C9E0 )
    {
      do
      {
        v12 = v11[4];
        if( v5 + PageFrameIndex <= v12 )
        {
          v11 = (_QWORD *)*v11;
        }
        else
        {
          if( PageFrameIndex < v11[5] + v12 )
            break;
          v11 = (_QWORD *)v11[1];
        }
      }
      while( v11 );
      if( v11 )
      {
        while( 1 )
        {
          v13 = (_QWORD *)*v11;
          v14 = v11;
          if( *v11 )
          {
            for( ; v13[1]; v13 = (_QWORD *)v13[1] )
              ;
          }
          else
          {
            for( i = v11[2]; ; i = v13[2] )
            {
              v13 = (_QWORD *)(i & 0xFFFFFFFFFFFFFFFCui64);
              if( !v13 || (_QWORD *)v13[1] == v14 )
                break;
              v14 = v13;
            }
          }
          if( !v13 || v13[4] + v13[5] <= PageFrameIndex )
            break;
          v11 = v13;
        }
        v4 = v11[4];
        if( PageFrameIndex >= v4 )
          v4 = PageFrameIndex;
      }
    }
    v16 = (_ETHREAD *)KeGetCurrentThread();
    if( _InterlockedCompareExchange64((volatile signed __int64 *)&qword_140C4C9E8, 0i64, 17i64) != 17 )
      ExfReleasePushLockShared((INT64 *)&qword_140C4C9E8);
    KeAbPostRelease(&qword_140C4C9E8);
    KiLeaveGuardedRegionUnsafe((__int64)v16);
  }
  return v4;
}

Referenced by:

FsRtlIsExtentDangling
MiAddPhysicalMemory