MiHandleDriverNonPagedSections

__int64 __fastcall MiHandleDriverNonPagedSections(__int64 a1, char a2, int a3){
  void *v4; 
  int v7; 
  int v8; 
  _MMPTE *v9; 
  int v10; 
  unsigned int v11; 
  _MMPTE *v12; 
  unsigned int v13; 
  _MMPTE *v14; 
  unsigned int v16; 
  MMPTE *LastPte[2]; 
  UINT64 v18; 
  _MMPTE *PointerPte; 
  PointerPte = 0i64;
  v4 = *(void **)(a1 + 48);
  LastPte[0] = 0i64;
  if( (unsigned int)MI_IS_PHYSICAL_ADDRESS(v4) )
    return 0i64;
  v7 = 0;
  v8 = 1;
  if( a3 == 1 )
  {
    if( (dword_140CFA174 & 1) == 0 && (a2 & 2) == 0 )
    {
      if( (a2 & 1) == 0 )
        MiDisablePagingOfDriver(a1);
      v8 = !(a2 & 1) + 1;
      goto LABEL_8;
    }
    v10 = ((a2 & 1) == 0) + 1;
    v11 = 0;
    v12 = 0i64;
    while( 1 )
    {
      v13 = MiSnapDriverRange(a1, v11, 8, 0i64, (char **)&PointerPte, (char **)LastPte);
      v14 = PointerPte;
      v11 = v13;
      if( !PointerPte )
        goto LABEL_17;
      if( v12 )
      {
        if( PointerPte == v12 )
          return(unsigned int)v7;
        MiUnlockCodePage(PointerPte, LastPte[0]);
LABEL_17:
        if( !v11 )
          return(unsigned int)v7;
      }
      else
      {
        v7 = MiLockCode(a1, (unsigned __int64)PointerPte, (unsigned __int64)LastPte[0], v10);
        if( v7 >= 0 )
          goto LABEL_17;
        v11 = 0;
        v12 = v14;
      }
    }
  }
  if( (dword_140CFA174 & 1) != 0 )
  {
    v16 = 0;
    do
    {
      v16 = MiSnapDriverRange(a1, v16, 8, 0i64, (char **)&PointerPte, (char **)LastPte);
      if( PointerPte )
        MiUnlockCodePage(PointerPte, LastPte[0]);
    }
    while( v16 );
    return 0i64;
  }
LABEL_8:
  LODWORD(v18) = 0;
  v9 = 0i64;
  while( (int)MiFindDriverNonPagedSections(a1, &v18, &PointerPte, LastPte) >= 0 )
  {
    if( a3 == 1 )
    {
      v7 = MiLockCode(a1, (unsigned __int64)PointerPte, (unsigned __int64)LastPte[0], v8);
      if( v7 < 0 )
      {
        v9 = PointerPte;
        a3 = 0;
        LODWORD(v18) = 0;
      }
    }
    else
    {
      if( PointerPte == v9 )
        return(unsigned int)v7;
      MiUnlockCodePage(PointerPte, LastPte[0]);
    }
  }
  return(unsigned int)v7;
}

Referenced by:

MiApplyHotPatchToLoadedDriver
MiSessionRemoveImage
MmLoadSystemImageEx