HalpReadWriteWheaPhysicalMemory

INT64 __fastcall HalpReadWriteWheaPhysicalMemory(
        INT64 Read,
        LARGE_INTEGER PhysicalAddress,
        UINT64 Length,
        VOID *Buffer){
  UINT8 *v4; 
  unsigned int v5; 
  LARGE_INTEGER v6; 
  int v7; 
  int v8; 
  UINT64 v9; 
  UINT64 *v10; 
  unsigned __int8 CurrentIrql; 
  __int64 v12; 
  unsigned int v13; 
  UINT8 *v14; 
  UINT8 *v15; 
  char v17; 
  char v18; 
  v17 = Read;
  v4 = (UINT8 *)Buffer;
  v5 = Length;
  v6 = PhysicalAddress;
  if( !PhysicalAddress.QuadPart )
    return 3221225485i64;
  if( (unsigned int)Length > 8 )
    return 3221225485i64;
  v7 = 278;
  if( !_bittest(&v7, Length) || !Buffer )
    return 3221225485i64;
  v8 = *((_DWORD *)KeGetPcr() + 105);
  if( HalpProcessorInMceHandler == v8 )
  {
    v9 = HalpWheaMappingMceReservation;
    v10 = &HalpWheaMappingMceLock;
  }
  else if( HalpProcessorInNmiHandler == v8 )
  {
    v9 = HalpWheaMappingNmiReservation;
    v10 = (UINT64 *)&HalpWheaMappingNmiLock;
  }
  else
  {
    v9 = HalpWheaMappingReservation;
    v10 = (UINT64 *)&HalpWheaMappingLock;
  }
  v18 = 0;
  CurrentIrql = KeGetCurrentIrql();
  if( CurrentIrql < 0xFu )
  {
    CurrentIrql = KeGetCurrentIrql();
    __writecr8(0xFui64);
    v18 = 1;
  }
  KxAcquireSpinLock(v10);
  for( ; v5; v5 -= v12 )
  {
    HalpRemapVirtualAddress64(v9, v6.QuadPart, 1);
    v12 = v5;
    v13 = 4096 - (v6.LowPart & 0xFFF);
    if( v5 >= v13 )
      v12 = v13;
    if( v17 )
    {
      v14 = (UINT8 *)(v9 + (v6.LowPart & 0xFFF));
      v15 = v4;
    }
    else
    {
      v14 = v4;
      v15 = (UINT8 *)(v9 + (v6.LowPart & 0xFFF));
    }
    memmove(v15, v14, (unsigned int)v12);
    v6.QuadPart += v12;
    v4 += v12;
  }
  KxReleaseSpinLock(v10);
  if( v18 )
    __writecr8(CurrentIrql);
  return 0i64;
}

Referenced by:

HalpReadWheaPhysicalMemory
HalpWriteWheaPhysicalMemory