Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,16 @@ static uintptr_t return_pointer_as_int(char* p) {
static inline uintptr_t
_Py_get_machine_stack_pointer(void) {
uintptr_t result;
#if defined(_M_ARM64)
#if _Py__has_builtin(__builtin_stack_address)
result = (uintptr_t)__builtin_stack_address();
#elif defined(_MSC_VER) && defined(_M_ARM64)
result = __getReg(31);
#elif defined(_M_X64) || defined(_M_IX86)
#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
result = (uintptr_t)_AddressOfReturnAddress();
#elif defined(__aarch64__)
__asm__ ("mov %0, sp" : "=r" (result));
#elif defined(__x86_64__)
__asm__("{movq %%rsp, %0" : "=r" (result));
__asm__ ("{movq %%rsp, %0|mov %0, rsp}" : "=r" (result));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? Does MinGW use a different assembler?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__asm__("{movq %%fs:0, %0|mov %0, qword ptr fs:[0]}" : "=r" (tid)); // x86_64 Linux, BSD uses FS

Just following _Py_ThreadId support for both assembler types.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's about defined(__x86_64__)

#else
char here;
result = (uintptr_t)&here;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix compilation of ``_Py_get_machine_stack_pointer()`` with MinGW on Windows.
Patch by Donghee Na.
Loading