SmAcquireReleaseResAvailForRead

UINT64 __stdcall SmAcquireReleaseResAvailForRead(VOID *UniqueOwnerId, UINT64 PageCount, UINT64 ReleaseCharges){
  struct _KPRCB *CurrentPrcb; 
  unsigned __int64 v6; 
  __int64 CachedResidentAvailable; 
  bool v8; 
  signed __int32 v9; 
  _BOOL4 v10; 

  if( (_DWORD)ReleaseCharges )
  {
    if( (VOID *)qword_140D23178 == UniqueOwnerId )
    {
      _InterlockedExchange64(&qword_140D23178, 0i64);
    }
    else
    {
      CurrentPrcb = KeGetCurrentPrcb();
      v6 = PageCount + 48;
      CachedResidentAvailable = (int)CurrentPrcb->CachedResidentAvailable;
      if( (_DWORD)CachedResidentAvailable != -1 )
      {
        if( v6 + CachedResidentAvailable <= 0x100 )
        {
          do
          {
            if( v6 >= 0x80000 )
              break;
            v9 = _InterlockedCompareExchange(
                   (volatile signed __int32 *)&CurrentPrcb->CachedResidentAvailable,
                   CachedResidentAvailable + v6,
                   CachedResidentAvailable);
            v8 = (_DWORD)CachedResidentAvailable == v9;
            LODWORD(CachedResidentAvailable) = v9;
            if( v8 )
              return 1;
          }
          while( v9 != -1 && v6 + v9 <= 0x100 );
        }
        if( (int)CachedResidentAvailable > 192
          && (_DWORD)CachedResidentAvailable != -1
          && (_DWORD)CachedResidentAvailable == _InterlockedCompareExchange(
                                                  (volatile signed __int32 *)&CurrentPrcb->CachedResidentAvailable,
                                                  192,
                                                  CachedResidentAvailable) )
        {
          v6 += (int)CachedResidentAvailable - 192;
        }
      }
      if( v6 )
        _InterlockedExchangeAdd64((_QWORD *)&stru_140C50B28 + 883, v6);
    }
    return 1;
  }
  else
  {
    v10 = MmStoreChargeResidentAvailableForRead(PageCount);
    if( !v10 )
    {
      if( qword_140D23178 )
        return 0;
      v10 = 1;
      if( PageCount != 1 || _InterlockedCompareExchange64(&qword_140D23178, (signed __int64)UniqueOwnerId, 0i64) )
        return 0;
    }
  }
  return v10;
}

Referenced by:

SMKM_STORE_MGR::SmIoCtxWorkItemComplete
SMKM_STORE_MGR::SmPageRead