https://github.com/python/cpython/commit/14542e3b8a3cf214997a26dfec5eb7816fdb8388
commit: 14542e3b8a3cf214997a26dfec5eb7816fdb8388
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: hugovk <[email protected]>
date: 2026-09-26T21:44:01+03:00
summary:

[3.15] gh-157212: Fix _Py_ThreadId() on Windows ARM64 with MinGW (gh-157253) 
(#158164)

Co-authored-by: Christian Aurich Zanettini Martins 
<[email protected]>

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 326254c335b4895..c8b8119d44bb1d0 100644
--- a/Include/cpython/object.h
+++ b/Include/cpython/object.h
@@ -521,7 +521,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 000000000000000..8d0970516242f93
--- /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