c-stack: stop worrying about stack direction
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 20 Jun 2011 21:59:13 +0000 (14:59 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 20 Jun 2011 22:14:58 +0000 (15:14 -0700)
* lib/c-stack.c (find_stack_direction): Remove.
(segv_handler): Don't worry about stack direction growth, as it's
too much of a pain to configure this correctly, given how compilers
are optimizing-away our stack-growth detection code.  Instead, assume
that any access to just before or just after the stack is OK.
* m4/c-stack.m4 (AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC):
Don't require AC_FUNC_ALLOCA; no longer needed.

ChangeLog
lib/c-stack.c
m4/c-stack.m4

index 1758d67..d595489 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-06-20  Paul Eggert  <eggert@cs.ucla.edu>
+
+       c-stack: stop worrying about stack direction
+       * lib/c-stack.c (find_stack_direction): Remove.
+       (segv_handler): Don't worry about stack direction growth, as it's
+       too much of a pain to configure this correctly, given how compilers
+       are optimizing-away our stack-growth detection code.  Instead, assume
+       that any access to just before or just after the stack is OK.
+       * m4/c-stack.m4 (AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC):
+       Don't require AC_FUNC_ALLOCA; no longer needed.
+
 2011-06-20  Eric Blake  <eblake@redhat.com>
 
        test-stat: don't allocate PATH_MAX bytes
index 7f0f488..e48b97c 100644 (file)
@@ -223,22 +223,6 @@ c_stack_action (void (*action) (int))
 
 #elif HAVE_SIGALTSTACK && HAVE_DECL_SIGALTSTACK && HAVE_STACK_OVERFLOW_HANDLING
 
-/* Direction of the C runtime stack.  This function is
-   async-signal-safe.  */
-
-# if STACK_DIRECTION
-#  define find_stack_direction(ptr) STACK_DIRECTION
-# else
-#  if ! SIGINFO_WORKS || HAVE_XSI_STACK_OVERFLOW_HEURISTIC
-static int
-find_stack_direction (char const *addr)
-{
-  char dummy;
-  return ! addr ? find_stack_direction (&dummy) : addr < &dummy ? 1 : -1;
-}
-#  endif
-# endif
-
 # if SIGINFO_WORKS
 
 /* Handle a segmentation violation and exit.  This function is
@@ -266,17 +250,14 @@ segv_handler (int signo, siginfo_t *info,
   if (0 < info->si_code)
     {
       /* If the faulting address is within the stack, or within one
-         page of the stack end, assume that it is a stack
-         overflow.  */
+         page of the stack, assume that it is a stack overflow.  */
       ucontext_t const *user_context = context;
       char const *stack_base = user_context->uc_stack.ss_sp;
       size_t stack_size = user_context->uc_stack.ss_size;
       char const *faulting_address = info->si_addr;
-      size_t s = faulting_address - stack_base;
       size_t page_size = sysconf (_SC_PAGESIZE);
-      if (find_stack_direction (NULL) < 0)
-        s += page_size;
-      if (s < stack_size + page_size)
+      size_t s = faulting_address - stack_base + page_size;
+      if (s < stack_size + 2 * page_size)
         signo = 0;
 
 #   if DEBUG
index d613fa8..8d34048 100644 (file)
@@ -7,11 +7,10 @@
 
 # Written by Paul Eggert.
 
-# serial 12
+# serial 13
 
 AC_DEFUN([AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC],
-  [# for STACK_DIRECTION
-   AC_REQUIRE([AC_FUNC_ALLOCA])
+  [
    AC_REQUIRE([AC_CANONICAL_HOST])
    AC_CHECK_FUNCS_ONCE([setrlimit])
    AC_CHECK_HEADERS_ONCE([ucontext.h])