Skip to content

Commit 1581d9c

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 b0b178a commit 1581d9c

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
@@ -1322,7 +1322,11 @@ _PyFaulthandler_Init(int enable)
13221322
* be able to allocate memory on the stack, even on a stack overflow. If it
13231323
* fails, ignore the error. */
13241324
stack.ss_flags = 0;
1325-
stack.ss_size = SIGSTKSZ;
1325+
/* bpo-21131: allocate dedicated stack of SIGSTKSZ*2 bytes, instead of just
1326+
SIGSTKSZ bytes. Calling the previous signal handler in faulthandler
1327+
signal handler uses more than SIGSTKSZ bytes of stack memory on some
1328+
platforms. */
1329+
stack.ss_size = SIGSTKSZ * 2;
13261330
stack.ss_sp = PyMem_Malloc(stack.ss_size);
13271331
if (stack.ss_sp != NULL) {
13281332
err = sigaltstack(&stack, &old_stack);

0 commit comments

Comments
 (0)