Skip to content

Commit 48143fb

Browse files
christianaurichzmhugovk
authored andcommitted
[3.14] gh-157212: Fix _Py_ThreadId() on Windows ARM64 with MinGW (gh-157253)
(cherry picked from commit c1af94a) Co-authored-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
1 parent 919f2ce commit 48143fb

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎Include/object.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ _Py_ThreadId(void)
198198
#elif defined(__MINGW32__) && defined(_M_IX86)
199199
tid = __readfsdword(24);
200200
#elif defined(__MINGW32__) && defined(_M_ARM64)
201-
tid = __getReg(18);
201+
// x18 is the Windows ARM64 platform register and points to the TEB.
202+
__asm__ ("mov %0, x18" : "=r" (tid));
202203
#elif defined(__i386__)
203204
__asm__("{movl %%gs:0, %0|mov %0, dword ptr gs:[0]}" : "=r" (tid)); // 32-bit always uses GS
204205
#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)