2 # stackovf.m4 -- how do we deal with stack overflow?
4 # Copyright (C) 2000, 2003, 2006-2007, 2010, 2013 Free Software
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/>.
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], [], [],
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>
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 */
56 ]])], [M4_cv_use_stackovf=yes])
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>
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])],
74 AC_CHECK_TYPES([sigcontext], [], [], [[#include <signal.h>
76 AC_CHECK_TYPES([siginfo_t], [], [], [[#include <signal.h>
81 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction], [], [],
85 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <signal.h>
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.])])