MiLockPagableImageSection

VOID __fastcall MiLockPagableImageSection(VOID *ImageSectionHandle, UINT64 Locking){
  ULONG_PTR v2; 
  INT64 v4; 
  INT64 v5; 
  _KLDR_DATA_TABLE_ENTRY *v6; 
  _QWORD *v7; 
  unsigned __int64 v8; 
  char *v9; 
  IMAGE_NT_HEADERS *v10; 
  ULONG_PTR BugCheckParameter4; 
  __int64 v12; 
  __int64 v13; 
  volatile INT64 *v14; 
  unsigned int v15; 
  unsigned __int64 v16; 
  _MMPTE *PteBase; 
  unsigned __int64 SectionAlignment; 
  _MMPTE *v19; 
  unsigned __int64 v20; 
  UINT8 OldIrql; 
  if( ImageSectionHandle == (VOID *)1 )
    return;
  v2 = (unsigned int)Locking;
  if( (unsigned int)MI_IS_PHYSICAL_ADDRESS(ImageSectionHandle)
    || (unsigned int)MiGetSystemRegionType((UINT64)ImageSectionHandle) == 1 )
  {
    return;
  }
  v6 = 0i64;
  OldIrql = 17;
  MmLockLoadedModuleListShared(&OldIrql, v4, v5);
  v7 = (_QWORD *)qword_140C4CAA0;
  if( !qword_140C4CAA0 )
    goto LABEL_10;
  while( 1 )
  {
    v8 = *(v7 - 23);
    if( (unsigned __int64)ImageSectionHandle > v8 + (unsigned int)(*((_DWORD *)v7 - 42) - 1) )
    {
      v7 = (_QWORD *)v7[1];
      goto LABEL_21;
    }
    if( (unsigned __int64)ImageSectionHandle >= v8 )
      break;
    v7 = (_QWORD *)*v7;
LABEL_21:
    if( !v7 )
      goto LABEL_10;
  }
  if( v7 )
    v6 = (_KLDR_DATA_TABLE_ENTRY *)(v7 - 29);
LABEL_10:
  MmUnlockLoadedModuleListShared(OldIrql);
  if( !v6 )
    KeBugCheckEx(0x1Au, 0x1012ui64, (ULONG_PTR)ImageSectionHandle, v2, 0i64);
  v9 = (char *)*((_QWORD *)v6 + 6);
  v10 = RtlImageNtHeader(v9);
  BugCheckParameter4 = v10->FileHeader.NumberOfSections;
  v12 = ((char *)ImageSectionHandle - v10->FileHeader.SizeOfOptionalHeader - (char *)v10 - 24) / 40;
  if( (unsigned int)v12 >= (unsigned int)BugCheckParameter4 )
    KeBugCheckEx(0x1Au, 0x1013ui64, (unsigned __int64)ImageSectionHandle | v2, (unsigned int)v12, BugCheckParameter4);
  v13 = *((unsigned int *)ImageSectionHandle + 4);
  v14 = (volatile INT64 *)(*((_QWORD *)v6 + 28) + 4i64 * (unsigned int)v12);
  v15 = *((_DWORD *)ImageSectionHandle + 2);
  if( (unsigned int)v13 < v15 )
    v13 = v15;
  v16 = (unsigned __int64)&v9[*((unsigned int *)ImageSectionHandle + 3)];
  PteBase = MmGetPteBase();
  SectionAlignment = v10->OptionalHeader.SectionAlignment;
  v19 = (_MMPTE *)((char *)PteBase + ((v16 >> 9) & 0x7FFFFFFFF8i64));
  if( SectionAlignment > 0x1000 )
    SectionAlignment = 4096i64;
  v20 = (((~(SectionAlignment - 1) & (v16 + SectionAlignment + v13 - 1)) + 4095) >> 9) & 0x7FFFFFFFF8i64;
  if( (_DWORD)v2 == 1 )
    MiLockImageSection(v6, v14, v19, (_MMPTE *)((char *)PteBase + v20 - 8));
  else
    MiUnlockImageSection(
      (INT64 *)v14,
      v19,
      (_MMPTE *)((char *)PteBase + v20 - 8),
      (IMAGE_SECTION_HEADER *)ImageSectionHandle);
}

Referenced by:

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