aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Modules/faulthandler.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-02-12 07:53:52 +0300
committerDaniil Cherednik <dcherednik@ydb.tech>2024-02-14 14:26:16 +0000
commit31f2a419764a8ba77c2a970cfc80056c6cd06756 (patch)
treec1995d239eba8571cefc640f6648e1d5dd4ce9e2 /contrib/tools/python3/src/Modules/faulthandler.c
parentfe2ef02b38d9c85d80060963b265a1df9f38c3bb (diff)
downloadydb-31f2a419764a8ba77c2a970cfc80056c6cd06756.tar.gz
Update Python from 3.11.8 to 3.12.2
Diffstat (limited to 'contrib/tools/python3/src/Modules/faulthandler.c')
-rw-r--r--contrib/tools/python3/src/Modules/faulthandler.c95
1 files changed, 21 insertions, 74 deletions
diff --git a/contrib/tools/python3/src/Modules/faulthandler.c b/contrib/tools/python3/src/Modules/faulthandler.c
index 520b7b603e..be77bb01f3 100644
--- a/contrib/tools/python3/src/Modules/faulthandler.c
+++ b/contrib/tools/python3/src/Modules/faulthandler.c
@@ -7,7 +7,6 @@
#include <object.h>
#include <signal.h>
-#include <signal.h>
#include <stdlib.h> // abort()
#if defined(HAVE_PTHREAD_SIGMASK) && !defined(HAVE_BROKEN_PTHREAD_SIGMASK) && defined(HAVE_PTHREAD_H)
# include <pthread.h>
@@ -19,12 +18,6 @@
# include <sys/resource.h>
#endif
-/* Using an alternative stack requires sigaltstack()
- and sigaction() SA_ONSTACK */
-#if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION)
-# define FAULTHANDLER_USE_ALT_STACK
-#endif
-
#if defined(FAULTHANDLER_USE_ALT_STACK) && defined(HAVE_LINUX_AUXVEC_H) && defined(HAVE_SYS_AUXV_H)
# include <linux/auxvec.h> // AT_MINSIGSTKSZ
# include <sys/auxv.h> // getauxval()
@@ -33,13 +26,6 @@
/* Allocate at maximum 100 MiB of the stack to raise the stack overflow */
#define STACK_OVERFLOW_MAX_SIZE (100 * 1024 * 1024)
-#ifndef MS_WINDOWS
- /* register() is useless on Windows, because only SIGSEGV, SIGABRT and
- SIGILL can be handled by the process, and these signals can only be used
- with enable(), not using register() */
-# define FAULTHANDLER_USER
-#endif
-
#define PUTS(fd, str) _Py_write_noraise(fd, str, strlen(str))
@@ -59,12 +45,6 @@
#endif
-#ifdef HAVE_SIGACTION
-typedef struct sigaction _Py_sighandler_t;
-#else
-typedef PyOS_sighandler_t _Py_sighandler_t;
-#endif
-
typedef struct {
int signum;
int enabled;
@@ -73,47 +53,12 @@ typedef struct {
int all_threads;
} fault_handler_t;
-static struct {
- int enabled;
- PyObject *file;
- int fd;
- int all_threads;
- PyInterpreterState *interp;
-#ifdef MS_WINDOWS
- void *exc_handler;
-#endif
-} fatal_error = {0, NULL, -1, 0};
-
-static struct {
- PyObject *file;
- int fd;
- PY_TIMEOUT_T timeout_us; /* timeout in microseconds */
- int repeat;
- PyInterpreterState *interp;
- int exit;
- char *header;
- size_t header_len;
- /* The main thread always holds this lock. It is only released when
- faulthandler_thread() is interrupted before this thread exits, or at
- Python exit. */
- PyThread_type_lock cancel_event;
- /* released by child thread when joined */
- PyThread_type_lock running;
-} thread;
+#define fatal_error _PyRuntime.faulthandler.fatal_error
+#define thread _PyRuntime.faulthandler.thread
#ifdef FAULTHANDLER_USER
-typedef struct {
- int enabled;
- PyObject *file;
- int fd;
- int all_threads;
- int chain;
- _Py_sighandler_t previous;
- PyInterpreterState *interp;
-} user_signal_t;
-
-static user_signal_t *user_signals;
-
+#define user_signals _PyRuntime.faulthandler.user_signals
+typedef struct faulthandler_user_signal user_signal_t;
static void faulthandler_user(int signum);
#endif /* FAULTHANDLER_USER */
@@ -135,8 +80,8 @@ static const size_t faulthandler_nsignals = \
Py_ARRAY_LENGTH(faulthandler_handlers);
#ifdef FAULTHANDLER_USE_ALT_STACK
-static stack_t stack;
-static stack_t old_stack;
+# define stack _PyRuntime.faulthandler.stack
+# define old_stack _PyRuntime.faulthandler.old_stack
#endif
@@ -175,7 +120,7 @@ faulthandler_get_fileno(PyObject **file_ptr)
return -1;
if (fd < 0) {
PyErr_SetString(PyExc_ValueError,
- "file is not a valid file descripter");
+ "file is not a valid file descriptor");
return -1;
}
*file_ptr = NULL;
@@ -270,7 +215,7 @@ faulthandler_dump_traceback_py(PyObject *self,
int fd;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "|Oi:dump_traceback", kwlist,
+ "|Op:dump_traceback", kwlist,
&file, &all_threads))
return NULL;
@@ -545,7 +490,7 @@ faulthandler_py_enable(PyObject *self, PyObject *args, PyObject *kwargs)
PyThreadState *tstate;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "|Oi:enable", kwlist, &file, &all_threads))
+ "|Op:enable", kwlist, &file, &all_threads))
return NULL;
fd = faulthandler_get_fileno(&file);
@@ -915,7 +860,7 @@ faulthandler_register_py(PyObject *self,
int err;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "i|Oii:register", kwlist,
+ "i|Opp:register", kwlist,
&signum, &file, &all_threads, &chain))
return NULL;
@@ -1006,7 +951,7 @@ faulthandler_unregister_py(PyObject *self, PyObject *args)
static void
faulthandler_suppress_crash_report(void)
{
-#ifdef MS_WINDOWS
+#ifdef MS_WINDOWS_DESKTOP
UINT mode;
/* Configure Windows to not display the Windows Error Reporting dialog */
@@ -1093,7 +1038,7 @@ faulthandler_fatal_error_thread(void *plock)
static PyObject *
faulthandler_fatal_error_c_thread(PyObject *self, PyObject *args)
{
- long thread;
+ long tid;
PyThread_type_lock lock;
faulthandler_suppress_crash_report();
@@ -1104,8 +1049,8 @@ faulthandler_fatal_error_c_thread(PyObject *self, PyObject *args)
PyThread_acquire_lock(lock, WAIT_LOCK);
- thread = PyThread_start_new_thread(faulthandler_fatal_error_thread, lock);
- if (thread == -1) {
+ tid = PyThread_start_new_thread(faulthandler_fatal_error_thread, lock);
+ if (tid == -1) {
PyThread_free_lock(lock);
PyErr_SetString(PyExc_RuntimeError, "unable to start the thread");
return NULL;
@@ -1251,7 +1196,7 @@ static PyMethodDef module_methods[] = {
"if all_threads is True, into file")},
{"dump_traceback_later",
_PyCFunction_CAST(faulthandler_dump_traceback_later), METH_VARARGS|METH_KEYWORDS,
- PyDoc_STR("dump_traceback_later(timeout, repeat=False, file=sys.stderrn, exit=False):\n"
+ PyDoc_STR("dump_traceback_later(timeout, repeat=False, file=sys.stderr, exit=False):\n"
"dump the traceback of all threads in timeout seconds,\n"
"or each timeout seconds if repeat is True. If exit is True, "
"call _exit(1) which is not safe.")},
@@ -1327,6 +1272,8 @@ PyExec_faulthandler(PyObject *module) {
static PyModuleDef_Slot faulthandler_slots[] = {
{Py_mod_exec, PyExec_faulthandler},
+ // XXX gh-103092: fix isolation.
+ //{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};
@@ -1348,13 +1295,13 @@ PyInit_faulthandler(void)
static int
faulthandler_init_enable(void)
{
- PyObject *module = PyImport_ImportModule("faulthandler");
- if (module == NULL) {
+ PyObject *enable = _PyImport_GetModuleAttrString("faulthandler", "enable");
+ if (enable == NULL) {
return -1;
}
- PyObject *res = PyObject_CallMethodNoArgs(module, &_Py_ID(enable));
- Py_DECREF(module);
+ PyObject *res = PyObject_CallNoArgs(enable);
+ Py_DECREF(enable);
if (res == NULL) {
return -1;
}