HalpAllocatePmcCounterSet

__int64 __fastcall HalpAllocatePmcCounterSet(unsigned int a1, unsigned int *a2, unsigned int a3, UINT8 **a4){
  __int64 v4; 
  __int64 v5; 
  UINT8 **v6; 
  unsigned int v7; 
  _HALP_ALLOC_CONTEXT *v9; 
  UINT8 *v10; 
  UINT8 *v11; 
  int v12; 
  unsigned __int8 CurrentIrql; 
  __int64 v14; 
  unsigned int v15; 
  unsigned int *v16; 
  __int64 v17; 
  __int64 v18; 
  int v19; 
  _HALP_ALLOC_CONTEXT *v20; 
  __int64 v21; 
  unsigned int *v22; 
  __int64 v23; 
  __int64 v24; 
  __int64 v28; 
  _GROUP_AFFINITY v29; 
  _GROUP_AFFINITY PreviousAffinity; 

  v4 = a1;
  v5 = a1;
  v29 = 0i64;
  v6 = a4;
  v7 = KiProcessorIndexToNumberMappingTable[a1];
  v29.Group = v7 >> 6;
  v28 = v4;
  v29.Mask = 1i64 << (v7 & 0x3F);
  PreviousAffinity = 0i64;
  KeSetSystemGroupAffinityThread(&v29, &PreviousAffinity);
  v10 = HalpMmAllocCtxAlloc(v9, 32 * a3 + 24);
  v11 = v10;
  if( !v10 )
  {
    v12 = -1073741801;
    goto LABEL_22;
  }
  memset(v10, 0i64, 32 * a3 + 24);
  *((_DWORD *)v11 + 4) = v4;
  v12 = 0;
  *((_DWORD *)v11 + 5) = a3;
  CurrentIrql = KeGetCurrentIrql();
  __writecr8(0xFui64);
  v14 = 0i64;
  v15 = 0;
  if( !a3 )
    goto LABEL_16;
  v16 = a2;
  while( 1 )
  {
    v17 = *v16;
    v18 = 32i64 * v15;
    *(_DWORD *)&v11[v18 + 24] = v17;
    v19 = (*((__int64(__fastcall **)(__int64, __int64, UINT8 *))HalpProfileInterface[0] + 1))(
            1i64,
            v17,
            &v11[v18 + 28]);
    v12 = v19;
    if( v19 < 0 )
      break;
    v21 = *(unsigned int *)&v11[v18 + 28];
    ++v15;
    *(_QWORD *)&v11[v18 + 32] = __readpmc(v21);
    v12 = (*((__int64(__fastcall **)(__int64, UINT8 *))HalpProfileInterface[0] + 16))(v21, &v11[v18 + 48]);
LABEL_9:
    v14 = (unsigned int)(v14 + 1);
    v16 = ++a2;
    if( (unsigned int)v14 >= a3 )
      goto LABEL_14;
  }
  if( v19 == -1073741637 )
  {
    --*((_DWORD *)v11 + 5);
    v12 = 0;
    goto LABEL_9;
  }
  if( (_DWORD)v14 )
  {
    v22 = (unsigned int *)(v11 + 24);
    do
    {
      (*((void(__fastcall **)(_QWORD, unsigned int *))HalpProfileInterface[0] + 2))(*v22, v22 + 1);
      v22 += 8;
      --v14;
    }
    while( v14 );
  }
LABEL_14:
  if( v12 >= 0 )
  {
    v5 = v28;
LABEL_16:
    v20 = (_HALP_ALLOC_CONTEXT *)(3 * v5);
    v23 = qword_140C4AD08 + 24 * v5;
    v24 = *(_QWORD *)v23;
    if( *(_QWORD *)(*(_QWORD *)v23 + 8i64) != v23 )
      __fastfail(3u);
    *(_QWORD *)v11 = v24;
    *((_QWORD *)v11 + 1) = v23;
    *(_QWORD *)(v24 + 8) = v11;
    *(_QWORD *)v23 = v11;
  }
  __writecr8(CurrentIrql);
  if( v12 < 0 )
    HalpMmAllocCtxFree(v20, v11);
  v6 = a4;
LABEL_22:
  KeRevertToUserGroupAffinityThread(&PreviousAffinity);
  if( v12 >= 0 )
    *v6 = v11;
  return(unsigned int)v12;
}

Referenced by:

No references.