MiIsExtentDangling

NTSTATUS __fastcall MiIsExtentDangling(UINT64 PageFrameIndex, UINT64 a2, CHAR a3){
  UINT64 v4; 
  UINT64 v5; 
  _MMPFN *PfnDb; 
  UINT64 v8; 
  union {$8D9ED47C9F2F2CD645B633E301950288 __s0;unsigned __int64 EntireField;} *p_u4; 
  int v10; 
  _ETHREAD *CurrentThread; 
  _RTL_BALANCED_NODE *Root; 
  _RTL_BALANCED_NODE *v13; 
  _RTL_BALANCED_NODE *v14; 
  _RTL_BALANCED_NODE *v15; 
  unsigned __int64 i; 
  _ETHREAD *v17; 

  v4 = PageFrameIndex + a2;
  v5 = a2;
  PfnDb = MmGetPfnDb();
  v8 = PageFrameIndex;
  if( PageFrameIndex < PageFrameIndex + a2 )
  {
    p_u4 = &PfnDb[PageFrameIndex].u4;
    while( 1 )
    {
      MiIsPfn(v8);
      if( v10 )
      {
        if( (p_u4->_bf_0 & 0x2000000000000i64) != 0 )
          break;
      }
      ++v8;
      p_u4 += 6;
      if( v8 >= v4 )
        goto LABEL_8;
    }
    LODWORD(v4) = v8;
    v5 = v8 - PageFrameIndex;
  }
LABEL_8:
  if( (a3 & 2) == 0 )
  {
    CurrentThread = (_ETHREAD *)KeGetCurrentThread();
    --CurrentThread->Tcb.SpecialApcDisable;
    ExAcquirePushLockSharedEx(&stru_140C4C9E8, 0i64);
    Root = stru_140C4C9E0.Root;
    if( stru_140C4C9E0.Root )
    {
      do
      {
        v13 = Root[1].Children[1];
        if( v5 + PageFrameIndex <= (unsigned __int64)v13 )
        {
          Root = Root->Children[0];
        }
        else
        {
          if( PageFrameIndex < (unsigned __int64)v13 + Root[1].ParentValue )
            break;
          Root = Root->Children[1];
        }
      }
      while( Root );
      if( Root )
      {
        while( 1 )
        {
          v14 = Root->Children[0];
          v15 = Root;
          if( Root->Children[0] )
          {
            for( ; v14->Children[1]; v14 = v14->Children[1] )
              ;
          }
          else
          {
            for( i = Root->ParentValue; ; i = v14->ParentValue )
            {
              v14 = (_RTL_BALANCED_NODE *)(i & 0xFFFFFFFFFFFFFFFCui64);
              if( !v14 || v14->Children[1] == v15 )
                break;
              v15 = v14;
            }
          }
          if( !v14
            || (_RTL_BALANCED_NODE *)((char *)v14[1].Children[1] + v14[1].ParentValue) <= (_RTL_BALANCED_NODE *)PageFrameIndex )
          {
            break;
          }
          Root = v14;
        }
        v4 = (UINT64)Root[1].Children[1];
        if( PageFrameIndex >= v4 )
          LODWORD(v4) = PageFrameIndex;
      }
    }
    v17 = (_ETHREAD *)KeGetCurrentThread();
    if( _InterlockedCompareExchange64(&stru_140C4C9E8._bf_0, 0i64, 17i64) != 17 )
      ExfReleasePushLockShared(&stru_140C4C9E8);
    KeAbPostRelease(&stru_140C4C9E8);
    KiLeaveGuardedRegionUnsafe((__int64)v17);
  }
  return v4;
}

Referenced by:

FsRtlIsExtentDangling
MiAddPhysicalMemory