@@ -952,18 +952,15 @@ faulthandler_fatal_error_py(PyObject *self, PyObject *args)
952
952
}
953
953
954
954
#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
961
955
static
962
956
Py_uintptr_t
963
957
stack_overflow (Py_uintptr_t min_sp , Py_uintptr_t max_sp , size_t * depth )
964
958
{
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 ];
967
964
Py_uintptr_t sp = (Py_uintptr_t )& buffer ;
968
965
* depth += 1 ;
969
966
if (sp < min_sp || max_sp < sp )
@@ -1146,7 +1143,11 @@ int _PyFaulthandler_Init(void)
1146
1143
* be able to allocate memory on the stack, even on a stack overflow. If it
1147
1144
* fails, ignore the error. */
1148
1145
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 ;
1150
1151
stack .ss_sp = PyMem_Malloc (stack .ss_size );
1151
1152
if (stack .ss_sp != NULL ) {
1152
1153
err = sigaltstack (& stack , & old_stack );
0 commit comments