SmAcquireReleaseResAvailForRead

UINT64 __stdcall SmAcquireReleaseResAvailForRead(PVOID UniqueOwnerId, UINT64 PageCount, UINT64 ReleaseCharges){
  struct _KPRCB *CurrentPrcb; 
  unsigned __int64 v6; 
  __int64 v7; 
  bool v8; 
  signed __int32 v9; 
  unsigned int v10; 
  if( (_DWORD)ReleaseCharges )
  {
    if( (PVOID)qword_140D23178 == UniqueOwnerId )
    {
      _InterlockedExchange64(&qword_140D23178, 0i64);
    }
    else
    {
      CurrentPrcb = KeGetCurrentPrcb();
      v6 = PageCount + 48;
      v7 = *((int *)CurrentPrcb + 8391);
      if( (_DWORD)v7 != -1 )
      {
        if( v6 + v7 <= 0x100 )
        {
          do
          {
            if( v6 >= 0x80000 )
              break;
            v9 = _InterlockedCompareExchange((volatile signed __int32 *)CurrentPrcb + 8391, v7 + v6, v7);
            v8 = (_DWORD)v7 == v9;
            LODWORD(v7) = v9;
            if( v8 )
              return 1;
          }
          while( v9 != -1 && v6 + v9 <= 0x100 );
        }
        if( (int)v7 > 192
          && (_DWORD)v7 != -1
          && (_DWORD)v7 == _InterlockedCompareExchange((volatile signed __int32 *)CurrentPrcb + 8391, 192, v7) )
        {
          v6 += (int)v7 - 192;
        }
      }
      if( v6 )
        _InterlockedExchangeAdd64(&qword_140C526C0, 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