MiReferenceActiveSubsection

NTSTATUS __stdcall MiReferenceActiveSubsection(_SUBSECTION *Subsection, UINT64 Flags, UINT8 OldIrql){
  _CONTROL_AREA *ControlArea; 
  UINT64 v4; 
  int v5; 
  unsigned __int8 v6; 
  unsigned int v7; 
  _BOOL8 v9; 
  _CONTROL_AREA *v10; 
  _BOOL8 v11; 
  NTSTATUS v12; 
  NTSTATUS result; 
  UINT64 v14; 
  __int64 CommittedPages; 
  _CONTROL_AREA *v16; 
  _CONTROL_AREA *v17; 
  NTSTATUS v18; 
  UINT64 a3; 

  ControlArea = Subsection->ControlArea;
  v4 = 0i64;
  a3 = 0i64;
  v5 = 0;
  v17 = Subsection->ControlArea;
  v6 = OldIrql;
  v7 = Flags;
  v9 = Subsection->ControlArea->FilePointer.Value != 0;
  if( OldIrql == 17 )
  {
    v5 = 1;
    v6 = ExAcquireSpinLockExclusive((INT64 *)&ControlArea->ControlAreaLock);
  }
  while( 1 )
  {
    v10 = Subsection->ControlArea;
    if( !Subsection->SubsectionBase )
      goto LABEL_19;
    v11 = v10->FilePointer.Value != 0;
    v12 = MiIncrementSubsectionViewCount((_MSUBSECTION *)Subsection, v7);
    if( v12 > 1 && v11 && (v10->u.LongFlags & 0x20) == 0 )
    {
      if( (Subsection->u.SubsectionFlags._bf_2 & 8) != 0 )
        MiRemoveUnusedSubsection((_MSUBSECTION *)Subsection);
      Subsection->u.SubsectionFlags._bf_0 |= 1u;
    }
    if( v12 >= 2 )
    {
      if( v12 == 2 && (v7 & 0x20) != 0 && a3 )
      {
        v16 = v17;
        ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)&v17->ControlAreaLock);
        __writecr8(v6);
        MiReturnCrossPartitionSectionCharges(
          *(_MI_CROSS_PARTITION_CHARGES **)(*(&stru_140C4DB30 + 267) + 8i64 * (v16->u1.Flags._bf_0 & 0x3FF)),
          v9,
          a3);
        if( !v5 )
          ExAcquireSpinLockExclusive((INT64 *)&v17->ControlAreaLock);
      }
      else if( v5 )
      {
        ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)&v17->ControlAreaLock);
        __writecr8(v6);
      }
      return 0;
    }
    if( !v12 )
      break;
    ControlArea = v17;
    v4 = a3;
LABEL_19:
    if( (v7 & 0x20) != 0 )
    {
      ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)&ControlArea->ControlAreaLock);
      __writecr8(v6);
      MiReturnCrossPartitionSectionCharges(
        *(_MI_CROSS_PARTITION_CHARGES **)(*(&stru_140C4DB30 + 267) + 8i64 * (ControlArea->u1.Flags._bf_0 & 0x3FF)),
        v9,
        v4);
      if( !v5 )
        ExAcquireSpinLockExclusive((INT64 *)&ControlArea->ControlAreaLock);
      return -1073741523;
    }
    LODWORD(v14) = MiComputeCrossPartitionSectionCharges((INT64 *)Subsection);
    a3 = v14;
    v4 = v14;
    if( v14 )
    {
      ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)&ControlArea->ControlAreaLock);
      __writecr8(v6);
      result = MiGetSubsectionCharges((UINT8)Subsection);
      v18 = result;
      if( result < 0 )
      {
        if( !v5 )
        {
          ExAcquireSpinLockExclusive((INT64 *)&ControlArea->ControlAreaLock);
          return v18;
        }
        return result;
      }
      v7 |= 0x20u;
      ExAcquireSpinLockExclusive((INT64 *)&ControlArea->ControlAreaLock);
      if( (ControlArea->u.LongFlags & 0x20) == 0 )
      {
        if( v9 )
        {
          if( !Subsection->SubsectionBase )
          {
LABEL_27:
            ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)&ControlArea->ControlAreaLock);
            __writecr8(v6);
            MiReturnCrossPartitionSectionCharges(
              *(_MI_CROSS_PARTITION_CHARGES **)(*(&stru_140C4DB30 + 267) + 8i64 * (ControlArea->u1.Flags._bf_0 & 0x3FF)),
              v9,
              v4);
            if( !v5 )
              ExAcquireSpinLockExclusive((INT64 *)&ControlArea->ControlAreaLock);
            return -1073741302;
          }
          CommittedPages = Subsection->PtesInSubsection - (Subsection->_bf_34 & 0x3FFFFFFF);
        }
        else
        {
          CommittedPages = MiGetCommittedPages(ControlArea);
        }
        if( v4 != CommittedPages )
          goto LABEL_27;
      }
    }
    else
    {
      v7 |= 0x20u;
    }
  }
  if( v5 )
  {
    ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)&v17->ControlAreaLock);
    __writecr8(v6);
  }
  return -1073740277;
}

Referenced by:

MiAddViewsForSection
MiApplyHotPatchToLoadedDriver
MiInsertInSystemSpace
MiMapImageInSystemSpace
MiMapViewOfImageSection
MiSessionInsertImage
MiUpControlAreaRefs
MmLoadSystemImageEx