ViSpecialAllocateCommonBuffer

char *__fastcall ViSpecialAllocateCommonBuffer(
        __int64 (__fastcall *a1)(_QWORD, _QWORD, _LIST_ENTRY **, __int64),
        __int64 a2,
        _LIST_ENTRY *a3,
        unsigned int a4,
        _QWORD *a5,
        char a6){
  unsigned int v7; 
  __int64 v10; 
  _LIST_ENTRY *PoolWithTag; 
  __int64 v12; 
  int v14; 
  int v15; 
  unsigned int v16; 
  __int64 v17; 
  __int64 v18; 
  _LIST_ENTRY *v19; 
  v7 = *(_DWORD *)(a2 + 172) - *(_DWORD *)(a2 + 176);
  v19 = 0i64;
  v10 = a4;
  if( v7 >= 0x20 || a4 > 0xFFFFDFFF )
    return 0i64;
  PoolWithTag = (_LIST_ENTRY *)ExAllocatePoolWithTag(NonPagedPoolNx, 0x40ui64, 0x566C6148ui64);
  if( !PoolWithTag )
  {
    VfUtilDbgPrint((INT8 *)"Couldn't track common buffer allocation\n");
    return 0i64;
  }
  if( (unsigned __int64)(v10 + 8) <= 0x1000 )
  {
    v14 = 4096;
LABEL_10:
    v15 = v14 - v10;
    goto LABEL_12;
  }
  if( (v10 & 0xFFF) != 0 )
  {
    v14 = ((v10 + 8) & 0xFFFFF000) + ((((_WORD)v10 + 8) & 0xFFF) != 0i64 ? 0x1000 : 0);
    goto LABEL_10;
  }
  v15 = 4096;
LABEL_12:
  LOBYTE(v12) = a6;
  v16 = v15 + v10 + 4096;
  v17 = a1(*(_QWORD *)(a2 + 16), v16, &v19, v12);
  if( !v17 )
  {
    ExFreePoolWithTag(PoolWithTag, 0);
    return 0i64;
  }
  WORD1(PoolWithTag->Flink) = v15;
  v18 = v17 + 4096;
  LOWORD(PoolWithTag->Flink) = 4096;
  PoolWithTag[1].Blink = (_LIST_ENTRY *)(v17 + 4096);
  LODWORD(PoolWithTag->Blink) = v10;
  HIDWORD(PoolWithTag->Flink) = v16;
  PoolWithTag[1].Flink = (_LIST_ENTRY *)v17;
  PoolWithTag[2].Flink = v19;
  PoolWithTag[2].Blink = a3;
  ViInitializePadding((VOID *)v17, v16, (VOID *)(v17 + 4096), (unsigned int)v10);
  *a5 = v19 + 256;
  ExInterlockedInsertHeadList((PLIST_ENTRY)(a2 + 80), PoolWithTag + 3, (PKSPIN_LOCK)(a2 + 96));
  _InterlockedIncrement((volatile signed __int32 *)(a2 + 172));
  return(char *)v18;
}

Referenced by:

VfAllocateCommonBuffer