mirror of
https://github.com/python/cpython.git
synced 2025-11-24 12:20:42 +00:00
gh-140815: Fix faulthandler for invalid/freed frame (#140921)
faulthandler now detects if a frame or a code object is invalid or freed. Add helper functions: * _PyCode_SafeAddr2Line() * _PyFrame_SafeGetCode() * _PyFrame_SafeGetLasti() _PyMem_IsPtrFreed() now detects pointers in [-0xff, 0xff] range as freed.
This commit is contained in:
parent
08115d241a
commit
a84181c31b
6 changed files with 128 additions and 33 deletions
|
|
@ -54,15 +54,17 @@ static inline int _PyMem_IsPtrFreed(const void *ptr)
|
|||
{
|
||||
uintptr_t value = (uintptr_t)ptr;
|
||||
#if SIZEOF_VOID_P == 8
|
||||
return (value == 0
|
||||
return (value <= 0xff // NULL, 0x1, 0x2, ..., 0xff
|
||||
|| value == (uintptr_t)0xCDCDCDCDCDCDCDCD
|
||||
|| value == (uintptr_t)0xDDDDDDDDDDDDDDDD
|
||||
|| value == (uintptr_t)0xFDFDFDFDFDFDFDFD);
|
||||
|| value == (uintptr_t)0xFDFDFDFDFDFDFDFD
|
||||
|| value >= (uintptr_t)0xFFFFFFFFFFFFFF00); // -0xff, ..., -2, -1
|
||||
#elif SIZEOF_VOID_P == 4
|
||||
return (value == 0
|
||||
return (value <= 0xff
|
||||
|| value == (uintptr_t)0xCDCDCDCD
|
||||
|| value == (uintptr_t)0xDDDDDDDD
|
||||
|| value == (uintptr_t)0xFDFDFDFD);
|
||||
|| value == (uintptr_t)0xFDFDFDFD
|
||||
|| value >= (uintptr_t)0xFFFFFF00);
|
||||
#else
|
||||
# error "unknown pointer size"
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue