0001-c-stack-stop-using-SIGSTKSZ.patch 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. From 87b3a8f9ceb2cf0a5c8b72e460465fb9ff2d62d9 Mon Sep 17 00:00:00 2001
  2. From: Khem Raj <raj.khem@gmail.com>
  3. Date: Fri, 30 Apr 2021 17:40:36 -0700
  4. Subject: [PATCH] c-stack: stop using SIGSTKSZ
  5. This patch is required with glibc 2.34+
  6. based on gnulib [1]
  7. [1] https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=f9e2b20a12a230efa30f1d479563ae07d276a94b
  8. Upstream-Status: Pending
  9. Signed-off-by: Khem Raj <raj.khem@gmail.com>
  10. ---
  11. lib/c-stack.c | 22 +++++++++++++---------
  12. 1 file changed, 13 insertions(+), 9 deletions(-)
  13. diff --git a/lib/c-stack.c b/lib/c-stack.c
  14. index 9bbe6fe..e0874c9 100644
  15. --- a/lib/c-stack.c
  16. +++ b/lib/c-stack.c
  17. @@ -51,13 +51,14 @@
  18. typedef struct sigaltstack stack_t;
  19. #endif
  20. #ifndef SIGSTKSZ
  21. -# define SIGSTKSZ 16384
  22. -#elif HAVE_LIBSIGSEGV && SIGSTKSZ < 16384
  23. +#define get_sigstksz() (16384)
  24. +#elif HAVE_LIBSIGSEGV
  25. /* libsigsegv 2.6 through 2.8 have a bug where some architectures use
  26. more than the Linux default of an 8k alternate stack when deciding
  27. if a fault was caused by stack overflow. */
  28. -# undef SIGSTKSZ
  29. -# define SIGSTKSZ 16384
  30. +#define get_sigstksz() ((SIGSTKSZ) < 16384 ? 16384 : (SIGSTKSZ))
  31. +#else
  32. +#define get_sigstksz() ((SIGSTKSZ))
  33. #endif
  34. #include <stdlib.h>
  35. @@ -136,7 +137,8 @@ die (int signo)
  36. /* Storage for the alternate signal stack. */
  37. static union
  38. {
  39. - char buffer[SIGSTKSZ];
  40. + /* allocate buffer with size from get_sigstksz() */
  41. + char *buffer;
  42. /* These other members are for proper alignment. There's no
  43. standard way to guarantee stack alignment, but this seems enough
  44. @@ -208,10 +210,11 @@ c_stack_action (void (*action) (int))
  45. program_error_message = _("program error");
  46. stack_overflow_message = _("stack overflow");
  47. + alternate_signal_stack.buffer = malloc(get_sigstksz());
  48. /* Always install the overflow handler. */
  49. if (stackoverflow_install_handler (overflow_handler,
  50. alternate_signal_stack.buffer,
  51. - sizeof alternate_signal_stack.buffer))
  52. + get_sigstksz()))
  53. {
  54. errno = ENOTSUP;
  55. return -1;
  56. @@ -284,14 +287,15 @@ c_stack_action (void (*action) (int))
  57. stack_t st;
  58. struct sigaction act;
  59. st.ss_flags = 0;
  60. + alternate_signal_stack.buffer = malloc(get_sigstksz());
  61. # if SIGALTSTACK_SS_REVERSED
  62. /* Irix mistakenly treats ss_sp as the upper bound, rather than
  63. lower bound, of the alternate stack. */
  64. - st.ss_sp = alternate_signal_stack.buffer + SIGSTKSZ - sizeof (void *);
  65. - st.ss_size = sizeof alternate_signal_stack.buffer - sizeof (void *);
  66. + st.ss_sp = alternate_signal_stack.buffer + get_sigstksz() - sizeof (void *);
  67. + st.ss_size = get_sigstksz() - sizeof (void *);
  68. # else
  69. st.ss_sp = alternate_signal_stack.buffer;
  70. - st.ss_size = sizeof alternate_signal_stack.buffer;
  71. + st.ss_size = get_sigstksz();
  72. # endif
  73. r = sigaltstack (&st, NULL);
  74. if (r != 0)
  75. --
  76. 2.31.1