KeQuerySystemAllowedCpuSetAffinity

VOID __stdcall KeQuerySystemAllowedCpuSetAffinity(_KAFFINITY_EX *Affinity, UINT64 *AffinityEpoch){
  UINT64 v4; 
  unsigned int v5; 
  unsigned int v6; 
  unsigned __int64 *v7; 
  unsigned __int64 v8; 
  __int64 v9; 
  unsigned __int64 v10; 
  while( 1 )
  {
    while( 1 )
    {
      v4 = KiCpuSetSequence;
      if( (KiCpuSetSequence & 1) == 0 )
        break;
      _mm_pause();
    }
    if( *AffinityEpoch == KiCpuSetSequence )
      break;
    *(_QWORD *)&Affinity->Count = 1310721i64;
    memset((INT64)Affinity->Bitmap, 0i64);
    if( KiRestrictedSystemCpuSetsActive )
    {
      v5 = (unsigned __int16)KiActiveGroups;
      v6 = 0;
      if( KiActiveGroups )
      {
        v7 = (unsigned __int64 *)KiSystemAllowedCpuSets;
        do
        {
          v8 = *v7;
          v9 = 0i64;
          if( *v7 )
          {
            do
            {
              _BitScanForward64(&v10, v8);
              v9 |= *(_QWORD *)&KiCpuSetAffinities[512 * v6 + 8 * (unsigned int)v10];
              v8 &= ~(1i64 << v10);
            }
            while( v8 );
            if( v9 )
            {
              if( Affinity->Count <= (unsigned __int16)v6 )
                Affinity->Count = v6 + 1;
              Affinity->Bitmap[(unsigned __int16)v6] |= v9;
            }
          }
          ++v6;
          v7 += 2;
        }
        while( v6 < v5 );
      }
    }
    else
    {
      KeCopyAffinityEx((__int64)Affinity, &KeActiveProcessors.Count);
    }
    if( KiCpuSetSequence == v4 )
    {
      *AffinityEpoch = v4;
      return;
    }
  }
}

Referenced by:

KeResumeClockTimerFromIdle
PpmCheckContinueExecution
PpmParkSteerInterrupts