[PATCH v2 3/5] kernel32: Reimplement GetActiveProcessorCount on top of GetLogicalProcessorInformationEx

Alex Henrie alexhenrie24 at gmail.com
Mon May 24 03:10:42 CDT 2021


Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
---
v2: Fix memory leak on error path
---
 dlls/kernel32/process.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index 710dfad8b7a..acdedd979f3 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -634,9 +634,32 @@ WORD WINAPI GetActiveProcessorGroupCount(void)
  */
 DWORD WINAPI GetActiveProcessorCount(WORD group)
 {
-    DWORD cpus = system_info.NumberOfProcessors;
+    DWORD cpus = 0;
+    DWORD size = 0;
+    SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *info;
 
-    FIXME("(0x%x): semi-stub, returning %u\n", group, cpus);
+    TRACE("(0x%x)\n", group);
+
+    if (!GetLogicalProcessorInformationEx(RelationGroup, NULL, &size)) return 0;
+    if (!(info = HeapAlloc(GetProcessHeap(), 0, size))) return 0;
+    if (!GetLogicalProcessorInformationEx(RelationGroup, info, &size))
+    {
+        HeapFree(GetProcessHeap(), 0, info);
+        return 0;
+    }
+
+    if (group == ALL_PROCESSOR_GROUPS)
+    {
+        for (group = 0; group < info->Group.ActiveGroupCount; group++)
+            cpus += info->Group.GroupInfo[group].ActiveProcessorCount;
+    }
+    else
+    {
+        if (group < info->Group.ActiveGroupCount)
+            cpus = info->Group.GroupInfo[group].ActiveProcessorCount;
+    }
+
+    HeapFree(GetProcessHeap(), 0, info);
     return cpus;
 }
 
-- 
2.31.1




More information about the wine-devel mailing list