MiInitializeEnclave

__int64 __fastcall MiInitializeEnclave(_EPROCESS *Process, UINT64 a2, PVOID SignatureInfo, int a4){
  INT64 v7; 
  void *v8; 
  INT64 v9; 
  int v11; 
  int v12; 
  int v13[6]; 
  v13[0] = 0;
  v7 = MiObtainReferencedVadEx(a2, 0, (INT64 *)v13);
  v9 = v7;
  if( !v7 )
    return(unsigned int)v13[0];
  if( (*(_DWORD *)(v7 + 48) & 0x3100000) == 34603008 )
  {
    v12 = *(_DWORD *)(v7 + 64);
    if( (v12 & 2) != 0 )
    {
      v11 = -1073740528;
    }
    else if( (v12 & 1) != 0 )
    {
      if( a4 == 4096 )
      {
        v11 = KeInitializeEnclave(
                (PVOID)((__int64)((*(_QWORD *)(v9 + 80) << 25) - ((_QWORD)MmGetPteBase() << 25)) >> 16),
                SignatureInfo,
                v8,
                (UINT64 *)SignatureInfo + 256);
        if( v11 >= 0 )
        {
          MiReturnReservedEnclavePages(v9, -1i64);
          *(_DWORD *)(v9 + 64) |= 2u;
          v11 = 0;
        }
      }
      else
      {
        v11 = -1073741820;
      }
    }
    else
    {
      v11 = MiInitializeVsmEnclave((PEPROCESS)Process);
    }
  }
  else
  {
    v11 = -1073741800;
  }
  MiUnlockAndDereferenceVad((PVOID)v9);
  return(unsigned int)v11;
}

Referenced by:

NtInitializeEnclave