File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1679,6 +1679,7 @@ Artur Zaprzala
16791679Mike Zarnstorff
16801680Yury V. Zaytsev
16811681Siebren van der Zee
1682+ Christophe Zeitouny
16821683Nickolai Zeldovich
16831684Yuxiao Zeng
16841685Uwe Zessin
Original file line number Diff line number Diff line change @@ -46,6 +46,9 @@ Extension Modules
4646Library
4747-------
4848
49+ - bpo-29884: faulthandler: Restore the old sigaltstack during teardown.
50+ Patch by Christophe Zeitouny.
51+
4952- bpo-25455: Fixed crashes in repr of recursive buffered file-like objects.
5053
5154- 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 unsigned char faulthandler_nsignals = \
124124
125125#ifdef HAVE_SIGALTSTACK
126126static stack_t stack ;
127+ static stack_t old_stack ;
127128#endif
128129
129130
@@ -1148,7 +1149,7 @@ int _PyFaulthandler_Init(void)
11481149 stack .ss_size = SIGSTKSZ ;
11491150 stack .ss_sp = PyMem_Malloc (stack .ss_size );
11501151 if (stack .ss_sp != NULL ) {
1151- err = sigaltstack (& stack , NULL );
1152+ err = sigaltstack (& stack , & old_stack );
11521153 if (err ) {
11531154 PyMem_Free (stack .ss_sp );
11541155 stack .ss_sp = NULL ;
@@ -1204,6 +1205,20 @@ void _PyFaulthandler_Fini(void)
12041205 faulthandler_disable ();
12051206#ifdef HAVE_SIGALTSTACK
12061207 if (stack .ss_sp != NULL ) {
1208+ /* Fetch the current alt stack */
1209+ stack_t current_stack ;
1210+ if (sigaltstack (NULL , & current_stack ) == 0 ) {
1211+ if (current_stack .ss_sp == stack .ss_sp ) {
1212+ /* The current alt stack is the one that we installed.
1213+ It is safe to restore the old stack that we found when
1214+ we installed ours */
1215+ sigaltstack (& old_stack , NULL );
1216+ } else {
1217+ /* Someone switched to a different alt stack and didn't
1218+ restore ours when they were done (if they're done).
1219+ There's not much we can do in this unlikely case */
1220+ }
1221+ }
12071222 PyMem_Free (stack .ss_sp );
12081223 stack .ss_sp = NULL ;
12091224 }
You can’t perform that action at this time.
0 commit comments