1 dnl Autoconf configuration for libsigsegv.
2 dnl Process this file with autoconf to produce a configure script.
4 dnl Copyright (C) 2002-2023 Bruno Haible <bruno@clisp.org>
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 of the License, or
9 dnl (at your option) any later version.
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.
16 dnl You should have received a copy of the GNU General Public License
17 dnl along with this program. If not, see <https://www.gnu.org/licenses/>.
20 AC_INIT([libsigsegv], [2.14])
21 AC_CONFIG_SRCDIR([src/sigsegv.h.in])
22 AC_CONFIG_AUX_DIR([build-aux])
23 AC_CONFIG_MACRO_DIRS([m4])
24 AC_CONFIG_HEADERS([config.h])
28 { echo; echo "${term_bold}Build Tools:${term_norm}"; } >& AS_MESSAGE_FD
32 dnl Override automake's tar command used for creating distributions.
33 am__tar='${AMTAR} chf - --owner=root --group=root "$$tardir"'
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])
49 changequote(,)dnl Autoconf 2.52 brokenness
52 kernelversion=`uname -r | sed -e 's/^\([0-9.]*\).*/\1/'`
53 sv_cv_host=`echo $sv_cv_host | sed -e "s/linux/linux$kernelversion/"`
56 changequote([,])dnl Autoconf 2.52 brokenness
57 cat > conftest.c << EOF
59 #ifdef __GNU_LIBRARY__
60 Version __GLIBC__ . __GLIBC_MINOR__
63 dnl We cannot simply use 'grep Version' on the output; see
64 dnl https://lists.gnu.org/archive/html/bug-autoconf/2017-02/msg00001.html
65 sed_extract_lines_after_version='/Version/{
71 glibcversion=`$CPP $CPPFLAGS conftest.c 2>/dev/null | sed -e '/^#/d' | sed -n -e "$sed_extract_lines_after_version" | tr -d '\n' | sed -e 's/Version//' -e 's/ //g'`
72 if test -n "$glibcversion"; then
73 sv_cv_host="$sv_cv_host-glibc$glibcversion"
75 AC_MSG_RESULT([$sv_cv_host])
76 PLATFORM="$sv_cv_host"
81 dnl ========================== Done with PLATFORM ==========================
86 LT_INIT([disable-shared])
88 # For testing cross-compilation behaviour.
91 { echo; echo "${term_bold}Optional Platform Environment:${term_norm}"; } >& AS_MESSAGE_FD
93 dnl Headers to be included with <signal.h>. On MacOS X (Darwin) one also
94 dnl needs <sys/signal.h>.
95 AC_CHECK_HEADERS([sys/signal.h])
98 dnl ========================== Determine CFG_SIGNALS ==========================
99 dnl Requires AC_CANONICAL_HOST.
101 dnl List of signals that are sent when an invalid virtual memory address
102 dnl is accessed, or when the stack overflows.
104 sunos4* | freebsd* | dragonfly* | openbsd* | netbsd* | midnightbsd* | \
105 kfreebsd* | knetbsd*)
106 CFG_SIGNALS=signals-bsd.h ;;
108 CFG_SIGNALS=signals-hpux.h ;;
110 CFG_SIGNALS=signals-macos.h ;;
112 CFG_SIGNALS=signals-hurd.h ;;
114 CFG_SIGNALS=signals.h ;;
116 AC_DEFINE_UNQUOTED([CFG_SIGNALS], ["$CFG_SIGNALS"],
117 [The name of the include file describing the fault signals.])
119 dnl ========================== Done with CFG_SIGNALS ==========================
122 # How to determine the memory page size.
125 # How to allocate fresh memory using mmap.
126 # (We need mmap, because mprotect() doesn't work on malloc()ed memory on
131 dnl ================== Determine CFG_HANDLER partially, ==================
132 dnl ================== CFG_FAULT, CFG_MACHFAULT, ==================
133 dnl ================== FAULT_CONTEXT, FAULT_CONTEXT_INCLUDE ==================
134 dnl Requires AC_CANONICAL_HOST, SV_MMAP_ANON.
136 # How to write a SIGSEGV handler with access to the fault address.
138 # Cygwin >= 2.1 supports sigaltstack(). For older versions of Cygwin,
139 # a Windows API based handler is needed, with complex code to make EFAULT work.
140 # Use the simpler approach by default.
141 AC_ARG_ENABLE([support-old-cygwin],
142 [AS_HELP_STRING([--enable-support-old-cygwin],
143 [enable support of Cygwin older than 2.1 (2015)])])
145 # On MacOS X 10.2 to 10.12, we don't need these tests, because we'll end up
146 # using handler-macos.c anyway. If we were to perform the tests, 5 Crash Report
147 # dialog windows would pop up.
148 # Starting with MacOS X 10.13 (at least), handler-unix.c works fine too.
150 macos* | darwin[[6-9]]* | darwin1[[0-6]]*) ;;
153 dnl FIXME: Put in some more known values into the third argument.
154 SV_TRY_FAULT([POSIX], sv_cv_fault_posix,
155 [*-*-solaris2.[7-9] | i?86-*-linux2.[4-9]* | sparc*-*-linux2.6.* | i?86-*-freebsd[4-9]* | i?86-*-freebsd[1-9][0-9]* | i?86-*-kfreebsd[4-9]* | i?86-*-kfreebsd[1-9][0-9]* | x86_64-*-kfreebsd[4-9]* | x86_64-*-kfreebsd[1-9][0-9]* | i?86-*-mirbsd1[0-9] | alpha*-dec-osf[4-9]* | *-*-hpux11* | mips-sgi-irix6*],
157 [int sig, siginfo_t *sip, void *ucp],
159 [action.sa_sigaction = &sigsegv_handler;
160 action.sa_flags = SA_SIGINFO;])
162 SV_TRY_FAULT([Linux/i386], sv_cv_fault_linux_i386, [i?86-*-linux2.[2-9]*],
163 [#include <asm/sigcontext.h>],
164 [int sig, struct sigcontext sc],
167 SV_TRY_FAULT([old Linux/i386], sv_cv_fault_linux_i386_old,
168 [i?86-*-linux2.[2-9]*],
170 [int sig, unsigned int more],
171 [((unsigned long *) &more) [21]])
173 dnl FIXME: Put in some more known values into the third argument.
174 SV_TRY_FAULT([Linux/m68k], sv_cv_fault_linux_m68k, [],
175 [#include <asm/sigcontext.h>
176 #include "$srcdir/src/fault-linux-m68k-old.c"],
177 [int sig, int code, struct sigcontext *scp],
178 [get_fault_addr (scp)])
180 dnl FIXME: Put in some more known values into the third argument.
181 SV_TRY_FAULT([Linux/PowerPC], sv_cv_fault_linux_powerpc, [],
182 [#include <asm/sigcontext.h>],
183 [int sig, struct sigcontext *scp],
186 dnl FIXME: Put in some more known values into the third argument.
187 SV_TRY_FAULT([Linux/HPPA], sv_cv_fault_linux_hppa, [],
189 [int sig, siginfo_t *sip, void *ucp],
191 [action.sa_sigaction = &sigsegv_handler;
192 action.sa_flags = SA_SIGINFO;])
194 dnl FIXME: Put in some more known values into the third argument.
195 SV_TRY_FAULT([BSD], sv_cv_fault_bsd, [i?86-*-freebsd[4-9]* | i?86-*-freebsd[1-9][0-9]* | x86_64-*-kfreebsd[4-9]* | x86_64-*-kfreebsd[1-9][0-9]*],
197 [int sig, int code, struct sigcontext *scp, void *addr],
200 dnl FIXME: Put in some more known values into the third argument.
201 SV_TRY_FAULT([IRIX], sv_cv_fault_irix, [mips-sgi-irix6*],
203 [int sig, int code, struct sigcontext *scp],
204 [(unsigned long) scp->sc_badvaddr])
206 dnl FIXME: Put in some more known values into the third argument.
207 SV_TRY_FAULT([HP-UX HPPA], sv_cv_fault_hpux_hppa, [hppa*-*-hpux11*],
209 #define USE_64BIT_REGS(mc) \
210 (((mc).ss_flags & SS_WIDEREGS) && ((mc).ss_flags & SS_NARROWISINVALID))
211 #define GET_CR21(mc) \
212 (USE_64BIT_REGS(mc) ? (mc).ss_wide.ss_64.ss_cr21 : (mc).ss_narrow.ss_cr21)
214 [int sig, int code, struct sigcontext *scp],
215 [GET_CR21 (scp->sc_sl.sl_ss)])
217 dnl FIXME: Put in some more known values into the third argument.
218 SV_TRY_FAULT([OSF/1 Alpha], sv_cv_fault_osf_alpha,
219 [alpha*-*-osf[4-9]* | alpha*-*-linux2.[4-9]*],
221 [int sig, int code, struct sigcontext *scp],
222 [scp->sc_traparg_a0])
224 dnl FIXME: Put in some more known values into the third argument.
225 SV_TRY_FAULT([NetBSD Alpha], sv_cv_fault_netbsd_alpha,
226 [alpha*-*-osf[4-9]* | alpha-*-*bsd*],
227 [#include "$srcdir/src/fault-netbsd-alpha.c"],
228 [int sig, int code, struct sigcontext *scp],
229 [get_fault_addr (scp)])
231 dnl FIXME: Put in some more known values into the third argument.
232 SV_TRY_FAULT([AIX], sv_cv_fault_aix, [*-*-aix[34]*],
234 [int sig, int code, struct sigcontext *scp],
235 [scp->sc_jmpbuf.jmp_context.o_vaddr])
237 SV_TRY_FAULT([MacOSX/Darwin7 PowerPC], sv_cv_fault_macosdarwin7_ppc,
238 [powerpc-*-darwin7*],
239 [#include "$srcdir/src/fault-macosdarwin7-powerpc.c"],
240 [int sig, siginfo_t *sip, ucontext_t *ucp],
241 [get_fault_addr (sip, ucp)],
242 [action.sa_sigaction = (void (*) (int, siginfo_t *, void *)) &sigsegv_handler;
243 action.sa_flags = SA_SIGINFO;])
245 if test "$sv_cv_fault_macosdarwin7_ppc" != yes; then
246 SV_TRY_FAULT([MacOSX/Darwin5 PowerPC], sv_cv_fault_macosdarwin5_ppc,
247 [powerpc-*-darwin5*],
248 [#include "$srcdir/src/fault-macosdarwin5-powerpc.c"],
249 [int sig, int code, struct sigcontext *scp],
250 [get_fault_addr (scp)])
253 dnl FIXME: Put in some more known values into the third argument.
254 SV_TRY_FAULT([Hurd], sv_cv_fault_hurd, [],
256 [int sig, int code, struct sigcontext *scp],
259 # End of MacOS X special casing.
263 dnl Now determine the fault handler include file.
264 dnl We prefer the platform specific include files to the generic fault-posix.h
265 dnl because the former often defines SIGSEGV_FAULT_STACKPOINTER.
266 dnl Also we put the BSD test second-to-last, because the test may produce
272 FAULT_CONTEXT_INCLUDE=
274 dnl First the cases where the OS provides the fault address.
276 if test -z "$CFG_FAULT" && test "$sv_cv_fault_aix" = yes; then
278 powerpc* | rs6000) CFG_FAULT=fault-aix3-powerpc.h ;;
279 *) CFG_FAULT=fault-aix3.h ;;
281 FAULT_CONTEXT='struct sigcontext'
283 if test -z "$CFG_FAULT" && test "$sv_cv_fault_irix" = yes; then
285 mips*) CFG_FAULT=fault-irix-mips.h ;;
286 *) CFG_FAULT=fault-irix.h ;;
288 FAULT_CONTEXT='struct sigcontext'
290 if test -z "$CFG_FAULT" && test "$sv_cv_fault_hpux_hppa" = yes; then
292 hppa* | parisc*) CFG_FAULT=fault-hpux-hppa.h ;;
293 *) CFG_FAULT=fault-hpux.h ;;
295 FAULT_CONTEXT='struct sigcontext'
297 if test -z "$CFG_FAULT" && test "$sv_cv_fault_osf_alpha" = yes; then
299 alpha*) CFG_FAULT=fault-osf-alpha.h ;;
300 *) CFG_FAULT=fault-osf.h ;;
302 FAULT_CONTEXT='struct sigcontext'
304 if test -z "$CFG_FAULT" && test "$sv_cv_fault_netbsd_alpha" = yes; then
306 alpha*) CFG_FAULT=fault-netbsd-alpha.h ;;
308 FAULT_CONTEXT='struct sigcontext'
310 if test -z "$CFG_FAULT" && test "$sv_cv_fault_hurd" = yes; then
313 # Test $sv_cv_fault_hurd before testing $sv_cv_fault_posix, because
314 # support for SA_SIGINFO in Hurd is present only in upstream glibc ≥ 2.33
315 # or in Debian glibc ≥ 2.19.
318 CFG_FAULT=fault-hurd-i386-old.h
321 CFG_FAULT=fault-hurd.h
324 FAULT_CONTEXT='struct sigcontext'
328 if test -z "$CFG_FAULT" && test "$sv_cv_fault_bsd" = yes; then
330 freebsd* | dragonfly* | kfreebsd*)
333 CFG_FAULT=fault-freebsd-i386.h
334 FAULT_CONTEXT='struct sigcontext'
337 CFG_FAULT=fault-bsd.h
343 CFG_FAULT=fault-bsd.h
348 if test -z "$CFG_FAULT" && test "$sv_cv_fault_posix" = yes; then
352 alpha*) CFG_FAULT=fault-openbsd-alpha.h ;;
353 arm* | strongarm* | xscale*) CFG_FAULT=fault-openbsd-arm.h ;;
354 hppa* | parisc*) CFG_FAULT=fault-openbsd-hppa.h ;;
355 i?86 | x86_64) CFG_FAULT=fault-openbsd-i386.h ;;
356 m68*) CFG_FAULT=fault-openbsd-m68k.h ;;
357 m88k*) CFG_FAULT=fault-openbsd-m88k.h ;;
358 mips*) CFG_FAULT=fault-openbsd-mips.h ;;
359 powerpc* | rs6000) CFG_FAULT=fault-openbsd-powerpc.h ;;
360 sh*) CFG_FAULT=fault-openbsd-sh.h ;;
361 sparc*) CFG_FAULT=fault-openbsd-sparc.h ;;
362 vax*) CFG_FAULT=fault-openbsd-vax.h ;;
363 *) CFG_FAULT=fault-openbsd.h ;;
365 FAULT_CONTEXT='struct sigcontext'
370 CFG_FAULT=fault-openbsd-i386.h
371 FAULT_CONTEXT='struct sigcontext'
378 CFG_FAULT=fault-linux-ia64-old.h
379 FAULT_CONTEXT='struct sigcontext'
385 aarch64*) CFG_FAULT=fault-macos-arm64.h ;;
386 i?86 | x86_64) CFG_FAULT=fault-macos-i386.h ;;
387 powerpc* | rs6000) CFG_FAULT=fault-macos-powerpc.h ;;
388 *) CFG_FAULT=fault-macos.h ;;
390 FAULT_CONTEXT='ucontext_t'
391 FAULT_CONTEXT_INCLUDE='#include <sys/ucontext.h>'
395 i?86 | x86_64) CFG_FAULT=fault-haiku-i386.h ;;
396 *) CFG_FAULT=fault-haiku.h ;;
398 FAULT_CONTEXT='ucontext_t'
399 FAULT_CONTEXT_INCLUDE='#include <signal.h>'
402 if test -z "$CFG_FAULT"; then
403 dnl <ucontext.h> was required by POSIX:2001, and many systems have it. But
404 dnl POSIX:2008 does not require it any more, and MirBSD does not have it.
405 AC_CHECK_HEADERS([ucontext.h])
406 if test $ac_cv_header_ucontext_h = yes; then
410 i?86 | x86_64) CFG_FAULT=fault-solaris-i386.h ;;
414 CFG_FAULT=fault-solaris11-sparc.h
417 CFG_FAULT=fault-solaris-sparc.h
421 *) CFG_FAULT=fault-solaris.h ;;
426 powerpc* | rs6000) CFG_FAULT=fault-aix5-powerpc.h ;;
427 *) CFG_FAULT=fault-aix5.h ;;
430 freebsd* | dragonfly* | kfreebsd*)
432 arm* | strongarm* | xscale* | aarch64*)
433 CFG_FAULT=fault-freebsd-arm.h
436 CFG_FAULT=fault-posix-ucontext.h
441 CFG_FAULT=fault-netbsd.h
446 CFG_FAULT=fault-linux-alpha.h
448 arm* | strongarm* | xscale* | aarch64*)
449 CFG_FAULT=fault-linux-arm.h
452 CFG_FAULT=fault-linux-cris.h
455 CFG_FAULT=fault-linux-hppa.h
458 CFG_FAULT=fault-linux-i386.h
461 CFG_FAULT=fault-linux-ia64.h
464 CFG_FAULT=fault-linux-loongarch.h
467 CFG_FAULT=fault-linux-m68k.h
470 CFG_FAULT=fault-linux-mips.h
473 CFG_FAULT=fault-linux-nds32.h
476 CFG_FAULT=fault-linux-powerpc.h
479 CFG_FAULT=fault-linux-riscv64.h
482 CFG_FAULT=fault-linux-s390.h
485 CFG_FAULT=fault-linux-sh.h
488 CFG_FAULT=fault-linux-sparc.h
491 CFG_FAULT=fault-posix-ucontext.h
498 CFG_FAULT=fault-cygwin-i386.h
501 CFG_FAULT=fault-cygwin.h
508 CFG_FAULT=fault-hurd-i386.h
511 CFG_FAULT=fault-posix-ucontext.h
516 CFG_FAULT=fault-posix-ucontext.h
519 FAULT_CONTEXT='ucontext_t'
520 FAULT_CONTEXT_INCLUDE='#include <ucontext.h>'
522 CFG_FAULT=fault-posix.h
527 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_i386" = yes; then
529 i?86 | x86_64) CFG_FAULT=fault-linux-i386-old.h ;;
531 FAULT_CONTEXT='struct sigcontext'
533 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_i386_old" = yes; then
535 i?86 | x86_64) CFG_FAULT=fault-linux-i386-oldold.h ;;
537 FAULT_CONTEXT='struct sigcontext'
539 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_powerpc" = yes; then
541 powerpc* | rs6000) CFG_FAULT=fault-linux-powerpc-old.h ;;
543 FAULT_CONTEXT='struct sigcontext'
545 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_hppa" = yes; then
547 hppa* | parisc*) CFG_FAULT=fault-linux-hppa-old.h ;;
550 if test -z "$CFG_FAULT"; then
552 macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*)
554 powerpc* | rs6000 | i?86 | x86_64 | aarch64)
555 CFG_MACHFAULT=machfault-macos.h
556 FAULT_CONTEXT_INCLUDE='#include <signal.h>
557 #include <mach/thread_status.h>
558 #if defined __aarch64__
559 #define sigsegv_thread_state_t arm_thread_state64_t
561 #if defined __ppc64__
562 #define sigsegv_thread_state_t ppc_thread_state64_t
563 #elif defined __ppc__
564 #define sigsegv_thread_state_t ppc_thread_state_t
566 #if defined __x86_64__
567 #define sigsegv_thread_state_t x86_thread_state64_t
568 #elif defined __i386__
569 #if defined x86_THREAD_STATE32
570 #define sigsegv_thread_state_t x86_thread_state32_t
572 #define sigsegv_thread_state_t i386_thread_state_t
575 FAULT_CONTEXT='sigsegv_thread_state_t'
578 if test -n "$CFG_MACHFAULT"; then
579 CFG_HANDLER=handler-macos.c
580 CFG_FAULT=fault-macos.h # nonexistent, just a dummy
586 dnl Next, the cases where there is a hairy CPU dependent way to get the
589 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_m68k" = yes; then
592 CFG_FAULT=fault-linux-m68k-old.h
593 FAULT_CONTEXT='struct sigcontext'
597 if test -z "$CFG_FAULT" && test "$sv_cv_fault_macosdarwin7_ppc" = yes; then
600 CFG_FAULT=fault-macosdarwin7-powerpc.h
601 FAULT_CONTEXT='ucontext_t'
602 FAULT_CONTEXT_INCLUDE='#include <signal.h>
603 #include <ucontext.h>'
607 if test -z "$CFG_FAULT" && test "$sv_cv_fault_macosdarwin5_ppc" = yes; then
610 CFG_FAULT=fault-macosdarwin5-powerpc.h
611 FAULT_CONTEXT='struct sigcontext'
617 FAULT_CONTEXT='CONTEXT'
618 FAULT_CONTEXT_INCLUDE='#include <windows.h>'
619 CFG_FAULT=fault-win32.h # nonexistent, just a dummy
622 if test "$enable_support_old_cygwin" = yes; then
623 FAULT_CONTEXT='struct _CONTEXT'
624 # CONTEXT is defined in <windows.h>, but cygwin programs should not
625 # normally inspect the contents of CONTEXT, and the outright inclusion
626 # of <windows.h> pollutes the namespace.
627 FAULT_CONTEXT_INCLUDE='struct _CONTEXT;'
628 # Cygwin 1.7 uses fault-posix.h. Cygwin 1.5.x needs a hacky workaround.
629 if test -z "$CFG_FAULT"; then
630 CFG_FAULT=fault-cygwin-old.h
631 AC_DEFINE([OLD_CYGWIN_WORKAROUND], [1],
632 [Define to 1 on Cygwin versions older than 1.7.])
637 if test -n "$CFG_FAULT"; then
638 sv_cv_have_sigsegv_recovery=yes
640 sv_cv_have_sigsegv_recovery=no
642 dnl No way to get the fault address. But other information is available.
648 CFG_FAULT=fault-linux-alpha-old.h
649 FAULT_CONTEXT='struct sigcontext'
651 arm* | strongarm* | xscale*)
652 CFG_FAULT=fault-linux-arm-old.h
653 FAULT_CONTEXT='struct sigcontext'
656 CFG_FAULT=fault-linux-cris-old.h
657 FAULT_CONTEXT='struct sigcontext'
660 CFG_FAULT=fault-linux-mips-old.h
661 FAULT_CONTEXT='struct sigcontext'
664 CFG_FAULT=fault-linux-s390-old.h
665 FAULT_CONTEXT='struct sigcontext'
668 CFG_FAULT=fault-linux-sh-old.h
669 FAULT_CONTEXT='struct sigcontext'
672 CFG_FAULT=fault-linux-sparc-old.h
673 FAULT_CONTEXT='struct sigcontext'
676 CFG_FAULT=fault-linux-x86_64-old.h
677 FAULT_CONTEXT='struct sigcontext'
683 i?86 | x86_64) CFG_FAULT=fault-beos-i386.h ;;
684 *) CFG_FAULT=fault-beos.h ;;
686 FAULT_CONTEXT='struct vregs'
690 i?86 | x86_64) CFG_FAULT=fault-macos-i386-old.h ;;
692 FAULT_CONTEXT='struct sigcontext'
696 AC_MSG_CHECKING([for the fault handler specifics])
697 if test -n "$CFG_FAULT"; then
698 sv_cv_fault_include=$CFG_FAULT
700 if test -n "$CFG_MACHFAULT"; then
701 sv_cv_fault_include=$CFG_MACHFAULT
703 sv_cv_fault_include=none
706 AC_MSG_RESULT([$sv_cv_fault_include])
707 if test -z "$CFG_FAULT"; then
708 CFG_FAULT=fault-none.h
710 AC_DEFINE_UNQUOTED([CFG_FAULT], ["$CFG_FAULT"],
711 [The name of the include file describing the fault handler.])
712 if test -z "$CFG_MACHFAULT"; then
713 CFG_MACHFAULT=fault-none.h
715 AC_DEFINE_UNQUOTED([CFG_MACHFAULT], ["$CFG_MACHFAULT"],
716 [The name of the include file describing the Mach fault handler.])
717 AC_SUBST([FAULT_CONTEXT])
718 AC_SUBST([FAULT_CONTEXT_INCLUDE])
719 dnl AM_SUBST_NOTMAKE, because FAULT_CONTEXT_INCLUDE may have a multiline value.
720 AM_SUBST_NOTMAKE([FAULT_CONTEXT_INCLUDE])
722 dnl ================== Done with CFG_HANDLER partially, ==================
723 dnl ================== CFG_FAULT, CFG_MACHFAULT, ==================
724 dnl ================== FAULT_CONTEXT, FAULT_CONTEXT_INCLUDE ==================
727 dnl ===================== Determine HAVE_SIGSEGV_RECOVERY =====================
728 dnl Requires CFG_HANDLER / CFG_FAULT / etc.
730 AC_MSG_CHECKING([if the system supports catching SIGSEGV])
731 AC_MSG_RESULT([$sv_cv_have_sigsegv_recovery])
732 if test $sv_cv_have_sigsegv_recovery != no; then
733 HAVE_SIGSEGV_RECOVERY=1
735 HAVE_SIGSEGV_RECOVERY=0
737 AC_SUBST([HAVE_SIGSEGV_RECOVERY])
739 dnl ===================== Done with HAVE_SIGSEGV_RECOVERY =====================
742 dnl The stackoverflow_context_t type depends on the CFG_FAULT include file.
748 dnl ========================= Determine CFG_STACKVMA =========================
749 dnl Requires AC_CANONICAL_HOST.
751 AC_ARG_ENABLE([stackvma],
752 AS_HELP_STRING([--disable-stackvma],
753 [detect stack overflow without stack VMA heuristic]),
754 [use_stackvma=$enableval], [use_stackvma=yes])
755 if test "$use_stackvma" != no; then
756 dnl Determination of the stack's virtual memory area.
757 AC_CACHE_CHECK([for prmap_t in sys/procfs.h], [sv_cv_procfsvma], [
760 /* Persuade Solaris OpenIndiana <signal.h> to declare 'struct sigaltstack'. */
761 #define __EXTENSIONS__ 1
762 #include <sys/procfs.h>
763 ]], [[prmap_t x;]])],
764 [sv_cv_procfsvma=yes], [sv_cv_procfsvma=no])
766 AC_CHECK_FUNCS([mquery mincore])
768 if test $sv_cv_procfsvma = yes; then
770 aix*) CFG_STACKVMA=stackvma-aix.c ;;
771 *) CFG_STACKVMA=stackvma-procfs.c ;;
774 if test -z "$CFG_STACKVMA"; then
776 linux*) CFG_STACKVMA=stackvma-linux.c ;;
777 freebsd* | kfreebsd*-gnu* | dragonfly*)
778 CFG_STACKVMA=stackvma-freebsd.c ;;
779 netbsd*) CFG_STACKVMA=stackvma-netbsd.c ;;
780 cygwin*) if test "$enable_support_old_cygwin" != yes; then
781 CFG_STACKVMA=stackvma-cygwin.c
784 beos* | haiku*) CFG_STACKVMA=stackvma-beos.c ;;
785 macos* | darwin*) CFG_STACKVMA=stackvma-mach.c ;;
786 dnl About gnu*): GNU/Hurd provides a /proc/self/maps file that is similar
787 dnl to one on Linux, and the vma_iterate (from gnulib) that reads this file
788 dnl works fine on GNU/Hurd under normal conditions. But in the context of
789 dnl libsigsegv, that is, during a SIGSEGV handler, it just hangs.
792 dnl We prefer the mquery based approach over the mincore based approach,
793 dnl because stackvma-mincore.c:is_unmapped() has a bad worst-case runtime.
794 if test -z "$CFG_STACKVMA" && test $ac_cv_func_mquery = yes; then
795 CFG_STACKVMA=stackvma-mquery.c
797 if test -z "$CFG_STACKVMA" && test $ac_cv_func_mincore = yes; then
798 CFG_STACKVMA=stackvma-aix.c
800 if test -n "$CFG_STACKVMA"; then
801 AC_DEFINE([HAVE_STACKVMA], [1],
802 [Define if CFG_STACKVMA is set to a nontrivial source file.])
804 CFG_STACKVMA=stackvma-none.c
807 CFG_STACKVMA=stackvma-none.c
809 AC_DEFINE_UNQUOTED([CFG_STACKVMA], ["$CFG_STACKVMA"],
810 [The name of the file determining the stack virtual memory area.])
811 AC_SUBST([CFG_STACKVMA])
813 dnl ========================= Done with CFG_STACKVMA =========================
816 AC_CHECK_FUNCS([getrlimit setrlimit])
818 dnl Catching stack overflow requires an alternate signal stack.
819 dnl The old "install a guard page" trick would be unreliable, because
820 dnl we don't know where exactly to place the guard page.
824 dnl =========================== Determine CFG_LEAVE ===========================
825 dnl Requires AC_CANONICAL_HOST.
827 # How to longjmp out of a signal handler, in such a way that the
828 # alternate signal stack remains functional.
830 # On MacOS X 10.2 or newer, we don't need these tests, because we'll end up
831 # using handler-macos.c anyway. If we were to perform the tests, 2 Crash Report
832 # dialog windows would pop up.
834 macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*) ;;
837 dnl FIXME: Put in some more known values into the third argument.
838 SV_TRY_LEAVE_HANDLER_LONGJMP([], sv_cv_leave_handler_longjmp,
839 [*-*-kfreebsd* | *-*-osf[4-9]* | *-*-hpux11* | *-*-linux2.[2-9]*],
842 dnl FIXME: Put in some more known values into the third argument.
843 SV_TRY_LEAVE_HANDLER_LONGJMP([ and sigaltstack],
844 sv_cv_leave_handler_longjmp_sigaltstack,
845 [*-*-freebsd* | *-*-kfreebsd*],
848 #define SS_ONSTACK SA_ONSTACK
852 if (sigaltstack (NULL, &ss) >= 0)
854 ss.ss_flags &= ~SS_ONSTACK;
855 sigaltstack (&ss, NULL);
859 dnl FIXME: Put in some more known values into the third argument.
860 SV_TRY_LEAVE_HANDLER_LONGJMP([ and setcontext],
861 sv_cv_leave_handler_longjmp_setcontext,
862 [*-*-kfreebsd* | *-*-irix* | *-*-solaris*],
863 [#include <ucontext.h>
865 #define SS_ONSTACK SA_ONSTACK
869 static ucontext_t uc;
871 if (getcontext (&uc) >= 0)
873 if (uc.uc_stack.ss_flags & SS_ONSTACK)
875 uc.uc_stack.ss_flags &= ~SS_ONSTACK;
881 # End of MacOS X special casing.
885 # How to siglongjmp out of a signal handler, in such a way that the
886 # alternate signal stack remains functional.
888 # On MacOS X 10.2 or newer, we don't need these tests, because we'll end up
889 # using handler-macos.c anyway. If we were to perform the tests, 2 Crash Report
890 # dialog windows would pop up.
892 macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*) ;;
895 dnl FIXME: Put in some more known values into the third argument.
896 SV_TRY_LEAVE_HANDLER_SIGLONGJMP([], sv_cv_leave_handler_siglongjmp,
897 [*-*-kfreebsd* | *-*-osf[4-9]* | *-*-hpux11* | *-*-linux2.[2-9]* | *-*-irix* | *-*-solaris*],
900 dnl FIXME: Put in some more known values into the third argument.
901 SV_TRY_LEAVE_HANDLER_SIGLONGJMP([ and sigaltstack],
902 sv_cv_leave_handler_siglongjmp_sigaltstack,
903 [*-*-freebsd* | *-*-kfreebsd*],
906 #define SS_ONSTACK SA_ONSTACK
910 if (sigaltstack (NULL, &ss) >= 0)
912 ss.ss_flags &= ~SS_ONSTACK;
913 sigaltstack (&ss, NULL);
917 dnl FIXME: Put in some more known values into the third argument.
918 SV_TRY_LEAVE_HANDLER_SIGLONGJMP([ and setcontext],
919 sv_cv_leave_handler_siglongjmp_setcontext,
921 [#include <ucontext.h>
923 #define SS_ONSTACK SA_ONSTACK
927 static ucontext_t uc;
929 if (getcontext(&uc) >= 0)
931 if (uc.uc_stack.ss_flags & SS_ONSTACK)
933 uc.uc_stack.ss_flags &= ~SS_ONSTACK;
939 # End of MacOS X special casing.
944 if test "$sv_cv_leave_handler_longjmp" != no; then
945 CFG_LEAVE=leave-nop.c
947 if test "$sv_cv_leave_handler_longjmp_sigaltstack" != no; then
948 CFG_LEAVE=leave-sigaltstack.c
950 if test "$sv_cv_leave_handler_longjmp_setcontext" != no; then
951 CFG_LEAVE=leave-setcontext.c
956 # On BeOS, the 6 tests fail because sigaltstack() doesn't exist.
957 # If one uses set_signal_stack() instead of sigaltstack(), the first
958 # test actually works. i.e. sv_cv_leave_handler_longjmp would be 'yes'.
959 beos*) CFG_LEAVE=leave-nop.c ;;
961 if test -z "$CFG_LEAVE"; then
962 CFG_LEAVE=leave-none.c
964 AC_DEFINE_UNQUOTED([CFG_LEAVE], ["$CFG_LEAVE"],
965 [The name of the file implementing sigsegv_reset_onstack_flag.])
966 AC_SUBST([CFG_LEAVE])
968 dnl =========================== Done with CFG_LEAVE ===========================
971 dnl ================= Determine HAVE_STACK_OVERFLOW_RECOVERY =================
972 dnl Requires AC_CANONICAL_HOST, CFG_HANDLER / CFG_FAULT / etc., CFG_STACKVMA,
975 AC_CACHE_CHECK([if the system supports catching stack overflow],
976 [sv_cv_have_stack_overflow_recovery],
978 dnl On Mach, it requires a machfault-*.h (see src/handler-macos.c).
979 dnl On Unix, it requires either sigaltstack() or the BeOS set_signal_stack()
980 dnl function, and the ability to longjmp out of the signal handler, and on
981 dnl Unix it also requires a fault-*.h or a stackvma-*.c with certain
982 dnl properties (see src/handler-unix.c).
983 if test "$CFG_MACHFAULT" != fault-none.h; then
984 sv_cv_have_stack_overflow_recovery=yes
987 mingw* | windows* | cygwin*) sv_cv_have_stack_overflow_recovery=yes ;;
989 if test "$CFG_LEAVE" != 'leave-none.c'; then
990 if test "$sv_cv_sigaltstack" != no; then
991 sv_cv_have_stack_overflow_recovery=maybe
994 beos*) sv_cv_have_stack_overflow_recovery=maybe ;;
995 *) sv_cv_have_stack_overflow_recovery=no ;;
999 sv_cv_have_stack_overflow_recovery=no
1004 if test $sv_cv_have_stack_overflow_recovery = maybe; then
1005 if test -n "$CFG_FAULT"; then
1006 AC_EGREP_CPP([xyzzy], [
1007 #include "$srcdir/src/$CFG_FAULT"
1008 #ifdef SIGSEGV_FAULT_HANDLER_ARGLIST
1009 #ifdef SIGSEGV_FAULT_ADDRESS
1013 ], [condA=true], [condA=false])
1017 if test -n "$CFG_FAULT"; then
1018 AC_EGREP_CPP([xyzzy], [
1019 #include "$srcdir/src/$CFG_FAULT"
1020 #ifdef SIGSEGV_FAULT_HANDLER_ARGLIST
1021 #ifdef SIGSEGV_FAULT_STACKPOINTER
1025 ], [condB=true], [condB=false])
1029 if test "$CFG_STACKVMA" != "stackvma-none.c"; then
1034 if { $condA && $condB; } || { $condA && $condC; } || { $condB && $condC; }; then
1035 sv_cv_have_stack_overflow_recovery=yes
1037 sv_cv_have_stack_overflow_recovery=no
1041 if test $sv_cv_have_stack_overflow_recovery != no; then
1042 HAVE_STACK_OVERFLOW_RECOVERY=1
1044 HAVE_STACK_OVERFLOW_RECOVERY=0
1046 AC_SUBST([HAVE_STACK_OVERFLOW_RECOVERY])
1048 dnl ================= Done with HAVE_STACK_OVERFLOW_RECOVERY =================
1051 dnl ======================= Determine CFG_HANDLER fully =======================
1052 dnl Requires AC_CANONICAL_HOST, CFG_HANDLER / CFG_FAULT / etc.,
1053 dnl HAVE_SIGSEGV_RECOVERY, HAVE_STACK_OVERFLOW_RECOVERY.
1056 mingw* | windows*) CFG_HANDLER=handler-win32.c ;;
1058 if test "$enable_support_old_cygwin" = yes; then
1059 CFG_HANDLER=handler-win32.c
1063 if test -z "$CFG_HANDLER"; then
1064 if test $sv_cv_have_sigsegv_recovery = no \
1065 && test $sv_cv_have_stack_overflow_recovery = no; then
1066 CFG_HANDLER=handler-none.c
1068 CFG_HANDLER=handler-unix.c
1071 AC_DEFINE_UNQUOTED([CFG_HANDLER], ["$CFG_HANDLER"],
1072 [The name of the file implementing the handler functionality.])
1073 AC_SUBST([CFG_HANDLER])
1075 dnl ======================= Done with CFG_HANDLER fully =======================
1077 dnl Test whether to enable Cygwin specific tests.
1078 AM_CONDITIONAL([CYGWIN],
1084 dnl Test whether to make system calls fail with error EFAULT.
1085 dnl More precisely: whether passing invalid memory accesses to system calls
1086 dnl should make the system call fail with error EFAULT, rather than invoking
1087 dnl the signal handler.
1088 dnl It is necessary on Cygwin: otherwise the cygwin1 test fails.
1090 cygwin*) enable_EFAULT=yes ;;
1091 *) enable_EFAULT=no ;;
1093 if test $enable_EFAULT = yes; then
1094 AC_DEFINE([ENABLE_EFAULT], [1],
1095 [Define to 1 if attempting to make system calls fail with error EFAULT])
1097 AM_CONDITIONAL([ENABLE_EFAULT], [test $enable_EFAULT = yes])
1099 if test $enable_EFAULT = yes; then
1104 dnl Test for features used in tests.
1108 { echo; echo "${term_bold}Build Parameters:${term_norm}"; } >& AS_MESSAGE_FD
1110 dnl Relocatability is a nop for this package.
1113 { echo; echo "${term_bold}Output Substitution:${term_norm}"; } >& AS_MESSAGE_FD
1115 dnl AC_CONFIG_FILES([Makefile])
1116 AC_CONFIG_FILES([Makefile
1117 src/Makefile src/sigsegv.h
1120 { echo; echo "Now please type '${term_bold}make${term_norm}' to compile. Good luck."; echo; } >& AS_MESSAGE_FD