https://github.com/python/cpython/commit/c1af94ae348da826ac530c8d5097fa887e19579c
commit: c1af94ae348da826ac530c8d5097fa887e19579c
branch: main
author: Christian Aurich Zanettini Martins <[email protected]>
committer: corona10 <[email protected]>
date: 2026-09-25T13:04:06Z
summary:

gh-157212: Fix _Py_ThreadId() on Windows ARM64 with MinGW (gh-157253)

files:
A Misc/NEWS.d/next/Windows/2026-09-10-02-00-00.gh-issue-157212.x18TEB.rst
M Include/cpython/object.h

diff --git a/Include/cpython/object.h b/Include/cpython/object.h
index 0ef52d4d2bc7b4..c0fcfc363ef90c 100644
--- a/Include/cpython/object.h
+++ b/Include/cpython/object.h
@@ -523,7 +523,8 @@ _Py_ThreadId(void)
 #elif defined(__MINGW32__) && defined(_M_IX86)
     tid = __readfsdword(24);
 #elif defined(__MINGW32__) && defined(_M_ARM64)
-    tid = __getReg(18);
+    // x18 is the Windows ARM64 platform register and points to the TEB.
+    __asm__ ("mov %0, x18" : "=r" (tid));
 #elif defined(__i386__)
     __asm__("{movl %%gs:0, %0|mov %0, dword ptr gs:[0]}" : "=r" (tid));  // 
32-bit always uses GS
 #elif defined(__MACH__) && defined(__x86_64__)
diff --git 
a/Misc/NEWS.d/next/Windows/2026-09-10-02-00-00.gh-issue-157212.x18TEB.rst 
b/Misc/NEWS.d/next/Windows/2026-09-10-02-00-00.gh-issue-157212.x18TEB.rst
new file mode 100644
index 00000000000000..8d0970516242f9
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2026-09-10-02-00-00.gh-issue-157212.x18TEB.rst
@@ -0,0 +1,3 @@
+Fix ``_Py_ThreadId()`` compilation on Windows ARM64 with MinGW toolchains,
+where ``__getReg()`` is unavailable. The TEB address is now read directly
+from ``x18``. Patch by Christian Aurich.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to