MiPickClusterForMappedFileFault

NTSTATUS __stdcall MiPickClusterForMappedFileFault(
        _MI_PARTITION *Partition,
        _MMINPAGE_SUPPORT *InPageSupport,
        _MI_FAULT_VA_LIST *FaultHead,
        _MMPTE *SubsectionBase,
        UINT64 SessionId,
        UINT64 PageFrameIndex,
        _MMPTE **ReturnBottomPte,
        _MMPTE **ReturnEndPte){
  _CONTROL_AREA *ControlArea; 
  NTSTATUS v9; 
  union {unsigned __int64 Long;volatile unsigned __int64 VolatileLong;_MMPTE_HARDWARE Hard;_MMPTE_PROTOTYPE Proto;_MMPTE_SOFTWARE Soft;_MMPTE_TIMESTAMP TimeStamp;_MMPTE_TRANSITION Trans;_MMPTE_SUBSECTION Subsect;_MMPTE_LIST List;} v10; 
  CHAR v11; 
  _MMPTE *PointerPte; 
  _ETHREAD *CurrentThread; 
  unsigned int v15; 
  _MMPTE *v16; 
  _MMPTE *v17; 
  UINT64 v18; 
  NTSTATUS result; 
  unsigned int ByteCount; 
  int v21; 
  unsigned int v22; 
  unsigned __int64 v23; 
  __int64 v24; 
  _MMPTE *v25; 
  unsigned __int64 v26; 
  unsigned __int64 v27; 
  __int64 v28; 
  int v29; 
  __int64 v30; 
  int ImageInformation; 
  __int64 v32; 
  _SEGMENT *Segment; 

  ControlArea = InPageSupport->ControlArea;
  v9 = 0;
  v10.Long = (unsigned __int64)InPageSupport->PteContents.u;
  v11 = 1;
  PointerPte = InPageSupport->PointerPte;
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  v15 = 1;
  Segment = ControlArea->Segment;
  if( (v10.Long & 0x400) == 0 )
    goto LABEL_5;
  if( CurrentThread->DisablePageFaultClustering )
    goto LABEL_5;
  ImageInformation = (int)ControlArea->Segment->u2.ImageInformation;
  if( (ImageInformation & 8) != 0 && CurrentThread->CacheManagerActive != 2 )
    goto LABEL_5;
  if( (__int64)Partition->Vp.ResidentAvailablePages < 160 )
    goto LABEL_5;
  if( *(&stru_140C4DB30 + 948) )
  {
    --*(&stru_140C4DB30 + 948);
LABEL_5:
    v16 = PointerPte;
    v17 = PointerPte;
    goto LABEL_6;
  }
  if( !MiSufficientAvailablePages((INT64)Partition, 0x140ui64) )
    goto LABEL_5;
  ByteCount = InPageSupport->ByteCount;
  if( ByteCount == 1 )
    goto LABEL_5;
  v17 = &SubsectionBase[HIDWORD(ControlArea->NumberOfMappedViews)
                      - (unsigned __int64)(HIDWORD(ControlArea->NumberOfUserReferences) & 0x3FFFFFFF)
                      - 1];
  v21 = ImageInformation;
  if( !FaultHead )
  {
    if( (ImageInformation & 0x20) != 0 )
    {
      ByteCount = 4;
      if( (ControlArea->NumberOfPfnReferences & 4) != 0 )
        ByteCount = 8;
    }
    else if( !ByteCount )
    {
      ByteCount = CurrentThread->ReadClusterSize + 1;
    }
  }
  v32 = 8i64 * ByteCount;
  if( v17 > &PointerPte[(unsigned __int64)v32 / 8 - 1] )
    v17 = &PointerPte[(unsigned __int64)v32 / 8 - 1];
  if( !FaultHead && (v21 & 0x20000000) != 0 )
  {
    v22 = MiStartingOffset((_SUBSECTION *)ControlArea, PointerPte, (unsigned int)SessionId);
    v29 = v22 & (*(&stru_140C4DB30 + 984) - 1);
    if( v17 > &PointerPte[((unsigned int)(*(&stru_140C4DB30 + 984) - v29) >> 12) - 1] )
      v17 = &PointerPte[((unsigned int)(*(&stru_140C4DB30 + 984) - v29) >> 12) - 1];
  }
  else
  {
    v22 = 0;
  }
  if( (unsigned __int64)v17 > ((unsigned __int64)PointerPte & 0xFFFFFFFFFFFFF000ui64 | 0xFF8) )
    v17 = (_MMPTE *)((unsigned __int64)PointerPte & 0xFFFFFFFFFFFFF000ui64 | 0xFF8);
  v23 = (unsigned __int64)v17;
  if( v17 > PointerPte )
  {
    do
    {
      LODWORD(v24) = MI_READ_PTE_LOCK_FREE(v23);
      if( v24 == v10.Long )
      {
        ++v15;
      }
      else if( (_MMPTE *)v23 == v17 )
      {
        --v17;
      }
      v23 -= 8i64;
    }
    while( v23 > (unsigned __int64)PointerPte );
  }
  v25 = &v17[v32 / 0xFFFFFFFFFFFFFFF8ui64 + 1];
  if( v25 < SubsectionBase )
    v25 = SubsectionBase;
  v26 = (unsigned __int64)PointerPte & 0xFFFFFFFFFFFFF000ui64;
  if( (unsigned __int64)v25 >= ((unsigned __int64)PointerPte & 0xFFFFFFFFFFFFF000ui64) )
    v26 = (unsigned __int64)v25;
  if( FaultHead || (InPageSupport->u1.e1._bf_0 & 0x40) != 0 )
  {
    v27 = (unsigned __int64)PointerPte;
  }
  else
  {
    v27 = v26;
    if( ((__int64)Segment->u2.ImageInformation & 0x20000000) != 0 )
    {
      v30 = (v22 >> 12) & ((unsigned int)(*(&stru_140C4DB30 + 984) - 1) >> 12);
      if( v26 < (unsigned __int64)&PointerPte[-v30] )
        v27 = (unsigned __int64)&PointerPte[-(unsigned int)v30];
    }
  }
  v16 = (_MMPTE *)v27;
  while( v27 < (unsigned __int64)PointerPte )
  {
    LODWORD(v28) = MI_READ_PTE_LOCK_FREE(v27);
    if( v28 == v10.Long )
    {
      ++v15;
    }
    else if( (_MMPTE *)v27 == v16 )
    {
      ++v16;
    }
    v27 += 8i64;
  }
LABEL_6:
  v18 = v15 - 1;
  if( PageFrameIndex == -1i64 )
    v18 = v15;
  if( (_DWORD)v18 )
  {
    if( PageFrameIndex == -1i64 )
      v11 = 3;
    v9 = MiObtainFaultCharges(Partition, v18, v11);
  }
  result = v9 + 1;
  if( PageFrameIndex == -1i64 )
    result = v9;
  *ReturnBottomPte = v16;
  *ReturnEndPte = v17;
  return result;
}

Referenced by:

MiResolveMappedFileFault