Skip to content

Commit b60b926

Browse files
authored
GH-126910: avoid reading the FP for getting the SP (GH-146521)
1 parent 6763d26 commit b60b926

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Include/internal/pycore_pystate.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -312,18 +312,7 @@ static uintptr_t return_pointer_as_int(char* p) {
312312
}
313313
#endif
314314

315-
static inline uintptr_t
316-
_Py_get_machine_stack_pointer(void) {
317-
#if _Py__has_builtin(__builtin_frame_address) || defined(__GNUC__)
318-
return (uintptr_t)__builtin_frame_address(0);
319-
#elif defined(_MSC_VER)
320-
return (uintptr_t)_AddressOfReturnAddress();
321-
#else
322-
char here;
323-
/* Avoid compiler warning about returning stack address */
324-
return return_pointer_as_int(&here);
325-
#endif
326-
}
315+
PyAPI_DATA(uintptr_t) _Py_get_machine_stack_pointer(void);
327316

328317
static inline intptr_t
329318
_Py_RecursionLimit_GetMargin(PyThreadState *tstate)

Python/pystate.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3286,3 +3286,16 @@ _Py_GetMainConfig(void)
32863286
}
32873287
return _PyInterpreterState_GetConfig(interp);
32883288
}
3289+
3290+
uintptr_t
3291+
_Py_get_machine_stack_pointer(void) {
3292+
#if _Py__has_builtin(__builtin_frame_address) || defined(__GNUC__)
3293+
return (uintptr_t)__builtin_frame_address(0);
3294+
#elif defined(_MSC_VER)
3295+
return (uintptr_t)_AddressOfReturnAddress();
3296+
#else
3297+
char here;
3298+
/* Avoid compiler warning about returning stack address */
3299+
return return_pointer_as_int(&here);
3300+
#endif
3301+
}

0 commit comments

Comments
 (0)