mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +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.
(cherry picked from commit a84181c31b)
This commit is contained in:
parent
7ac9048ce9
commit
43882c7c4e
6 changed files with 108 additions and 26 deletions
|
|
@ -997,6 +997,23 @@ PyCode_Addr2Line(PyCodeObject *co, int addrq)
|
|||
return _PyCode_CheckLineNumber(addrq, &bounds);
|
||||
}
|
||||
|
||||
int
|
||||
_PyCode_SafeAddr2Line(PyCodeObject *co, int addrq)
|
||||
{
|
||||
if (addrq < 0) {
|
||||
return co->co_firstlineno;
|
||||
}
|
||||
if (co->_co_monitoring && co->_co_monitoring->lines) {
|
||||
return _Py_Instrumentation_GetLine(co, addrq/sizeof(_Py_CODEUNIT));
|
||||
}
|
||||
if (!(addrq >= 0 && addrq < _PyCode_NBYTES(co))) {
|
||||
return -1;
|
||||
}
|
||||
PyCodeAddressRange bounds;
|
||||
_PyCode_InitAddressRange(co, &bounds);
|
||||
return _PyCode_CheckLineNumber(addrq, &bounds);
|
||||
}
|
||||
|
||||
void
|
||||
_PyLineTable_InitAddressRange(const char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue