From b6c79917506b438217aa2eaea3b13b9acf9e1c81 Mon Sep 17 00:00:00 2001
From: Dean M Greer <38226388+Gcenx@users.noreply.github.com>
Date: Tue, 22 Aug 2023 19:17:59 -0400
Subject: [PATCH] Game Porting Toolkit 1.0 (beta 4)

based on commit https://github.com/apple/homebrew-apple/commit/74b4a34683e5e7487e09866f3fdc41a7d94d3d65
---
 dlls/ntdll/unix/system.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c
index 970285a1f..9c2959521 100644
--- a/dlls/ntdll/unix/system.c
+++ b/dlls/ntdll/unix/system.c
@@ -1031,6 +1031,8 @@ static NTSTATUS create_logical_proc_info(void)
     size = sizeof(cores_no);
     if (sysctlbyname("hw.physicalcpu", &cores_no, &size, NULL, 0))
         cores_no = lcpu_no;
+    else
+        cores_no = MIN(cores_no, lcpu_no);
 
     TRACE("%u logical CPUs from %u physical cores across %u packages\n",
             lcpu_no, cores_no, pkgs_no);
@@ -1152,6 +1154,19 @@ static NTSTATUS create_logical_proc_info(void)
 }
 #endif
 
+#if defined(__APPLE__) && __APPLE__
+unsigned get_cpu_count_override(void)
+{
+    unsigned count = 4;
+    const char* ncpu = getenv("WINENCPU");
+    if (ncpu)
+    {
+        count = atoi(ncpu);
+    }
+    return count;
+}
+#endif
+
 /******************************************************************
  *		init_cpu_info
  *
@@ -1186,6 +1201,15 @@ void init_cpu_info(void)
     num = 1;
     FIXME("Detecting the number of processors is not supported.\n");
 #endif
+#if defined(__APPLE__) && __APPLE__
+    unsigned num_override = get_cpu_count_override();
+    if (num_override != -1)
+    {
+        WARN("Overriding cpu count from %u to %u\n", num, num_override);
+        num = num_override;
+    }
+#endif
+
     peb->NumberOfProcessors = num;
     get_cpuinfo( &cpu_info );
     TRACE( "<- CPU arch %d, level %d, rev %d, features 0x%x\n",
