PsSetCpuQuotaInformation

NTSTATUS __stdcall PsSetCpuQuotaInformation(VOID *SystemInformation, UINT64 SystemInformationLength, INT8 PreviousMode){
  __int64 v4; 
  __int64 v7; 
  char *PoolWithQuotaTag; 
  _QWORD *v9; 
  _KSCHEDULING_GROUP **v10; 
  _KSCHEDULING_GROUP **v11; 
  __int64 i; 
  int v13; 
  int v14; 
  __int64 j; 
  VOID *v16; 
  VOID *v17; 
  _KSCHEDULING_GROUP *SessionSchedulingGroup; 
  PVOID SessionObject; 

  v4 = (unsigned int)SystemInformationLength;
  if( !PsCpuFairShareEnabled )
    return -1073741823;
  if( (unsigned int)SystemInformationLength < 0x10 || (SystemInformationLength & 0xF) != 0 )
    return -1073741820;
  if( PreviousMode )
  {
    if( !SeSinglePrivilegeCheck(*(_QWORD *)&SeIncreaseQuotaPrivilege, PreviousMode) )
      return -1073741727;
    if( PreviousMode )
    {
      if( ((unsigned __int8)SystemInformation & 7) != 0 )
        ExRaiseDatatypeMisalignment();
      if( (unsigned __int64)SystemInformation + v4 > 0x7FFFFFFF0000i64
        || (char *)SystemInformation + v4 < SystemInformation )
      {
        MEMORY[0x7FFFFFFF0000] = 0;
      }
    }
  }
  v7 = (unsigned int)v4 >> 4;
  if( (unsigned __int64)(24 * v7) > 0xFFFFFFFF )
    return -1073741675;
  PoolWithQuotaTag = (char *)ExAllocatePoolWithQuotaTag((POOL_TYPE)520, (unsigned int)(24 * v7), 0x63537350ui64);
  v9 = PoolWithQuotaTag;
  if( !PoolWithQuotaTag )
    return -1073741670;
  v10 = (_KSCHEDULING_GROUP **)&PoolWithQuotaTag[8 * v7];
  v11 = &v10[v7];
  for( i = 0i64; (unsigned int)i < (unsigned int)v7; i = (unsigned int)(i + 1) )
  {
    v9[i] = *((_QWORD *)SystemInformation + 2 * (unsigned int)i);
    HIDWORD(v11[i]) = 0;
    v13 = *((_DWORD *)SystemInformation + 4 * (unsigned int)i + 2);
    LODWORD(v11[i]) = v13;
    if( (unsigned __int16)(v13 - 1) > 8u )
    {
      v14 = -1073740712;
      goto LABEL_32;
    }
  }
  v14 = 0;
  for( j = 0i64; (unsigned int)j < (unsigned int)v7; j = (unsigned int)(j + 1) )
  {
    v16 = (VOID *)v9[j];
    SessionObject = 0i64;
    v14 = ObReferenceObjectByHandle(v16, 2ui64, MmSessionObjectType, PreviousMode, &SessionObject, 0i64);
    v17 = SessionObject;
    v9[j] = SessionObject;
    if( v14 < 0 )
      goto LABEL_30;
    SessionSchedulingGroup = MmGetSessionSchedulingGroup(v17);
    v10[j] = SessionSchedulingGroup;
    if( !SessionSchedulingGroup )
    {
      v14 = -1073740715;
      goto LABEL_30;
    }
  }
  KeSetSchedulingGroupWeights((unsigned int)v7, v10, (_KSCHEDULING_GROUP_POLICY *)&v10[v7]);
LABEL_30:
  while( (_DWORD)j )
  {
    j = (unsigned int)(j - 1);
    ObfDereferenceObjectWithTag((VOID *)v9[j], 0x746C6644ui64);
  }
LABEL_32:
  ExFreePoolWithTag(v9, 0x63537350u);
  return v14;
}

Referenced by:

NtSetSystemInformation