Skip to content

bpo-43390: Set SA_ONSTACK in PyOS_setsig #24730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CPython now sets the ``SA_ONSTACK`` flag in ``PyOS_setsig`` for the VM's
default signal handlers. This is friendlier to other in-process code that
an extension module or embedding use could pull in (such as Golang's cgo)
where tiny thread stacks are the norm and ``sigaltstack()`` has been used to
provide for signal handlers. This is a no-op change for the vast majority
of processes that don't use sigaltstack.
5 changes: 4 additions & 1 deletion Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -2884,7 +2884,10 @@ PyOS_setsig(int sig, PyOS_sighandler_t handler)
struct sigaction context, ocontext;
context.sa_handler = handler;
sigemptyset(&context.sa_mask);
context.sa_flags = 0;
/* Using SA_ONSTACK is friendlier to other C/C++/Golang-VM code that
* extension module or embedding code may use where tiny thread stacks
* are used. https://bugs.python.org/issue43390 */
context.sa_flags = SA_ONSTACK;
if (sigaction(sig, &context, &ocontext) == -1)
return SIG_ERR;
return ocontext.sa_handler;
Expand Down