HalpMapCR3Ex

NTSTATUS __stdcall HalpMapCR3Ex(PVOID BaseAddress){
  PHYSICAL_ADDRESS v1; 
  unsigned int v2; 
  unsigned int v3; 
  PHYSICAL_ADDRESS PhysicalAddress; 
  int v6; 
  __int64 v7; 
  INT64 *v8; 
  INT64 v9; 
  __int64 v10; 
  __int64 v11; 
  __int64 v12; 
  __int64 v13; 
  __int64 v14; 
  __int64 v15; 
  v3 = v2;
  PhysicalAddress = v1;
  v6 = 3;
  v7 = *(_QWORD *)(HalpCR3Root + 8i64 * v2);
  v8 = (INT64 *)(v7 + 8 * (((unsigned __int64)BaseAddress >> 39) & 0x1FF));
  do
  {
    v9 = *v8;
    if( !*v8 )
    {
      v10 = HalpMmAllocCtxAlloc(v7, 4096i64);
      v9 = v10;
      if( !v10 )
        return -1073741670;
      memset(v10, 0i64);
      if( (int)HalpStoreFreeCr3(v3, v9) < 0 )
      {
        HalpMmAllocCtxFree(v12, v11);
        return -1073741670;
      }
      *v8 = v9;
    }
    --v6;
    v7 = (unsigned int)(v6 + 8 * v6 + 12);
    v8 = (INT64 *)(v9 + 8 * (((unsigned __int64)BaseAddress >> (v6 + 8 * (unsigned __int8)v6 + 12)) & 0x1FF));
  }
  while( v6 );
  if( !PhysicalAddress.QuadPart )
    PhysicalAddress = MmGetPhysicalAddress(BaseAddress);
  v13 = 1i64;
  v14 = *v8 ^ (PhysicalAddress.QuadPart ^ *v8) & 0xFFFFFFFFF000i64;
  v15 = 2i64;
  do
  {
    v14 |= v13++;
    --v15;
  }
  while( v15 );
  *v8 = v14;
  return 0;
}

Referenced by:

HalpMmBuildTiledMemoryMap