]> Savannah Git Hosting - gnulib.git/commitdiff
c-stack: stop using SIGSTKSZ
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 30 Sep 2020 20:50:36 +0000 (13:50 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 3 Oct 2020 20:02:40 +0000 (13:02 -0700)
It’s been proposed to stop making SIGSTKSZ an integer constant:
https://sourceware.org/pipermail/libc-alpha/2020-September/118028.html
Also, using SIGSTKSZ in #if did not conform to current POSIX.
Also, avoiding SIGSTKSZ makes the code simpler and easier to grok.
* lib/c-stack.c (SIGSTKSZ): Remove.
(alternate_signal_stack): Now a 64 KiB array, for simplicity.
All uses changed.

ChangeLog
lib/c-stack.c
lib/c-stack.h

index 76a76fbc46001babd8edabbd7be9c5c443750d4b..7f54b7860cdb69cf0acc57bddd9f770ba62d1e5b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2020-10-03  Paul Eggert  <eggert@cs.ucla.edu>
 
+       c-stack: stop using SIGSTKSZ
+       It’s been proposed to stop making SIGSTKSZ an integer constant:
+       https://sourceware.org/pipermail/libc-alpha/2020-September/118028.html
+       Also, using SIGSTKSZ in #if did not conform to current POSIX.
+       Also, avoiding SIGSTKSZ makes the code simpler and easier to grok.
+       * lib/c-stack.c (SIGSTKSZ): Remove.
+       (alternate_signal_stack): Now a 64 KiB array, for simplicity.
+       All uses changed.
+
        c-stack: fix libsigsegv typo
        Problem reported by Bruno Haible in:
        https://lists.gnu.org/r/bug-gnulib/2020-09/msg00175.html
index 80ebcbf00fb3b54ad1a0be9e6507e4bdc13d9bd2..cf0fe8da0e081fb03e2c7bd35bca5585a4ad7ec8 100644 (file)
@@ -70,15 +70,6 @@ typedef struct sigaltstack stack_t;
 
 #if USE_LIBSIGSEGV
 # include <sigsegv.h>
-/* libsigsegv 2.6 through 2.8 have a bug where some architectures use
-   more than the Linux default of an 8k alternate stack when deciding
-   if a fault was caused by stack overflow.  */
-# if LIBSIGSEGV_VERSION <= 0x0208 && SIGSTKSZ < 16384
-#  undef SIGSTKSZ
-# endif
-#endif
-#ifndef SIGSTKSZ
-# define SIGSTKSZ 16384
 #endif
 
 #include "exitfail.h"
@@ -95,6 +86,16 @@ typedef struct sigaltstack stack_t;
 # endif
 #endif
 
+/* Storage for the alternate signal stack.
+   64 KiB is not too large for Gnulib-using apps, and is large enough
+   for all known platforms.  Smaller sizes may run into trouble.
+   For example, libsigsegv 2.6 through 2.8 have a bug where some
+   architectures use more than the Linux default of an 8 KiB alternate
+   stack when deciding if a fault was caused by stack overflow.  */
+static max_align_t alternate_signal_stack[(64 * 1024
+                                           + sizeof (max_align_t) - 1)
+                                          / sizeof (max_align_t)];
+
 /* The user-specified action to take when a SEGV-related program error
    or stack overflow occurs.  */
 static _GL_ASYNC_SAFE void (* volatile segv_action) (int);
@@ -133,7 +134,7 @@ die (int signo)
   size_t prognamelen = strlen (progname);
   size_t messagelen = strlen (message);
   static char const separator[] = {':', ' '};
-  char buf[SIGSTKSZ / 16 + sizeof separator];
+  char buf[sizeof alternate_signal_stack / 16 + sizeof separator];
   ptrdiff_t buflen;
   if (prognamelen + messagelen < sizeof buf - sizeof separator)
     {
@@ -159,13 +160,6 @@ die (int signo)
   abort ();
 }
 
-/* Storage for the alternate signal stack.  */
-static union
-{
-  char buffer[SIGSTKSZ];
-  max_align_t align;
-} alternate_signal_stack;
-
 static _GL_ASYNC_SAFE void
 null_action (int signo _GL_UNUSED)
 {
@@ -230,8 +224,8 @@ c_stack_action (_GL_ASYNC_SAFE void (*action) (int))
 
   /* Always install the overflow handler.  */
   if (stackoverflow_install_handler (overflow_handler,
-                                     alternate_signal_stack.buffer,
-                                     sizeof alternate_signal_stack.buffer))
+                                     alternate_signal_stack,
+                                     sizeof alternate_signal_stack))
     {
       errno = ENOTSUP;
       return -1;
@@ -323,14 +317,14 @@ c_stack_action (_GL_ASYNC_SAFE void (*action) (int))
 {
   stack_t st;
   st.ss_flags = 0;
+  st.ss_sp = alternate_signal_stack;
+  st.ss_size = sizeof alternate_signal_stack;
 # if SIGALTSTACK_SS_REVERSED
   /* Irix mistakenly treats ss_sp as the upper bound, rather than
      lower bound, of the alternate stack.  */
-  st.ss_sp = alternate_signal_stack.buffer + SIGSTKSZ - sizeof (void *);
-  st.ss_size = sizeof alternate_signal_stack.buffer - sizeof (void *);
-# else
-  st.ss_sp = alternate_signal_stack.buffer;
-  st.ss_size = sizeof alternate_signal_stack.buffer;
+  st.ss_size -= sizeof (void *);
+  char *ss_sp = st.ss_sp;
+  st.ss_sp = ss_sp + st.ss_size;
 # endif
   int r = sigaltstack (&st, NULL);
   if (r != 0)
index a11fa3123e619bf15019aaf7b344b2b19dc1d0b6..a119ef29e3385ced1a78912dc267b5df9d01dc4c 100644 (file)
@@ -34,7 +34,7 @@
    A null ACTION acts like an action that does nothing.
 
    ACTION must be async-signal-safe.  ACTION together with its callees
-   must not require more than SIGSTKSZ bytes of stack space.  Also,
+   must not require more than 64 KiB of stack space.  Also,
    ACTION should not call longjmp, because this implementation does
    not guarantee that it is safe to return to the original stack.