MiCreateSessionDriverProtos

__int64 __fastcall MiCreateSessionDriverProtos(__int64 *a1, __int64 a2, __int64 a3){
  __int64 v5; 
  __int64 v6; 
  unsigned __int64 v8; 
  __int64 *v9; 
  unsigned int i; 
  __int64 v11; 
  __int16 v12; 
  __int64 *v13; 
  __int64 *v14; 
  __int64 v15; 
  INT64 result[10]; 
  v15 = a3;
  memset((INT64)result, 0i64);
  v5 = *a1;
  v14 = 0i64;
  if( (*(_WORD *)(v5 + 12) & 0x800) != 0 )
    return 1i64;
  v6 = a2 - *(_QWORD *)(v5 + 32);
  if( MiMapImageInSystemSpace((__int64)a1, 3, (__int64)result) < 0 )
    return 0i64;
  v8 = result[0];
  v9 = a1 + 16;
  for( i = 0; ; i += v11 )
  {
    if( !v9 )
    {
      MiUnmapImageInSystemSpace((INT64)result);
      *(_WORD *)(v5 + 12) |= 0x800u;
      return 1i64;
    }
    v11 = *((unsigned int *)v9 + 11);
    v12 = *((_WORD *)v9 + 16) >> 1;
    if( (v12 & 4) == 0 && ((MiFlags & 0x8000) != 0 || (MiFlags & 0x10000) == 0 || (v12 & 2) == 0) )
      break;
LABEL_12:
    v9 = (__int64 *)v9[2];
    v8 += v11 << 12;
  }
  if( (int)MiAllocatePerSessionProtos((__int64)v9, v8, i, v6, &v14) >= 0 )
  {
    v13 = v14;
    *((_DWORD *)v14 + 16) = 0;
    *v13 = a2;
    v9[3] = (__int64)v13;
    if( v15 )
      RtlClearBits(*(RTL_BITMAP **)(v15 + 40), i, *((unsigned int *)v9 + 11));
    goto LABEL_12;
  }
  MiUnmapImageInSystemSpace((INT64)result);
  MiDeleteSessionDriverProtos(a1);
  return 0i64;
}

Referenced by:

MiAddPrivateFixupEntryForSystemImage
MmLoadSystemImageEx