From: Paul Eggert Date: Mon, 20 Jun 2011 21:59:13 +0000 (-0700) Subject: c-stack: stop worrying about stack direction X-Git-Tag: v0.1~2223 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=3c4ad6125cf33faf3cc090b4232d35f3866b9799;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 1758d670f..d59548993 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-06-20 Paul Eggert + + 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 test-stat: don't allocate PATH_MAX bytes diff --git a/lib/c-stack.c b/lib/c-stack.c index 7f0f48845..e48b97c3b 100644 --- a/lib/c-stack.c +++ b/lib/c-stack.c @@ -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 diff --git a/m4/c-stack.m4 b/m4/c-stack.m4 index d613fa8bd..8d34048e4 100644 --- a/m4/c-stack.m4 +++ b/m4/c-stack.m4 @@ -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])