diff --git a/Include/cpython/object.h b/Include/cpython/object.h index 4c5a677e5543ece..a77ab09f6fa8f0a 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 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.