Reduce size of configure.ac.
[libsigsegv/ericb.git] / configure.ac
blob30eb84fa2944bc63ca6bb1a94fecb254457299f7
1 dnl Autoconf configuration for libsigsegv.
2 dnl Process this file with autoconf to produce a configure script.
3 dnl
4 dnl Copyright (C) 2002-2009  Bruno Haible <bruno@clisp.org>
5 dnl
6 dnl This program is free software; you can redistribute it and/or modify
7 dnl it under the terms of the GNU General Public License as published by
8 dnl the Free Software Foundation; either version 2, or (at your option)
9 dnl any later version.
10 dnl
11 dnl This program is distributed in the hope that it will be useful,
12 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 dnl GNU General Public License for more details.
15 dnl
16 dnl You should have received a copy of the GNU General Public License
17 dnl along with this program; if not, write to the Free Software Foundation,
18 dnl Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 AC_PREREQ([2.62])
21 AC_INIT
22 AC_CONFIG_SRCDIR([src/sigsegv.h.in])
23 AC_CONFIG_AUX_DIR([build-aux])
25 RSE_BOLD
27 { echo; echo "${term_bold}Build Tools:${term_norm}"; } >& AS_MESSAGE_FD
29 AM_INIT_AUTOMAKE(libsigsegv, 2.7)
30 AM_CONFIG_HEADER(config.h)
32 dnl Override automake's tar command used for creating distributions.
33 am__tar='${AMTAR} chf - --owner=root --group=root "$$tardir"'
35 AC_PROG_CC
36 AC_PROG_CPP
38 AC_CANONICAL_HOST
39 AC_MSG_CHECKING([host platform])
40 sv_cv_host="$host"
41 changequote(,)dnl Autoconf 2.52 brokenness
42 case "$host_os" in
43   linux | linux-*)
44     kernelversion=`uname -r | sed -e 's/^\([0-9.]*\).*/\1/'`
45     sv_cv_host=`echo $sv_cv_host | sed -e "s/linux/linux$kernelversion/"`
46     ;;
47 esac
48 changequote([,])dnl Autoconf 2.52 brokenness
49 cat > conftest.c << EOF
50 #include <features.h>
51 #ifdef __GNU_LIBRARY__
52 Version __GLIBC__ . __GLIBC_MINOR__
53 #endif
54 EOF
55 glibcversion=`$CPP $CPPFLAGS conftest.c 2>/dev/null | grep Version | sed -e 's/Version//' -e 's/ //g'`
56 if test -n "$glibcversion"; then
57   sv_cv_host="$sv_cv_host-glibc$glibcversion"
59 AC_MSG_RESULT([$sv_cv_host])
60 PLATFORM="$sv_cv_host"
61 AC_SUBST([PLATFORM])
63 AC_PROG_INSTALL
65 LT_INIT([disable-shared])
67 # For testing cross-compilation behaviour.
68 #cross_compiling=yes
70 { echo; echo "${term_bold}Optional Platform Environment:${term_norm}"; } >& AS_MESSAGE_FD
72 dnl Headers to be included with <signal.h>. On MacOS X (Darwin) one also
73 dnl needs <sys/signal.h>.
74 AC_CHECK_HEADERS([sys/signal.h])
76 dnl List of signals that are sent when an invalid virtual memory address
77 dnl is accessed, or when the stack overflows.
78 case "$host_os" in
79   sunos4* | freebsd* | dragonfly* | openbsd* | netbsd* | kfreebsd* | knetbsd*)
80     CFG_SIGNALS=signals-bsd.h ;;
81   hpux*)
82     CFG_SIGNALS=signals-hpux.h ;;
83   macos* | darwin*)
84     CFG_SIGNALS=signals-macos.h ;;
85   gnu*)
86     CFG_SIGNALS=signals-hurd.h ;;
87   *)
88     CFG_SIGNALS=signals.h ;;
89 esac
90 AC_DEFINE_UNQUOTED([CFG_SIGNALS], ["$CFG_SIGNALS"],
91   [The name of the include file describing the fault signals.])
93 # How to determine the memory page size.
94 SV_GETPAGESIZE
96 # How to allocate fresh memory using mmap.
97 # (We need mmap, because mprotect() doesn't work on malloc()ed memory on
98 # some systems.)
99 SV_MMAP_ANON
101 # How to write a SIGSEGV handler with access to the fault address.
103 # On MacOS X 10.2 or newer, we don't need these tests, because we'll end up
104 # using handler-macos.c anyway. If we were to perform the tests, 5 Crash Report
105 # dialog windows would pop up.
106 case "$host_os" in
107   macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*) ;;
108   *)
110 dnl FIXME: Put in some more known values into the third argument.
111 SV_TRY_FAULT([POSIX], sv_cv_fault_posix,
112   [*-*-solaris2.[7-9] | i?86-*-linux2.[4-9]* | i?86-*-freebsd[4-9]* | i?86-*-mirbsd1[0-9] | alpha*-dec-osf[4-9]* | *-*-hpux11* | mips-sgi-irix6*],
113   [],
114   [int sig, siginfo_t *sip, void *ucp],
115   [sip->si_addr],
116   [action.sa_sigaction = &sigsegv_handler;
117    action.sa_flags = SA_SIGINFO;])
119 SV_TRY_FAULT([Linux/i386], sv_cv_fault_linux_i386, [i?86-*-linux2.[2-9]*],
120   [#include <asm/sigcontext.h>],
121   [int sig, struct sigcontext sc],
122   [sc.cr2])
124 SV_TRY_FAULT([old Linux/i386], sv_cv_fault_linux_i386_old,
125   [i?86-*-linux2.[2-9]*],
126   [],
127   [int sig, unsigned int more],
128   [((unsigned long *) &more) [21]])
130 dnl FIXME: Put in some more known values into the third argument.
131 SV_TRY_FAULT([Linux/m68k], sv_cv_fault_linux_m68k, [],
132   [#include <asm/sigcontext.h>
133 #include "$srcdir/src/fault-linux-m68k-old.c"],
134   [int sig, int code, struct sigcontext *scp],
135   [get_fault_addr (scp)])
137 dnl FIXME: Put in some more known values into the third argument.
138 SV_TRY_FAULT([Linux/PowerPC], sv_cv_fault_linux_powerpc, [],
139   [#include <asm/sigcontext.h>],
140   [int sig, struct sigcontext *scp],
141   [scp->regs->dar])
143 dnl FIXME: Put in some more known values into the third argument.
144 SV_TRY_FAULT([Linux/HPPA], sv_cv_fault_linux_hppa, [],
145   [],
146   [int sig, siginfo_t *sip, void *ucp],
147   [sip->si_ptr],
148   [action.sa_sigaction = &sigsegv_handler;
149    action.sa_flags = SA_SIGINFO;])
151 dnl FIXME: Put in some more known values into the third argument.
152 SV_TRY_FAULT([BSD], sv_cv_fault_bsd, [i?86-*-freebsd[4-9]*],
153   [],
154   [int sig, int code, struct sigcontext *scp, void *addr],
155   [addr])
157 dnl FIXME: Put in some more known values into the third argument.
158 SV_TRY_FAULT([IRIX], sv_cv_fault_irix, [mips-sgi-irix6*],
159   [],
160   [int sig, int code, struct sigcontext *scp],
161   [(unsigned long) scp->sc_badvaddr])
163 dnl FIXME: Put in some more known values into the third argument.
164 SV_TRY_FAULT([HP-UX HPPA], sv_cv_fault_hpux_hppa, [hppa*-*-hpux11*],
165   [
166 #define USE_64BIT_REGS(mc) \
167   (((mc).ss_flags & SS_WIDEREGS) && ((mc).ss_flags & SS_NARROWISINVALID))
168 #define GET_CR21(mc) \
169   (USE_64BIT_REGS(mc) ? (mc).ss_wide.ss_64.ss_cr21 : (mc).ss_narrow.ss_cr21)
171   [int sig, int code, struct sigcontext *scp],
172   [GET_CR21 (scp->sc_sl.sl_ss)])
174 dnl FIXME: Put in some more known values into the third argument.
175 SV_TRY_FAULT([OSF/1 Alpha], sv_cv_fault_osf_alpha,
176   [alpha*-*-osf[4-9]* | alpha*-*-linux2.[4-9]*],
177   [],
178   [int sig, int code, struct sigcontext *scp],
179   [scp->sc_traparg_a0])
181 dnl FIXME: Put in some more known values into the third argument.
182 SV_TRY_FAULT([NetBSD Alpha], sv_cv_fault_netbsd_alpha,
183   [alpha*-*-osf[4-9]* | alpha-*-*bsd*],
184   [#include "$srcdir/src/fault-netbsd-alpha.c"],
185   [int sig, int code, struct sigcontext *scp],
186   [get_fault_addr (scp)])
188 dnl FIXME: Put in some more known values into the third argument.
189 SV_TRY_FAULT([AIX], sv_cv_fault_aix, [*-*-aix[34]*],
190   [],
191   [int sig, int code, struct sigcontext *scp],
192   [scp->sc_jmpbuf.jmp_context.o_vaddr])
194 SV_TRY_FAULT([MacOSX/Darwin7 PowerPC], sv_cv_fault_macosdarwin7_ppc,
195   [powerpc-*-darwin7*],
196   [#include "$srcdir/src/fault-macosdarwin7-powerpc.c"],
197   [int sig, siginfo_t *sip, ucontext_t *ucp],
198   [get_fault_addr (sip, ucp)],
199   [action.sa_sigaction = &sigsegv_handler;
200    action.sa_flags = SA_SIGINFO;])
202 if test "$sv_cv_fault_macosdarwin7_ppc" != yes; then
203 SV_TRY_FAULT([MacOSX/Darwin5 PowerPC], sv_cv_fault_macosdarwin5_ppc,
204   [powerpc-*-darwin5*],
205   [#include "$srcdir/src/fault-macosdarwin5-powerpc.c"],
206   [int sig, int code, struct sigcontext *scp],
207   [get_fault_addr (scp)])
210 dnl FIXME: Put in some more known values into the third argument.
211 SV_TRY_FAULT([Hurd], sv_cv_fault_hurd, [],
212   [],
213   [int sig, int code, struct sigcontext *scp],
214   [code])
216 # End of MacOS X special casing.
217     ;;
218 esac
220 dnl Now determine the fault handler include file.
221 dnl We prefer the platform specific include files to the generic fault-posix.h
222 dnl because the former often defines SIGSEGV_FAULT_STACKPOINTER.
223 dnl Also we put the BSD test second-to-last, because the test may produce
224 dnl false positives.
225 CFG_HANDLER=
226 CFG_FAULT=
227 CFG_MACHFAULT=
228 FAULT_CONTEXT=void
229 FAULT_CONTEXT_INCLUDE=
231 dnl First the cases where the OS provides the fault address.
233 if test -z "$CFG_FAULT" && test "$sv_cv_fault_aix" = yes; then
234   case "$host_cpu" in
235     powerpc* | rs6000) CFG_FAULT=fault-aix3-powerpc.h ;;
236     *) CFG_FAULT=fault-aix3.h ;;
237   esac
238   FAULT_CONTEXT='struct sigcontext'
240 if test -z "$CFG_FAULT" && test "$sv_cv_fault_irix" = yes; then
241   case "$host_cpu" in
242     mips*) CFG_FAULT=fault-irix-mips.h ;;
243     *) CFG_FAULT=fault-irix.h ;;
244   esac
245   FAULT_CONTEXT='struct sigcontext'
247 if test -z "$CFG_FAULT" && test "$sv_cv_fault_hpux_hppa" = yes; then
248   case "$host_cpu" in
249     hppa* | parisc*) CFG_FAULT=fault-hpux-hppa.h ;;
250     *) CFG_FAULT=fault-hpux.h ;;
251   esac
252   FAULT_CONTEXT='struct sigcontext'
254 if test -z "$CFG_FAULT" && test "$sv_cv_fault_osf_alpha" = yes; then
255   case "$host_cpu" in
256     alpha*) CFG_FAULT=fault-osf-alpha.h ;;
257     *) CFG_FAULT=fault-osf.h ;;
258   esac
259   FAULT_CONTEXT='struct sigcontext'
261 if test -z "$CFG_FAULT" && test "$sv_cv_fault_netbsd_alpha" = yes; then
262   case "$host_cpu" in
263     alpha*) CFG_FAULT=fault-netbsd-alpha.h ;;
264   esac
265   FAULT_CONTEXT='struct sigcontext'
267 if test -z "$CFG_FAULT" && test "$sv_cv_fault_hurd" = yes; then
268   case "$host_os" in
269     netbsd*) # A false positive.
270       ;;
271     *)
272       CFG_FAULT=fault-hurd.h
273       FAULT_CONTEXT='struct sigcontext'
274       ;;
275   esac
277 if test -z "$CFG_FAULT" && test "$sv_cv_fault_bsd" = yes; then
278   case "$host_os" in
279     freebsd* | dragonfly* | kfreebsd*)
280       case "$host_cpu" in
281         i?86 | x86_64)
282           CFG_FAULT=fault-freebsd-i386.h
283           FAULT_CONTEXT='struct sigcontext'
284           ;;
285         *)
286           CFG_FAULT=fault-bsd.h
287           FAULT_CONTEXT='void'
288           ;;
289       esac
290       ;;
291     *)
292       CFG_FAULT=fault-bsd.h
293       FAULT_CONTEXT='void'
294       ;;
295   esac
297 if test -z "$CFG_FAULT" && test "$sv_cv_fault_posix" = yes; then
298   case "$host_os" in
299     openbsd*)
300       case "$host_cpu" in
301         i?86 | x86_64) CFG_FAULT=fault-openbsd-i386.h ;;
302         *) CFG_FAULT=fault-openbsd.h ;;
303       esac
304       FAULT_CONTEXT='struct sigcontext'
305       ;;
306     mirbsd*)
307       case "$host_cpu" in
308         i?86 | x86_64)
309           CFG_FAULT=fault-openbsd-i386.h
310           FAULT_CONTEXT='struct sigcontext'
311           ;;
312       esac
313       ;;
314     linux*)
315       case "$host_cpu" in
316         ia64)
317           CFG_FAULT=fault-linux-ia64-old.h
318           FAULT_CONTEXT='struct sigcontext'
319           ;;
320       esac
321       ;;
322   esac
323   if test -z "$CFG_FAULT"; then
324     dnl <ucontext.h> was required by POSIX:2001, and many systems have it. But
325     dnl POSIX:2008 does not require it any more, and MirBSD does not have it.
326     AC_CHECK_HEADERS([ucontext.h])
327     if test $ac_cv_header_ucontext_h = yes; then
328       case "$host_os" in
329         solaris*)
330           case "$host_cpu" in
331             i?86 | x86_64) CFG_FAULT=fault-solaris-i386.h ;;
332             sparc*) CFG_FAULT=fault-solaris-sparc.h ;;
333             *) CFG_FAULT=fault-solaris.h ;;
334           esac
335           ;;
336         aix*)
337           case "$host_cpu" in
338             powerpc* | rs6000) CFG_FAULT=fault-aix5-powerpc.h ;;
339             *) CFG_FAULT=fault-aix5.h ;;
340           esac
341           ;;
342         netbsd*)
343           CFG_FAULT=fault-netbsd.h
344           ;;
345         linux*)
346           case "$host_cpu" in
347             alpha*)
348               CFG_FAULT=fault-linux-alpha.h
349               ;;
350             arm* | strongarm* | xscale*)
351               CFG_FAULT=fault-linux-arm.h
352               ;;
353             cris)
354               CFG_FAULT=fault-linux-cris.h
355               ;;
356             hppa* | parisc*)
357               CFG_FAULT=fault-linux-hppa.h
358               ;;
359             i?86 | x86_64)
360               CFG_FAULT=fault-linux-i386.h
361               ;;
362             ia64)
363               CFG_FAULT=fault-linux-ia64.h
364               ;;
365             m68*)
366               CFG_FAULT=fault-linux-m68k.h
367               ;;
368             mips*)
369               CFG_FAULT=fault-linux-mips.h
370               ;;
371             powerpc* | rs6000)
372               CFG_FAULT=fault-linux-powerpc.h
373               ;;
374             s390*)
375               CFG_FAULT=fault-linux-s390.h
376               ;;
377             sh*)
378               CFG_FAULT=fault-linux-sh.h
379               ;;
380             sparc*)
381               CFG_FAULT=fault-linux-sparc.h
382               ;;
383             *)
384               CFG_FAULT=fault-posix-ucontext.h
385               ;;
386           esac
387           ;;
388         *)
389           CFG_FAULT=fault-posix-ucontext.h
390           ;;
391       esac
392       FAULT_CONTEXT='ucontext_t'
393       FAULT_CONTEXT_INCLUDE='#include <ucontext.h>'
394     else
395       CFG_FAULT=fault-posix.h
396       FAULT_CONTEXT='void'
397     fi
398   fi
400 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_i386" = yes; then
401   case "$host_cpu" in
402     i?86 | x86_64) CFG_FAULT=fault-linux-i386-old.h ;;
403   esac
404   FAULT_CONTEXT='struct sigcontext'
406 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_i386_old" = yes; then
407   case "$host_cpu" in
408     i?86 | x86_64) CFG_FAULT=fault-linux-i386-oldold.h ;;
409   esac
410   FAULT_CONTEXT='struct sigcontext'
412 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_powerpc" = yes; then
413   case "$host_cpu" in
414     powerpc* | rs6000) CFG_FAULT=fault-linux-powerpc-old.h ;;
415   esac
416   FAULT_CONTEXT='struct sigcontext'
418 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_hppa" = yes; then
419   case "$host_cpu" in
420     hppa* | parisc*) CFG_FAULT=fault-linux-hppa-old.h ;;
421   esac
423 if test -z "$CFG_FAULT"; then
424   case "$host_os" in
425     macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*)
426       case "$host_cpu" in
427         powerpc* | rs6000 | i?86 | x86_64)
428           CFG_MACHFAULT=machfault-macos.h
429           FAULT_CONTEXT_INCLUDE='#include <signal.h>
430 #include <mach/thread_status.h>
431 #if defined __ppc64__
432 #define sigsegv_thread_state_t ppc_thread_state64_t
433 #elif defined __ppc__
434 #define sigsegv_thread_state_t ppc_thread_state_t
435 #endif
436 #if defined __x86_64__
437 #define sigsegv_thread_state_t x86_thread_state64_t
438 #elif defined __i386__
439 #if defined x86_THREAD_STATE32
440 #define sigsegv_thread_state_t x86_thread_state32_t
441 #else
442 #define sigsegv_thread_state_t i386_thread_state_t
443 #endif
444 #endif'
445           FAULT_CONTEXT='sigsegv_thread_state_t'
446           ;;
447       esac
448       if test -n "$CFG_MACHFAULT"; then
449         CFG_HANDLER=handler-macos.c
450         CFG_FAULT=fault-macos.h # nonexistent, just a dummy
451       fi
452       ;;
453   esac
456 dnl Next, the cases where there is a hairy CPU dependent way to get the
457 dnl fault address.
459 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_m68k" = yes; then
460   case "$host_cpu" in
461     m68*)
462       CFG_FAULT=fault-linux-m68k-old.h
463       FAULT_CONTEXT='struct sigcontext'
464       ;;
465   esac
467 if test -z "$CFG_FAULT" && test "$sv_cv_fault_macosdarwin7_ppc" = yes; then
468   case "$host_cpu" in
469     powerpc* | rs6000)
470       CFG_FAULT=fault-macosdarwin7-powerpc.h
471       FAULT_CONTEXT='ucontext_t'
472       FAULT_CONTEXT_INCLUDE='#include <signal.h>
473 #include <ucontext.h>'
474       ;;
475   esac
477 if test -z "$CFG_FAULT" && test "$sv_cv_fault_macosdarwin5_ppc" = yes; then
478   case "$host_cpu" in
479     powerpc* | rs6000)
480       CFG_FAULT=fault-macosdarwin5-powerpc.h
481       FAULT_CONTEXT='struct sigcontext'
482       ;;
483   esac
485 if test -z "$CFG_FAULT"; then
486   case "$host_os" in
487     mingw* | cygwin*)
488       FAULT_CONTEXT='CONTEXT'
489       FAULT_CONTEXT_INCLUDE='#include <windows.h>'
490       CFG_FAULT=fault-win32.h # nonexistent, just a dummy
491       ;;
492   esac
494 if test -n "$CFG_FAULT"; then
495   sv_cv_have_sigsegv_recovery=yes
496 else
497   sv_cv_have_sigsegv_recovery=no
498   dnl
499   dnl No way to get the fault address. But other information is available.
500   dnl
501   case "$host_os" in
502     linux*)
503       case "$host_cpu" in
504         alpha*)
505           CFG_FAULT=fault-linux-alpha-old.h
506           FAULT_CONTEXT='struct sigcontext'
507           ;;
508         arm* | strongarm* | xscale*)
509           CFG_FAULT=fault-linux-arm-old.h
510           FAULT_CONTEXT='struct sigcontext'
511           ;;
512         cris)
513           CFG_FAULT=fault-linux-cris-old.h
514           FAULT_CONTEXT='struct sigcontext'
515           ;;
516         mips*)
517           CFG_FAULT=fault-linux-mips-old.h
518           FAULT_CONTEXT='struct sigcontext'
519           ;;
520         s390*)
521           CFG_FAULT=fault-linux-s390-old.h
522           FAULT_CONTEXT='struct sigcontext'
523           ;;
524         sh*)
525           CFG_FAULT=fault-linux-sh-old.h
526           FAULT_CONTEXT='struct sigcontext'
527           ;;
528         sparc*)
529           CFG_FAULT=fault-linux-sparc-old.h
530           FAULT_CONTEXT='struct sigcontext'
531           ;;
532         x86_64)
533           CFG_FAULT=fault-linux-x86_64-old.h
534           FAULT_CONTEXT='struct sigcontext'
535           ;;
536       esac
537       ;;
538     beos*)
539       case "$host_cpu" in
540         i?86 | x86_64) CFG_FAULT=fault-beos-i386.h ;;
541         *) CFG_FAULT=fault-beos.h ;;
542       esac
543       FAULT_CONTEXT='struct vregs'
544       ;;
545     macos* | darwin*)
546       case "$host_cpu" in
547         i?86 | x86_64) CFG_FAULT=fault-macos-i386.h ;;
548       esac
549       FAULT_CONTEXT='struct sigcontext'
550       ;;
551   esac
553 AC_MSG_CHECKING([for the fault handler specifics])
554 if test -n "$CFG_FAULT"; then
555   sv_cv_fault_include=$CFG_FAULT
556 else
557   if test -n "$CFG_MACHFAULT"; then
558     sv_cv_fault_include=$CFG_MACHFAULT
559   else
560     sv_cv_fault_include=none
561   fi
563 AC_MSG_RESULT([$sv_cv_fault_include])
564 if test -z "$CFG_FAULT"; then
565   CFG_FAULT=fault-none.h
567 AC_DEFINE_UNQUOTED([CFG_FAULT], ["$CFG_FAULT"],
568   [The name of the include file describing the fault handler.])
569 if test -z "$CFG_MACHFAULT"; then
570   CFG_MACHFAULT=fault-none.h
572 AC_DEFINE_UNQUOTED([CFG_MACHFAULT], ["$CFG_MACHFAULT"],
573   [The name of the include file describing the Mach fault handler.])
574 AC_SUBST([FAULT_CONTEXT])
575 AC_SUBST([FAULT_CONTEXT_INCLUDE])
576 dnl AM_SUBST_NOTMAKE, because FAULT_CONTEXT_INCLUDE may have a multiline value.
577 AM_SUBST_NOTMAKE([FAULT_CONTEXT_INCLUDE])
579 AC_MSG_CHECKING([if the system supports catching SIGSEGV])
580 AC_MSG_RESULT([$sv_cv_have_sigsegv_recovery])
581 if test $sv_cv_have_sigsegv_recovery != no; then
582   HAVE_SIGSEGV_RECOVERY=1
583 else
584   HAVE_SIGSEGV_RECOVERY=0
586 AC_SUBST([HAVE_SIGSEGV_RECOVERY])
588 dnl The stackoverflow_context_t type depends on the CFG_FAULT include file.
590 dnl Stack direction.
591 SV_STACK_DIRECTION
593 dnl Determination of the stack's virtual memory area.
594 AC_CACHE_CHECK([for PIOCMAP in sys/procfs.h], [sv_cv_procfsvma], [
595   AC_TRY_LINK([#include <sys/procfs.h>],
596     [int x = PIOCNMAP + PIOCMAP; prmap_t y;],
597     [sv_cv_procfsvma=yes], [sv_cv_procfsvma=no])
599 AC_CHECK_FUNCS([mincore])
600 CFG_STACKVMA=
601 if test $sv_cv_procfsvma = yes; then
602   CFG_STACKVMA=stackvma-procfs.c
603 else
604   case "$host_os" in
605     linux*)                CFG_STACKVMA=stackvma-linux.c ;;
606     freebsd* | dragonfly*) CFG_STACKVMA=stackvma-freebsd.c ;;
607     beos*)                 CFG_STACKVMA=stackvma-beos.c ;;
608     macos* | darwin*)      CFG_STACKVMA=stackvma-mach.c ;;
609   esac
611 if test -z "$CFG_STACKVMA" && test $ac_cv_func_mincore = yes; then
612   CFG_STACKVMA=stackvma-mincore.c
614 if test -n "$CFG_STACKVMA"; then
615   AC_DEFINE([HAVE_STACKVMA], [1],
616     [Define if CFG_STACKVMA is set to a nontrivial source file.])
617 else
618   CFG_STACKVMA=stackvma-none.c
620 AC_DEFINE_UNQUOTED([CFG_STACKVMA], ["$CFG_STACKVMA"],
621   [The name of the file determining the stack virtual memory area.])
622 AC_SUBST([CFG_STACKVMA])
624 AC_CHECK_FUNCS([getrlimit setrlimit])
626 dnl Catching stack overflow requires an alternate signal stack.
627 dnl The old "install a guard page" trick would be unreliable, because
628 dnl we don't know where exactly to place the guard page.
629 SV_SIGALTSTACK
631 # How to longjmp out of a signal handler, in such a way that the
632 # alternate signal stack remains functional.
634 # On MacOS X 10.2 or newer, we don't need these tests, because we'll end up
635 # using handler-macos.c anyway. If we were to perform the tests, 2 Crash Report
636 # dialog windows would pop up.
637 case "$host_os" in
638   macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*) ;;
639   *)
641 dnl FIXME: Put in some more known values into the third argument.
642 SV_TRY_LEAVE_HANDLER_LONGJMP([], sv_cv_leave_handler_longjmp,
643   [*-*-osf[4-9]* | *-*-hpux11* | *-*-linux2.[2-9]*],
644   [], [])
646 dnl FIXME: Put in some more known values into the third argument.
647 SV_TRY_LEAVE_HANDLER_LONGJMP([ and sigaltstack],
648   sv_cv_leave_handler_longjmp_sigaltstack,
649   [*-*-freebsd*],
650   [
651 #ifndef SS_ONSTACK
652 #define SS_ONSTACK SA_ONSTACK
653 #endif
654   ],
655   [stack_t ss;
656    if (sigaltstack (NULL, &ss) >= 0)
657      {
658        ss.ss_flags &= ~SS_ONSTACK;
659        sigaltstack (&ss, NULL);
660      }
661   ])
663 dnl FIXME: Put in some more known values into the third argument.
664 SV_TRY_LEAVE_HANDLER_LONGJMP([ and setcontext],
665   sv_cv_leave_handler_longjmp_setcontext,
666   [*-*-irix* | *-*-solaris*],
667   [#include <ucontext.h>
668 #ifndef SS_ONSTACK
669 #define SS_ONSTACK SA_ONSTACK
670 #endif
671   ],
672   [static int fl;
673    static ucontext_t uc;
674    fl = 0;
675    if (getcontext (&uc) >= 0)
676      if (fl == 0)
677        if (uc.uc_stack.ss_flags & SS_ONSTACK)
678          {
679            uc.uc_stack.ss_flags &= ~SS_ONSTACK;
680            fl = 1;
681            setcontext (&uc);
682          }
683   ])
685 # End of MacOS X special casing.
686     ;;
687 esac
689 # How to siglongjmp out of a signal handler, in such a way that the
690 # alternate signal stack remains functional.
692 # On MacOS X 10.2 or newer, we don't need these tests, because we'll end up
693 # using handler-macos.c anyway. If we were to perform the tests, 2 Crash Report
694 # dialog windows would pop up.
695 case "$host_os" in
696   macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*) ;;
697   *)
699 dnl FIXME: Put in some more known values into the third argument.
700 SV_TRY_LEAVE_HANDLER_SIGLONGJMP([], sv_cv_leave_handler_siglongjmp,
701   [*-*-osf[4-9]* | *-*-hpux11* | *-*-linux2.[2-9]* | *-*-irix* | *-*-solaris*],
702   [], [])
704 dnl FIXME: Put in some more known values into the third argument.
705 SV_TRY_LEAVE_HANDLER_SIGLONGJMP([ and sigaltstack],
706   sv_cv_leave_handler_siglongjmp_sigaltstack,
707   [*-*-freebsd*],
708   [
709 #ifndef SS_ONSTACK
710 #define SS_ONSTACK SA_ONSTACK
711 #endif
712   ],
713   [stack_t ss;
714    if (sigaltstack (NULL, &ss) >= 0)
715      {
716        ss.ss_flags &= ~SS_ONSTACK;
717        sigaltstack (&ss, NULL);
718      }
719   ])
721 dnl FIXME: Put in some more known values into the third argument.
722 SV_TRY_LEAVE_HANDLER_SIGLONGJMP([ and setcontext],
723   sv_cv_leave_handler_siglongjmp_setcontext,
724   [],
725   [#include <ucontext.h>
726 #ifndef SS_ONSTACK
727 #define SS_ONSTACK SA_ONSTACK
728 #endif
729   ],
730   [static int fl;
731    static ucontext_t uc;
732    fl = 0;
733    if (getcontext(&uc) >= 0)
734      if (fl == 0)
735        if (uc.uc_stack.ss_flags & SS_ONSTACK)
736          {
737            uc.uc_stack.ss_flags &= ~SS_ONSTACK;
738            fl = 1;
739            setcontext(&uc);
740          }
741   ])
743 # End of MacOS X special casing.
744     ;;
745 esac
747 CFG_LEAVE=
748 if test "$sv_cv_leave_handler_longjmp" != no; then
749   CFG_LEAVE=leave-nop.c
750 else
751   if test "$sv_cv_leave_handler_longjmp_sigaltstack" != no; then
752     CFG_LEAVE=leave-sigaltstack.c
753   else
754     if test "$sv_cv_leave_handler_longjmp_setcontext" != no; then
755       CFG_LEAVE=leave-setcontext.c
756     fi
757   fi
759 case "$host_os" in
760   # On BeOS, the 6 tests fail because sigaltstack() doesn't exist.
761   # If one uses set_signal_stack() instead of sigaltstack(), the first
762   # test actually works. i.e. sv_cv_leave_handler_longjmp would be 'yes'.
763   beos*) CFG_LEAVE=leave-nop.c ;;
764 esac
765 if test -z "$CFG_LEAVE"; then
766   CFG_LEAVE=leave-none.c
768 AC_DEFINE_UNQUOTED([CFG_LEAVE], ["$CFG_LEAVE"],
769   [The name of the file implementing sigsegv_reset_onstack_flag.])
770 AC_SUBST([CFG_LEAVE])
772 AC_CACHE_CHECK([if the system supports catching stack overflow],
773                [sv_cv_have_stack_overflow_recovery],
775   dnl On Mach, it requires a machfault-*.h (see src/handler-macos.c).
776   dnl On Unix, it requires either sigaltstack() or the BeOS set_signal_stack()
777   dnl function, and the ability to longjmp out of the signal handler, and on
778   dnl Unix it also requires a fault-*.h or a stackvma-*.c with certain
779   dnl properties (see src/handler-unix.c).
780   if test "$CFG_MACHFAULT" != fault-none.h; then
781     sv_cv_have_stack_overflow_recovery=yes
782   else
783     case "$host_os" in
784       mingw* | cygwin*) sv_cv_have_stack_overflow_recovery=yes ;;
785       *)
786         if test "$CFG_LEAVE" != 'leave-none.c'; then
787           if test "$sv_cv_sigaltstack" != no; then
788             sv_cv_have_stack_overflow_recovery=maybe
789           else
790             case "$host_os" in
791               beos*) sv_cv_have_stack_overflow_recovery=maybe ;;
792               *) sv_cv_have_stack_overflow_recovery=no ;;
793             esac
794           fi
795         else
796           sv_cv_have_stack_overflow_recovery=no
797         fi
798         ;;
799     esac
800   fi
801   if test $sv_cv_have_stack_overflow_recovery = maybe; then
802     if test -n "$CFG_FAULT"; then
803       AC_EGREP_CPP([xyzzy], [
804 #include "$srcdir/src/$CFG_FAULT"
805 #ifdef SIGSEGV_FAULT_HANDLER_ARGLIST
806 #ifdef SIGSEGV_FAULT_ADDRESS
807 xyzzy
808 #endif
809 #endif
810 ], [condA=true], [condA=false])
811     else
812       condA=false
813     fi
814     if test -n "$CFG_FAULT"; then
815       AC_EGREP_CPP([xyzzy], [
816 #include "$srcdir/src/$CFG_FAULT"
817 #ifdef SIGSEGV_FAULT_HANDLER_ARGLIST
818 #ifdef SIGSEGV_FAULT_STACKPOINTER
819 xyzzy
820 #endif
821 #endif
822 ], [condB=true], [condB=false])
823     else
824       condB=false
825     fi
826     if test "$CFG_STACKVMA" != "stackvma-none.c"; then
827       condC=true
828     else
829       condC=false
830     fi
831     if { $condA && $condB; } || { $condA && $condC; } || { $condB && $condC; }; then
832       sv_cv_have_stack_overflow_recovery=yes
833     else
834       sv_cv_have_stack_overflow_recovery=no
835     fi
836   fi
838 if test $sv_cv_have_stack_overflow_recovery != no; then
839   HAVE_STACK_OVERFLOW_RECOVERY=1
840 else
841   HAVE_STACK_OVERFLOW_RECOVERY=0
843 AC_SUBST([HAVE_STACK_OVERFLOW_RECOVERY])
845 case "$host_os" in
846   mingw* | cygwin*) CFG_HANDLER=handler-win32.c ;;
847   *)
848     if test -z "$CFG_HANDLER"; then
849       if test $sv_cv_have_sigsegv_recovery = no \
850          && test $sv_cv_have_stack_overflow_recovery = no; then
851         CFG_HANDLER=handler-none.c
852       else
853         CFG_HANDLER=handler-unix.c
854       fi
855     fi
856     ;;
857 esac
858 AC_DEFINE_UNQUOTED([CFG_HANDLER], ["$CFG_HANDLER"],
859   [The name of the file implementing the handler functionality.])
860 AC_SUBST([CFG_HANDLER])
862 { echo; echo "${term_bold}Build Parameters:${term_norm}"; } >& AS_MESSAGE_FD
864 dnl Relocatability is a nop for this package.
865 AC_RELOCATABLE_NOP
867 { echo; echo "${term_bold}Output Substitution:${term_norm}"; } >& AS_MESSAGE_FD
869 dnl AC_OUTPUT([Makefile])
870 AC_OUTPUT([Makefile
871            src/Makefile src/sigsegv.h
872            tests/Makefile])
874 { echo; echo "Now please type '${term_bold}make${term_norm}' to compile. Good luck."; echo; } >& AS_MESSAGE_FD