Skip to content

Instantly share code, notes, and snippets.

@kode54
Created July 27, 2013 22:55
Show Gist options
  • Save kode54/6096605 to your computer and use it in GitHub Desktop.
Save kode54/6096605 to your computer and use it in GitHub Desktop.
Patch against wine which adds basic implementations of the existing stubbed NUMA functions, which are required by the Concurrency::critical_section and other scheduling code used by std::mutex and std::thread in the MSVC 2012 and newer runtime libraries.
diff -ur wine-crossover.orig/sources/wine/dlls/kernel32/process.c wine-crossover/sources/wine/dlls/kernel32/process.c
--- wine-crossover.orig/sources/wine/dlls/kernel32/process.c 2013-05-13 12:06:06.000000000 -0700
+++ wine-crossover/sources/wine/dlls/kernel32/process.c 2013-07-27 15:52:34.000000000 -0700
@@ -3922,9 +3922,10 @@
*/
BOOL WINAPI GetNumaHighestNodeNumber(PULONG highestnode)
{
- FIXME("(%p): stub\n", highestnode);
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return FALSE;
+ if(highestnode)
+ *highestnode = 0;
+
+ return TRUE;
}
/**********************************************************************
@@ -3932,9 +3933,26 @@
*/
BOOL WINAPI GetNumaNodeProcessorMask(UCHAR node, PULONGLONG mask)
{
- FIXME("(%c %p): stub\n", node, mask);
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return FALSE;
+ unsigned long numCPU = 1;
+
+#ifdef __APPLE__
+ int mib[4];
+ size_t len = sizeof(numCPU);
+
+ /* set the mib for hw.ncpu */
+ mib[0] = CTL_HW;
+ mib[1] = HW_AVAILCPU; // alternatively, try HW_NCPU;
+
+ /* get the number of CPUs from the system */
+ sysctl(mib, 2, &numCPU, &len, NULL, 0);
+#else
+ cpu_set_t mask;
+ if (sched_getaffinity(0, sizeof(mask), &mask) == 0)
+ numCPU = CPU_COUNT(mask);
+#endif
+
+ *mask = (1 << numCPU) - 1;
+ return TRUE;
}
/**********************************************************************
@@ -3942,9 +3960,10 @@
*/
BOOL WINAPI GetNumaAvailableMemoryNode(UCHAR node, PULONGLONG available_bytes)
{
- FIXME("(%c %p): stub\n", node, available_bytes);
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return FALSE;
+ MEMORYSTATUSEX msx;
+ GlobalMemoryStatusEx(&msx);
+ *available_bytes = msx.ullAvailPhys;
+ return TRUE;
}
/**********************************************************************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment