PspWritePebAffinityInfo

VOID __stdcall PspWritePebAffinityInfo(_ETHREAD *CurrentThread, _EX_RUNDOWN_REF *Process){
  unsigned int v3; 
  unsigned __int64 Count; 
  __int64 v5; 
  __int64 *v6; 
  __int64 v7; 
  unsigned int v8; 
  __int64 v9; 
  unsigned __int64 v10; 
  __int64 v11; 
  int v12; 
  int v13; 
  int v14[8]; 
  unsigned int v15; 
  unsigned int v16; 
  unsigned int v17; 
  unsigned int v18; 
  unsigned __int64 v19; 
  unsigned __int64 v20; 
  __int64 v21; 
  _EX_RUNDOWN_REF *v22; 
  _KAPC_STATE ApcState; 

  v22 = Process;
  memset(&ApcState, 0, sizeof(ApcState));
  v3 = 0;
  v15 = 0;
  v16 = 0;
  Count = Process[170].Count;
  v20 = Count;
  if( !Count )
    return;
  if( Process[136].Count )
  {
    if( Process == (_EX_RUNDOWN_REF *)CurrentThread->Tcb.ApcState.Process )
    {
      if( Process != (_EX_RUNDOWN_REF *)CurrentThread->Tcb.Process )
        v3 = 2;
      v15 = v3;
      if( v3 < 2 )
      {
LABEL_19:
        if( (v3 & 1) != 0 )
          KiStackAttachProcess(Process, 0i64, &ApcState);
        goto LABEL_3;
      }
    }
    else
    {
      v3 = 3;
      v15 = 3;
    }
    if( !ExAcquireRundownProtection(Process + 139) )
      return;
    goto LABEL_19;
  }
LABEL_3:
  v18 = v3;
  v5 = 0i64;
  v6 = (__int64 *)Process[176].Count;
  if( v6 )
    v5 = *v6;
  v21 = v5;
  do
  {
    do
    {
      KeQueryGroupMaskProcess((_EPROCESS *)Process);
      v17 = v8;
      _BitScanForward((unsigned int *)&v9, v8);
      v16 = v9;
      v10 = Process[v9 + 11].Count;
      v19 = v10;
    }
    while( !v10 );
    *(_QWORD *)(Count + 312) = v10;
    if( v7 )
      *(_DWORD *)(v7 + 192) = v10 | HIDWORD(v10);
    _InterlockedOr(v14, 0);
    KeQueryGroupMaskProcess((_EPROCESS *)Process);
  }
  while( v13 != v12 || v11 != Process[v16 + 11].Count );
  if( v3 )
  {
    if( (v3 & 1) != 0 )
      KiUnstackDetachProcess(&ApcState, 0i64);
    ExReleaseRundownProtection(Process + 139);
  }
}

Referenced by:

NtSetInformationProcess
PspAllocateProcess
PspApplyJobLimitsToProcess
PspSetupUserProcessAddressSpace
PspUpdateSingleProcessAffinity