/* Stack overflow handling.
- Copyright (C) 2002, 2004, 2006, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004, 2006, 2008, 2009 Free Software
+ Foundation, Inc.
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
#define _(msgid) gettext (msgid)
#include <errno.h>
-#ifndef ENOTSUP
-# define ENOTSUP EINVAL
-#endif
#include <signal.h>
#if ! HAVE_STACK_T && ! defined stack_t
#endif
#include <unistd.h>
-#ifndef STDERR_FILENO
-# define STDERR_FILENO 2
-#endif
#if HAVE_LIBSIGSEGV
# include <sigsegv.h>
# define SIGACTION_WORKS 1
#else
# define SIGACTION_WORKS 0
+# ifndef SA_ONSTACK
+# define SA_ONSTACK 0
+# endif
#endif
extern char *program_name;
void *context __attribute__ ((unused)))
{
/* Clear SIGNO if it seems to have been a stack overflow. */
- if (0 < info->si_code)
- {
# if ! HAVE_XSI_STACK_OVERFLOW_HEURISTIC
- /* We can't easily determine whether it is a stack overflow; so
- assume that the rest of our program is perfect (!) and that
- this segmentation violation is a stack overflow.
-
- Note that although both Linux and Solaris provide
- sigaltstack, SA_ONSTACK, and SA_SIGINFO, currently only
- Solaris satisfies the XSI heueristic. This is because
- Solaris populates uc_stack with the details of the
- interrupted stack, while Linux populates it with the details
- of the current stack. */
- signo = 0;
+ /* We can't easily determine whether it is a stack overflow; so
+ assume that the rest of our program is perfect (!) and that
+ this segmentation violation is a stack overflow.
+
+ Note that although both Linux and Solaris provide
+ sigaltstack, SA_ONSTACK, and SA_SIGINFO, currently only
+ Solaris satisfies the XSI heueristic. This is because
+ Solaris populates uc_stack with the details of the
+ interrupted stack, while Linux populates it with the details
+ of the current stack. */
+ signo = 0;
# else
+ if (0 < info->si_code)
+ {
/* If the faulting address is within the stack, or within one
page of the stack end, assume that it is a stack
overflow. */
write (STDERR_FILENO, buf, strlen (buf));
}
# endif
-# endif
}
+# endif
die (signo);
}
act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND | SA_SIGINFO;
act.sa_sigaction = segv_handler;
# else
- act.sa_flags = SA_NODEFER | SA_RESETHAND;
+ act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND;
act.sa_handler = die;
# endif