|
15 | 15 | # include <sys/resource.h> |
16 | 16 | #endif |
17 | 17 |
|
| 18 | +/* Using an alternative stack requires sigaltstack() |
| 19 | + and sigaction() SA_ONSTACK */ |
| 20 | +#if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION) |
| 21 | +# define FAULTHANDLER_USE_ALT_STACK |
| 22 | +#endif |
| 23 | + |
| 24 | +#if defined(FAULTHANDLER_USE_ALT_STACK) && defined(HAVE_LINUX_AUXVEC_H) |
| 25 | +# include <linux/auxvec.h> |
| 26 | +# include <sys/auxv.h> |
| 27 | +#endif |
| 28 | + |
18 | 29 | /* Allocate at maximum 100 MiB of the stack to raise the stack overflow */ |
19 | 30 | #define STACK_OVERFLOW_MAX_SIZE (100 * 1024 * 1024) |
20 | 31 |
|
@@ -137,12 +148,6 @@ static fault_handler_t faulthandler_handlers[] = { |
137 | 148 | static const size_t faulthandler_nsignals = \ |
138 | 149 | Py_ARRAY_LENGTH(faulthandler_handlers); |
139 | 150 |
|
140 | | -/* Using an alternative stack requires sigaltstack() |
141 | | - and sigaction() SA_ONSTACK */ |
142 | | -#if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION) |
143 | | -# define FAULTHANDLER_USE_ALT_STACK |
144 | | -#endif |
145 | | - |
146 | 151 | #ifdef FAULTHANDLER_USE_ALT_STACK |
147 | 152 | static stack_t stack; |
148 | 153 | static stack_t old_stack; |
@@ -1395,6 +1400,15 @@ _PyFaulthandler_Init(int enable) |
1395 | 1400 | signal handler uses more than SIGSTKSZ bytes of stack memory on some |
1396 | 1401 | platforms. */ |
1397 | 1402 | stack.ss_size = SIGSTKSZ * 2; |
| 1403 | +#ifdef AT_MINSIGSTKSZ |
| 1404 | + /* bpo-46968: Query Linux for minimal stack size to ensure signal delivery |
| 1405 | + for the hardware running CPython. This OS feature is available in |
| 1406 | + Linux kernel version >= 5.14 */ |
| 1407 | + unsigned long at_minstack_size = getauxval(AT_MINSIGSTKSZ); |
| 1408 | + if (at_minstack_size != 0) { |
| 1409 | + stack.ss_size = SIGSTKSZ + at_minstack_size; |
| 1410 | + } |
| 1411 | +#endif |
1398 | 1412 | #endif |
1399 | 1413 |
|
1400 | 1414 | memset(&thread, 0, sizeof(thread)); |
|
0 commit comments