MiReturnCrossPartitionCloneCharges

VOID __stdcall MiReturnCrossPartitionCloneCharges(_MI_CROSS_PARTITION_CHARGES *ChargeInfo){
  unsigned __int64 v1; 
  struct _KPRCB *CurrentPrcb; 
  __int64 CachedResidentAvailable; 
  bool v4; 
  signed __int32 v5; 

  v1 = 1i64;
  if( ChargeInfo != (_MI_CROSS_PARTITION_CHARGES *)&Irp )
    goto LABEL_12;
  CurrentPrcb = KeGetCurrentPrcb();
  CachedResidentAvailable = (int)CurrentPrcb->CachedResidentAvailable;
  if( (_DWORD)CachedResidentAvailable == -1 )
    goto LABEL_12;
  if( (unsigned __int64)(CachedResidentAvailable + 1) > 0x100 )
  {
LABEL_7:
    if( (int)CachedResidentAvailable > 192
      && (_DWORD)CachedResidentAvailable != -1
      && (_DWORD)CachedResidentAvailable == _InterlockedCompareExchange(
                                              (volatile signed __int32 *)&CurrentPrcb->CachedResidentAvailable,
                                              192,
                                              CachedResidentAvailable) )
    {
      v1 = (int)CachedResidentAvailable - 192 + 1i64;
    }
    if( !v1 )
      goto LABEL_13;
LABEL_12:
    _InterlockedExchangeAdd64((volatile signed __int64 *)&ChargeInfo[224], v1);
    goto LABEL_13;
  }
  while( 1 )
  {
    v5 = _InterlockedCompareExchange(
           (volatile signed __int32 *)&CurrentPrcb->CachedResidentAvailable,
           CachedResidentAvailable + 1,
           CachedResidentAvailable);
    v4 = (_DWORD)CachedResidentAvailable == v5;
    LODWORD(CachedResidentAvailable) = v5;
    if( v4 )
      break;
    if( v5 == -1 || (unsigned __int64)(v5 + 1i64) > 0x100 )
      goto LABEL_7;
  }
LABEL_13:
  MiReturnCrossPartitionCharges(ChargeInfo, 6ui64);
}

Referenced by:

MiBuildForkPte
MiDecrementCloneBlockReference
MiHandleForkTransitionPte
MiReferenceCloneProto