@@ -952,18 +952,15 @@ faulthandler_fatal_error_py(PyObject *self, PyObject *args)
952952}
953953
954954#if defined(HAVE_SIGALTSTACK ) && defined(HAVE_SIGACTION )
955- #ifdef __INTEL_COMPILER
956- /* Issue #23654: Turn off ICC's tail call optimization for the
957- * stack_overflow generator. ICC turns the recursive tail call into
958- * a loop. */
959- # pragma intel optimization_level 0
960- #endif
961955static
962956Py_uintptr_t
963957stack_overflow (Py_uintptr_t min_sp , Py_uintptr_t max_sp , size_t * depth )
964958{
965- /* allocate 4096 bytes on the stack at each call */
966- unsigned char buffer [4096 ];
959+ /* Allocate (at least) 4096 bytes on the stack at each call.
960+
961+ bpo-23654, bpo-38965: use volatile keyword to prevent tail call
962+ optimization. */
963+ volatile unsigned char buffer [4096 ];
967964 Py_uintptr_t sp = (Py_uintptr_t )& buffer ;
968965 * depth += 1 ;
969966 if (sp < min_sp || max_sp < sp )
@@ -1146,7 +1143,11 @@ int _PyFaulthandler_Init(void)
11461143 * be able to allocate memory on the stack, even on a stack overflow. If it
11471144 * fails, ignore the error. */
11481145 stack .ss_flags = 0 ;
1149- stack .ss_size = SIGSTKSZ ;
1146+ /* bpo-21131: allocate dedicated stack of SIGSTKSZ*2 bytes, instead of just
1147+ SIGSTKSZ bytes. Calling the previous signal handler in faulthandler
1148+ signal handler uses more than SIGSTKSZ bytes of stack memory on some
1149+ platforms. */
1150+ stack .ss_size = SIGSTKSZ * 2 ;
11501151 stack .ss_sp = PyMem_Malloc (stack .ss_size );
11511152 if (stack .ss_sp != NULL ) {
11521153 err = sigaltstack (& stack , & old_stack );
0 commit comments