Skip to content

Commit 02ac6f4

Browse files
authored
bpo-43390: Set SA_ONSTACK in PyOS_setsig (GH-24730)
This is friendlier to other in-process code that an extension module or embedding use could pull in such as CGo where tiny stacks are the norm and sigaltstack() has been used to provide for signal handlers. Without this, signals received by a process using tiny stacks may lead to stack overflow crashes.
1 parent 2122e48 commit 02ac6f4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CPython now sets the ``SA_ONSTACK`` flag in ``PyOS_setsig`` for the VM's
2+
default signal handlers. This is friendlier to other in-process code that
3+
an extension module or embedding use could pull in (such as Golang's cgo)
4+
where tiny thread stacks are the norm and ``sigaltstack()`` has been used to
5+
provide for signal handlers. This is a no-op change for the vast majority
6+
of processes that don't use sigaltstack.

Python/pylifecycle.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2884,7 +2884,10 @@ PyOS_setsig(int sig, PyOS_sighandler_t handler)
28842884
struct sigaction context, ocontext;
28852885
context.sa_handler = handler;
28862886
sigemptyset(&context.sa_mask);
2887-
context.sa_flags = 0;
2887+
/* Using SA_ONSTACK is friendlier to other C/C++/Golang-VM code that
2888+
* extension module or embedding code may use where tiny thread stacks
2889+
* are used. https://bugs.python.org/issue43390 */
2890+
context.sa_flags = SA_ONSTACK;
28882891
if (sigaction(sig, &context, &ocontext) == -1)
28892892
return SIG_ERR;
28902893
return ocontext.sa_handler;

0 commit comments

Comments
 (0)