summaryrefslogtreecommitdiff
path: root/signal.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-27 06:05:07 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-27 06:05:07 +0000
commit7348aa6113cdc2c9ce62044ab83f2ac1db82816d (patch)
tree67f6170252317e0ed1234217f5fb1a80c2592264 /signal.c
parentfc75648baff072ec223d88fdb86b3384e22ea71f (diff)
* gc.c (ruby_stack_check): no check if using sigaltstack.
* signal.c (register_sigaltstack): minimum size is insufficient for method calls. * signal.c (sigsegv): handles stack overflow if possible. * thread.c (ruby_thread_stack_overflow): helper function to raise sysstack_error. * thread_pthread.c (ruby_stack_overflowed_p): checks for stack overflow. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'signal.c')
-rw-r--r--signal.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/signal.c b/signal.c
index b6bb12bec9..df41ddbdfd 100644
--- a/signal.c
+++ b/signal.c
@@ -415,6 +415,7 @@ typedef RETSIGTYPE (*sighandler_t)(int);
#endif
#ifdef USE_SIGALTSTACK
+#define SIGINFO_ARG , siginfo_t *info, void *ctx
#ifdef SIGSTKSZ
#define ALT_STACK_SIZE SIGSTKSZ
#else
@@ -430,7 +431,7 @@ register_sigaltstack()
if (is_altstack_defined)
return;
- newSS.ss_sp = malloc(ALT_STACK_SIZE);
+ newSS.ss_sp = malloc(ALT_STACK_SIZE * 2);
if (newSS.ss_sp == NULL)
/* should handle error */
rb_bug("register_sigaltstack. malloc error\n");
@@ -441,6 +442,8 @@ register_sigaltstack()
rb_bug("register_sigaltstack. error\n");
is_altstack_defined = 1;
}
+#else
+#define SIGINFO_ARG
#endif
static sighandler_t
@@ -570,8 +573,16 @@ sigbus(int sig)
#ifdef SIGSEGV
static int segv_received = 0;
static RETSIGTYPE
-sigsegv(int sig)
+sigsegv(int sig SIGINFO_ARG)
{
+#ifdef USE_SIGALTSTACK
+ int ruby_stack_overflowed_p(const rb_thread_t *, const void *);
+ NORETURN(void ruby_thread_stack_overflow(rb_thread_t *th));
+ rb_thread_t *th = GET_THREAD();
+ if (ruby_stack_overflowed_p(th, info->si_addr)) {
+ ruby_thread_stack_overflow(th);
+ }
+#endif
if (segv_received) {
fprintf(stderr, "SEGV recieved in SEGV handler\n");
exit(EXIT_FAILURE);
@@ -700,7 +711,7 @@ default_handler(int sig)
#endif
#ifdef SIGSEGV
case SIGSEGV:
- func = sigsegv;
+ func = (sighandler_t)sigsegv;
#ifdef USE_SIGALTSTACK
register_sigaltstack();
#endif
@@ -1114,7 +1125,7 @@ Init_signal(void)
#ifdef USE_SIGALTSTACK
register_sigaltstack();
#endif
- install_sighandler(SIGSEGV, sigsegv);
+ install_sighandler(SIGSEGV, (sighandler_t)sigsegv);
#endif
}
#ifdef SIGPIPE