Skip to content

Commit 14542e3

Browse files
[3.15] gh-157212: Fix _Py_ThreadId() on Windows ARM64 with MinGW (gh-157253) (#158164)
Co-authored-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
1 parent 2168416 commit 14542e3

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎Include/cpython/object.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,8 @@ _Py_ThreadId(void)
521521
#elif defined(__MINGW32__) && defined(_M_IX86)
522522
tid = __readfsdword(24);
523523
#elif defined(__MINGW32__) && defined(_M_ARM64)
524-
tid = __getReg(18);
524+
// x18 is the Windows ARM64 platform register and points to the TEB.
525+
__asm__ ("mov %0, x18" : "=r" (tid));
525526
#elif defined(__i386__)
526527
__asm__("{movl %%gs:0, %0|mov %0, dword ptr gs:[0]}" : "=r" (tid)); // 32-bit always uses GS
527528
#elif defined(__MACH__) && defined(__x86_64__)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix ``_Py_ThreadId()`` compilation on Windows ARM64 with MinGW toolchains,
2+
where ``__getReg()`` is unavailable. The TEB address is now read directly
3+
from ``x18``. Patch by Christian Aurich.

0 commit comments

Comments
 (0)