HalpReadWriteWheaPhysicalMemory

NTSTATUS __stdcall HalpReadWriteWheaPhysicalMemory(
        INT64 Read,
        _LARGE_INTEGER PhysicalAddress,
        UINT64 Length,
        VOID *Buffer){
  char *v4; 
  unsigned int v5; 
  _LARGE_INTEGER v6; 
  int v7; 
  unsigned int Number; 
  UINT64 v9; 
  UINT64 *v10; 
  unsigned __int8 CurrentIrql; 
  __int64 v12; 
  unsigned int v13; 
  const VOID *v14; 
  VOID *v15; 
  char v17; 
  char v18; 

  v17 = Read;
  v4 = (char *)Buffer;
  v5 = Length;
  v6 = PhysicalAddress;
  if( !PhysicalAddress.QuadPart )
    return -1073741811;
  if( (unsigned int)Length > 8 )
    return -1073741811;
  v7 = 278;
  if( !_bittest(&v7, Length) || !Buffer )
    return -1073741811;
  Number = KeGetPcr()->Prcb.Number;
  if( HalpProcessorInMceHandler == Number )
  {
    v9 = *(&CmpDummyThreadEvent + 526);
    v10 = (UINT64 *)((char *)&CmpDummyThreadEvent + 4176);
  }
  else if( HalpProcessorInNmiHandler == Number )
  {
    v9 = *(&CmpDummyThreadEvent + 524);
    v10 = (UINT64 *)((char *)&CmpDummyThreadEvent + 4216);
  }
  else
  {
    v9 = *(&CmpDummyThreadEvent + 525);
    v10 = (UINT64 *)((char *)&CmpDummyThreadEvent + 4184);
  }
  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.anonymous_0.LowPart & 0xFFF);
    if( v5 >= v13 )
      v12 = v13;
    if( v17 )
    {
      v14 = (const VOID *)(v9 + (v6.anonymous_0.LowPart & 0xFFF));
      v15 = v4;
    }
    else
    {
      v14 = v4;
      v15 = (VOID *)(v9 + (v6.anonymous_0.LowPart & 0xFFF));
    }
    memmove(v15, v14, v12);
    v6.QuadPart += v12;
    v4 += v12;
  }
  KxReleaseSpinLock(v10);
  if( v18 )
    __writecr8(CurrentIrql);
  return 0;
}

Referenced by:

HalpReadWheaPhysicalMemory
HalpWriteWheaPhysicalMemory