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_errorenabledboolfilePyObject *.fdalivefdintall_threadsboolinterpPyInterpreterState *the one that enabled faulthandler
exc_handlervoid *MS_WINDOWSname
type
#ifdef
notes
threadfilePyObject *.fdalivefdintsys.stderrtimeout_usPY_TIMEOUT_TrepeatboolinterpPyInterpreterState *the one that requested the info
exitboolheaderchar *header_lensize_tcancel_eventPyThread_type_lockrunningPyThread_type_lockname
type
#ifdef
notes
user_signalsstruct faulthandler_user_signal *FAULTHANDLER_USERPy_NSIG)user_signals[signum]enabledboolfilePyObject *fdintall_threadsboolchainboolprevious_Py_sighandler_tinterpPyInterpreterState *the one that added the handler
name
type
#ifdef
notes
old_stackstack_tFAULTHANDLER_USE_ALT_STACKstackstack_tFAULTHANDLER_USE_ALT_STACKUsage
simple:
name
context
get
set
fatal_errorenabledfaulthandler_is_enabled()faulthandler_disable_py()faulthandler_fatal_error()faulthandler_enable()faulthandler_disable()faulthandler_enable()faulthandler_disable()filefaulthandler_traverse()faulthandler_py_enable()faulthandler_traverse()faulthandler_disable()faulthandler_disable()fdfaulthandler_fatal_error()faulthandler_exc_handler()all_threadsfaulthandler_py_enable()faulthandler_fatal_error()faulthandler_exc_handler()interpfaulthandler_py_enable()faulthandler_fatal_error()faulthandler_exc_handler()exc_handlerfaulthandler_enable()faulthandler_disable()faulthandler_enable()faulthandler_disable()name
context
get
set
threadfilefaulthandler_dump_traceback_later()faulthandler_traverse()faulthandler_dump_traceback_later()faulthandler_traverse()cancel_dump_traceback_later()cancel_dump_traceback_later()fdfaulthandler_dump_traceback_later()faulthandler_thread()timeout_usfaulthandler_dump_traceback_later()faulthandler_thread()repeatfaulthandler_dump_traceback_later()faulthandler_thread()interpfaulthandler_dump_traceback_later()faulthandler_thread()exitfaulthandler_dump_traceback_later()faulthandler_thread()headerfaulthandler_dump_traceback_later()faulthandler_thread()cancel_dump_traceback_later()cancel_dump_traceback_later()header_lenfaulthandler_dump_traceback_later()faulthandler_thread()cancel_eventfaulthandler_dump_traceback_later()faulthandler_dump_traceback_later()faulthandler_thread()cancel_dump_traceback_later()runningfaulthandler_dump_traceback_later()faulthandler_dump_traceback_later()faulthandler_thread()cancel_dump_traceback_later()name
context
get
set
user_signalsfaulthandler_register_py()faulthandler_unregister_py()faulthandler_register_py()faulthandler_traverse()_PyFaulthandler_Fini()_PyFaulthandler_Fini()faulthandler_user()user_signals[signum]enabledfaulthandler_register_py()faulthandler_register_py()faulthandler_user()faulthandler_unregister()faulthandler_unregister()filefaulthandler_register_py()faulthandler_traverse()faulthandler_register_py()faulthandler_traverse()faulthandler_unregister()faulthandler_unregister()fdfaulthandler_register_py()faulthandler_user()faulthandler_unregister()all_threadsfaulthandler_register_py()faulthandler_user()chainfaulthandler_register_py()faulthandler_user()previousfaulthandler_register_py()faulthandler_user()faulthandler_unregister()interpfaulthandler_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 .fdfaulthandler_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.fdfaulthandler_thread()->_Py_write_noraise()faulthandler_thread()->_Py_DumpTracebackThreads()thread .cancel_eventfaulthandler_dump_traceback_later()_PyFaulthandler_Fini()faulthandler_thread()cancel_dump_traceback_later()thread .runningfaulthandler_dump_traceback_later()faulthandler_thread()cancel_dump_traceback_later()user_signals[signum] .fdfaulthandler_user()->faulthandler_dump_traceback()stack_PyFaulthandler_Init()_PyFaulthandler_Fini()faulthandler_allocate_stack()old_stackfaulthandler_allocate_stack()->sigaltstack()The text was updated successfully, but these errors were encountered: