Library
-------
+- bpo-29884: faulthandler: Restore the old sigaltstack during teardown.
+ Patch by Christophe Zeitouny.
+
- bpo-25455: Fixed crashes in repr of recursive buffered file-like objects.
- bpo-29800: Fix crashes in partial.__repr__ if the keys of partial.keywords
#ifdef HAVE_SIGALTSTACK
static stack_t stack;
+static stack_t old_stack;
#endif
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;
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;
}