aboutsummaryrefslogtreecommitdiffstats
path: root/libsigsegv/tests
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2010-07-16 14:52:31 +0300
committerArnold D. Robbins <arnold@skeeve.com>2010-07-16 14:52:31 +0300
commit3ba50a15ebd976f7a88393e2e45dc14b6478b9a9 (patch)
tree6a6bbe6bed1141051fefe94b2d39eacd4854235a /libsigsegv/tests
parent6a2caf2157d87b4b582b2494bdd7d6a688dd0b1f (diff)
downloadegawk-3ba50a15ebd976f7a88393e2e45dc14b6478b9a9.tar.gz
egawk-3ba50a15ebd976f7a88393e2e45dc14b6478b9a9.tar.bz2
egawk-3ba50a15ebd976f7a88393e2e45dc14b6478b9a9.zip
Move to gawk-3.1.7.
Diffstat (limited to 'libsigsegv/tests')
-rw-r--r--libsigsegv/tests/Makefile.am34
-rw-r--r--libsigsegv/tests/Makefile.in612
-rw-r--r--libsigsegv/tests/mmaputil.h105
-rw-r--r--libsigsegv/tests/sigsegv1.c111
-rw-r--r--libsigsegv/tests/sigsegv2.c150
-rw-r--r--libsigsegv/tests/sigsegv3.c134
-rw-r--r--libsigsegv/tests/stackoverflow1.c147
-rw-r--r--libsigsegv/tests/stackoverflow2.c198
8 files changed, 1491 insertions, 0 deletions
diff --git a/libsigsegv/tests/Makefile.am b/libsigsegv/tests/Makefile.am
new file mode 100644
index 00000000..45615fed
--- /dev/null
+++ b/libsigsegv/tests/Makefile.am
@@ -0,0 +1,34 @@
+## Makefile for libsigsegv/tests.
+## Copyright (C) 2002-2003, 2008-2009 Bruno Haible <bruno@clisp.org>
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+## USA.
+
+## Process this file with automake to produce Makefile.in.
+
+AUTOMAKE_OPTIONS = 1.11 gnits no-dependencies color-tests
+
+TESTS = sigsegv1 sigsegv2 sigsegv3 stackoverflow1 stackoverflow2
+
+EXTRA_DIST = mmaputil.h
+
+INCLUDES = -I../src
+DEFS = @DEFS@
+LDADD = ../src/libsigsegv.la
+noinst_PROGRAMS = sigsegv1 sigsegv2 sigsegv3 stackoverflow1 stackoverflow2
+
+# The following rule is necessary to avoid a toplevel "make -n" failure.
+../src/libsigsegv.la :
+ cd ../src && $(MAKE) libsigsegv.la
diff --git a/libsigsegv/tests/Makefile.in b/libsigsegv/tests/Makefile.in
new file mode 100644
index 00000000..91dc9e24
--- /dev/null
+++ b/libsigsegv/tests/Makefile.in
@@ -0,0 +1,612 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+TESTS = sigsegv1$(EXEEXT) sigsegv2$(EXEEXT) sigsegv3$(EXEEXT) \
+ stackoverflow1$(EXEEXT) stackoverflow2$(EXEEXT)
+noinst_PROGRAMS = sigsegv1$(EXEEXT) sigsegv2$(EXEEXT) \
+ sigsegv3$(EXEEXT) stackoverflow1$(EXEEXT) \
+ stackoverflow2$(EXEEXT)
+subdir = tests
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/bold.m4 \
+ $(top_srcdir)/m4/fault.m4 $(top_srcdir)/m4/getpagesize.m4 \
+ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
+ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+ $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/mmap-anon.m4 \
+ $(top_srcdir)/m4/relocatable.m4 \
+ $(top_srcdir)/m4/sigaltstack-longjmp.m4 \
+ $(top_srcdir)/m4/sigaltstack-siglongjmp.m4 \
+ $(top_srcdir)/m4/sigaltstack.m4 $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+PROGRAMS = $(noinst_PROGRAMS)
+sigsegv1_SOURCES = sigsegv1.c
+sigsegv1_OBJECTS = sigsegv1.$(OBJEXT)
+sigsegv1_LDADD = $(LDADD)
+sigsegv1_DEPENDENCIES = ../src/libsigsegv.la
+sigsegv2_SOURCES = sigsegv2.c
+sigsegv2_OBJECTS = sigsegv2.$(OBJEXT)
+sigsegv2_LDADD = $(LDADD)
+sigsegv2_DEPENDENCIES = ../src/libsigsegv.la
+sigsegv3_SOURCES = sigsegv3.c
+sigsegv3_OBJECTS = sigsegv3.$(OBJEXT)
+sigsegv3_LDADD = $(LDADD)
+sigsegv3_DEPENDENCIES = ../src/libsigsegv.la
+stackoverflow1_SOURCES = stackoverflow1.c
+stackoverflow1_OBJECTS = stackoverflow1.$(OBJEXT)
+stackoverflow1_LDADD = $(LDADD)
+stackoverflow1_DEPENDENCIES = ../src/libsigsegv.la
+stackoverflow2_SOURCES = stackoverflow2.c
+stackoverflow2_OBJECTS = stackoverflow2.$(OBJEXT)
+stackoverflow2_LDADD = $(LDADD)
+stackoverflow2_DEPENDENCIES = ../src/libsigsegv.la
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp =
+am__depfiles_maybe =
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+ $(LDFLAGS) -o $@
+SOURCES = sigsegv1.c sigsegv2.c sigsegv3.c stackoverflow1.c \
+ stackoverflow2.c
+DIST_SOURCES = sigsegv1.c sigsegv2.c sigsegv3.c stackoverflow1.c \
+ stackoverflow2.c
+ETAGS = etags
+CTAGS = ctags
+# If stdout is a non-dumb tty, use colors. If test -t is not supported,
+# then this fails; a conservative approach. Of course do not redirect
+# stdout here, just stderr.
+am__tty_colors = \
+red=; grn=; lgn=; blu=; std=; \
+test "X$(AM_COLOR_TESTS)" != Xno \
+&& test "X$$TERM" != Xdumb \
+&& { test "X$(AM_COLOR_TESTS)" = Xalways || test -t 1 2>/dev/null; } \
+&& { \
+ red=''; \
+ grn=''; \
+ lgn=''; \
+ blu=''; \
+ std=''; \
+}
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFG_HANDLER = @CFG_HANDLER@
+CFG_LEAVE = @CFG_LEAVE@
+CFG_STACKVMA = @CFG_STACKVMA@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FAULT_CONTEXT = @FAULT_CONTEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+HAVE_SIGSEGV_RECOVERY = @HAVE_SIGSEGV_RECOVERY@
+HAVE_STACK_OVERFLOW_RECOVERY = @HAVE_STACK_OVERFLOW_RECOVERY@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PLATFORM = @PLATFORM@
+RANLIB = @RANLIB@
+RELOCATABLE = @RELOCATABLE@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AUTOMAKE_OPTIONS = 1.11 gnits no-dependencies color-tests
+EXTRA_DIST = mmaputil.h
+INCLUDES = -I../src
+LDADD = ../src/libsigsegv.la
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnits tests/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --gnits tests/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstPROGRAMS:
+ @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \
+ echo " rm -f" $$list; \
+ rm -f $$list || exit $$?; \
+ test -n "$(EXEEXT)" || exit 0; \
+ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f" $$list; \
+ rm -f $$list
+sigsegv1$(EXEEXT): $(sigsegv1_OBJECTS) $(sigsegv1_DEPENDENCIES)
+ @rm -f sigsegv1$(EXEEXT)
+ $(LINK) $(sigsegv1_OBJECTS) $(sigsegv1_LDADD) $(LIBS)
+sigsegv2$(EXEEXT): $(sigsegv2_OBJECTS) $(sigsegv2_DEPENDENCIES)
+ @rm -f sigsegv2$(EXEEXT)
+ $(LINK) $(sigsegv2_OBJECTS) $(sigsegv2_LDADD) $(LIBS)
+sigsegv3$(EXEEXT): $(sigsegv3_OBJECTS) $(sigsegv3_DEPENDENCIES)
+ @rm -f sigsegv3$(EXEEXT)
+ $(LINK) $(sigsegv3_OBJECTS) $(sigsegv3_LDADD) $(LIBS)
+stackoverflow1$(EXEEXT): $(stackoverflow1_OBJECTS) $(stackoverflow1_DEPENDENCIES)
+ @rm -f stackoverflow1$(EXEEXT)
+ $(LINK) $(stackoverflow1_OBJECTS) $(stackoverflow1_LDADD) $(LIBS)
+stackoverflow2$(EXEEXT): $(stackoverflow2_OBJECTS) $(stackoverflow2_DEPENDENCIES)
+ @rm -f stackoverflow2$(EXEEXT)
+ $(LINK) $(stackoverflow2_OBJECTS) $(stackoverflow2_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+.c.o:
+ $(COMPILE) -c $<
+
+.c.obj:
+ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+ $(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ set x; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+check-TESTS: $(TESTS)
+ @failed=0; all=0; xfail=0; xpass=0; skip=0; \
+ srcdir=$(srcdir); export srcdir; \
+ list=' $(TESTS) '; \
+ $(am__tty_colors); \
+ if test -n "$$list"; then \
+ for tst in $$list; do \
+ if test -f ./$$tst; then dir=./; \
+ elif test -f $$tst; then dir=; \
+ else dir="$(srcdir)/"; fi; \
+ if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *[\ \ ]$$tst[\ \ ]*) \
+ xpass=`expr $$xpass + 1`; \
+ failed=`expr $$failed + 1`; \
+ col=$$red; res=XPASS; \
+ ;; \
+ *) \
+ col=$$grn; res=PASS; \
+ ;; \
+ esac; \
+ elif test $$? -ne 77; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *[\ \ ]$$tst[\ \ ]*) \
+ xfail=`expr $$xfail + 1`; \
+ col=$$lgn; res=XFAIL; \
+ ;; \
+ *) \
+ failed=`expr $$failed + 1`; \
+ col=$$red; res=FAIL; \
+ ;; \
+ esac; \
+ else \
+ skip=`expr $$skip + 1`; \
+ col=$$blu; res=SKIP; \
+ fi; \
+ echo "$${col}$$res$${std}: $$tst"; \
+ done; \
+ if test "$$all" -eq 1; then \
+ tests="test"; \
+ All=""; \
+ else \
+ tests="tests"; \
+ All="All "; \
+ fi; \
+ if test "$$failed" -eq 0; then \
+ if test "$$xfail" -eq 0; then \
+ banner="$$All$$all $$tests passed"; \
+ else \
+ if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \
+ banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \
+ fi; \
+ else \
+ if test "$$xpass" -eq 0; then \
+ banner="$$failed of $$all $$tests failed"; \
+ else \
+ if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \
+ banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \
+ fi; \
+ fi; \
+ dashes="$$banner"; \
+ skipped=""; \
+ if test "$$skip" -ne 0; then \
+ if test "$$skip" -eq 1; then \
+ skipped="($$skip test was not run)"; \
+ else \
+ skipped="($$skip tests were not run)"; \
+ fi; \
+ test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
+ dashes="$$skipped"; \
+ fi; \
+ report=""; \
+ if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
+ report="Please report to $(PACKAGE_BUGREPORT)"; \
+ test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
+ dashes="$$report"; \
+ fi; \
+ dashes=`echo "$$dashes" | sed s/./=/g`; \
+ if test "$$failed" -eq 0; then \
+ echo "$$grn$$dashes"; \
+ else \
+ echo "$$red$$dashes"; \
+ fi; \
+ echo "$$banner"; \
+ test -z "$$skipped" || echo "$$skipped"; \
+ test -z "$$report" || echo "$$report"; \
+ echo "$$dashes$$std"; \
+ test "$$failed" -eq 0; \
+ else :; fi
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+ $(MAKE) $(AM_MAKEFLAGS) check-TESTS
+check: check-am
+all-am: Makefile $(PROGRAMS)
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: check-am install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \
+ clean-generic clean-libtool clean-noinstPROGRAMS ctags \
+ distclean distclean-compile distclean-generic \
+ distclean-libtool distclean-tags distdir dvi dvi-am html \
+ html-am info info-am install install-am install-data \
+ install-data-am install-dvi install-dvi-am install-exec \
+ install-exec-am install-html install-html-am install-info \
+ install-info-am install-man install-pdf install-pdf-am \
+ install-ps install-ps-am install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags uninstall uninstall-am
+
+
+# The following rule is necessary to avoid a toplevel "make -n" failure.
+../src/libsigsegv.la :
+ cd ../src && $(MAKE) libsigsegv.la
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/libsigsegv/tests/mmaputil.h b/libsigsegv/tests/mmaputil.h
new file mode 100644
index 00000000..707b34c5
--- /dev/null
+++ b/libsigsegv/tests/mmaputil.h
@@ -0,0 +1,105 @@
+/* Some auxiliary stuff for using mmap & friends.
+ Copyright (C) 2002-2003 Bruno Haible <bruno@clisp.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#if defined _WIN32 && !defined __CYGWIN__
+# define HAVE_WIN32_VM
+#else
+# include "config.h"
+#endif
+
+#ifdef HAVE_WIN32_VM
+
+/* ------------------------ Windows ------------------------ */
+
+#define WIN32_LEAN_AND_MEAN /* avoid including junk */
+#include <windows.h>
+#include <winerror.h>
+#define PROT_NONE PAGE_NOACCESS
+#define PROT_READ PAGE_READONLY
+#define PROT_READ_WRITE PAGE_READWRITE
+
+static void *
+mmap_zeromap (void *map_addr_hint, unsigned long map_len)
+{
+ if (VirtualAlloc ((void *)((unsigned long) map_addr_hint & -0x10000),
+ (((unsigned long) map_addr_hint + map_len - 1) | 0xffff) + 1
+ - ((unsigned long) map_addr_hint & -0x10000),
+ MEM_RESERVE, PAGE_NOACCESS)
+ && VirtualAlloc (map_addr_hint, map_len, MEM_COMMIT, PAGE_READWRITE))
+ return map_addr_hint;
+ else
+ return (void *)(-1);
+}
+
+int munmap (void *addr, unsigned long len)
+{
+ if (VirtualFree (addr, len, MEM_DECOMMIT))
+ return 0;
+ else
+ return -1;
+}
+
+int mprotect (void *addr, unsigned long len, int prot)
+{
+ DWORD oldprot;
+
+ if (VirtualProtect (addr, len, prot, &oldprot))
+ return 0;
+ else
+ return -1;
+}
+
+#else
+
+/* ------------------------ Unix ------------------------ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+
+#ifndef PROT_NONE
+# define PROT_NONE 0
+#endif
+#define PROT_READ_WRITE (PROT_READ|PROT_WRITE)
+
+#if HAVE_MMAP_ANON
+# define zero_fd -1
+# define map_flags MAP_ANON | MAP_PRIVATE
+#elif HAVE_MMAP_ANONYMOUS
+# define zero_fd -1
+# define map_flags MAP_ANONYMOUS | MAP_PRIVATE
+#elif HAVE_MMAP_DEVZERO
+# include <fcntl.h>
+# ifndef MAP_FILE
+# define MAP_FILE 0
+# endif
+static int zero_fd;
+# define map_flags MAP_FILE | MAP_PRIVATE
+#endif
+
+static void *
+mmap_zeromap (void *map_addr_hint, unsigned long map_len)
+{
+#ifdef __hpux
+ /* HP-UX 10 mmap() often fails when given a hint. So give the OS complete
+ freedom about the address range. */
+ return (void *) mmap ((void *) 0, map_len, PROT_READ_WRITE, map_flags, zero_fd, 0);
+#else
+ return (void *) mmap (map_addr_hint, map_len, PROT_READ_WRITE, map_flags, zero_fd, 0);
+#endif
+}
+
+#endif
diff --git a/libsigsegv/tests/sigsegv1.c b/libsigsegv/tests/sigsegv1.c
new file mode 100644
index 00000000..ce006428
--- /dev/null
+++ b/libsigsegv/tests/sigsegv1.c
@@ -0,0 +1,111 @@
+/* Test that the handler is called, with the right fault address.
+ Copyright (C) 2002-2006, 2008 Bruno Haible <bruno@clisp.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#ifndef _MSC_VER
+# include <config.h>
+#endif
+
+#include "sigsegv.h"
+#include <stdio.h>
+
+#if HAVE_SIGSEGV_RECOVERY
+
+#include "mmaputil.h"
+#include <stdlib.h>
+
+unsigned long page;
+
+volatile int handler_called = 0;
+
+int
+handler (void *fault_address, int serious)
+{
+ handler_called++;
+ if (handler_called > 10)
+ abort ();
+ if (fault_address != (void *)(page + 0x678))
+ abort ();
+ if (mprotect ((void *) page, 0x4000, PROT_READ_WRITE) == 0)
+ return 1;
+ return 0;
+}
+
+void
+crasher (unsigned long p)
+{
+ *(volatile int *) (p + 0x678) = 42;
+}
+
+int
+main ()
+{
+ void *p;
+
+ /* Preparations. */
+#if !HAVE_MMAP_ANON && !HAVE_MMAP_ANONYMOUS && HAVE_MMAP_DEVZERO
+ zero_fd = open ("/dev/zero", O_RDONLY, 0644);
+#endif
+
+ /* Setup some mmaped memory. */
+ p = mmap_zeromap ((void *) 0x12340000, 0x4000);
+ if (p == (void *)(-1))
+ {
+ fprintf (stderr, "mmap_zeromap failed.\n");
+ exit (2);
+ }
+ page = (unsigned long) p;
+
+ /* Make it read-only. */
+ if (mprotect ((void *) page, 0x4000, PROT_READ) < 0)
+ {
+ fprintf (stderr, "mprotect failed.\n");
+ exit (2);
+ }
+ /* Test whether it's possible to make it read-write after it was read-only.
+ This is not possible on Cygwin. */
+ if (mprotect ((void *) page, 0x4000, PROT_READ_WRITE) < 0
+ || mprotect ((void *) page, 0x4000, PROT_READ) < 0)
+ {
+ fprintf (stderr, "mprotect failed.\n");
+ exit (2);
+ }
+
+ /* Install the SIGSEGV handler. */
+ sigsegv_install_handler (&handler);
+
+ /* The first write access should invoke the handler and then complete. */
+ crasher (page);
+ /* The second write access should not invoke the handler. */
+ crasher (page);
+
+ /* Check that the handler was called only once. */
+ if (handler_called != 1)
+ exit (1);
+ /* Test passed! */
+ printf ("Test passed.\n");
+ return 0;
+}
+
+#else
+
+int
+main ()
+{
+ return 77;
+}
+
+#endif
diff --git a/libsigsegv/tests/sigsegv2.c b/libsigsegv/tests/sigsegv2.c
new file mode 100644
index 00000000..39961a6a
--- /dev/null
+++ b/libsigsegv/tests/sigsegv2.c
@@ -0,0 +1,150 @@
+/* Test the dispatcher.
+ Copyright (C) 2002-2006, 2008 Bruno Haible <bruno@clisp.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#ifndef _MSC_VER
+# include <config.h>
+#endif
+
+#include "sigsegv.h"
+#include <stdio.h>
+
+#if HAVE_SIGSEGV_RECOVERY
+
+#include "mmaputil.h"
+#include <stdlib.h>
+
+static sigsegv_dispatcher dispatcher;
+
+static volatile unsigned int logcount = 0;
+static volatile unsigned long logdata[10];
+
+static int
+area_handler (void *fault_address, void *user_arg)
+{
+ unsigned long area = *(unsigned long *)user_arg;
+ logdata[logcount++] = area;
+ if (logcount >= sizeof (logdata) / sizeof (logdata[0]))
+ abort ();
+ if (!((unsigned long)fault_address >= area
+ && (unsigned long)fault_address - area < 0x4000))
+ abort ();
+ if (mprotect ((void *) area, 0x4000, PROT_READ_WRITE) == 0)
+ return 1;
+ return 0;
+}
+
+static int
+handler (void *fault_address, int serious)
+{
+ return sigsegv_dispatch (&dispatcher, fault_address);
+}
+
+static void
+barrier ()
+{
+}
+
+int
+main ()
+{
+ void *p;
+ unsigned long area1;
+ unsigned long area2;
+ unsigned long area3;
+
+ /* Preparations. */
+#if !HAVE_MMAP_ANON && !HAVE_MMAP_ANONYMOUS && HAVE_MMAP_DEVZERO
+ zero_fd = open ("/dev/zero", O_RDONLY, 0644);
+#endif
+ sigsegv_init (&dispatcher);
+ sigsegv_install_handler (&handler);
+
+ /* Setup some mmaped memory. */
+
+ p = mmap_zeromap ((void *) 0x12340000, 0x4000);
+ if (p == (void *)(-1))
+ {
+ fprintf (stderr, "mmap_zeromap failed.\n");
+ exit (2);
+ }
+ area1 = (unsigned long) p;
+ sigsegv_register (&dispatcher, (void *) area1, 0x4000, &area_handler, &area1);
+ if (mprotect ((void *) area1, 0x4000, PROT_NONE) < 0)
+ {
+ fprintf (stderr, "mprotect failed.\n");
+ exit (2);
+ }
+
+ p = mmap_zeromap ((void *) 0x0BEE0000, 0x4000);
+ if (p == (void *)(-1))
+ {
+ fprintf (stderr, "mmap_zeromap failed.\n");
+ exit (2);
+ }
+ area2 = (unsigned long) p;
+ sigsegv_register (&dispatcher, (void *) area2, 0x4000, &area_handler, &area2);
+ if (mprotect ((void *) area2, 0x4000, PROT_READ) < 0)
+ {
+ fprintf (stderr, "mprotect failed.\n");
+ exit (2);
+ }
+ if (mprotect ((void *) area2, 0x4000, PROT_READ_WRITE) < 0
+ || mprotect ((void *) area2, 0x4000, PROT_READ) < 0)
+ {
+ fprintf (stderr, "mprotect failed.\n");
+ exit (2);
+ }
+
+ p = mmap_zeromap ((void *) 0x06990000, 0x4000);
+ if (p == (void *)(-1))
+ {
+ fprintf (stderr, "mmap_zeromap failed.\n");
+ exit (2);
+ }
+ area3 = (unsigned long) p;
+ sigsegv_register (&dispatcher, (void *) area3, 0x4000, &area_handler, &area3);
+ mprotect ((void *) area3, 0x4000, PROT_READ);
+
+ /* This access should call the handler. */
+ ((volatile int *)area2)[230] = 22;
+ /* This access should call the handler. */
+ ((volatile int *)area3)[412] = 33;
+ /* This access should not give a signal. */
+ ((volatile int *)area2)[135] = 22;
+ /* This access should call the handler. */
+ ((volatile int *)area1)[612] = 11;
+
+ barrier();
+
+ /* Check that the handler was called three times. */
+ if (logcount != 3)
+ exit (1);
+ if (!(logdata[0] == area2 && logdata[1] == area3 && logdata[2] == area1))
+ exit (1);
+ printf ("Test passed.\n");
+ return 0;
+}
+
+#else
+
+int
+main ()
+{
+ return 77;
+}
+
+#endif
diff --git a/libsigsegv/tests/sigsegv3.c b/libsigsegv/tests/sigsegv3.c
new file mode 100644
index 00000000..1ea0ec40
--- /dev/null
+++ b/libsigsegv/tests/sigsegv3.c
@@ -0,0 +1,134 @@
+/* Test that the handler can be exited multiple times.
+ Copyright (C) 2002-2006, 2008 Bruno Haible <bruno@clisp.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#ifndef _MSC_VER
+# include <config.h>
+#endif
+
+#include "sigsegv.h"
+#include <stdio.h>
+
+#if HAVE_SIGSEGV_RECOVERY
+
+#if defined _WIN32 && !defined __CYGWIN__
+ /* Windows doesn't have sigset_t. */
+ typedef int sigset_t;
+# define sigemptyset(set)
+# define sigprocmask(how,set,oldset)
+#endif
+
+#include "mmaputil.h"
+#include <stdlib.h> /* for abort, exit */
+#include <signal.h>
+#include <setjmp.h>
+
+jmp_buf mainloop;
+sigset_t mainsigset;
+
+volatile int pass = 0;
+unsigned long page;
+
+volatile int handler_called = 0;
+
+static void
+handler_continuation (void *arg1, void *arg2, void *arg3)
+{
+ longjmp (mainloop, pass);
+}
+
+int
+handler (void *fault_address, int serious)
+{
+ handler_called++;
+ if (handler_called > 10)
+ abort ();
+ if (fault_address != (void *)(page + 0x678 + 8 * pass))
+ abort ();
+ pass++;
+ printf ("Stack overflow %d caught.\n", pass);
+ sigprocmask (SIG_SETMASK, &mainsigset, NULL);
+ return sigsegv_leave_handler (handler_continuation, NULL, NULL, NULL);
+}
+
+void
+crasher (unsigned long p)
+{
+ *(volatile int *) (p + 0x678 + 8 * pass) = 42;
+}
+
+int
+main ()
+{
+ sigset_t emptyset;
+ void *p;
+
+ /* Preparations. */
+#if !HAVE_MMAP_ANON && !HAVE_MMAP_ANONYMOUS && HAVE_MMAP_DEVZERO
+ zero_fd = open ("/dev/zero", O_RDONLY, 0644);
+#endif
+
+ /* Setup some mmaped memory. */
+ p = mmap_zeromap ((void *) 0x12340000, 0x4000);
+ if (p == (void *)(-1))
+ {
+ fprintf (stderr, "mmap_zeromap failed.\n");
+ exit (2);
+ }
+ page = (unsigned long) p;
+
+ /* Make it read-only. */
+ if (mprotect ((void *) page, 0x4000, PROT_READ) < 0)
+ {
+ fprintf (stderr, "mprotect failed.\n");
+ exit (2);
+ }
+
+ /* Install the SIGSEGV handler. */
+ if (sigsegv_install_handler (&handler) < 0)
+ exit (2);
+
+ /* Save the current signal mask. */
+ sigemptyset (&emptyset);
+ sigprocmask (SIG_BLOCK, &emptyset, &mainsigset);
+
+ /* Provoke two SIGSEGVs in a row. */
+ switch (setjmp (mainloop))
+ {
+ case 0: case 1:
+ printf ("Doing SIGSEGV pass %d.\n", pass + 1);
+ crasher (page);
+ printf ("no SIGSEGV?!\n"); exit (1);
+ case 2:
+ break;
+ default:
+ abort ();
+ }
+
+ /* Test passed! */
+ printf ("Test passed.\n");
+ return 0;
+}
+
+#else
+
+int
+main ()
+{
+ return 77;
+}
+
+#endif
diff --git a/libsigsegv/tests/stackoverflow1.c b/libsigsegv/tests/stackoverflow1.c
new file mode 100644
index 00000000..0970e794
--- /dev/null
+++ b/libsigsegv/tests/stackoverflow1.c
@@ -0,0 +1,147 @@
+/* Test the stack overflow handler.
+ Copyright (C) 2002-2006, 2008 Bruno Haible <bruno@clisp.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#ifndef _MSC_VER
+# include <config.h>
+#endif
+
+#include "sigsegv.h"
+#include <stdio.h>
+#include <limits.h>
+
+#if HAVE_STACK_OVERFLOW_RECOVERY
+
+#if defined _WIN32 && !defined __CYGWIN__
+ /* Windows doesn't have sigset_t. */
+ typedef int sigset_t;
+# define sigemptyset(set)
+# define sigprocmask(how,set,oldset)
+#endif
+
+#include <stddef.h> /* needed for NULL on SunOS4 */
+#include <stdlib.h> /* for abort, exit */
+#include <signal.h>
+#include <setjmp.h>
+#if HAVE_SETRLIMIT
+# include <sys/types.h>
+# include <sys/time.h>
+# include <sys/resource.h>
+#endif
+#ifndef SIGSTKSZ
+# define SIGSTKSZ 16384
+#endif
+
+jmp_buf mainloop;
+sigset_t mainsigset;
+
+volatile int pass = 0;
+
+volatile char *stack_lower_bound;
+volatile char *stack_upper_bound;
+
+static void
+stackoverflow_handler_continuation (void *arg1, void *arg2, void *arg3)
+{
+ int arg = (int) (long) arg1;
+ longjmp (mainloop, arg);
+}
+
+void
+stackoverflow_handler (int emergency, stackoverflow_context_t scp)
+{
+ char dummy;
+ volatile char *addr = &dummy;
+ if (!(addr >= stack_lower_bound && addr <= stack_upper_bound))
+ abort ();
+ pass++;
+ printf ("Stack overflow %d caught.\n", pass);
+ sigprocmask (SIG_SETMASK, &mainsigset, NULL);
+ sigsegv_leave_handler (stackoverflow_handler_continuation,
+ (void *) (long) (emergency ? -1 : pass), NULL, NULL);
+}
+
+volatile int *
+recurse_1 (int n, volatile int *p)
+{
+ if (n < INT_MAX)
+ *recurse_1 (n + 1, p) += n;
+ return p;
+}
+
+int
+recurse (volatile int n)
+{
+ return *recurse_1 (n, &n);
+}
+
+int
+main ()
+{
+ /* glibc says: Users should use SIGSTKSZ as the size of user-supplied
+ buffers. */
+ char mystack[SIGSTKSZ];
+ sigset_t emptyset;
+
+#if HAVE_SETRLIMIT && defined RLIMIT_STACK
+ /* Before starting the endless recursion, try to be friendly to the user's
+ machine. On some Linux 2.2.x systems, there is no stack limit for user
+ processes at all. We don't want to kill such systems. */
+ struct rlimit rl;
+ rl.rlim_cur = rl.rlim_max = 0x100000; /* 1 MB */
+ setrlimit (RLIMIT_STACK, &rl);
+#endif
+
+ /* Install the stack overflow handler. */
+ if (stackoverflow_install_handler (&stackoverflow_handler,
+ mystack, sizeof (mystack))
+ < 0)
+ exit (2);
+ stack_lower_bound = mystack;
+ stack_upper_bound = mystack + sizeof (mystack) - 1;
+
+ /* Save the current signal mask. */
+ sigemptyset (&emptyset);
+ sigprocmask (SIG_BLOCK, &emptyset, &mainsigset);
+
+ /* Provoke two stack overflows in a row. */
+ switch (setjmp (mainloop))
+ {
+ case -1:
+ printf ("emergency exit\n"); exit (1);
+ case 0: case 1:
+ printf ("Starting recursion pass %d.\n", pass + 1);
+ recurse (0);
+ printf ("no endless recursion?!\n"); exit (1);
+ case 2:
+ break;
+ default:
+ abort ();
+ }
+
+ printf ("Test passed.\n");
+ exit (0);
+}
+
+#else
+
+int
+main ()
+{
+ return 77;
+}
+
+#endif
diff --git a/libsigsegv/tests/stackoverflow2.c b/libsigsegv/tests/stackoverflow2.c
new file mode 100644
index 00000000..2475bf21
--- /dev/null
+++ b/libsigsegv/tests/stackoverflow2.c
@@ -0,0 +1,198 @@
+/* Test that stack overflow and SIGSEGV are correctly distinguished.
+ Copyright (C) 2002-2006, 2008 Bruno Haible <bruno@clisp.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#ifndef _MSC_VER
+# include <config.h>
+#endif
+
+#include "sigsegv.h"
+#include <stdio.h>
+#include <limits.h>
+
+#if HAVE_STACK_OVERFLOW_RECOVERY && HAVE_SIGSEGV_RECOVERY
+
+#if defined _WIN32 && !defined __CYGWIN__
+ /* Windows doesn't have sigset_t. */
+ typedef int sigset_t;
+# define sigemptyset(set)
+# define sigprocmask(how,set,oldset)
+#endif
+
+#include "mmaputil.h"
+#include <stddef.h> /* needed for NULL on SunOS4 */
+#include <stdlib.h> /* for abort, exit */
+#include <signal.h>
+#include <setjmp.h>
+#if HAVE_SETRLIMIT
+# include <sys/types.h>
+# include <sys/time.h>
+# include <sys/resource.h>
+#endif
+#ifndef SIGSTKSZ
+# define SIGSTKSZ 16384
+#endif
+
+jmp_buf mainloop;
+sigset_t mainsigset;
+
+volatile int pass = 0;
+unsigned long page;
+
+static void
+stackoverflow_handler_continuation (void *arg1, void *arg2, void *arg3)
+{
+ int arg = (int) (long) arg1;
+ longjmp (mainloop, arg);
+}
+
+void
+stackoverflow_handler (int emergency, stackoverflow_context_t scp)
+{
+ pass++;
+ if (pass <= 2)
+ printf ("Stack overflow %d caught.\n", pass);
+ else
+ {
+ printf ("Segmentation violation misdetected as stack overflow.\n");
+ exit (1);
+ }
+ sigprocmask (SIG_SETMASK, &mainsigset, NULL);
+ sigsegv_leave_handler (stackoverflow_handler_continuation,
+ (void *) (long) (emergency ? -1 : pass), NULL, NULL);
+}
+
+int
+sigsegv_handler (void *address, int emergency)
+{
+ /* This test is necessary to distinguish stack overflow and SIGSEGV. */
+ if (!emergency)
+ return 0;
+
+ pass++;
+ if (pass <= 2)
+ {
+ printf ("Stack overflow %d missed.\n", pass);
+ exit (1);
+ }
+ else
+ printf ("Segmentation violation correctly detected.\n");
+ sigprocmask (SIG_SETMASK, &mainsigset, NULL);
+ return sigsegv_leave_handler (stackoverflow_handler_continuation,
+ (void *) (long) pass, NULL, NULL);
+}
+
+volatile int *
+recurse_1 (int n, volatile int *p)
+{
+ if (n < INT_MAX)
+ *recurse_1 (n + 1, p) += n;
+ return p;
+}
+
+int
+recurse (volatile int n)
+{
+ return *recurse_1 (n, &n);
+}
+
+int
+main ()
+{
+ /* glibc says: Users should use SIGSTKSZ as the size of user-supplied
+ buffers. */
+ char mystack[SIGSTKSZ];
+ sigset_t emptyset;
+ void *p;
+
+#if HAVE_SETRLIMIT && defined RLIMIT_STACK
+ /* Before starting the endless recursion, try to be friendly to the user's
+ machine. On some Linux 2.2.x systems, there is no stack limit for user
+ processes at all. We don't want to kill such systems. */
+ struct rlimit rl;
+ rl.rlim_cur = rl.rlim_max = 0x100000; /* 1 MB */
+ setrlimit (RLIMIT_STACK, &rl);
+#endif
+
+ /* Install the stack overflow handler. */
+ if (stackoverflow_install_handler (&stackoverflow_handler,
+ mystack, sizeof (mystack))
+ < 0)
+ exit (2);
+
+ /* Preparations. */
+#if !HAVE_MMAP_ANON && !HAVE_MMAP_ANONYMOUS && HAVE_MMAP_DEVZERO
+ zero_fd = open ("/dev/zero", O_RDONLY, 0644);
+#endif
+
+ /* Setup some mmaped memory. */
+ p = mmap_zeromap ((void *) 0x12340000, 0x4000);
+ if (p == (void *)(-1))
+ {
+ fprintf (stderr, "mmap_zeromap failed.\n");
+ exit (2);
+ }
+ page = (unsigned long) p;
+
+ /* Make it read-only. */
+ if (mprotect ((void *) page, 0x4000, PROT_READ) < 0)
+ {
+ fprintf (stderr, "mprotect failed.\n");
+ exit (2);
+ }
+
+ /* Install the SIGSEGV handler. */
+ if (sigsegv_install_handler (&sigsegv_handler) < 0)
+ exit (2);
+
+ /* Save the current signal mask. */
+ sigemptyset (&emptyset);
+ sigprocmask (SIG_BLOCK, &emptyset, &mainsigset);
+
+ /* Provoke two stack overflows in a row. */
+ switch (setjmp (mainloop))
+ {
+ case -1:
+ printf ("emergency exit\n"); exit (1);
+ case 0: case 1:
+ printf ("Starting recursion pass %d.\n", pass + 1);
+ recurse (0);
+ printf ("no endless recursion?!\n"); exit (1);
+ case 2:
+ *(volatile int *) (page + 0x678) = 42;
+ break;
+ case 3:
+ *(volatile int *) 0 = 42;
+ break;
+ case 4:
+ break;
+ default:
+ abort ();
+ }
+
+ printf ("Test passed.\n");
+ exit (0);
+}
+
+#else
+
+int
+main ()
+{
+ return 77;
+}
+
+#endif