Avoid polluting cygwin namespace.
[libsigsegv/ericb.git] / configure.ac
blob19320421ced714b06560ec3ee2bc07ce03cfa0db
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-2011  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.10])
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
41 dnl ========================== Determine PLATFORM ==========================
42 dnl Requires AC_CANONICAL_HOST.
43 dnl PLATFORM is a modified config.guess triple that is supposed to contain
44 dnl the bits of information which influence the configuration or functioning
45 dnl of catching faults.
47 AC_MSG_CHECKING([host platform])
48 sv_cv_host="$host"
49 changequote(,)dnl Autoconf 2.52 brokenness
50 case "$host_os" in
51   linux | linux-*)
52     kernelversion=`uname -r | sed -e 's/^\([0-9.]*\).*/\1/'`
53     sv_cv_host=`echo $sv_cv_host | sed -e "s/linux/linux$kernelversion/"`
54     ;;
55 esac
56 changequote([,])dnl Autoconf 2.52 brokenness
57 cat > conftest.c << EOF
58 #include <features.h>
59 #ifdef __GNU_LIBRARY__
60 Version __GLIBC__ . __GLIBC_MINOR__
61 #endif
62 EOF
63 glibcversion=`$CPP $CPPFLAGS conftest.c 2>/dev/null | grep Version | sed -e 's/Version//' -e 's/ //g'`
64 if test -n "$glibcversion"; then
65   sv_cv_host="$sv_cv_host-glibc$glibcversion"
67 AC_MSG_RESULT([$sv_cv_host])
68 PLATFORM="$sv_cv_host"
69 AC_SUBST([PLATFORM])
71 dnl ========================== Done with PLATFORM ==========================
74 AC_PROG_INSTALL
76 LT_INIT([disable-shared])
78 # For testing cross-compilation behaviour.
79 #cross_compiling=yes
81 { echo; echo "${term_bold}Optional Platform Environment:${term_norm}"; } >& AS_MESSAGE_FD
83 dnl Headers to be included with <signal.h>. On MacOS X (Darwin) one also
84 dnl needs <sys/signal.h>.
85 AC_CHECK_HEADERS([sys/signal.h])
88 dnl ========================== Determine CFG_SIGNALS ==========================
89 dnl Requires AC_CANONICAL_HOST.
91 dnl List of signals that are sent when an invalid virtual memory address
92 dnl is accessed, or when the stack overflows.
93 case "$host_os" in
94   sunos4* | freebsd* | dragonfly* | openbsd* | netbsd* | kfreebsd* | knetbsd*)
95     CFG_SIGNALS=signals-bsd.h ;;
96   hpux*)
97     CFG_SIGNALS=signals-hpux.h ;;
98   macos* | darwin*)
99     CFG_SIGNALS=signals-macos.h ;;
100   gnu*)
101     CFG_SIGNALS=signals-hurd.h ;;
102   *)
103     CFG_SIGNALS=signals.h ;;
104 esac
105 AC_DEFINE_UNQUOTED([CFG_SIGNALS], ["$CFG_SIGNALS"],
106   [The name of the include file describing the fault signals.])
108 dnl ========================== Done with CFG_SIGNALS ==========================
111 # How to determine the memory page size.
112 SV_GETPAGESIZE
114 # How to allocate fresh memory using mmap.
115 # (We need mmap, because mprotect() doesn't work on malloc()ed memory on
116 # some systems.)
117 SV_MMAP_ANON
120 dnl ================== Determine CFG_HANDLER partially,     ==================
121 dnl ================== CFG_FAULT, CFG_MACHFAULT,            ==================
122 dnl ================== FAULT_CONTEXT, FAULT_CONTEXT_INCLUDE ==================
123 dnl Requires AC_CANONICAL_HOST, SV_MMAP_ANON.
125 # How to write a SIGSEGV handler with access to the fault address.
127 # On MacOS X 10.2 or newer, we don't need these tests, because we'll end up
128 # using handler-macos.c anyway. If we were to perform the tests, 5 Crash Report
129 # dialog windows would pop up.
130 case "$host_os" in
131   macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*) ;;
132   *)
134 dnl FIXME: Put in some more known values into the third argument.
135 SV_TRY_FAULT([POSIX], sv_cv_fault_posix,
136   [*-*-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*],
137   [],
138   [int sig, siginfo_t *sip, void *ucp],
139   [sip->si_addr],
140   [action.sa_sigaction = &sigsegv_handler;
141    action.sa_flags = SA_SIGINFO;])
143 SV_TRY_FAULT([Linux/i386], sv_cv_fault_linux_i386, [i?86-*-linux2.[2-9]*],
144   [#include <asm/sigcontext.h>],
145   [int sig, struct sigcontext sc],
146   [sc.cr2])
148 SV_TRY_FAULT([old Linux/i386], sv_cv_fault_linux_i386_old,
149   [i?86-*-linux2.[2-9]*],
150   [],
151   [int sig, unsigned int more],
152   [((unsigned long *) &more) [21]])
154 dnl FIXME: Put in some more known values into the third argument.
155 SV_TRY_FAULT([Linux/m68k], sv_cv_fault_linux_m68k, [],
156   [#include <asm/sigcontext.h>
157 #include "$srcdir/src/fault-linux-m68k-old.c"],
158   [int sig, int code, struct sigcontext *scp],
159   [get_fault_addr (scp)])
161 dnl FIXME: Put in some more known values into the third argument.
162 SV_TRY_FAULT([Linux/PowerPC], sv_cv_fault_linux_powerpc, [],
163   [#include <asm/sigcontext.h>],
164   [int sig, struct sigcontext *scp],
165   [scp->regs->dar])
167 dnl FIXME: Put in some more known values into the third argument.
168 SV_TRY_FAULT([Linux/HPPA], sv_cv_fault_linux_hppa, [],
169   [],
170   [int sig, siginfo_t *sip, void *ucp],
171   [sip->si_ptr],
172   [action.sa_sigaction = &sigsegv_handler;
173    action.sa_flags = SA_SIGINFO;])
175 dnl FIXME: Put in some more known values into the third argument.
176 SV_TRY_FAULT([BSD], sv_cv_fault_bsd, [i?86-*-freebsd[4-9]*],
177   [],
178   [int sig, int code, struct sigcontext *scp, void *addr],
179   [addr])
181 dnl FIXME: Put in some more known values into the third argument.
182 SV_TRY_FAULT([IRIX], sv_cv_fault_irix, [mips-sgi-irix6*],
183   [],
184   [int sig, int code, struct sigcontext *scp],
185   [(unsigned long) scp->sc_badvaddr])
187 dnl FIXME: Put in some more known values into the third argument.
188 SV_TRY_FAULT([HP-UX HPPA], sv_cv_fault_hpux_hppa, [hppa*-*-hpux11*],
189   [
190 #define USE_64BIT_REGS(mc) \
191   (((mc).ss_flags & SS_WIDEREGS) && ((mc).ss_flags & SS_NARROWISINVALID))
192 #define GET_CR21(mc) \
193   (USE_64BIT_REGS(mc) ? (mc).ss_wide.ss_64.ss_cr21 : (mc).ss_narrow.ss_cr21)
195   [int sig, int code, struct sigcontext *scp],
196   [GET_CR21 (scp->sc_sl.sl_ss)])
198 dnl FIXME: Put in some more known values into the third argument.
199 SV_TRY_FAULT([OSF/1 Alpha], sv_cv_fault_osf_alpha,
200   [alpha*-*-osf[4-9]* | alpha*-*-linux2.[4-9]*],
201   [],
202   [int sig, int code, struct sigcontext *scp],
203   [scp->sc_traparg_a0])
205 dnl FIXME: Put in some more known values into the third argument.
206 SV_TRY_FAULT([NetBSD Alpha], sv_cv_fault_netbsd_alpha,
207   [alpha*-*-osf[4-9]* | alpha-*-*bsd*],
208   [#include "$srcdir/src/fault-netbsd-alpha.c"],
209   [int sig, int code, struct sigcontext *scp],
210   [get_fault_addr (scp)])
212 dnl FIXME: Put in some more known values into the third argument.
213 SV_TRY_FAULT([AIX], sv_cv_fault_aix, [*-*-aix[34]*],
214   [],
215   [int sig, int code, struct sigcontext *scp],
216   [scp->sc_jmpbuf.jmp_context.o_vaddr])
218 SV_TRY_FAULT([MacOSX/Darwin7 PowerPC], sv_cv_fault_macosdarwin7_ppc,
219   [powerpc-*-darwin7*],
220   [#include "$srcdir/src/fault-macosdarwin7-powerpc.c"],
221   [int sig, siginfo_t *sip, ucontext_t *ucp],
222   [get_fault_addr (sip, ucp)],
223   [action.sa_sigaction = &sigsegv_handler;
224    action.sa_flags = SA_SIGINFO;])
226 if test "$sv_cv_fault_macosdarwin7_ppc" != yes; then
227 SV_TRY_FAULT([MacOSX/Darwin5 PowerPC], sv_cv_fault_macosdarwin5_ppc,
228   [powerpc-*-darwin5*],
229   [#include "$srcdir/src/fault-macosdarwin5-powerpc.c"],
230   [int sig, int code, struct sigcontext *scp],
231   [get_fault_addr (scp)])
234 dnl FIXME: Put in some more known values into the third argument.
235 SV_TRY_FAULT([Hurd], sv_cv_fault_hurd, [],
236   [],
237   [int sig, int code, struct sigcontext *scp],
238   [code])
240 # End of MacOS X special casing.
241     ;;
242 esac
244 dnl Now determine the fault handler include file.
245 dnl We prefer the platform specific include files to the generic fault-posix.h
246 dnl because the former often defines SIGSEGV_FAULT_STACKPOINTER.
247 dnl Also we put the BSD test second-to-last, because the test may produce
248 dnl false positives.
249 CFG_HANDLER=
250 CFG_FAULT=
251 CFG_MACHFAULT=
252 FAULT_CONTEXT=void
253 FAULT_CONTEXT_INCLUDE=
255 dnl First the cases where the OS provides the fault address.
257 if test -z "$CFG_FAULT" && test "$sv_cv_fault_aix" = yes; then
258   case "$host_cpu" in
259     powerpc* | rs6000) CFG_FAULT=fault-aix3-powerpc.h ;;
260     *) CFG_FAULT=fault-aix3.h ;;
261   esac
262   FAULT_CONTEXT='struct sigcontext'
264 if test -z "$CFG_FAULT" && test "$sv_cv_fault_irix" = yes; then
265   case "$host_cpu" in
266     mips*) CFG_FAULT=fault-irix-mips.h ;;
267     *) CFG_FAULT=fault-irix.h ;;
268   esac
269   FAULT_CONTEXT='struct sigcontext'
271 if test -z "$CFG_FAULT" && test "$sv_cv_fault_hpux_hppa" = yes; then
272   case "$host_cpu" in
273     hppa* | parisc*) CFG_FAULT=fault-hpux-hppa.h ;;
274     *) CFG_FAULT=fault-hpux.h ;;
275   esac
276   FAULT_CONTEXT='struct sigcontext'
278 if test -z "$CFG_FAULT" && test "$sv_cv_fault_osf_alpha" = yes; then
279   case "$host_cpu" in
280     alpha*) CFG_FAULT=fault-osf-alpha.h ;;
281     *) CFG_FAULT=fault-osf.h ;;
282   esac
283   FAULT_CONTEXT='struct sigcontext'
285 if test -z "$CFG_FAULT" && test "$sv_cv_fault_netbsd_alpha" = yes; then
286   case "$host_cpu" in
287     alpha*) CFG_FAULT=fault-netbsd-alpha.h ;;
288   esac
289   FAULT_CONTEXT='struct sigcontext'
291 if test -z "$CFG_FAULT" && test "$sv_cv_fault_hurd" = yes; then
292   case "$host_os" in
293     netbsd*) # A false positive.
294       ;;
295     *)
296       CFG_FAULT=fault-hurd.h
297       FAULT_CONTEXT='struct sigcontext'
298       ;;
299   esac
301 if test -z "$CFG_FAULT" && test "$sv_cv_fault_bsd" = yes; then
302   case "$host_os" in
303     freebsd* | dragonfly* | kfreebsd*)
304       case "$host_cpu" in
305         i?86 | x86_64)
306           CFG_FAULT=fault-freebsd-i386.h
307           FAULT_CONTEXT='struct sigcontext'
308           ;;
309         *)
310           CFG_FAULT=fault-bsd.h
311           FAULT_CONTEXT='void'
312           ;;
313       esac
314       ;;
315     *)
316       CFG_FAULT=fault-bsd.h
317       FAULT_CONTEXT='void'
318       ;;
319   esac
321 if test -z "$CFG_FAULT" && test "$sv_cv_fault_posix" = yes; then
322   case "$host_os" in
323     openbsd*)
324       case "$host_cpu" in
325         alpha*) CFG_FAULT=fault-openbsd-alpha.h ;;
326         arm* | strongarm* | xscale*) CFG_FAULT=fault-openbsd-arm.h ;;
327         hppa* | parisc*) CFG_FAULT=fault-openbsd-hppa.h ;;
328         i?86 | x86_64) CFG_FAULT=fault-openbsd-i386.h ;;
329         m68*) CFG_FAULT=fault-openbsd-m68k.h ;;
330         m88k*) CFG_FAULT=fault-openbsd-m88k.h ;;
331         mips*) CFG_FAULT=fault-openbsd-mips.h ;;
332         powerpc* | rs6000) CFG_FAULT=fault-openbsd-powerpc.h ;;
333         sh*) CFG_FAULT=fault-openbsd-sh.h ;;
334         sparc*) CFG_FAULT=fault-openbsd-sparc.h ;;
335         vax*) CFG_FAULT=fault-openbsd-vax.h ;;
336         *) CFG_FAULT=fault-openbsd.h ;;
337       esac
338       FAULT_CONTEXT='struct sigcontext'
339       ;;
340     mirbsd*)
341       case "$host_cpu" in
342         i?86 | x86_64)
343           CFG_FAULT=fault-openbsd-i386.h
344           FAULT_CONTEXT='struct sigcontext'
345           ;;
346       esac
347       ;;
348     linux*)
349       case "$host_cpu" in
350         ia64)
351           CFG_FAULT=fault-linux-ia64-old.h
352           FAULT_CONTEXT='struct sigcontext'
353           ;;
354       esac
355       ;;
356   esac
357   if test -z "$CFG_FAULT"; then
358     dnl <ucontext.h> was required by POSIX:2001, and many systems have it. But
359     dnl POSIX:2008 does not require it any more, and MirBSD does not have it.
360     AC_CHECK_HEADERS([ucontext.h])
361     if test $ac_cv_header_ucontext_h = yes; then
362       case "$host_os" in
363         solaris*)
364           case "$host_cpu" in
365             i?86 | x86_64) CFG_FAULT=fault-solaris-i386.h ;;
366             sparc*) CFG_FAULT=fault-solaris-sparc.h ;;
367             *) CFG_FAULT=fault-solaris.h ;;
368           esac
369           ;;
370         aix*)
371           case "$host_cpu" in
372             powerpc* | rs6000) CFG_FAULT=fault-aix5-powerpc.h ;;
373             *) CFG_FAULT=fault-aix5.h ;;
374           esac
375           ;;
376         netbsd*)
377           CFG_FAULT=fault-netbsd.h
378           ;;
379         linux*)
380           case "$host_cpu" in
381             alpha*)
382               CFG_FAULT=fault-linux-alpha.h
383               ;;
384             arm* | strongarm* | xscale*)
385               CFG_FAULT=fault-linux-arm.h
386               ;;
387             cris)
388               CFG_FAULT=fault-linux-cris.h
389               ;;
390             hppa* | parisc*)
391               CFG_FAULT=fault-linux-hppa.h
392               ;;
393             i?86 | x86_64)
394               CFG_FAULT=fault-linux-i386.h
395               ;;
396             ia64)
397               CFG_FAULT=fault-linux-ia64.h
398               ;;
399             m68*)
400               CFG_FAULT=fault-linux-m68k.h
401               ;;
402             mips*)
403               CFG_FAULT=fault-linux-mips.h
404               ;;
405             powerpc* | rs6000)
406               CFG_FAULT=fault-linux-powerpc.h
407               ;;
408             s390*)
409               CFG_FAULT=fault-linux-s390.h
410               ;;
411             sh*)
412               CFG_FAULT=fault-linux-sh.h
413               ;;
414             sparc*)
415               CFG_FAULT=fault-linux-sparc.h
416               ;;
417             *)
418               CFG_FAULT=fault-posix-ucontext.h
419               ;;
420           esac
421           ;;
422         *)
423           CFG_FAULT=fault-posix-ucontext.h
424           ;;
425       esac
426       FAULT_CONTEXT='ucontext_t'
427       FAULT_CONTEXT_INCLUDE='#include <ucontext.h>'
428     else
429       CFG_FAULT=fault-posix.h
430       FAULT_CONTEXT='void'
431     fi
432   fi
434 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_i386" = yes; then
435   case "$host_cpu" in
436     i?86 | x86_64) CFG_FAULT=fault-linux-i386-old.h ;;
437   esac
438   FAULT_CONTEXT='struct sigcontext'
440 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_i386_old" = yes; then
441   case "$host_cpu" in
442     i?86 | x86_64) CFG_FAULT=fault-linux-i386-oldold.h ;;
443   esac
444   FAULT_CONTEXT='struct sigcontext'
446 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_powerpc" = yes; then
447   case "$host_cpu" in
448     powerpc* | rs6000) CFG_FAULT=fault-linux-powerpc-old.h ;;
449   esac
450   FAULT_CONTEXT='struct sigcontext'
452 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_hppa" = yes; then
453   case "$host_cpu" in
454     hppa* | parisc*) CFG_FAULT=fault-linux-hppa-old.h ;;
455   esac
457 if test -z "$CFG_FAULT"; then
458   case "$host_os" in
459     macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*)
460       case "$host_cpu" in
461         powerpc* | rs6000 | i?86 | x86_64)
462           CFG_MACHFAULT=machfault-macos.h
463           FAULT_CONTEXT_INCLUDE='#include <signal.h>
464 #include <mach/thread_status.h>
465 #if defined __ppc64__
466 #define sigsegv_thread_state_t ppc_thread_state64_t
467 #elif defined __ppc__
468 #define sigsegv_thread_state_t ppc_thread_state_t
469 #endif
470 #if defined __x86_64__
471 #define sigsegv_thread_state_t x86_thread_state64_t
472 #elif defined __i386__
473 #if defined x86_THREAD_STATE32
474 #define sigsegv_thread_state_t x86_thread_state32_t
475 #else
476 #define sigsegv_thread_state_t i386_thread_state_t
477 #endif
478 #endif'
479           FAULT_CONTEXT='sigsegv_thread_state_t'
480           ;;
481       esac
482       if test -n "$CFG_MACHFAULT"; then
483         CFG_HANDLER=handler-macos.c
484         CFG_FAULT=fault-macos.h # nonexistent, just a dummy
485       fi
486       ;;
487   esac
490 dnl Next, the cases where there is a hairy CPU dependent way to get the
491 dnl fault address.
493 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_m68k" = yes; then
494   case "$host_cpu" in
495     m68*)
496       CFG_FAULT=fault-linux-m68k-old.h
497       FAULT_CONTEXT='struct sigcontext'
498       ;;
499   esac
501 if test -z "$CFG_FAULT" && test "$sv_cv_fault_macosdarwin7_ppc" = yes; then
502   case "$host_cpu" in
503     powerpc* | rs6000)
504       CFG_FAULT=fault-macosdarwin7-powerpc.h
505       FAULT_CONTEXT='ucontext_t'
506       FAULT_CONTEXT_INCLUDE='#include <signal.h>
507 #include <ucontext.h>'
508       ;;
509   esac
511 if test -z "$CFG_FAULT" && test "$sv_cv_fault_macosdarwin5_ppc" = yes; then
512   case "$host_cpu" in
513     powerpc* | rs6000)
514       CFG_FAULT=fault-macosdarwin5-powerpc.h
515       FAULT_CONTEXT='struct sigcontext'
516       ;;
517   esac
519 case "$host_os" in
520   mingw*)
521     FAULT_CONTEXT='CONTEXT'
522     FAULT_CONTEXT_INCLUDE='#include <windows.h>'
523     CFG_FAULT=fault-win32.h # nonexistent, just a dummy
524     ;;
525   cygwin*)
526     FAULT_CONTEXT='struct _CONTEXT'
527     # CONTEXT is defined in <windows.h>, but cygwin programs should not
528     # normally inspect the contents of CONTEXT, and the outright inclusion
529     # of <windows.h> pollutes the namespace.
530     FAULT_CONTEXT_INCLUDE='struct _CONTEXT;'
531     # Cygwin 1.7 uses fault-posix.h. Cygwin 1.5.x needs a hacky workaround.
532     if test -z "$CFG_FAULT"; then
533       CFG_FAULT=fault-cygwin-old.h
534       AC_DEFINE([OLD_CYGWIN_WORKAROUND], [1],
535         [Define to 1 on Cygwin versions older than 1.7.])
536     fi
537     ;;
538 esac
539 if test -n "$CFG_FAULT"; then
540   sv_cv_have_sigsegv_recovery=yes
541 else
542   sv_cv_have_sigsegv_recovery=no
543   dnl
544   dnl No way to get the fault address. But other information is available.
545   dnl
546   case "$host_os" in
547     linux*)
548       case "$host_cpu" in
549         alpha*)
550           CFG_FAULT=fault-linux-alpha-old.h
551           FAULT_CONTEXT='struct sigcontext'
552           ;;
553         arm* | strongarm* | xscale*)
554           CFG_FAULT=fault-linux-arm-old.h
555           FAULT_CONTEXT='struct sigcontext'
556           ;;
557         cris)
558           CFG_FAULT=fault-linux-cris-old.h
559           FAULT_CONTEXT='struct sigcontext'
560           ;;
561         mips*)
562           CFG_FAULT=fault-linux-mips-old.h
563           FAULT_CONTEXT='struct sigcontext'
564           ;;
565         s390*)
566           CFG_FAULT=fault-linux-s390-old.h
567           FAULT_CONTEXT='struct sigcontext'
568           ;;
569         sh*)
570           CFG_FAULT=fault-linux-sh-old.h
571           FAULT_CONTEXT='struct sigcontext'
572           ;;
573         sparc*)
574           CFG_FAULT=fault-linux-sparc-old.h
575           FAULT_CONTEXT='struct sigcontext'
576           ;;
577         x86_64)
578           CFG_FAULT=fault-linux-x86_64-old.h
579           FAULT_CONTEXT='struct sigcontext'
580           ;;
581       esac
582       ;;
583     beos*)
584       case "$host_cpu" in
585         i?86 | x86_64) CFG_FAULT=fault-beos-i386.h ;;
586         *) CFG_FAULT=fault-beos.h ;;
587       esac
588       FAULT_CONTEXT='struct vregs'
589       ;;
590     macos* | darwin*)
591       case "$host_cpu" in
592         i?86 | x86_64) CFG_FAULT=fault-macos-i386.h ;;
593       esac
594       FAULT_CONTEXT='struct sigcontext'
595       ;;
596   esac
598 AC_MSG_CHECKING([for the fault handler specifics])
599 if test -n "$CFG_FAULT"; then
600   sv_cv_fault_include=$CFG_FAULT
601 else
602   if test -n "$CFG_MACHFAULT"; then
603     sv_cv_fault_include=$CFG_MACHFAULT
604   else
605     sv_cv_fault_include=none
606   fi
608 AC_MSG_RESULT([$sv_cv_fault_include])
609 if test -z "$CFG_FAULT"; then
610   CFG_FAULT=fault-none.h
612 AC_DEFINE_UNQUOTED([CFG_FAULT], ["$CFG_FAULT"],
613   [The name of the include file describing the fault handler.])
614 if test -z "$CFG_MACHFAULT"; then
615   CFG_MACHFAULT=fault-none.h
617 AC_DEFINE_UNQUOTED([CFG_MACHFAULT], ["$CFG_MACHFAULT"],
618   [The name of the include file describing the Mach fault handler.])
619 AC_SUBST([FAULT_CONTEXT])
620 AC_SUBST([FAULT_CONTEXT_INCLUDE])
621 dnl AM_SUBST_NOTMAKE, because FAULT_CONTEXT_INCLUDE may have a multiline value.
622 AM_SUBST_NOTMAKE([FAULT_CONTEXT_INCLUDE])
624 dnl ================== Done with CFG_HANDLER partially,     ==================
625 dnl ================== CFG_FAULT, CFG_MACHFAULT,            ==================
626 dnl ================== FAULT_CONTEXT, FAULT_CONTEXT_INCLUDE ==================
629 dnl ===================== Determine HAVE_SIGSEGV_RECOVERY =====================
630 dnl Requires CFG_HANDLER / CFG_FAULT / etc.
632 AC_MSG_CHECKING([if the system supports catching SIGSEGV])
633 AC_MSG_RESULT([$sv_cv_have_sigsegv_recovery])
634 if test $sv_cv_have_sigsegv_recovery != no; then
635   HAVE_SIGSEGV_RECOVERY=1
636 else
637   HAVE_SIGSEGV_RECOVERY=0
639 AC_SUBST([HAVE_SIGSEGV_RECOVERY])
641 dnl ===================== Done with HAVE_SIGSEGV_RECOVERY =====================
644 dnl The stackoverflow_context_t type depends on the CFG_FAULT include file.
646 dnl Stack direction.
647 SV_STACK_DIRECTION
650 dnl ========================= Determine CFG_STACKVMA =========================
651 dnl Requires AC_CANONICAL_HOST.
653 dnl Determination of the stack's virtual memory area.
654 AC_CACHE_CHECK([for PIOCMAP in sys/procfs.h], [sv_cv_procfsvma], [
655   AC_TRY_LINK([#include <sys/procfs.h>],
656     [int x = PIOCNMAP + PIOCMAP; prmap_t y;],
657     [sv_cv_procfsvma=yes], [sv_cv_procfsvma=no])
659 AC_CHECK_FUNCS([mquery mincore])
660 CFG_STACKVMA=
661 if test $sv_cv_procfsvma = yes; then
662   CFG_STACKVMA=stackvma-procfs.c
663 else
664   case "$host_os" in
665     linux*)                CFG_STACKVMA=stackvma-linux.c ;;
666     freebsd* | dragonfly*) CFG_STACKVMA=stackvma-freebsd.c ;;
667     netbsd*)               CFG_STACKVMA=stackvma-netbsd.c ;;
668     beos*)                 CFG_STACKVMA=stackvma-beos.c ;;
669     macos* | darwin*)      CFG_STACKVMA=stackvma-mach.c ;;
670   esac
672 dnl We prefer the mquery based approach over the mincore based approach,
673 dnl because stackvma-mincore.c:is_unmapped() has a bad worst-case runtime.
674 if test -z "$CFG_STACKVMA" && test $ac_cv_func_mquery = yes; then
675   CFG_STACKVMA=stackvma-mquery.c
677 if test -z "$CFG_STACKVMA" && test $ac_cv_func_mincore = yes; then
678   CFG_STACKVMA=stackvma-mincore.c
680 if test -n "$CFG_STACKVMA"; then
681   AC_DEFINE([HAVE_STACKVMA], [1],
682     [Define if CFG_STACKVMA is set to a nontrivial source file.])
683 else
684   CFG_STACKVMA=stackvma-none.c
686 AC_DEFINE_UNQUOTED([CFG_STACKVMA], ["$CFG_STACKVMA"],
687   [The name of the file determining the stack virtual memory area.])
688 AC_SUBST([CFG_STACKVMA])
690 dnl ========================= Done with CFG_STACKVMA =========================
693 AC_CHECK_FUNCS([getrlimit setrlimit])
695 dnl Catching stack overflow requires an alternate signal stack.
696 dnl The old "install a guard page" trick would be unreliable, because
697 dnl we don't know where exactly to place the guard page.
698 SV_SIGALTSTACK
701 dnl =========================== Determine CFG_LEAVE ===========================
702 dnl Requires AC_CANONICAL_HOST.
704 # How to longjmp out of a signal handler, in such a way that the
705 # alternate signal stack remains functional.
707 # On MacOS X 10.2 or newer, we don't need these tests, because we'll end up
708 # using handler-macos.c anyway. If we were to perform the tests, 2 Crash Report
709 # dialog windows would pop up.
710 case "$host_os" in
711   macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*) ;;
712   *)
714 dnl FIXME: Put in some more known values into the third argument.
715 SV_TRY_LEAVE_HANDLER_LONGJMP([], sv_cv_leave_handler_longjmp,
716   [*-*-osf[4-9]* | *-*-hpux11* | *-*-linux2.[2-9]*],
717   [], [])
719 dnl FIXME: Put in some more known values into the third argument.
720 SV_TRY_LEAVE_HANDLER_LONGJMP([ and sigaltstack],
721   sv_cv_leave_handler_longjmp_sigaltstack,
722   [*-*-freebsd*],
723   [
724 #ifndef SS_ONSTACK
725 #define SS_ONSTACK SA_ONSTACK
726 #endif
727   ],
728   [stack_t ss;
729    if (sigaltstack (NULL, &ss) >= 0)
730      {
731        ss.ss_flags &= ~SS_ONSTACK;
732        sigaltstack (&ss, NULL);
733      }
734   ])
736 dnl FIXME: Put in some more known values into the third argument.
737 SV_TRY_LEAVE_HANDLER_LONGJMP([ and setcontext],
738   sv_cv_leave_handler_longjmp_setcontext,
739   [*-*-irix* | *-*-solaris*],
740   [#include <ucontext.h>
741 #ifndef SS_ONSTACK
742 #define SS_ONSTACK SA_ONSTACK
743 #endif
744   ],
745   [static int fl;
746    static ucontext_t uc;
747    fl = 0;
748    if (getcontext (&uc) >= 0)
749      if (fl == 0)
750        if (uc.uc_stack.ss_flags & SS_ONSTACK)
751          {
752            uc.uc_stack.ss_flags &= ~SS_ONSTACK;
753            fl = 1;
754            setcontext (&uc);
755          }
756   ])
758 # End of MacOS X special casing.
759     ;;
760 esac
762 # How to siglongjmp out of a signal handler, in such a way that the
763 # alternate signal stack remains functional.
765 # On MacOS X 10.2 or newer, we don't need these tests, because we'll end up
766 # using handler-macos.c anyway. If we were to perform the tests, 2 Crash Report
767 # dialog windows would pop up.
768 case "$host_os" in
769   macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*) ;;
770   *)
772 dnl FIXME: Put in some more known values into the third argument.
773 SV_TRY_LEAVE_HANDLER_SIGLONGJMP([], sv_cv_leave_handler_siglongjmp,
774   [*-*-osf[4-9]* | *-*-hpux11* | *-*-linux2.[2-9]* | *-*-irix* | *-*-solaris*],
775   [], [])
777 dnl FIXME: Put in some more known values into the third argument.
778 SV_TRY_LEAVE_HANDLER_SIGLONGJMP([ and sigaltstack],
779   sv_cv_leave_handler_siglongjmp_sigaltstack,
780   [*-*-freebsd*],
781   [
782 #ifndef SS_ONSTACK
783 #define SS_ONSTACK SA_ONSTACK
784 #endif
785   ],
786   [stack_t ss;
787    if (sigaltstack (NULL, &ss) >= 0)
788      {
789        ss.ss_flags &= ~SS_ONSTACK;
790        sigaltstack (&ss, NULL);
791      }
792   ])
794 dnl FIXME: Put in some more known values into the third argument.
795 SV_TRY_LEAVE_HANDLER_SIGLONGJMP([ and setcontext],
796   sv_cv_leave_handler_siglongjmp_setcontext,
797   [],
798   [#include <ucontext.h>
799 #ifndef SS_ONSTACK
800 #define SS_ONSTACK SA_ONSTACK
801 #endif
802   ],
803   [static int fl;
804    static ucontext_t uc;
805    fl = 0;
806    if (getcontext(&uc) >= 0)
807      if (fl == 0)
808        if (uc.uc_stack.ss_flags & SS_ONSTACK)
809          {
810            uc.uc_stack.ss_flags &= ~SS_ONSTACK;
811            fl = 1;
812            setcontext(&uc);
813          }
814   ])
816 # End of MacOS X special casing.
817     ;;
818 esac
820 CFG_LEAVE=
821 if test "$sv_cv_leave_handler_longjmp" != no; then
822   CFG_LEAVE=leave-nop.c
823 else
824   if test "$sv_cv_leave_handler_longjmp_sigaltstack" != no; then
825     CFG_LEAVE=leave-sigaltstack.c
826   else
827     if test "$sv_cv_leave_handler_longjmp_setcontext" != no; then
828       CFG_LEAVE=leave-setcontext.c
829     fi
830   fi
832 case "$host_os" in
833   # On BeOS, the 6 tests fail because sigaltstack() doesn't exist.
834   # If one uses set_signal_stack() instead of sigaltstack(), the first
835   # test actually works. i.e. sv_cv_leave_handler_longjmp would be 'yes'.
836   beos*) CFG_LEAVE=leave-nop.c ;;
837 esac
838 if test -z "$CFG_LEAVE"; then
839   CFG_LEAVE=leave-none.c
841 AC_DEFINE_UNQUOTED([CFG_LEAVE], ["$CFG_LEAVE"],
842   [The name of the file implementing sigsegv_reset_onstack_flag.])
843 AC_SUBST([CFG_LEAVE])
845 dnl =========================== Done with CFG_LEAVE ===========================
848 dnl ================= Determine HAVE_STACK_OVERFLOW_RECOVERY =================
849 dnl Requires AC_CANONICAL_HOST, CFG_HANDLER / CFG_FAULT / etc., CFG_STACKVMA,
850 dnl CFG_LEAVE.
852 AC_CACHE_CHECK([if the system supports catching stack overflow],
853                [sv_cv_have_stack_overflow_recovery],
855   dnl On Mach, it requires a machfault-*.h (see src/handler-macos.c).
856   dnl On Unix, it requires either sigaltstack() or the BeOS set_signal_stack()
857   dnl function, and the ability to longjmp out of the signal handler, and on
858   dnl Unix it also requires a fault-*.h or a stackvma-*.c with certain
859   dnl properties (see src/handler-unix.c).
860   if test "$CFG_MACHFAULT" != fault-none.h; then
861     sv_cv_have_stack_overflow_recovery=yes
862   else
863     case "$host_os" in
864       mingw* | cygwin*) sv_cv_have_stack_overflow_recovery=yes ;;
865       *)
866         if test "$CFG_LEAVE" != 'leave-none.c'; then
867           if test "$sv_cv_sigaltstack" != no; then
868             sv_cv_have_stack_overflow_recovery=maybe
869           else
870             case "$host_os" in
871               beos*) sv_cv_have_stack_overflow_recovery=maybe ;;
872               *) sv_cv_have_stack_overflow_recovery=no ;;
873             esac
874           fi
875         else
876           sv_cv_have_stack_overflow_recovery=no
877         fi
878         ;;
879     esac
880   fi
881   if test $sv_cv_have_stack_overflow_recovery = maybe; then
882     if test -n "$CFG_FAULT"; then
883       AC_EGREP_CPP([xyzzy], [
884 #include "$srcdir/src/$CFG_FAULT"
885 #ifdef SIGSEGV_FAULT_HANDLER_ARGLIST
886 #ifdef SIGSEGV_FAULT_ADDRESS
887 xyzzy
888 #endif
889 #endif
890 ], [condA=true], [condA=false])
891     else
892       condA=false
893     fi
894     if test -n "$CFG_FAULT"; then
895       AC_EGREP_CPP([xyzzy], [
896 #include "$srcdir/src/$CFG_FAULT"
897 #ifdef SIGSEGV_FAULT_HANDLER_ARGLIST
898 #ifdef SIGSEGV_FAULT_STACKPOINTER
899 xyzzy
900 #endif
901 #endif
902 ], [condB=true], [condB=false])
903     else
904       condB=false
905     fi
906     if test "$CFG_STACKVMA" != "stackvma-none.c"; then
907       condC=true
908     else
909       condC=false
910     fi
911     if { $condA && $condB; } || { $condA && $condC; } || { $condB && $condC; }; then
912       sv_cv_have_stack_overflow_recovery=yes
913     else
914       sv_cv_have_stack_overflow_recovery=no
915     fi
916   fi
918 if test $sv_cv_have_stack_overflow_recovery != no; then
919   HAVE_STACK_OVERFLOW_RECOVERY=1
920 else
921   HAVE_STACK_OVERFLOW_RECOVERY=0
923 AC_SUBST([HAVE_STACK_OVERFLOW_RECOVERY])
925 dnl ================= Done with HAVE_STACK_OVERFLOW_RECOVERY =================
928 dnl ======================= Determine CFG_HANDLER fully =======================
929 dnl Requires AC_CANONICAL_HOST, CFG_HANDLER / CFG_FAULT / etc.,
930 dnl HAVE_SIGSEGV_RECOVERY, HAVE_STACK_OVERFLOW_RECOVERY.
932 case "$host_os" in
933   mingw* | cygwin*) CFG_HANDLER=handler-win32.c ;;
934   *)
935     if test -z "$CFG_HANDLER"; then
936       if test $sv_cv_have_sigsegv_recovery = no \
937          && test $sv_cv_have_stack_overflow_recovery = no; then
938         CFG_HANDLER=handler-none.c
939       else
940         CFG_HANDLER=handler-unix.c
941       fi
942     fi
943     ;;
944 esac
945 AC_DEFINE_UNQUOTED([CFG_HANDLER], ["$CFG_HANDLER"],
946   [The name of the file implementing the handler functionality.])
947 AC_SUBST([CFG_HANDLER])
949 dnl ======================= Done with CFG_HANDLER fully =======================
951 dnl Test whether to enable Cygwin specific tests.
952 AM_CONDITIONAL([CYGWIN],
953   [case "$host_os" in
954      cygwin*) true;;
955      *)       false;;
956    esac])
958 dnl Test whether to make system calls fail with error EFAULT.
959 dnl More precisely: whether passing invalid memory accesses to system calls
960 dnl should make the system call fail with error EFAULT, rather than invoking
961 dnl the signal handler.
962 dnl It is necessary on Cygwin: otherwise the cygwin1 test fails.
963 case "$host_os" in
964   cygwin*) enable_EFAULT=yes ;;
965   *)       enable_EFAULT=no ;;
966 esac
967 if test $enable_EFAULT = yes; then
968   AC_DEFINE([ENABLE_EFAULT], [1],
969     [Define to 1 if attempting to make system calls fail with error EFAULT])
971 AM_CONDITIONAL([ENABLE_EFAULT], [test $enable_EFAULT = yes])
973 if test $enable_EFAULT = yes; then
974   SV_SYSCALLS_EFAULT
978 dnl Test for features used in tests.
979 AC_TYPE_UINTPTR_T
982 { echo; echo "${term_bold}Build Parameters:${term_norm}"; } >& AS_MESSAGE_FD
984 dnl Relocatability is a nop for this package.
985 gl_RELOCATABLE_NOP
987 { echo; echo "${term_bold}Output Substitution:${term_norm}"; } >& AS_MESSAGE_FD
989 dnl AC_OUTPUT([Makefile])
990 AC_OUTPUT([Makefile
991            src/Makefile src/sigsegv.h
992            tests/Makefile])
994 { echo; echo "Now please type '${term_bold}make${term_norm}' to compile. Good luck."; echo; } >& AS_MESSAGE_FD