/* confdefs.h. */ #define PACKAGE_NAME "" #define PACKAGE_TARNAME "" #define PACKAGE_VERSION "" #define PACKAGE_STRING "" #define PACKAGE_BUGREPORT "" #define PACKAGE "libsigsegv" #define VERSION "2.7-pre1" #define STDC_HEADERS 1 #define HAVE_SYS_TYPES_H 1 #define HAVE_SYS_STAT_H 1 #define HAVE_STDLIB_H 1 #define HAVE_STRING_H 1 #define HAVE_MEMORY_H 1 #define HAVE_STRINGS_H 1 #define HAVE_INTTYPES_H 1 #define HAVE_STDINT_H 1 #define HAVE_UNISTD_H 1 #define HAVE_DLFCN_H 1 #define LT_OBJDIR ".libs/" #define HAVE_SYS_SIGNAL_H 1 #define CFG_SIGNALS "signals.h" #define HAVE_UNISTD_H 1 #define HAVE_GETPAGESIZE 1 #define HAVE_SYSCONF_PAGESIZE 1 #define HAVE_MMAP_DEVZERO 1 #define CFG_FAULT "fault-irix-mips.h" #define CFG_MACHFAULT "fault-none.h" #define STACK_DIRECTION -1 #define HAVE_STACKVMA 1 #define CFG_STACKVMA "stackvma-procfs.c" #define HAVE_GETRLIMIT 1 #define HAVE_SETRLIMIT 1 #define HAVE_SIGALTSTACK 1 #define HAVE_WORKING_SIGALTSTACK 1 #define SIGALTSTACK_SS_REVERSED 1 /* end confdefs.h. */ #include #include #include #include #ifndef SS_ONSTACK #define SS_ONSTACK SA_ONSTACK #endif #if HAVE_SETRLIMIT # include # include # include #endif #ifndef SIGSTKSZ # define SIGSTKSZ 16384 #endif sigjmp_buf mainloop; int pass = 0; void stackoverflow_handler (int sig) { pass++; { static int fl; static ucontext_t uc; fl = 0; if (getcontext(&uc) >= 0) if (fl == 0) if (uc.uc_stack.ss_flags & SS_ONSTACK) { uc.uc_stack.ss_flags &= ~SS_ONSTACK; fl = 1; setcontext(&uc); } } siglongjmp (mainloop, pass); } volatile int * recurse_1 (volatile int n, volatile int *p) { if (n >= 0) *recurse_1 (n + 1, p) += n; return p; } int recurse (volatile int n) { int sum = 0; return *recurse_1 (n, &sum); } int main () { char mystack[2 * SIGSTKSZ]; stack_t altstack; struct sigaction action; #ifdef __BEOS__ /* On BeOS, this would hang, burning CPU time. Better fail than hang. */ exit (1); #endif #if defined 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 alternate stack. Use the midpoint of mystack, to guard against a buggy interpretation of ss_sp on IRIX. */ altstack.ss_sp = mystack + SIGSTKSZ; altstack.ss_size = SIGSTKSZ; altstack.ss_flags = 0; /* no SS_DISABLE */ if (sigaltstack (&altstack, NULL) < 0) exit (1); /* Install the SIGSEGV handler. */ sigemptyset (&action.sa_mask); action.sa_handler = &stackoverflow_handler; action.sa_flags = SA_ONSTACK; sigaction (SIGSEGV, &action, (struct sigaction *) NULL); sigaction (SIGBUS, &action, (struct sigaction *) NULL); /* Provoke two stack overflows in a row. */ if (sigsetjmp (mainloop, 1) < 2) { recurse (0); exit (2); } exit (0); }