Skip to content

Commit b8e6824

Browse files
bpo-21131: Fix faulthandler.register(chain=True) stack (GH-15276)
faulthandler now allocates a dedicated stack of SIGSTKSZ*2 bytes, instead of just SIGSTKSZ bytes. Calling the previous signal handler in faulthandler signal handler uses more than SIGSTKSZ bytes of stack memory on some platforms. (cherry picked from commit ac827ed) Co-authored-by: Victor Stinner <[email protected]>
1 parent 123f6c4 commit b8e6824

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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.

Modules/faulthandler.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,11 @@ _PyFaulthandler_Init(int enable)
13251325
* be able to allocate memory on the stack, even on a stack overflow. If it
13261326
* fails, ignore the error. */
13271327
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;
13291333
stack.ss_sp = PyMem_Malloc(stack.ss_size);
13301334
if (stack.ss_sp != NULL) {
13311335
err = sigaltstack(&stack, &old_stack);

0 commit comments

Comments
 (0)