2727
2828extern iSK_INI* osd_ini;
2929
30+
31+ typedef enum _SYSTEM_INFORMATION_CLASS {
32+ SystemProcessorPerformanceInformation = 8 ,
33+ } SYSTEM_INFORMATION_CLASS ;
34+
35+ typedef NTSTATUS (WINAPI * NtQuerySystemInformation_pfn)(
36+ _In_ SYSTEM_INFORMATION_CLASS SystemInformationClass,
37+ _Inout_ PVOID SystemInformation,
38+ _In_ ULONG SystemInformationLength,
39+ _Out_opt_ PULONG ReturnLength
40+ );
41+
42+ static NtQuerySystemInformation_pfn NtQuerySystemInformation =
43+ (NtQuerySystemInformation_pfn)SK_GetProcAddress(L" NtDll" ,
44+ " NtQuerySystemInformation" );
45+
46+
3047ULONG
3148CALLBACK
3249SK_CPU_DeviceNotifyCallback (
@@ -1717,14 +1734,21 @@ class SKWG_CPU_Monitor : public SK_Widget
17171734 SK_TLS_Bottom ();
17181735
17191736 // Processor count is not going to change at run-time or I will eat my hat
1737+ static const unsigned int cpu_count = []() -> unsigned int {
1738+ unsigned long len = 0 ;
1739+ NtQuerySystemInformation (SystemProcessorPerformanceInformation,
1740+ nullptr , 0 , &len);
1741+ return len / sizeof (_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION__SK);
1742+ }();
1743+
17201744 static SYSTEM_INFO sinfo = { };
17211745 SK_RunOnce (SK_GetSystemInfo (&sinfo));
17221746
17231747 PPROCESSOR_POWER_INFORMATION pwi =
17241748 reinterpret_cast <PPROCESSOR_POWER_INFORMATION > (
17251749 pTLS != nullptr ?
17261750 pTLS->scratch_memory ->cpu_info .alloc (
1727- sizeof (PROCESSOR_POWER_INFORMATION ) * sinfo. dwNumberOfProcessors )
1751+ sizeof (PROCESSOR_POWER_INFORMATION ) * cpu_count )
17281752 : nullptr );
17291753
17301754 if (pwi == nullptr ) return ; // Ohnoes, I No Can Haz RAM (!!)
@@ -1735,7 +1759,7 @@ class SKWG_CPU_Monitor : public SK_Widget
17351759 const NTSTATUS ntStatus =
17361760 CallNtPowerInformation ( ProcessorInformation,
17371761 nullptr , 0 ,
1738- pwi, sizeof (PROCESSOR_POWER_INFORMATION ) * sinfo. dwNumberOfProcessors );
1762+ pwi, sizeof (PROCESSOR_POWER_INFORMATION ) * cpu_count );
17391763
17401764 bUseNtPower =
17411765 NT_SUCCESS (ntStatus);
0 commit comments