From 67461c3ae4e118020b974b6632156494a9a7ce40 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 6 Dec 2008 15:01:09 +0100 Subject: [PATCH] Treat SIGBUS like SIFSEGV on platforms that need it. --- ChangeLog | 10 ++++++++++ lib/c-stack.c | 4 ++++ m4/c-stack.m4 | 29 ++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 26a393a4f..d37da3ba8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2008-12-06 Bruno Haible + Fix a c-stack test failure on MacOS X. + * m4/c-stack.m4 (AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC): Require + AC_CANONICAL_HOST. Define FAULT_YIELDS_SIGBUS. If set, install a signal + handler for SIGBUS as well. + * lib/c-stack.c (c_stack_action): If FAULT_YIELDS_SIGBUS is set, + install a signal handler for SIGBUS as well. + Reported by Bruce Dugan via Eric Blake. + +2008-12-06 Bruno Haible + Advocacy documentation. * doc/gnulib-intro.texi (Benefits): New section. * doc/gnulib.texi: Update. diff --git a/lib/c-stack.c b/lib/c-stack.c index 11cb9efc6..ae300af0f 100644 --- a/lib/c-stack.c +++ b/lib/c-stack.c @@ -321,6 +321,10 @@ c_stack_action (void (*action) (int)) act.sa_handler = die; # endif +# if FAULT_YIELDS_SIGBUS + if (sigaction (SIGBUS, &act, NULL) < 0) + return -1; +# endif return sigaction (SIGSEGV, &act, NULL); } diff --git a/m4/c-stack.m4 b/m4/c-stack.m4 index 50693331a..efd6798a8 100644 --- a/m4/c-stack.m4 +++ b/m4/c-stack.m4 @@ -7,14 +7,33 @@ # Written by Paul Eggert. -# serial 7 +# serial 8 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]) + dnl List of signals that are sent when an invalid virtual memory address + dnl is accessed, or when the stack overflows. + dnl Either { SIGSEGV } or { SIGSEGV, SIGBUS }. + case "$host_os" in + sunos4* | freebsd* | dragonfly* | openbsd* | netbsd* | kfreebsd* | knetbsd*) # BSD systems + FAULT_YIELDS_SIGBUS=1 ;; + hpux*) # HP-UX + FAULT_YIELDS_SIGBUS=1 ;; + macos* | darwin*) # MacOS X + FAULT_YIELDS_SIGBUS=1 ;; + gnu*) # Hurd + FAULT_YIELDS_SIGBUS=1 ;; + *) + FAULT_YIELDS_SIGBUS=0 ;; + esac + AC_DEFINE_UNQUOTED([FAULT_YIELDS_SIGBUS], [$FAULT_YIELDS_SIGBUS], + [Define to 1 if an invalid memory address access may yield a SIGBUS.]) + AC_CACHE_CHECK([for working C stack overflow detection], [ac_cv_sys_stack_overflow_works], [AC_TRY_RUN( @@ -62,6 +81,10 @@ AC_DEFUN([AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC], sigemptyset (&act.sa_mask); act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND; act.sa_handler = segv_handler; + #if FAULT_YIELDS_SIGBUS + if (sigaction (SIGBUS, &act, 0) < 0) + return -1; + #endif return sigaction (SIGSEGV, &act, 0); } static volatile int * @@ -244,6 +267,10 @@ int main () sigemptyset (&act.sa_mask); act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND | SA_SIGINFO; act.sa_sigaction = segv_handler; + #if FAULT_YIELDS_SIGBUS + if (sigaction (SIGBUS, &act, 0) < 0) + return -1; + #endif return sigaction (SIGSEGV, &act, 0); } static volatile int * -- 2.11.0