MiLockPagableImageSection

VOID __stdcall MiLockPagableImageSection(VOID *ImageSectionHandle, ULONG_PTR Locking){
  unsigned __int64 v2; 
  _KLDR_DATA_TABLE_ENTRY *v4; 
  _QWORD *v5; 
  unsigned __int64 v6; 
  UINT64 DllBase; 
  __int64 v8; 
  __int64 v9; 
  void *BugCheckParameter4; 
  __int128 v11; 
  __int64 v12; 
  __int64 v13; 
  INT64 *v14; 
  unsigned int v15; 
  UINT64 v16; 
  _MMPTE *PteBase; 
  unsigned __int64 v18; 
  _MMPTE *v19; 
  unsigned __int64 v20; 
  unsigned __int8 v21; 

  if( ImageSectionHandle == (VOID *)1 )
    return;
  v2 = Locking;
  if( MI_IS_PHYSICAL_ADDRESS(ImageSectionHandle) || MiGetSystemRegionType((UINT64)ImageSectionHandle) == 1 )
    return;
  v4 = 0i64;
  v21 = 17;
  MmLockLoadedModuleListShared(&v21);
  v5 = BugCheckParameter3;
  if( !BugCheckParameter3 )
    goto LABEL_10;
  while( 1 )
  {
    v6 = *(v5 - 23);
    if( (unsigned __int64)ImageSectionHandle > v6 + (unsigned int)(*((_DWORD *)v5 - 42) - 1) )
    {
      v5 = (_QWORD *)v5[1];
      goto LABEL_21;
    }
    if( (unsigned __int64)ImageSectionHandle >= v6 )
      break;
    v5 = (_QWORD *)*v5;
LABEL_21:
    if( !v5 )
      goto LABEL_10;
  }
  if( v5 )
    v4 = (_KLDR_DATA_TABLE_ENTRY *)(v5 - 29);
LABEL_10:
  MmUnlockLoadedModuleListShared(v21);
  if( !v4 )
    KeBugCheckEx(0x1Au, (PVOID)0x1012, ImageSectionHandle, (PVOID)v2, 0i64);
  DllBase = (UINT64)v4->DllBase;
  LODWORD(v8) = RtlImageNtHeader(DllBase);
  v9 = v8;
  BugCheckParameter4 = (void *)*(unsigned __int16 *)(v8 + 6);
  v11 = ((__int64)ImageSectionHandle + -v8 - *(unsigned __int16 *)(v8 + 20) - 24) * (__int128)0x6666666666666667i64;
  v12 = (*((_QWORD *)&v11 + 1) >> 63) + (*((__int64 *)&v11 + 1) >> 4);
  if( (unsigned int)v12 >= (unsigned int)BugCheckParameter4 )
    KeBugCheckEx(
      0x1Au,
      (PVOID)0x1013,
      (PVOID)((unsigned __int64)ImageSectionHandle | v2),
      (PVOID)(unsigned int)v12,
      BugCheckParameter4);
  v13 = *((unsigned int *)ImageSectionHandle + 4);
  v14 = (INT64 *)(*(_QWORD *)&v4[1].SizeOfImage + 4i64 * (unsigned int)v12);
  v15 = *((_DWORD *)ImageSectionHandle + 2);
  if( (unsigned int)v13 < v15 )
    v13 = v15;
  v16 = DllBase + *((unsigned int *)ImageSectionHandle + 3);
  PteBase = MmGetPteBase();
  v18 = *(unsigned int *)(v9 + 56);
  v19 = (_MMPTE *)((char *)PteBase + ((v16 >> 9) & 0x7FFFFFFFF8i64));
  if( v18 > 0x1000 )
    v18 = 4096i64;
  v20 = (((~(v18 - 1) & (v16 + v18 + v13 - 1)) + 4095) >> 9) & 0x7FFFFFFFF8i64;
  if( (_DWORD)v2 == 1 )
    MiLockImageSection(v4, v14, v19, (_MMPTE *)((char *)PteBase + v20 - 8));
  else
    MiUnlockImageSection(v14, v19, (_MMPTE *)((char *)PteBase + v20 - 8), (ULONG_PTR)ImageSectionHandle);
}

Referenced by:

HalpPowerStateCallback
IopLiveDumpLockPages
IopLiveDumpUnLockPages
KiInitializeMTRR
KiStartDynamicProcessor
MiApplyImageHotPatch
MiLockPagableSections
MmLockPagableDataSection
MmLockPagableSectionByHandle
MmUnlockPagableImageSection
PnprLockPagesForReplace
PoRunDownDeviceObject
PopDirectedDripsNotifyAppsAndServices