Isolate the faulthandler Module Between Interpreters #101509
Labels
3.12
bugs and security fixes
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-subinterpreters
type-feature
A feature request or enhancement
(See gh-100227.)
Currently the faulthandler module has some state in
_PyRuntimeState
, including objects, which is shared by all interpreters. Interpreters should be isolated from each other, for a variety of reasons (including the possibility of a per-interpreter GIL). Isolating the module will involve moving some of the state toPyInterpreterState
(and, under per-interpreter GIL, guarding other state with a global lock).Code Analysis:
(expand)
Signals
The module installs handlers for various signals.
(expand)
fatal:
SIGBUS
- bus errorSIGILL
- illegal instructionSIGFPE
- floating point exceptionSIGABRT
- abortSIGSEGV
- segfault"user":
Py_NSIG
)handlers:
faulthandler_fatal_error(signum)
faulthandler_exc_handler()
(on Windows)faulthandler_user()
State
Fields
https://github.com/python/cpython/blob/main/Include/internal/pycore_faulthandler.h#L49-L86
https://github.com/python/cpython/blob/main/Include/internal/pycore_runtime.h#L146
raw
cpython/Include/internal/pycore_faulthandler.h
Lines 49 to 86 in 62251c3
cpython/Include/internal/pycore_faulthandler.h
Lines 36 to 46 in 62251c3
tables:
name
type
#ifdef
notes
fatal_error
enabled
bool
file
PyObject *
.fd
alivefd
int
all_threads
bool
interp
PyInterpreterState *
the one that enabled faulthandler
exc_handler
void *
MS_WINDOWS
name
type
#ifdef
notes
thread
file
PyObject *
.fd
alivefd
int
sys.stderr
timeout_us
PY_TIMEOUT_T
repeat
bool
interp
PyInterpreterState *
the one that requested the info
exit
bool
header
char *
header_len
size_t
cancel_event
PyThread_type_lock
running
PyThread_type_lock
name
type
#ifdef
notes
user_signals
struct faulthandler_user_signal *
FAULTHANDLER_USER
Py_NSIG
)user_signals[signum]
enabled
bool
file
PyObject *
fd
int
all_threads
bool
chain
bool
previous
_Py_sighandler_t
interp
PyInterpreterState *
the one that added the handler
name
type
#ifdef
notes
old_stack
stack_t
FAULTHANDLER_USE_ALT_STACK
stack
stack_t
FAULTHANDLER_USE_ALT_STACK
Usage
simple:
name
context
get
set
fatal_error
enabled
faulthandler_is_enabled()
faulthandler_disable_py()
faulthandler_fatal_error()
faulthandler_enable()
faulthandler_disable()
faulthandler_enable()
faulthandler_disable()
file
faulthandler_traverse()
faulthandler_py_enable()
faulthandler_traverse()
faulthandler_disable()
faulthandler_disable()
fd
faulthandler_fatal_error()
faulthandler_exc_handler()
all_threads
faulthandler_py_enable()
faulthandler_fatal_error()
faulthandler_exc_handler()
interp
faulthandler_py_enable()
faulthandler_fatal_error()
faulthandler_exc_handler()
exc_handler
faulthandler_enable()
faulthandler_disable()
faulthandler_enable()
faulthandler_disable()
name
context
get
set
thread
file
faulthandler_dump_traceback_later()
faulthandler_traverse()
faulthandler_dump_traceback_later()
faulthandler_traverse()
cancel_dump_traceback_later()
cancel_dump_traceback_later()
fd
faulthandler_dump_traceback_later()
faulthandler_thread()
timeout_us
faulthandler_dump_traceback_later()
faulthandler_thread()
repeat
faulthandler_dump_traceback_later()
faulthandler_thread()
interp
faulthandler_dump_traceback_later()
faulthandler_thread()
exit
faulthandler_dump_traceback_later()
faulthandler_thread()
header
faulthandler_dump_traceback_later()
faulthandler_thread()
cancel_dump_traceback_later()
cancel_dump_traceback_later()
header_len
faulthandler_dump_traceback_later()
faulthandler_thread()
cancel_event
faulthandler_dump_traceback_later()
faulthandler_dump_traceback_later()
faulthandler_thread()
cancel_dump_traceback_later()
running
faulthandler_dump_traceback_later()
faulthandler_dump_traceback_later()
faulthandler_thread()
cancel_dump_traceback_later()
name
context
get
set
user_signals
faulthandler_register_py()
faulthandler_unregister_py()
faulthandler_register_py()
faulthandler_traverse()
_PyFaulthandler_Fini()
_PyFaulthandler_Fini()
faulthandler_user()
user_signals[signum]
enabled
faulthandler_register_py()
faulthandler_register_py()
faulthandler_user()
faulthandler_unregister()
faulthandler_unregister()
file
faulthandler_register_py()
faulthandler_traverse()
faulthandler_register_py()
faulthandler_traverse()
faulthandler_unregister()
faulthandler_unregister()
fd
faulthandler_register_py()
faulthandler_user()
faulthandler_unregister()
all_threads
faulthandler_register_py()
faulthandler_user()
chain
faulthandler_register_py()
faulthandler_user()
previous
faulthandler_register_py()
faulthandler_user()
faulthandler_unregister()
interp
faulthandler_register_py()
faulthandler_user()
name
context
get
set
stack
_PyFaulthandler_Init()
_PyFaulthandler_Fini()
faulthandler_enable()
faulthandler_register()
faulthandler_allocate_stack()
old_stack
_PyFaulthandler_Fini()
modify data in complex fields:
name
context
calls
fatal_error .fd
faulthandler_fatal_error()
->faulthandler_dump_traceback()
faulthandler_fatal_error()
->_Py_DumpExtensionModules()
faulthandler_exc_handler()
faulthandler_exc_handler()
->_Py_DumpHexadecimal()
faulthandler_exc_handler()
->faulthandler_dump_traceback()
thread.fd
faulthandler_thread()
->_Py_write_noraise()
faulthandler_thread()
->_Py_DumpTracebackThreads()
thread .cancel_event
faulthandler_dump_traceback_later()
_PyFaulthandler_Fini()
faulthandler_thread()
cancel_dump_traceback_later()
thread .running
faulthandler_dump_traceback_later()
faulthandler_thread()
cancel_dump_traceback_later()
user_signals[signum] .fd
faulthandler_user()
->faulthandler_dump_traceback()
stack
_PyFaulthandler_Init()
_PyFaulthandler_Fini()
faulthandler_allocate_stack()
old_stack
faulthandler_allocate_stack()
->sigaltstack()
The text was updated successfully, but these errors were encountered: