diff options
author | Christophe Zeitouny <tich@users.noreply.github.com> | 2017-03-23 17:14:29 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-03-23 17:14:29 (GMT) |
commit | 20fbf8accd494fd15b0fc4c84928178c71ead4d1 (patch) | |
tree | 2253e52eac35b134a555813ce61b08df9ff10e8e /Modules | |
parent | 0b3ec192259a65971001ce8f0de85a9c1e71d9c7 (diff) | |
download | cpython-20fbf8accd494fd15b0fc4c84928178c71ead4d1.zip cpython-20fbf8accd494fd15b0fc4c84928178c71ead4d1.tar.gz cpython-20fbf8accd494fd15b0fc4c84928178c71ead4d1.tar.bz2 |
faulthandler: Restore the old sigaltstack during teardown (#777)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/faulthandler.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index 4a03eaf..fc9490d 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -124,6 +124,7 @@ static const size_t faulthandler_nsignals = \ #ifdef HAVE_SIGALTSTACK static stack_t stack; +static stack_t old_stack; #endif @@ -1317,7 +1318,7 @@ int _PyFaulthandler_Init(void) stack.ss_size = SIGSTKSZ; stack.ss_sp = PyMem_Malloc(stack.ss_size); if (stack.ss_sp != NULL) { - err = sigaltstack(&stack, NULL); + err = sigaltstack(&stack, &old_stack); if (err) { PyMem_Free(stack.ss_sp); stack.ss_sp = NULL; @@ -1373,6 +1374,20 @@ void _PyFaulthandler_Fini(void) faulthandler_disable(); #ifdef HAVE_SIGALTSTACK if (stack.ss_sp != NULL) { + /* Fetch the current alt stack */ + stack_t current_stack; + if (sigaltstack(NULL, ¤t_stack) == 0) { + if (current_stack.ss_sp == stack.ss_sp) { + /* The current alt stack is the one that we installed. + It is safe to restore the old stack that we found when + we installed ours */ + sigaltstack(&old_stack, NULL); + } else { + /* Someone switched to a different alt stack and didn't + restore ours when they were done (if they're done). + There's not much we can do in this unlikely case */ + } + } PyMem_Free(stack.ss_sp); stack.ss_sp = NULL; } |