GH-126910: avoid reading the FP for getting the SP (GH-146521)

This commit is contained in:
Diego Russo 2026-03-27 17:52:48 +00:00 committed by GitHub
parent 6763d26b2b
commit b60b9261b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 12 deletions

View file

@ -3286,3 +3286,16 @@ _Py_GetMainConfig(void)
}
return _PyInterpreterState_GetConfig(interp);
}
uintptr_t
_Py_get_machine_stack_pointer(void) {
#if _Py__has_builtin(__builtin_frame_address) || defined(__GNUC__)
return (uintptr_t)__builtin_frame_address(0);
#elif defined(_MSC_VER)
return (uintptr_t)_AddressOfReturnAddress();
#else
char here;
/* Avoid compiler warning about returning stack address */
return return_pointer_as_int(&here);
#endif
}