1 # sigaltstack.m4 serial 7 (libsigsegv-2.5)
2 dnl Copyright (C) 2002-2006 Bruno Haible <bruno@clisp.org>
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
9 AC_DEFUN([SV_SIGALTSTACK],
11 AC_REQUIRE([AC_PROG_CC])
12 AC_REQUIRE([AC_CANONICAL_HOST])
14 AC_CHECK_FUNCS(sigaltstack)
16 if test "$ac_cv_func_sigaltstack" = yes; then
17 AC_CHECK_TYPE(stack_t, ,
18 [AC_DEFINE(stack_t, [struct sigaltstack],
19 [Define to 'struct sigaltstack' if that's the type of the argument to sigaltstack])
24 # include <sys/signal.h>
29 AC_CACHE_CHECK([for working sigaltstack], sv_cv_sigaltstack, [
30 if test "$ac_cv_func_sigaltstack" = yes; then
32 macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*)
33 # On MacOS X 10.2 or newer, just assume that if it compiles, it will
34 # work. If we were to perform the real test, 1 Crash Report dialog
35 # window would pop up.
37 AC_LANG_PROGRAM([[#include <signal.h>]],
38 [[int x = SA_ONSTACK; stack_t ss; sigaltstack ((stack_t*)0, &ss);]])],
39 [sv_cv_sigaltstack="guessing yes"],
40 [sv_cv_sigaltstack=no])
48 # include <sys/signal.h>
51 # include <sys/types.h>
52 # include <sys/time.h>
53 # include <sys/resource.h>
56 # define SIGSTKSZ 16384
58 void stackoverflow_handler (int sig)
60 /* If we get here, the stack overflow was caught. */
63 volatile int * recurse_1 (volatile int n, volatile int *p)
66 *recurse_1 (n + 1, p) += n;
69 volatile int recurse (volatile int n)
72 return *recurse_1 (n, &sum);
76 char mystack[SIGSTKSZ];
78 struct sigaction action;
79 #if defined HAVE_SETRLIMIT && defined RLIMIT_STACK
80 /* Before starting the endless recursion, try to be friendly to the user's
81 machine. On some Linux 2.2.x systems, there is no stack limit for user
82 processes at all. We don't want to kill such systems. */
84 rl.rlim_cur = rl.rlim_max = 0x100000; /* 1 MB */
85 setrlimit (RLIMIT_STACK, &rl);
87 /* Install the alternate stack. */
88 altstack.ss_sp = mystack;
89 altstack.ss_size = sizeof (mystack);
90 altstack.ss_flags = 0; /* no SS_DISABLE */
91 if (sigaltstack (&altstack, NULL) < 0)
93 /* Install the SIGSEGV handler. */
94 sigemptyset (&action.sa_mask);
95 action.sa_handler = &stackoverflow_handler;
96 action.sa_flags = SA_ONSTACK;
97 sigaction (SIGSEGV, &action, (struct sigaction *) NULL);
98 sigaction (SIGBUS, &action, (struct sigaction *) NULL);
99 /* Provoke a stack overflow. */
103 [sv_cv_sigaltstack=yes],
104 [sv_cv_sigaltstack=no],
106 dnl FIXME: Put in some more known values here.
110 AC_LANG_PROGRAM([[#include <signal.h>]],
111 [[int x = SA_ONSTACK; stack_t ss; sigaltstack ((stack_t*)0, &ss);]])],
112 [sv_cv_sigaltstack="guessing yes"],
113 [sv_cv_sigaltstack=no])
123 if test "$sv_cv_sigaltstack" != no; then
124 AC_DEFINE(HAVE_WORKING_SIGALTSTACK, 1,
125 [Define if you have the sigaltstack() function and it works.])