HalpDmaGrowContiguousMapBuffers

VOID __stdcall HalpDmaGrowContiguousMapBuffers(_HALP_DMA_ADAPTER_OBJECT *Adapter, UINT64 PagesToAllocate){
  unsigned int v2; 
  unsigned int v3; 
  unsigned int v5; 
  unsigned int v6; 
  _MDL *v7; 
  VOID *VirtualAddressOut; 
  PVOID P; 
  UINT64 PhysicalAddressOut; 

  VirtualAddressOut = 0i64;
  v2 = 16;
  PhysicalAddressOut = 0i64;
  v3 = PagesToAllocate;
  P = 0i64;
  if( Adapter->DmaCanCross64K )
    v2 = PagesToAllocate;
  while( v3 )
  {
    v5 = v3;
    if( v3 >= v2 )
      v5 = v2;
    v6 = HalpDmaAllocateContiguousMemory(Adapter, v5, &VirtualAddressOut, &PhysicalAddressOut, (_MDL **)&P);
    if( v6 )
    {
      if( !HalpDmaCommitContiguousMapBuffers(Adapter, VirtualAddressOut, PhysicalAddressOut, v6) )
      {
        v7 = (_MDL *)P;
        if( P )
        {
          if( VirtualAddressOut )
            MmUnmapLockedPages(VirtualAddressOut, (_MDL *)P);
          MmFreePagesFromMdl(v7);
          ExFreePoolWithTag(v7, 0);
        }
        else
        {
          MmFreeContiguousMemory(VirtualAddressOut);
        }
        return;
      }
      if( P )
        ExFreePoolWithTag(P, 0);
      v3 -= v5;
    }
    else
    {
      if( !Adapter->DmaCanCross64K || v2 <= 0x10 || v3 <= 0x10 )
        return;
      v2 = 16;
    }
  }
}

Referenced by:

HalpAllocateMapRegisters
HalpGrowMapBufferWorker