configury: move autoconf macros to build-aux subdirectory.
[m4/ericb.git] / build-aux / m4 / stackovf.m4
blobd18122301cbdb1fe6c38077a9f8e471bab6d5a8e
1 #                                                            -*- Autoconf -*-
2 # stackovf.m4 -- how do we deal with stack overflow?
4 # Copyright (C) 2000, 2003, 2006-2007, 2010, 2013 Free Software
5 # Foundation, Inc.
7 # This file is part of GNU M4.
9 # GNU M4 is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # GNU M4 is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 # serial 7
24 # M4_SYS_STACKOVF
25 # ---------------
26 AC_DEFUN([M4_SYS_STACKOVF],
27 [AC_PREREQ([2.60])dnl We use the _ONCE variants
28 AC_REQUIRE([AC_TYPE_SIGNAL])dnl
30 AC_CHECK_HEADERS_ONCE([siginfo.h])
31 AC_CHECK_FUNCS_ONCE([sigaction sigaltstack sigstack sigvec])
32 AC_CHECK_MEMBERS([stack_t.ss_sp], [], [],
33 [[#include <signal.h>
34 #if HAVE_SIGINFO_H
35 # include <siginfo.h>
36 #endif
37 ]])
39 # Code from Jim Avera <jima@netcom.com>.
40 # stackovf.c requires:
41 #  1. Either sigaction with SA_ONSTACK, or sigvec with SV_ONSTACK
42 #  2. Either sigaltstack or sigstack
43 #  3. getrlimit, including support for RLIMIT_STACK
44 AC_CACHE_CHECK([if stack overflow is detectable], [M4_cv_use_stackovf],
45 [M4_cv_use_stackovf=no
46 if test "$ac_cv_func_sigaction" = yes || test "$ac_cv_func_sigvec" = yes; then
47   if test "$ac_cv_func_sigaltstack" = yes || test "$ac_cv_func_sigstack" = yes; then
48     AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/time.h>
49 #include <sys/resource.h>
50 #include <signal.h>
51 ]], [[struct rlimit r; getrlimit (RLIMIT_STACK, &r);
52 #if (!defined HAVE_SIGACTION || !defined SA_ONSTACK) \
53     && (!defined HAVE_SIGVEC || !defined SV_ONSTACK)
54 choke me /* SA_ONSTACK and/or SV_ONSTACK are not defined */
55 #endif
56 ]])], [M4_cv_use_stackovf=yes])
57   fi
58 fi])
60 AM_CONDITIONAL([STACKOVF], [test "$M4_cv_use_stackovf" = yes])
61 if test "$M4_cv_use_stackovf" = yes; then
62   AC_DEFINE([USE_STACKOVF], [1],
63     [Define to 1 if using stack overflow detection.])
64   AC_CHECK_TYPES([rlim_t], [],
65     [AC_DEFINE([rlim_t], [int],
66       [Define to int if rlim_t is not defined in sys/resource.h])],
67     [[#include <sys/resource.h>
68 ]])
69   AC_CHECK_TYPES([stack_t], [],
70     [AC_DEFINE([stack_t], [struct sigaltstack],
71       [Define to struct sigaltstack if stack_t is not in signal.h])],
72     [[#include <signal.h>
73 ]])
74   AC_CHECK_TYPES([sigcontext], [], [], [[#include <signal.h>
75 ]])
76   AC_CHECK_TYPES([siginfo_t], [], [], [[#include <signal.h>
77 #if HAVE_SIGINFO_H
78 # include <siginfo.h>
79 #endif
80 ]])
81   AC_CHECK_MEMBERS([struct sigaction.sa_sigaction], [], [],
82 [[#include <signal.h>
83 ]])
85   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <signal.h>
86 ]],
87             [[struct sigaltstack x; x.ss_base = 0;]])],
88             [AC_DEFINE([ss_sp], [ss_base],
89             [Define to ss_base if stack_t has ss_base instead of ss_sp.])])
91 ])# M4_SYS_STACKOVF