Signed-off-by: Alex Henrie alexhenrie24@gmail.com --- https://www.geoffchappell.com/studies/windows/km/ntoskrnl/api/ex/sysinfo/pro... --- dlls/ntdll/unix/system.c | 29 +++++++++++++++++++++++++++++ include/winternl.h | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c index 491cdb37b8f..784fb6212a5 100644 --- a/dlls/ntdll/unix/system.c +++ b/dlls/ntdll/unix/system.c @@ -173,6 +173,31 @@ struct smbios_boot_info
SYSTEM_CPU_INFORMATION cpu_info = { 0 };
+static int get_possible_cpus(void) +{ + int ret = NtCurrentTeb()->Peb->NumberOfProcessors; +#ifdef linux + FILE *f = fopen("/sys/devices/system/cpu/possible", "r"); + char line[32]; + char *value; + if (f) + { + if (fgets(line, sizeof(line), f)) + { + value = strchr(line, '-'); + if (value) + { + *value = 0; + value++; + ret = atoi(value) - atoi(line) + 1; + } + } + fclose(f); + } +#endif + return ret; +} + /******************************************************************************* * Architecture specific feature detection for CPUs * @@ -246,6 +271,8 @@ static void get_cpuinfo( SYSTEM_CPU_INFORMATION *info ) info->Architecture = PROCESSOR_ARCHITECTURE_AMD64; #endif
+ info->MaximumCpus = get_possible_cpus(); + /* We're at least a 386 */ info->FeatureSet = CPU_FEATURE_VME | CPU_FEATURE_X86 | CPU_FEATURE_PGE; info->Level = 3; @@ -400,6 +427,7 @@ static inline void get_cpuinfo( SYSTEM_CPU_INFORMATION *info ) FIXME("CPU Feature detection not implemented.\n"); #endif info->Architecture = PROCESSOR_ARCHITECTURE_ARM; + info->MaximumCpus = get_possible_cpus(); }
#elif defined(__aarch64__) @@ -448,6 +476,7 @@ static void get_cpuinfo( SYSTEM_CPU_INFORMATION *info ) #endif info->Level = max(info->Level, 8); info->Architecture = PROCESSOR_ARCHITECTURE_ARM64; + info->MaximumCpus = get_possible_cpus(); }
#endif /* End architecture specific feature detection for CPUs */ diff --git a/include/winternl.h b/include/winternl.h index dd2bdbbebbe..1104865a053 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -2132,7 +2132,7 @@ typedef struct _SYSTEM_CPU_INFORMATION { WORD Architecture; WORD Level; WORD Revision; /* combination of CPU model and stepping */ - WORD Reserved; /* always zero */ + WORD MaximumCpus; /* number of CPUs if as many as possible are hot-added */ DWORD FeatureSet; /* see bit flags below */ } SYSTEM_CPU_INFORMATION, *PSYSTEM_CPU_INFORMATION;
Signed-off-by: Alex Henrie alexhenrie24@gmail.com --- This fixes the console spam when the Clinithink natural language processing software https://www.clinithink.com/ calls GetMaximumProcessorCount repeatedly. --- dlls/kernel32/kernel_main.c | 1 + dlls/kernel32/kernel_private.h | 1 + dlls/kernel32/process.c | 9 +++++++-- 3 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/dlls/kernel32/kernel_main.c b/dlls/kernel32/kernel_main.c index 89394e16430..531a580749f 100644 --- a/dlls/kernel32/kernel_main.c +++ b/dlls/kernel32/kernel_main.c @@ -123,6 +123,7 @@ static BOOL process_attach( HMODULE module ) RtlSetUnhandledExceptionFilter( UnhandledExceptionFilter );
NtQuerySystemInformation( SystemBasicInformation, &system_info, sizeof(system_info), NULL ); + NtQuerySystemInformation( SystemCpuInformation, &cpu_info, sizeof(cpu_info), NULL );
copy_startup_info();
diff --git a/dlls/kernel32/kernel_private.h b/dlls/kernel32/kernel_private.h index 633511d6140..cbd23f52f10 100644 --- a/dlls/kernel32/kernel_private.h +++ b/dlls/kernel32/kernel_private.h @@ -30,6 +30,7 @@ static inline BOOL set_ntstatus( NTSTATUS status ) }
extern SYSTEM_BASIC_INFORMATION system_info DECLSPEC_HIDDEN; +extern SYSTEM_CPU_INFORMATION cpu_info DECLSPEC_HIDDEN;
extern WCHAR *FILE_name_AtoW( LPCSTR name, BOOL alloc ) DECLSPEC_HIDDEN; extern DWORD FILE_name_WtoA( LPCWSTR src, INT srclen, LPSTR dest, INT destlen ) DECLSPEC_HIDDEN; diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c index b31d73bc5a5..7bfdf635dbb 100644 --- a/dlls/kernel32/process.c +++ b/dlls/kernel32/process.c @@ -52,6 +52,7 @@ typedef struct } LOADPARMS32;
SYSTEM_BASIC_INFORMATION system_info = { 0 }; +SYSTEM_CPU_INFORMATION cpu_info = { 0 };
/* Process flags */ #define PDB32_DEBUGGED 0x0001 /* Process is being debugged */ @@ -629,9 +630,13 @@ DWORD WINAPI GetActiveProcessorCount(WORD group) */ DWORD WINAPI GetMaximumProcessorCount(WORD group) { - DWORD cpus = system_info.NumberOfProcessors; + DWORD cpus = cpu_info.MaximumCpus; + + if (group == ALL_PROCESSOR_GROUPS) + TRACE("(0x%x): returning %u\n", group, cpus); + else + FIXME("(0x%x): processor groups not supported, returning %u\n", group, cpus);
- FIXME("(0x%x): semi-stub, returning %u\n", group, cpus); return cpus; }
Alex Henrie alexhenrie24@gmail.com writes:
@@ -629,9 +630,13 @@ DWORD WINAPI GetActiveProcessorCount(WORD group) */ DWORD WINAPI GetMaximumProcessorCount(WORD group) {
- DWORD cpus = system_info.NumberOfProcessors;
- DWORD cpus = cpu_info.MaximumCpus;
- if (group == ALL_PROCESSOR_GROUPS)
TRACE("(0x%x): returning %u\n", group, cpus);
- else
FIXME("(0x%x): processor groups not supported, returning %u\n", group, cpus);
That doesn't seem much better than the previous stub. It shouldn't be hard to implement these functions correctly now that we support GetLogicalProcessorInformationEx().
On Fri, Apr 30, 2021 at 8:18 AM Alexandre Julliard julliard@winehq.org wrote:
Alex Henrie alexhenrie24@gmail.com writes:
@@ -629,9 +630,13 @@ DWORD WINAPI GetActiveProcessorCount(WORD group) */ DWORD WINAPI GetMaximumProcessorCount(WORD group) {
- DWORD cpus = system_info.NumberOfProcessors;
- DWORD cpus = cpu_info.MaximumCpus;
- if (group == ALL_PROCESSOR_GROUPS)
TRACE("(0x%x): returning %u\n", group, cpus);
- else
FIXME("(0x%x): processor groups not supported, returning %u\n", group, cpus);
That doesn't seem much better than the previous stub. It shouldn't be hard to implement these functions correctly now that we support GetLogicalProcessorInformationEx().
Sorry for not responding sooner; Gmail put your last two messages into the spam folder and I didn't notice until Friday. Thank you for the feedback. I will send new patches shortly.
-Alex