MiGetCrossPartitionCloneCharges

INT64 __fastcall MiGetCrossPartitionCloneCharges(INT64 a1){
  unsigned __int64 v2; 
  struct _KPRCB *CurrentPrcb; 
  __int64 v4; 
  bool v5; 
  signed __int32 v6; 
  v2 = 1i64;
  if( !(unsigned int)MiChargeResident((ULONG_PTR *)a1, 1ui64, 0i64) )
    return 0i64;
  if( (int)MiGetCrossPartitionCharges(a1, 6i64, 0, 1i64) < 0 )
  {
    if( (ULONG_PTR *)a1 != &MiSystemPartition )
      goto LABEL_14;
    CurrentPrcb = KeGetCurrentPrcb();
    v4 = *((int *)CurrentPrcb + 8391);
    if( (_DWORD)v4 == -1 )
      goto LABEL_14;
    if( (unsigned __int64)(v4 + 1) <= 0x100 )
    {
      do
      {
        v6 = _InterlockedCompareExchange((volatile signed __int32 *)CurrentPrcb + 8391, v4 + 1, v4);
        v5 = (_DWORD)v4 == v6;
        LODWORD(v4) = v6;
        if( v5 )
          return 0i64;
      }
      while( v6 != -1 && (unsigned __int64)(v6 + 1i64) <= 0x100 );
    }
    if( (int)v4 > 192
      && (_DWORD)v4 != -1
      && (_DWORD)v4 == _InterlockedCompareExchange((volatile signed __int32 *)CurrentPrcb + 8391, 192, v4) )
    {
      v2 = (int)v4 - 192 + 1i64;
    }
    if( v2 )
LABEL_14:
      _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 7168), v2);
    return 0i64;
  }
  return 1i64;
}

Referenced by:

MiBuildForkPte
MiHandleForkTransitionPte
MiReferenceCloneProto