MiReleaseNonPagedResources

VOID __stdcall MiReleaseNonPagedResources(_MI_PARTITION *Partition, UINT64 NumberOfPages){
  unsigned __int64 v2; 
  struct _KPRCB *CurrentPrcb; 
  __int64 v5; 
  bool v6; 
  signed __int32 v7; 
  v2 = NumberOfPages;
  MiReturnCommit(Partition, NumberOfPages);
  if( Partition == (_MI_PARTITION *)&MiSystemPartition )
  {
    CurrentPrcb = KeGetCurrentPrcb();
    v5 = *((int *)CurrentPrcb + 8391);
    if( (_DWORD)v5 != -1 )
    {
      if( v2 + v5 <= 0x100 )
      {
        do
        {
          if( v2 >= 0x80000 )
            break;
          v7 = _InterlockedCompareExchange((volatile signed __int32 *)CurrentPrcb + 8391, v5 + v2, v5);
          v6 = (_DWORD)v5 == v7;
          LODWORD(v5) = v7;
          if( v6 )
            return;
        }
        while( v7 != -1 && v2 + v7 <= 0x100 );
      }
      if( (int)v5 > 192
        && (_DWORD)v5 != -1
        && (_DWORD)v5 == _InterlockedCompareExchange((volatile signed __int32 *)CurrentPrcb + 8391, 192, v5) )
      {
        v2 += (int)v5 - 192;
      }
    }
  }
  if( v2 )
    _InterlockedExchangeAdd64((volatile signed __int64 *)Partition + 896, v2);
}

Referenced by:

MiAllocatePartitionPhysicalPages
MiChargeSystemImageCommitment
MiFreeLargePageCharges
MiReturnMdlExcess