Many new reports.
[libsigsegv/ericb.git] / configure.ac
blob483d4e181cb1dbfd8223e482eb97cdc64b9be8cc
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-2006  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.52)
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.4)
30 AM_CONFIG_HEADER(config.h)
32 AC_PROG_CC
33 AC_PROG_CPP
35 AC_CANONICAL_HOST
36 AC_MSG_CHECKING([host platform])
37 sv_cv_host="$host"
38 changequote(,)dnl Autoconf 2.52 brokenness
39 case "$host_os" in
40   linux | linux-*)
41     kernelversion=`uname -r | sed -e 's/^\([0-9.]*\).*/\1/'`
42     sv_cv_host=`echo $sv_cv_host | sed -e "s/linux/linux$kernelversion/"`
43     ;;
44 esac
45 changequote([,])dnl Autoconf 2.52 brokenness
46 cat > conftest.c << EOF
47 #include <features.h>
48 #ifdef __GNU_LIBRARY__
49 Version __GLIBC__ . __GLIBC_MINOR__
50 #endif
51 EOF
52 glibcversion=`$CPP $CPPFLAGS conftest.c 2>/dev/null | grep Version | sed -e 's/Version//' -e 's/ //g'`
53 if test -n "$glibcversion"; then
54   sv_cv_host="$sv_cv_host-glibc$glibcversion"
56 AC_MSG_RESULT([$sv_cv_host])
57 PLATFORM="$sv_cv_host"
58 AC_SUBST(PLATFORM)
60 AC_PROG_INSTALL
62 AM_DISABLE_SHARED
63 AM_PROG_LIBTOOL
65 # For testing cross-compilation behaviour.
66 #cross_compiling=yes
68 { echo; echo "${term_bold}Optional Platform Environment:${term_norm}"; } >& AS_MESSAGE_FD
70 dnl Headers to be included with <signal.h>. On MacOS X (Darwin) one also
71 dnl needs <sys/signal.h>.
72 AC_CHECK_HEADERS([sys/signal.h])
74 dnl List of signals that are sent when an invalid virtual memory address
75 dnl is accessed, or when the stack overflows.
76 case "$host_os" in
77   sunos4* | freebsd* | openbsd* | netbsd*)
78     CFG_SIGNALS=signals-bsd.h ;;
79   hpux*)
80     CFG_SIGNALS=signals-hpux.h ;;
81   macos* | darwin*)
82     CFG_SIGNALS=signals-macos.h ;;
83   gnu*)
84     CFG_SIGNALS=signals-hurd.h ;;
85   *)
86     CFG_SIGNALS=signals.h ;;
87 esac
88 AC_DEFINE_UNQUOTED(CFG_SIGNALS, "$CFG_SIGNALS",
89   [The name of the include file describing the fault signals.])
91 # How to determine the memory page size.
92 SV_GETPAGESIZE
94 # How to allocate fresh memory using mmap.
95 # (We need mmap, because mprotect() doesn't work on malloc()ed memory on
96 # some systems.)
97 SV_MMAP_ANON
99 # How to write a SIGSEGV handler with access to the fault address.
101 # On MacOS X 10.2 or newer, we don't need these tests, because we'll end up
102 # using handler-macos.c anyway. If we were to perform the tests, 5 Crash Report
103 # dialog windows would pop up.
104 case "$host_os" in
105   macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*) ;;
106   *)
108 dnl FIXME: Put in some more known values into the third argument.
109 SV_TRY_FAULT([POSIX], sv_cv_fault_posix,
110   [*-*-solaris2.[7-9] | i?86-*-linux2.[4-9]* | i?86-*-freebsd[4-9]* | alpha*-dec-osf[4-9]* | *-*-hpux11* | mips-sgi-irix6*],
111   [],
112   [int sig, siginfo_t *sip, void *ucp],
113   [sip->si_addr],
114   [action.sa_sigaction = &sigsegv_handler;
115    action.sa_flags = SA_SIGINFO;])
117 SV_TRY_FAULT([Linux/i386], sv_cv_fault_linux_i386, [i?86-*-linux2.[2-9]*],
118   [#include <asm/sigcontext.h>],
119   [int sig, struct sigcontext sc],
120   [sc.cr2])
122 SV_TRY_FAULT([old Linux/i386], sv_cv_fault_linux_i386_old,
123   [i?86-*-linux2.[2-9]*],
124   [],
125   [int sig, unsigned int more],
126   [((unsigned long *) &more) [21]])
128 dnl FIXME: Put in some more known values into the third argument.
129 SV_TRY_FAULT([Linux/m68k], sv_cv_fault_linux_m68k, [],
130   [#include <asm/sigcontext.h>
131 #include "$srcdir/src/fault-linux-m68k.c"],
132   [int sig, int code, struct sigcontext *scp],
133   [get_fault_addr (scp)])
135 dnl FIXME: Put in some more known values into the third argument.
136 SV_TRY_FAULT([Linux/PowerPC], sv_cv_fault_linux_powerpc, [],
137   [#include <asm/sigcontext.h>],
138   [int sig, struct sigcontext *scp],
139   [scp->regs->dar])
141 dnl FIXME: Put in some more known values into the third argument.
142 SV_TRY_FAULT([Linux/HPPA], sv_cv_fault_linux_hppa, [],
143   [],
144   [int sig, siginfo_t *sip, void *ucp],
145   [sip->si_ptr],
146   [action.sa_sigaction = &sigsegv_handler;
147    action.sa_flags = SA_SIGINFO;])
149 dnl FIXME: Put in some more known values into the third argument.
150 SV_TRY_FAULT([BSD], sv_cv_fault_bsd, [i?86-*-freebsd[4-9]*],
151   [],
152   [int sig, int code, struct sigcontext *scp, void *addr],
153   [addr])
155 dnl FIXME: Put in some more known values into the third argument.
156 SV_TRY_FAULT([IRIX], sv_cv_fault_irix, [mips-sgi-irix6*],
157   [],
158   [int sig, int code, struct sigcontext *scp],
159   [(unsigned long) scp->sc_badvaddr])
161 dnl FIXME: Put in some more known values into the third argument.
162 SV_TRY_FAULT([HP-UX HPPA], sv_cv_fault_hpux_hppa, [hppa*-*-hpux11*],
163   [
164 #define USE_64BIT_REGS(mc) \
165   (((mc).ss_flags & SS_WIDEREGS) && ((mc).ss_flags & SS_NARROWISINVALID))
166 #define GET_CR21(mc) \
167   (USE_64BIT_REGS(mc) ? (mc).ss_wide.ss_64.ss_cr21 : (mc).ss_narrow.ss_cr21)
169   [int sig, int code, struct sigcontext *scp],
170   [GET_CR21 (scp->sc_sl.sl_ss)])
172 dnl FIXME: Put in some more known values into the third argument.
173 SV_TRY_FAULT([OSF/1 Alpha], sv_cv_fault_osf_alpha,
174   [alpha*-*-osf[4-9]* | alpha*-*-linux2.[4-9]*],
175   [],
176   [int sig, int code, struct sigcontext *scp],
177   [scp->sc_traparg_a0])
179 dnl FIXME: Put in some more known values into the third argument.
180 SV_TRY_FAULT([NetBSD Alpha], sv_cv_fault_netbsd_alpha,
181   [alpha*-*-osf[4-9]* | alpha-*-*bsd*],
182   [#include "$srcdir/src/fault-netbsd-alpha.c"],
183   [int sig, int code, struct sigcontext *scp],
184   [get_fault_addr (scp)])
186 dnl FIXME: Put in some more known values into the third argument.
187 SV_TRY_FAULT([AIX], sv_cv_fault_aix, [*-*-aix[34]*],
188   [],
189   [int sig, int code, struct sigcontext *scp],
190   [scp->sc_jmpbuf.jmp_context.o_vaddr])
192 SV_TRY_FAULT([MacOSX/Darwin7 PowerPC], sv_cv_fault_macosdarwin7_ppc,
193   [powerpc-*-darwin7*],
194   [#include "$srcdir/src/fault-macosdarwin7-powerpc.c"],
195   [int sig, siginfo_t *sip, ucontext_t *ucp],
196   [get_fault_addr (sip, ucp)],
197   [action.sa_sigaction = &sigsegv_handler;
198    action.sa_flags = SA_SIGINFO;])
200 if test "$sv_cv_fault_macosdarwin7_ppc" != yes; then
201 SV_TRY_FAULT([MacOSX/Darwin5 PowerPC], sv_cv_fault_macosdarwin5_ppc,
202   [powerpc-*-darwin5*],
203   [#include "$srcdir/src/fault-macosdarwin5-powerpc.c"],
204   [int sig, int code, struct sigcontext *scp],
205   [get_fault_addr (scp)])
208 dnl FIXME: Put in some more known values into the third argument.
209 SV_TRY_FAULT([Hurd], sv_cv_fault_hurd, [],
210   [],
211   [int sig, int code, struct sigcontext *scp],
212   [code])
214 # End of MacOS X special casing.
215     ;;
216 esac
218 dnl Now determine the fault handler include file.
219 dnl We prefer the platform specific include files to the generic fault-posix.h
220 dnl because the former often defines SIGSEGV_FAULT_STACKPOINTER.
221 dnl Also we put the BSD test second-to-last, because the test may produce
222 dnl false positives.
223 CFG_HANDLER=
224 CFG_FAULT=
225 CFG_MACHFAULT=
226 FAULT_CONTEXT=void
227 FAULT_CONTEXT_INCLUDE=
228 FAULT_CONTEXT_INCLUDE2=
230 dnl First the cases where the OS provides the fault address.
232 if test -z "$CFG_FAULT" && test "$sv_cv_fault_aix" = yes; then
233   case "$host_cpu" in
234     powerpc* | rs6000) CFG_FAULT=fault-aix3-powerpc.h ;;
235     *) CFG_FAULT=fault-aix3.h ;;
236   esac
237   FAULT_CONTEXT='struct sigcontext'
239 if test -z "$CFG_FAULT" && test "$sv_cv_fault_irix" = yes; then
240   case "$host_cpu" in
241     mips*) CFG_FAULT=fault-irix-mips.h ;;
242     *) CFG_FAULT=fault-irix.h ;;
243   esac
244   FAULT_CONTEXT='struct sigcontext'
246 if test -z "$CFG_FAULT" && test "$sv_cv_fault_hpux_hppa" = yes; then
247   case "$host_cpu" in
248     hppa* | parisc*) CFG_FAULT=fault-hpux-hppa.h ;;
249     *) CFG_FAULT=fault-hpux.h ;;
250   esac
251   FAULT_CONTEXT='struct sigcontext'
253 if test -z "$CFG_FAULT" && test "$sv_cv_fault_osf_alpha" = yes; then
254   case "$host_cpu" in
255     alpha*) CFG_FAULT=fault-osf-alpha.h ;;
256     *) CFG_FAULT=fault-osf.h ;;
257   esac
258   FAULT_CONTEXT='struct sigcontext'
260 if test -z "$CFG_FAULT" && test "$sv_cv_fault_netbsd_alpha" = yes; then
261   case "$host_cpu" in
262     alpha*) CFG_FAULT=fault-netbsd-alpha.h ;;
263   esac
264   FAULT_CONTEXT='struct sigcontext'
266 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_i386" = yes; then
267   case "$host_cpu" in
268     i?86 | x86_64) CFG_FAULT=fault-linux-i386.h ;;
269   esac
270   FAULT_CONTEXT='struct sigcontext'
272 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_i386_old" = yes; then
273   case "$host_cpu" in
274     i?86 | x86_64) CFG_FAULT=fault-linux-i386-old.h ;;
275   esac
276   FAULT_CONTEXT='struct sigcontext'
278 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_powerpc" = yes; then
279   case "$host_cpu" in
280     powerpc* | rs6000) CFG_FAULT=fault-linux-powerpc.h ;;
281   esac
282   FAULT_CONTEXT='struct sigcontext'
284 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_hppa" = yes; then
285   case "$host_cpu" in
286     hppa* | parisc*) CFG_FAULT=fault-linux-hppa.h ;;
287   esac
289 if test -z "$CFG_FAULT" && test "$sv_cv_fault_hurd" = yes; then
290   case "$host_os" in
291     netbsd*) # A false positive.
292       ;;
293     *)
294       CFG_FAULT=fault-hurd.h
295       FAULT_CONTEXT='struct sigcontext'
296       ;;
297   esac
299 if test -z "$CFG_FAULT" && test "$sv_cv_fault_bsd" = yes; then
300   case "$host_os" in
301     freebsd*)
302       case "$host_cpu" in
303         i?86 | x86_64)
304           CFG_FAULT=fault-freebsd-i386.h
305           FAULT_CONTEXT='struct sigcontext'
306           ;;
307         *)
308           CFG_FAULT=fault-bsd.h
309           FAULT_CONTEXT='void'
310           ;;
311       esac
312       ;;
313     *)
314       CFG_FAULT=fault-bsd.h
315       FAULT_CONTEXT='void'
316       ;;
317   esac
319 if test -z "$CFG_FAULT" && test "$sv_cv_fault_posix" = yes; then
320   case "$host_os" in
321     openbsd*)
322       case "$host_cpu" in
323         i?86 | x86_64) CFG_FAULT=fault-openbsd-i386.h ;;
324         *) CFG_FAULT=fault-openbsd.h ;;
325       esac
326       FAULT_CONTEXT='struct sigcontext'
327       ;;
328     linux*)
329       case "$host_cpu" in
330         ia64)
331           CFG_FAULT=fault-linux-ia64.h
332           FAULT_CONTEXT='struct sigcontext'
333           ;;
334       esac
335       ;;
336   esac
337   if test -z "$CFG_FAULT"; then
338     case "$host_os" in
339       solaris*)
340         case "$host_cpu" in
341           i?86 | x86_64) CFG_FAULT=fault-solaris-i386.h ;;
342           sparc*) CFG_FAULT=fault-solaris-sparc.h ;;
343           *) CFG_FAULT=fault-solaris.h ;;
344         esac
345         ;;
346       aix*)
347         case "$host_cpu" in
348           powerpc* | rs6000) CFG_FAULT=fault-aix5-powerpc.h ;;
349           *) CFG_FAULT=fault-aix5.h ;;
350         esac
351         ;;
352       netbsd*)
353         CFG_FAULT=fault-netbsd.h
354         ;;
355       *)
356         CFG_FAULT=fault-posix.h
357         ;;
358     esac
359     FAULT_CONTEXT='ucontext_t'
360     FAULT_CONTEXT_INCLUDE='#include <ucontext.h>'
361   fi
363 if test -z "$CFG_FAULT"; then
364   case "$host_os" in
365     macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*)
366       case "$host_cpu" in
367         powerpc* | rs6000)
368           CFG_MACHFAULT=machfault-macos-powerpc.h
369           FAULT_CONTEXT='ppc_thread_state_t'
370           ;;
371         i?86 | x86_64)
372           CFG_MACHFAULT=machfault-macos-i386.h
373           FAULT_CONTEXT='i386_thread_state_t'
374           ;;
375       esac
376       if test -n "$CFG_MACHFAULT"; then
377         CFG_HANDLER=handler-macos.c
378         FAULT_CONTEXT_INCLUDE='#include <signal.h>'
379         FAULT_CONTEXT_INCLUDE2='#include <mach/thread_status.h>'
380         CFG_FAULT=fault-macos.h # nonexistent, just a dummy
381       fi
382       ;;
383   esac
386 dnl Next, the cases where there is a hairy CPU dependent way to get the
387 dnl fault address.
389 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_m68k" = yes; then
390   case "$host_cpu" in
391     m68*)
392       CFG_FAULT=fault-linux-m68k.h
393       FAULT_CONTEXT='struct sigcontext'
394       ;;
395   esac
397 if test -z "$CFG_FAULT" && test "$sv_cv_fault_macosdarwin7_ppc" = yes; then
398   case "$host_cpu" in
399     powerpc* | rs6000)
400       CFG_FAULT=fault-macosdarwin7-powerpc.h
401       FAULT_CONTEXT='ucontext_t'
402       FAULT_CONTEXT_INCLUDE='#include <signal.h>'
403       FAULT_CONTEXT_INCLUDE2='#include <ucontext.h>'
404       ;;
405   esac
407 if test -z "$CFG_FAULT" && test "$sv_cv_fault_macosdarwin5_ppc" = yes; then
408   case "$host_cpu" in
409     powerpc* | rs6000)
410       CFG_FAULT=fault-macosdarwin5-powerpc.h
411       FAULT_CONTEXT='struct sigcontext'
412       ;;
413   esac
415 if test -z "$CFG_FAULT"; then
416   case "$host_os" in
417     mingw* | cygwin*)
418       FAULT_CONTEXT='CONTEXT'
419       FAULT_CONTEXT_INCLUDE='#include <windows.h>'
420       CFG_FAULT=fault-win32.h # nonexistent, just a dummy
421       ;;
422   esac
424 if test -n "$CFG_FAULT"; then
425   sv_cv_have_sigsegv_recovery=yes
426 else
427   sv_cv_have_sigsegv_recovery=no
428   dnl
429   dnl No way to get the fault address. But other information is available.
430   dnl
431   case "$host_os" in
432     linux*)
433       case "$host_cpu" in
434         alpha*)
435           CFG_FAULT=fault-linux-alpha.h
436           FAULT_CONTEXT='struct sigcontext'
437           ;;
438         arm* | strongarm* | xscale*)
439           CFG_FAULT=fault-linux-arm.h
440           FAULT_CONTEXT='struct sigcontext'
441           ;;
442         cris)
443           CFG_FAULT=fault-linux-cris.h
444           FAULT_CONTEXT='struct sigcontext'
445           ;;
446         mips*)
447           CFG_FAULT=fault-linux-mips.h
448           FAULT_CONTEXT='struct sigcontext'
449           ;;
450         s390*)
451           CFG_FAULT=fault-linux-s390.h
452           FAULT_CONTEXT='struct sigcontext'
453           ;;
454         sh*)
455           CFG_FAULT=fault-linux-sh.h
456           FAULT_CONTEXT='struct sigcontext'
457           ;;
458         sparc*)
459           CFG_FAULT=fault-linux-sparc.h
460           FAULT_CONTEXT='struct sigcontext'
461           ;;
462         x86_64)
463           CFG_FAULT=fault-linux-x86_64.h
464           FAULT_CONTEXT='struct sigcontext'
465           ;;
466       esac
467       ;;
468     beos*)
469       case "$host_cpu" in
470         i?86 | x86_64) CFG_FAULT=fault-beos-i386.h ;;
471         *) CFG_FAULT=fault-beos.h ;;
472       esac
473       FAULT_CONTEXT='struct vregs'
474       ;;
475     macos* | darwin*)
476       case "$host_cpu" in
477         i?86 | x86_64) CFG_FAULT=fault-macos-i386.h ;;
478       esac
479       FAULT_CONTEXT='struct sigcontext'
480       ;;
481   esac
483 AC_MSG_CHECKING([for the fault handler specifics])
484 if test -n "$CFG_FAULT"; then
485   sv_cv_fault_include=$CFG_FAULT
486 else
487   if test -n "$CFG_MACHFAULT"; then
488     sv_cv_fault_include=$CFG_MACHFAULT
489   else
490     sv_cv_fault_include=none
491   fi
493 AC_MSG_RESULT([$sv_cv_fault_include])
494 if test -z "$CFG_FAULT"; then
495   CFG_FAULT=fault-none.h
497 AC_DEFINE_UNQUOTED(CFG_FAULT, "$CFG_FAULT",
498   [The name of the include file describing the fault handler.])
499 if test -z "$CFG_MACHFAULT"; then
500   CFG_MACHFAULT=fault-none.h
502 AC_DEFINE_UNQUOTED(CFG_MACHFAULT, "$CFG_MACHFAULT",
503   [The name of the include file describing the Mach fault handler.])
504 AC_SUBST(FAULT_CONTEXT)
505 AC_SUBST(FAULT_CONTEXT_INCLUDE)
506 AC_SUBST(FAULT_CONTEXT_INCLUDE2)
508 AC_MSG_CHECKING([if the system supports catching SIGSEGV])
509 AC_MSG_RESULT([$sv_cv_have_sigsegv_recovery])
510 if test $sv_cv_have_sigsegv_recovery != no; then
511   HAVE_SIGSEGV_RECOVERY=1
512 else
513   HAVE_SIGSEGV_RECOVERY=0
515 AC_SUBST(HAVE_SIGSEGV_RECOVERY)
517 dnl The stackoverflow_context_t type depends on the CFG_FAULT include file.
519 dnl Stack direction.
520 AC_CACHE_CHECK([for stack direction], sv_cv_stack_direction_msg, [
521   case "$host_cpu" in
522     dnl See the #define STACK_GROWS_DOWNWARD in gcc-3.1/gcc/config/*/*.h.
523     a29k | \
524     alpha* | \
525     arc | \
526     arm* | strongarm* | xscale* | \
527     avr | \
528     c1 | c2 | c32 | c34 | c38 | \
529     clipper | \
530     cris | \
531     d30v | \
532     elxsi | \
533     fr30 | \
534     h8300 | \
535     i?86 | x86_64 | \
536     i860 | \
537     ia64 | \
538     m32r | \
539     m68* | \
540     m88k | \
541     mcore | \
542     mips* | \
543     mmix | \
544     mn10200 | \
545     mn10300 | \
546     ns32k | \
547     pdp11 | \
548     pj* | \
549     powerpc* | rs6000 | \
550     romp | \
551     s390* | \
552     sh* | \
553     sparc* | \
554     v850 | \
555     vax | \
556     xtensa)
557       sv_cv_stack_direction=-1 ;;
558     c4x | \
559     dsp16xx | \
560     i960 | \
561     hppa* | parisc* | \
562     stormy16 | \
563     we32k)
564       sv_cv_stack_direction=1 ;;
565     *)
566       if test $cross_compiling = no; then
567         cat > conftest.c <<EOF
568 #include <stdio.h>
570 get_stack_direction ()
572   auto char dummy;
573   static char *dummyaddr = (char *)0;
574   if (dummyaddr != (char *)0)
575     return &dummy > dummyaddr ? 1 : &dummy < dummyaddr ? -1 : 0;
576   else
577     {
578       dummyaddr = &dummy;
579       {
580         int result = get_stack_direction ();
581         /* The next assignment avoids tail recursion elimination
582            (IRIX 6.4 CC).  */
583         dummyaddr = (char *)0;
584         return result;
585       }
586     }
589 main ()
591   printf ("%d\n", get_stack_direction ());
592   return 0;
595         AC_TRY_EVAL(ac_link)
596         sv_cv_stack_direction=`./conftest`
597       else
598         sv_cv_stack_direction=0
599       fi
600       ;;
601   esac
602   case $sv_cv_stack_direction in
603     1)  sv_cv_stack_direction_msg="grows up";;
604     -1) sv_cv_stack_direction_msg="grows down";;
605     *)  sv_cv_stack_direction_msg="unknown";;
606   esac
608 AC_DEFINE_UNQUOTED(STACK_DIRECTION, [$sv_cv_stack_direction],
609   [Define as the direction of stack growth for your system.
610    STACK_DIRECTION > 0 => grows toward higher addresses
611    STACK_DIRECTION < 0 => grows toward lower addresses
612    STACK_DIRECTION = 0 => spaghetti stack.])
614 dnl Determination of the stack's virtual memory area.
615 AC_CACHE_CHECK([for PIOCMAP in sys/procfs.h], sv_cv_procfsvma, [
616   AC_TRY_LINK([#include <sys/procfs.h>],
617     [int x = PIOCNMAP + PIOCMAP; prmap_t y;],
618     sv_cv_procfsvma=yes, sv_cv_procfsvma=no)
620 AC_CHECK_FUNCS([mincore])
621 CFG_STACKVMA=
622 if test $sv_cv_procfsvma = yes; then
623   CFG_STACKVMA=stackvma-procfs.c
624 else
625   case "$host_os" in
626     linux*) CFG_STACKVMA=stackvma-linux.c ;;
627     freebsd*) CFG_STACKVMA=stackvma-freebsd.c ;;
628     beos*) CFG_STACKVMA=stackvma-beos.c ;;
629     macos* | darwin*) CFG_STACKVMA=stackvma-mach.c ;;
630   esac
632 if test -z "$CFG_STACKVMA" && test $ac_cv_func_mincore = yes; then
633   CFG_STACKVMA=stackvma-mincore.c
635 if test -n "$CFG_STACKVMA"; then
636   AC_DEFINE(HAVE_STACKVMA, 1,
637     [Define if CFG_STACKVMA is set to a nontrivial source file.])
638 else
639   CFG_STACKVMA=stackvma-none.c
641 AC_DEFINE_UNQUOTED(CFG_STACKVMA, "$CFG_STACKVMA",
642   [The name of the file determining the stack virtual memory area.])
643 AC_SUBST(CFG_STACKVMA)
645 AC_CHECK_FUNCS([getrlimit setrlimit])
647 dnl Catching stack overflow requires an alternate signal stack.
648 dnl The old "install a guard page" trick would be unreliable, because
649 dnl we don't know where exactly to place the guard page.
650 SV_SIGALTSTACK
652 AC_CACHE_CHECK([if the system supports catching stack overflow],
653                sv_cv_have_stack_overflow_recovery,
655   dnl On Mach, it requires a machfault-*.h (see src/handler-macos.c).
656   dnl On Unix, it requires either sigaltstack() or the BeOS set_signal_stack()
657   dnl function, and on Unix it requires a fault-*.h or a stackvma-*.c with
658   dnl certain properties (see src/handler-unix.c).
659   if test "$CFG_MACHFAULT" != fault-none.h; then
660     sv_cv_have_stack_overflow_recovery=yes
661   else
662     if test "$sv_cv_sigaltstack" != no; then
663       sv_cv_have_stack_overflow_recovery=maybe
664     else
665       case "$host_os" in
666         beos*) sv_cv_have_stack_overflow_recovery=maybe ;;
667         mingw* | cygwin*) sv_cv_have_stack_overflow_recovery=yes ;;
668         *) sv_cv_have_stack_overflow_recovery=no ;;
669       esac
670     fi
671   fi
672   if test $sv_cv_have_stack_overflow_recovery = maybe; then
673     if test -n "$CFG_FAULT"; then
674       AC_EGREP_CPP([xyzzy], [
675 #include "$srcdir/src/$CFG_FAULT"
676 #ifdef SIGSEGV_FAULT_HANDLER_ARGLIST
677 #ifdef SIGSEGV_FAULT_ADDRESS
678 xyzzy
679 #endif
680 #endif
681 ], [condA=true], [condA=false])
682     else
683       condA=false
684     fi
685     if test -n "$CFG_FAULT"; then
686       AC_EGREP_CPP([xyzzy], [
687 #include "$srcdir/src/$CFG_FAULT"
688 #ifdef SIGSEGV_FAULT_HANDLER_ARGLIST
689 #ifdef SIGSEGV_FAULT_STACKPOINTER
690 xyzzy
691 #endif
692 #endif
693 ], [condB=true], [condB=false])
694     else
695       condB=false
696     fi
697     if test "$CFG_STACKVMA" != "stackvma-none.c"; then
698       condC=true
699     else
700       condC=false
701     fi
702     if { $condA && $condB; } || { $condA && $condC; } || { $condB && $condC; }; then
703       sv_cv_have_stack_overflow_recovery=yes
704     else
705       sv_cv_have_stack_overflow_recovery=no
706     fi
707   fi
709 if test $sv_cv_have_stack_overflow_recovery != no; then
710   HAVE_STACK_OVERFLOW_RECOVERY=1
711 else
712   HAVE_STACK_OVERFLOW_RECOVERY=0
714 AC_SUBST(HAVE_STACK_OVERFLOW_RECOVERY)
716 # How to longjmp out of a signal handler, in such a way that the
717 # alternate signal stack remains functional.
719 # On MacOS X 10.2 or newer, we don't need these tests, because we'll end up
720 # using handler-macos.c anyway. If we were to perform the tests, 2 Crash Report
721 # dialog windows would pop up.
722 case "$host_os" in
723   macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*) ;;
724   *)
726 dnl FIXME: Put in some more known values into the third argument.
727 SV_TRY_LEAVE_HANDLER_LONGJMP([], sv_cv_leave_handler_longjmp,
728   [*-*-osf[4-9]* | *-*-hpux11* | *-*-linux2.[2-9]*],
729   [], [])
731 dnl FIXME: Put in some more known values into the third argument.
732 SV_TRY_LEAVE_HANDLER_LONGJMP([ and sigaltstack],
733   sv_cv_leave_handler_longjmp_sigaltstack,
734   [*-*-freebsd*],
735   [
736 #ifndef SS_ONSTACK
737 #define SS_ONSTACK SA_ONSTACK
738 #endif
739   ],
740   [stack_t ss;
741    if (sigaltstack (NULL, &ss) >= 0)
742      {
743        ss.ss_flags &= ~SS_ONSTACK;
744        sigaltstack (&ss, NULL);
745      }
746   ])
748 dnl FIXME: Put in some more known values into the third argument.
749 SV_TRY_LEAVE_HANDLER_LONGJMP([ and setcontext],
750   sv_cv_leave_handler_longjmp_setcontext,
751   [*-*-irix* | *-*-solaris*],
752   [#include <ucontext.h>
753 #ifndef SS_ONSTACK
754 #define SS_ONSTACK SA_ONSTACK
755 #endif
756   ],
757   [static int fl;
758    static ucontext_t uc;
759    fl = 0;
760    if (getcontext (&uc) >= 0)
761      if (fl == 0)
762        if (uc.uc_stack.ss_flags & SS_ONSTACK)
763          {
764            uc.uc_stack.ss_flags &= ~SS_ONSTACK;
765            fl = 1;
766            setcontext (&uc);
767          }
768   ])
770 # End of MacOS X special casing.
771     ;;
772 esac
774 # How to siglongjmp out of a signal handler, in such a way that the
775 # alternate signal stack remains functional.
777 # On MacOS X 10.2 or newer, we don't need these tests, because we'll end up
778 # using handler-macos.c anyway. If we were to perform the tests, 2 Crash Report
779 # dialog windows would pop up.
780 case "$host_os" in
781   macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*) ;;
782   *)
784 dnl FIXME: Put in some more known values into the third argument.
785 SV_TRY_LEAVE_HANDLER_SIGLONGJMP([], sv_cv_leave_handler_siglongjmp,
786   [*-*-osf[4-9]* | *-*-hpux11* | *-*-linux2.[2-9]* | *-*-irix* | *-*-solaris*],
787   [], [])
789 dnl FIXME: Put in some more known values into the third argument.
790 SV_TRY_LEAVE_HANDLER_SIGLONGJMP([ and sigaltstack],
791   sv_cv_leave_handler_siglongjmp_sigaltstack,
792   [*-*-freebsd*],
793   [
794 #ifndef SS_ONSTACK
795 #define SS_ONSTACK SA_ONSTACK
796 #endif
797   ],
798   [stack_t ss;
799    if (sigaltstack (NULL, &ss) >= 0)
800      {
801        ss.ss_flags &= ~SS_ONSTACK;
802        sigaltstack (&ss, NULL);
803      }
804   ])
806 dnl FIXME: Put in some more known values into the third argument.
807 SV_TRY_LEAVE_HANDLER_SIGLONGJMP([ and setcontext],
808   sv_cv_leave_handler_siglongjmp_setcontext,
809   [],
810   [#include <ucontext.h>
811 #ifndef SS_ONSTACK
812 #define SS_ONSTACK SA_ONSTACK
813 #endif
814   ],
815   [static int fl;
816    static ucontext_t uc;
817    fl = 0;
818    if (getcontext(&uc) >= 0)
819      if (fl == 0)
820        if (uc.uc_stack.ss_flags & SS_ONSTACK)
821          {
822            uc.uc_stack.ss_flags &= ~SS_ONSTACK;
823            fl = 1;
824            setcontext(&uc);
825          }
826   ])
828 # End of MacOS X special casing.
829     ;;
830 esac
832 CFG_LEAVE=
833 if test "$sv_cv_leave_handler_longjmp" != no; then
834   CFG_LEAVE=leave-nop.c
835 else
836   if test "$sv_cv_leave_handler_longjmp_sigaltstack" != no; then
837     CFG_LEAVE=leave-sigaltstack.c
838   else
839     if test "$sv_cv_leave_handler_longjmp_setcontext" != no; then
840       CFG_LEAVE=leave-setcontext.c
841     fi
842   fi
844 case "$host_os" in
845   # On BeOS, the 6 tests fail because sigaltstack() doesn't exist.
846   # If one uses set_signal_stack() instead of sigaltstack(), the first
847   # test actually works. i.e. sv_cv_leave_handler_longjmp would be 'yes'.
848   beos*) CFG_LEAVE=leave-nop.c ;;
849 esac
850 if test -z "$CFG_LEAVE"; then
851   CFG_LEAVE=leave-none.c
853 AC_DEFINE_UNQUOTED(CFG_LEAVE, "$CFG_LEAVE",
854   [The name of the file implementing sigsegv_reset_onstack_flag.])
855 AC_SUBST(CFG_LEAVE)
857 case "$host_os" in
858   mingw* | cygwin*) CFG_HANDLER=handler-win32.c ;;
859   *)
860     if test -z "$CFG_HANDLER"; then
861       if test $sv_cv_have_sigsegv_recovery = no \
862          && test $sv_cv_have_stack_overflow_recovery = no; then
863         CFG_HANDLER=handler-none.c
864       else
865         CFG_HANDLER=handler-unix.c
866       fi
867     fi
868     ;;
869 esac
870 AC_DEFINE_UNQUOTED(CFG_HANDLER, "$CFG_HANDLER",
871   [The name of the file implementing the handler functionality.])
872 AC_SUBST(CFG_HANDLER)
874 { echo; echo "${term_bold}Build Parameters:${term_norm}"; } >& AS_MESSAGE_FD
876 dnl Relocatability is a nop for this package.
877 AC_RELOCATABLE_NOP
879 { echo; echo "${term_bold}Output Substitution:${term_norm}"; } >& AS_MESSAGE_FD
881 dnl AC_OUTPUT(Makefile)
882 AC_OUTPUT([Makefile
883            src/Makefile src/sigsegv.h
884            tests/Makefile])
886 { echo; echo "Now please type '${term_bold}make${term_norm}' to compile. Good luck."; echo; } >& AS_MESSAGE_FD