MiMapRetpolineStubs

UINT64 __fastcall MiMapRetpolineStubs(UINT64 a1, INT64 a2){
  UINT64 v4; 
  INT64 SessionVm; 
  INT64 v6; 
  _MMPTE *PteBase; 
  UINT64 v8; 
  char *v9; 
  __int64 v10; 
  INT64 v11; 
  UINT64 *v12; 
  INT64 ContainingPageTable; 
  __int64 v15; 
  UINT8 v16; 
  v4 = 0i64;
  if( (unsigned int)MiGetSystemRegionType(a1) == 1 )
    SessionVm = MiGetSessionVm();
  else
    SessionVm = (INT64)MiGetAnyMultiplexedVm(1i64);
  v6 = SessionVm;
  PteBase = MmGetPteBase();
  v8 = a1 + ((a2 + ((unsigned int)dword_140C4C9F0 >> 12) + ((dword_140C4C9F0 & 0xFFF) != 0)) << 12);
  v9 = (char *)PteBase + ((v8 >> 9) & 0x7FFFFFFFF8i64);
  v15 = qword_140C4C990;
  v10 = 0i64;
  v16 = MiLockWorkingSetShared(SessionVm);
  if( !dword_140C4C9C8 )
    goto LABEL_12;
  do
  {
    v11 = *(_QWORD *)(v15 + 8 * v10 + 48);
    v12 = (UINT64 *)&v9[8 * v10];
    if( v4 )
    {
      if( ((unsigned __int16)v12 & 0xFFF) != 0 )
        goto LABEL_9;
      MiUnlockPageTableInternal(v6, v4);
    }
    v4 = (UINT64)PteBase + (((unsigned __int64)v12 >> 9) & 0x7FFFFFFFF8i64);
    MiLockPageTableInternal(v6, v4, 0i64);
LABEL_9:
    ContainingPageTable = MiGetContainingPageTable((UINT64)&v9[8 * v10]);
    MiLockAndIncrementShareCount(ContainingPageTable);
    MiLockAndIncrementShareCount(v11);
    *v12 = MiMakeValidPte((UINT64)&v9[8 * v10], v11, 3i64) & 0xF0FFFFFFFFFFFFFFui64 | 0x900000000000000i64;
    v10 = (unsigned int)(v10 + 1);
    PteBase = MmGetPteBase();
  }
  while( (unsigned int)v10 < dword_140C4C9C8 );
  if( v4 )
    MiUnlockPageTableInternal(v6, v4);
LABEL_12:
  MiUnlockWorkingSetShared(v6, v16);
  return v8;
}

Referenced by:

MiFinalizeImageRetpolineState
MiReloadBootLoadedDrivers