HalpDmaGrowContiguousMapBuffers

void __fastcall HalpDmaGrowContiguousMapBuffers(__int64 a1, unsigned int a2){
  unsigned int v2; 
  unsigned int v3; 
  unsigned int v5; 
  unsigned int v6; 
  MDL *v7; 
  PVOID BaseAddress; 
  PVOID P; 
  PHYSICAL_ADDRESS v10; 
  BaseAddress = 0i64;
  v2 = 16;
  v10.QuadPart = 0i64;
  v3 = a2;
  P = 0i64;
  if( *(_BYTE *)(a1 + 145) )
    v2 = a2;
  while( v3 )
  {
    v5 = v3;
    if( v3 >= v2 )
      v5 = v2;
    v6 = HalpDmaAllocateContiguousMemory(a1, v5, &BaseAddress, &v10, &P);
    if( v6 )
    {
      if( !HalpDmaCommitContiguousMapBuffers(a1, (__int64)BaseAddress, v10.QuadPart, v6) )
      {
        v7 = (MDL *)P;
        if( P )
        {
          if( BaseAddress )
            MmUnmapLockedPages(BaseAddress, (PMDL)P);
          MmFreePagesFromMdl(v7);
          ExFreePoolWithTag(v7, 0);
        }
        else
        {
          MmFreeContiguousMemory(BaseAddress);
        }
        return;
      }
      if( P )
        ExFreePoolWithTag(P, 0);
      v3 -= v5;
    }
    else
    {
      if( !*(_BYTE *)(a1 + 145) || v2 <= 0x10 || v3 <= 0x10 )
        return;
      v2 = 16;
    }
  }
}

Referenced by:

HalpAllocateMapRegisters
HalpGrowMapBufferWorker