HalpAllocateScratchMemory

NTSTATUS __stdcall HalpAllocateScratchMemory(_LOADER_PARAMETER_BLOCK *LoaderBlock, DEBUG_DEVICE_DESCRIPTOR *Device){
  unsigned int Length; 
  LONG HighPart; 
  int v5; 
  UINT64 v6; 
  _LARGE_INTEGER v7; 
  void *v9; 
  LARGE_INTEGER MaxPhysicalAddress; 
  Length = Device->Memory.Length;
  if( Length && !Device->Memory.VirtualAddress )
  {
    if( Device->Memory.MaxEnd.QuadPart )
    {
      HighPart = Device->Memory.MaxEnd.HighPart;
    }
    else
    {
      HighPart = -1;
      Device->Memory.MaxEnd.QuadPart = -1i64;
    }
    MaxPhysicalAddress.HighPart = 0;
    if( HighPart )
      MaxPhysicalAddress.LowPart = -1;
    else
      MaxPhysicalAddress.LowPart = Device->Memory.MaxEnd.LowPart;
    v5 = (Length >> 12) + ((Length & 0xFFF) != 0);
    v6 = HalpAllocPhysicalMemory(LoaderBlock, &MaxPhysicalAddress);
    v7.QuadPart = v6;
    if( !v6 )
      return -1073741670;
    v9 = (void *)HalpMapPhysicalMemory64((LARGE_INTEGER)v6, (MEMORY_CACHING_TYPE)v5);
    Device->Flags |= 1u;
    Device->Memory.VirtualAddress = v9;
    Device->Memory.Start = v7;
  }
  return 0;
}

Referenced by:

HalpKdSetupDebuggingDevice