bpo-21131: Fix faulthandler.register(chain=True) stack (GH-15276) · python/cpython@b8e6824 (original) (raw)

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1 +Fix ``faulthandler.register(chain=True)`` stack. faulthandler now allocates a
2 +dedicated stack of ``SIGSTKSZ*2`` bytes, instead of just ``SIGSTKSZ`` bytes.
3 +Calling the previous signal handler in faulthandler signal handler uses more
4 +than ``SIGSTKSZ`` bytes of stack memory on some platforms.
Original file line number Diff line number Diff line change
@@ -1325,7 +1325,11 @@ _PyFaulthandler_Init(int enable)
1325 1325 * be able to allocate memory on the stack, even on a stack overflow. If it
1326 1326 * fails, ignore the error. */
1327 1327 stack.ss_flags = 0;
1328 -stack.ss_size = SIGSTKSZ;
1328 +/* bpo-21131: allocate dedicated stack of SIGSTKSZ*2 bytes, instead of just
1329 + SIGSTKSZ bytes. Calling the previous signal handler in faulthandler
1330 + signal handler uses more than SIGSTKSZ bytes of stack memory on some
1331 + platforms. */
1332 +stack.ss_size = SIGSTKSZ * 2;
1329 1333 stack.ss_sp = PyMem_Malloc(stack.ss_size);
1330 1334 if (stack.ss_sp != NULL) {
1331 1335 err = sigaltstack(&stack, &old_stack);