KiEnableXSave

VOID __stdcall KiEnableXSave(){
  unsigned __int64 v0; 
  struct _KPRCB *CurrentPrcb; 

  v0 = __readcr4();
  if( ((unsigned __int64)KeFeatureBits & 0x800000) != 0 )
  {
    if( (v0 & 0x40000) == 0 )
      __writecr4(v0 | 0x40000);
    _xsetbv(0, KUSER_SHARED_DATA.XState.EnabledFeatures);
    if( KUSER_SHARED_DATA.XState.EnabledSupervisorFeatures )
      __writemsr(0xDA0u, KUSER_SHARED_DATA.XState.EnabledSupervisorFeatures);
    CurrentPrcb = KeGetCurrentPrcb();
    if( CurrentPrcb->Context != &CurrentPrcb->ProcessorState.ContextFrame )
      CurrentPrcb->ContextFlagsInit |= 0x100040u;
  }
  else if( (v0 & 0x40000) != 0 )
  {
    __writecr4(v0 & 0xFFFFFFFFFFFBFFFFui64);
  }
}

Referenced by:

KiConfigureDynamicProcessor
KiInitializeKernel
KiRestoreXSaveSupport