File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed
Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -1716,6 +1716,7 @@ Artur Zaprzala
17161716Mike Zarnstorff
17171717Yury V. Zaytsev
17181718Siebren van der Zee
1719+ Christophe Zeitouny
17191720Nickolai Zeldovich
17201721Yuxiao Zeng
17211722Uwe Zessin
Original file line number Diff line number Diff line change @@ -287,6 +287,9 @@ Extension Modules
287287Library
288288-------
289289
290+ - bpo-29884: faulthandler: Restore the old sigaltstack during teardown.
291+ Patch by Christophe Zeitouny.
292+
290293- bpo-25455: Fixed crashes in repr of recursive buffered file-like objects.
291294
292295- bpo-29800: Fix crashes in partial.__repr__ if the keys of partial.keywords
Original file line number Diff line number Diff line change @@ -124,6 +124,7 @@ static const size_t faulthandler_nsignals = \
124124
125125#ifdef HAVE_SIGALTSTACK
126126static stack_t stack ;
127+ static stack_t old_stack ;
127128#endif
128129
129130
@@ -1317,7 +1318,7 @@ int _PyFaulthandler_Init(void)
13171318 stack .ss_size = SIGSTKSZ ;
13181319 stack .ss_sp = PyMem_Malloc (stack .ss_size );
13191320 if (stack .ss_sp != NULL ) {
1320- err = sigaltstack (& stack , NULL );
1321+ err = sigaltstack (& stack , & old_stack );
13211322 if (err ) {
13221323 PyMem_Free (stack .ss_sp );
13231324 stack .ss_sp = NULL ;
@@ -1373,6 +1374,20 @@ void _PyFaulthandler_Fini(void)
13731374 faulthandler_disable ();
13741375#ifdef HAVE_SIGALTSTACK
13751376 if (stack .ss_sp != NULL ) {
1377+ /* Fetch the current alt stack */
1378+ stack_t current_stack ;
1379+ if (sigaltstack (NULL , & current_stack ) == 0 ) {
1380+ if (current_stack .ss_sp == stack .ss_sp ) {
1381+ /* The current alt stack is the one that we installed.
1382+ It is safe to restore the old stack that we found when
1383+ we installed ours */
1384+ sigaltstack (& old_stack , NULL );
1385+ } else {
1386+ /* Someone switched to a different alt stack and didn't
1387+ restore ours when they were done (if they're done).
1388+ There's not much we can do in this unlikely case */
1389+ }
1390+ }
13761391 PyMem_Free (stack .ss_sp );
13771392 stack .ss_sp = NULL ;
13781393 }
You can’t perform that action at this time.
0 commit comments