16#define XSTATE_UINTR 14
18#define XSTATE_MASK_PKRU (1LL << (XSTATE_PKRU))
19#define XSTATE_MASK_HDC (1LL << (XSTATE_HDC))
20#define XSTATE_MASK_UINTR (1LL << (XSTATE_UINTR))
21#define XSTATE_MASK_LBR (1LL << (XSTATE_LBR))
23#define XSTATE_MASK_SUPERVISOR \
32template<ULONG NtDdiVersion>
41 struct _XSTATE_FEATURE Features[64];
60 struct _XSTATE_FEATURE Features[64];
142 trace(
"UnsuUnknown Windows version: 0x%lX\n", WinVersion);
149template<ULONG NtDdiVersion>
166template<ULONG NtDdiVersion>
177 ULONG64 SupportedSupervisorMask;
178 ULONG64 SupportedComponentMask;
179 ULONG NextUserOffset, NextSupervisorOffset, NextOffset;
185 trace(
"XSAVE not supported\n");
196 SupportedUserMask = (
ULONG64)ExtStateMain.
Edx << 32 |
200 SupportedUserMask &= XSTATE_MASK_ALLOWED;
201 XStateConfig->EnabledFeatures = SupportedUserMask;
202 XStateConfig->EnabledVolatileFeatures = SupportedUserMask & ~XSTATE_MASK_PERSISTENT;
211 XStateConfig->OptimizedSave = ExtStateSub.
Eax.
Bits.XSAVEOPT;
212 XStateConfig->CompactionEnabled = ExtStateSub.
Eax.
Bits.XSAVEC;
213 XStateConfig->ExtendedFeatureDisable = ExtStateSub.
Eax.
Bits.Xfd;
216 SupportedSupervisorMask = 0;
217 if (ExtStateSub.
Eax.
Bits.XSAVES)
219 SupportedSupervisorMask = (
ULONG64)ExtStateSub.
Edx << 32 |
225 XStateConfig->EnabledSupervisorFeatures = SupportedSupervisorMask;
229 SupportedComponentMask = SupportedUserMask | SupportedSupervisorMask;
240 NextUserOffset = NextSupervisorOffset =
sizeof(
XSAVE_AREA);
254 XStateConfig->AllFeatures[
Component] = ExtStateComponent.
Size;
257 if (ExtStateComponent.
Size == 0)
continue;
260 if ((ComponentBit & SupportedComponentMask) == 0)
266 XStateConfig->Features[
Component].Size = ExtStateComponent.
Size;
274 if (XStateConfig->CompactionEnabled)
277 if (ExtStateComponent.
Ecx.
Bits.Aligned)
279 XStateConfig->AlignedFeatures |= ComponentBit;
280 NextSupervisorOffset =
ALIGN_UP(NextSupervisorOffset, 64);
281 if ((ComponentBit & SupportedUserMask) != 0)
283 NextUserOffset =
ALIGN_UP(NextUserOffset, 64);
288 NextSupervisorOffset += ExtStateComponent.
Size;
291 if ((ComponentBit & SupportedUserMask) != 0)
293 XStateConfig->Features[
Component].Offset = NextUserOffset;
294 XStateConfig->Features[
Component].Size = ExtStateComponent.
Size;
295 NextUserOffset += ExtStateComponent.
Size;
301 NextOffset = ExtStateComponent.
Offset + ExtStateComponent.
Size;
302 NextSupervisorOffset =
max(NextSupervisorOffset, NextOffset);
305 if ((ComponentBit & SupportedUserMask) != 0)
308 XStateConfig->Features[
Component].Size = ExtStateComponent.
Size;
309 NextUserOffset =
max(NextUserOffset, NextOffset);
314 XStateConfig->Size = NextUserOffset;
315 XStateConfig->AllFeatureSize = NextSupervisorOffset;
318template<ULONG NtDdiVersion>
328 ok_eq_hex64(XStateConfig->EnabledFeatures, ExpectedConfig->EnabledFeatures);
329 ok_eq_ulong(XStateConfig->Size, ExpectedConfig->Size);
330 ok_eq_ulong(XStateConfig->OptimizedSave, ExpectedConfig->OptimizedSave);
333 ok(XStateConfig->Features[
i].Offset == ExpectedConfig->Features[
i].Offset,
334 "XStateConfig->Features[%lu].Offset = 0x%lx, expected 0x%lx\n",
335 i, XStateConfig->Features[
i].Offset, ExpectedConfig->Features[
i].Offset);
336 ok(XStateConfig->Features[
i].Offset == ExpectedConfig->Features[
i].Offset,
337 "XStateConfig->Features[%lu].Size = 0x%lx, expected 0x%lx\n",
338 i, XStateConfig->Features[
i].Size, ExpectedConfig->Features[
i].Size);
347 ok_eq_hex64(XStateConfig->EnabledFeatures, ExpectedConfig->EnabledFeatures);
348 ok_eq_hex64(XStateConfig->EnabledVolatileFeatures, ExpectedConfig->EnabledVolatileFeatures);
349 ok_eq_ulong(XStateConfig->Size, ExpectedConfig->Size);
350 ok_eq_ulong(XStateConfig->OptimizedSave, ExpectedConfig->OptimizedSave);
353 ok(XStateConfig->Features[
i].Offset == ExpectedConfig->Features[
i].Offset,
354 "XStateConfig->Features[%lu].Offset = 0x%lx, expected 0x%lx\n",
355 i, XStateConfig->Features[
i].Offset, ExpectedConfig->Features[
i].Offset);
356 ok(XStateConfig->Features[
i].Size == ExpectedConfig->Features[
i].Size,
357 "XStateConfig->Features[%lu].Size = 0x%lx, expected 0x%lx\n",
358 i, XStateConfig->Features[
i].Size, ExpectedConfig->Features[
i].Size);
368 ok_eq_hex64(XStateConfig->EnabledSupervisorFeatures, ExpectedConfig->EnabledSupervisorFeatures);
369 ok_eq_hex64(XStateConfig->AlignedFeatures, ExpectedConfig->AlignedFeatures);
370 ok_eq_ulong(XStateConfig->AllFeatureSize, ExpectedConfig->AllFeatureSize);
373 ok(XStateConfig->AllFeatures[
i] == ExpectedConfig->AllFeatures[
i],
374 "XStateConfig->AllFeatures[%lu] = 0x%lx, expected 0x%lx\n",
375 i, XStateConfig->AllFeatures[
i], ExpectedConfig->AllFeatures[
i]);
385 ok_eq_hex64(XStateConfig->EnabledUserVisibleSupervisorFeatures, ExpectedConfig->EnabledUserVisibleSupervisorFeatures);
394 ok_eq_hex64(XStateConfig->ExtendedFeatureDisableFeatures, ExpectedConfig->ExtendedFeatureDisableFeatures);
395 ok_eq_ulong(XStateConfig->AllNonLargeFeatureSize, ExpectedConfig->AllNonLargeFeatureSize);
396 ok_eq_ulong(XStateConfig->Spare, ExpectedConfig->Spare);
399template<ULONG NtDdiVersion>
407 ValidateXState<NtDdiVersion>(ActualXState, &ExpectedXState);
420 switch (NtDdiVersion)
423 TestXStateConfig<NTDDI_WIN7>();
426 TestXStateConfig<NTDDI_WIN8>();
429 TestXStateConfig<NTDDI_WIN10>();
432 TestXStateConfig<NTDDI_WIN10_RS5>();
435 TestXStateConfig<NTDDI_WIN11>();
439 skip(
"Skipping XStateConfig test on usupported Windows version\n");
#define CPUID_EXTENDED_STATE
#define CPUID_EXTENDED_STATE_SUB_LEAF
#define CPUID_EXTENDED_STATE_MAIN_LEAF
#define XSTATE_MASK_SUPERVISOR
void GetExpectedXStateConfig(TXSTATE_CONFIGURATION< NTDDI_WIN11 > *XStateConfig)
void ValidateXState< NTDDI_WIN7 >(TXSTATE_CONFIGURATION< NTDDI_WIN7 > *XStateConfig, TXSTATE_CONFIGURATION< NTDDI_WIN11 > *ExpectedConfig)
void ValidateXState< NTDDI_WIN8 >(TXSTATE_CONFIGURATION< NTDDI_WIN8 > *XStateConfig, TXSTATE_CONFIGURATION< NTDDI_WIN11 > *ExpectedConfig)
ULONG GetXStateNtDdiVersion(void)
void ValidateXState< NTDDI_WIN10_RS5 >(TXSTATE_CONFIGURATION< NTDDI_WIN10_RS5 > *XStateConfig, TXSTATE_CONFIGURATION< NTDDI_WIN11 > *ExpectedConfig)
TXSTATE_CONFIGURATION< NtDdiVersion > * GetOsXState(void)
void ValidateXState< NTDDI_WIN10 >(TXSTATE_CONFIGURATION< NTDDI_WIN10 > *XStateConfig, TXSTATE_CONFIGURATION< NTDDI_WIN11 > *ExpectedConfig)
SIZE_T GetXStateOffset(void)
void TestXStateConfig(void)
void ValidateXState< NTDDI_WIN11 >(TXSTATE_CONFIGURATION< NTDDI_WIN11 > *XStateConfig, TXSTATE_CONFIGURATION< NTDDI_WIN11 > *ExpectedConfig)
void ValidateXState(TXSTATE_CONFIGURATION< NtDdiVersion > *XStateConfig, TXSTATE_CONFIGURATION< NTDDI_WIN11 > *ExpectedConfig)
#define ok_eq_ulong(value, expected)
#define ok_eq_hex64(value, expected)
BOOL WINAPI IsProcessorFeaturePresent(IN DWORD ProcessorFeature)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
unsigned __int64 __cdecl _xgetbv(unsigned int)
__INTRIN_INLINE void __cpuidex(int CPUInfo[4], int InfoType, int ECXValue)
#define RTL_FIELD_SIZE(type, field)
_In_ ULONG _In_ ULONG Offset
#define _WIN32_WINNT_WIN10
#define _WIN32_WINNT_WINBLUE
#define _WIN32_WINNT_WIN8
#define _WIN32_WINNT_WIN7
ULONGLONG AlignedFeatures
ULONGLONG EnabledSupervisorFeatures
ULONGLONG EnabledUserVisibleSupervisorFeatures
ULONG AllNonLargeFeatureSize
ULONGLONG ExtendedFeatureDisableFeatures
ULONGLONG EnabledFeatures
ULONGLONG EnabledVolatileFeatures
ULONGLONG EnabledFeatures
ULONG ExtendedFeatureDisable
#define FIELD_OFFSET(t, f)
#define RtlZeroMemory(Destination, Length)
#define ALIGN_UP(size, type)
CPUID_EXTENDED_STATE_MAIN_LEAF_EAX Eax
struct CPUID_EXTENDED_STATE_SIZE_OFFSET_ECX::@4047 Bits
CPUID_EXTENDED_STATE_SIZE_OFFSET_ECX Ecx
struct CPUID_EXTENDED_STATE_SUB_LEAF_EAX::@4045 Bits
CPUID_EXTENDED_STATE_SUB_LEAF_EAX Eax
CPUID_EXTENDED_STATE_SUB_LEAF_ECX Ecx
#define MAXIMUM_XSTATE_FEATURES
#define XSTATE_LEGACY_SSE
#define XSTATE_LEGACY_FLOATING_POINT
#define XSTATE_MASK_USER_VISIBLE_SUPERVISOR