[PATCH] ntdll: Implement NtGetCurrentProcessorNumber() for Mac OS.
Chip Davis
cdavis5x at gmail.com
Tue Apr 19 19:18:38 CDT 2022
Signed-off-by: Chip Davis <cdavis5x at gmail.com>
---
dlls/ntdll/unix/thread.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/dlls/ntdll/unix/thread.c b/dlls/ntdll/unix/thread.c
index 451402159d46..3e9e4d740e6a 100644
--- a/dlls/ntdll/unix/thread.c
+++ b/dlls/ntdll/unix/thread.c
@@ -2285,6 +2285,21 @@ ULONG WINAPI NtGetCurrentProcessorNumber(void)
if (res != -1) return processor;
#endif
+#if defined(__APPLE__) && (defined(__i386__) || defined(__x86_64__))
+ /* A little known feature of macOS is that it will stash the CPU number
+ * in the low 12 bits of the IDTR's limit field.
+ */
+#include "pshpack1.h"
+ struct
+ {
+ USHORT limit;
+ ULONG_PTR base;
+ } idtr;
+#include "poppack.h"
+ asm("sidt %0" : "=m" (idtr));
+ return idtr.limit & 0xfff;
+#endif
+
if (peb->NumberOfProcessors > 1)
{
ULONG_PTR thread_mask, processor_mask;
--
2.34.1
More information about the wine-devel
mailing list