summaryrefslogtreecommitdiff
path: root/signal.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-20 21:38:27 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-20 21:38:27 +0000
commit475b4aa40b6cf83e57176a063d368d55bf779e7c (patch)
tree569c6a6db871c4e762b293038ed456afbcf36c1c /signal.c
parente72a86fc9373e4477b6e275735fecdf4eac9944a (diff)
simplify altstack and enable reuse with thread cache
Instead of allocating and registering the altstack in different places, do it together to reduce code and improve readability. When thread cache is enabled, storing altstack in rb_thread_t is wasteful and we may reuse altstack in the same pthread. This also lets us clearly allow use of xmalloc to allow GC to recover from ENOMEM. [ruby-core:85621] [Feature #14487] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'signal.c')
-rw-r--r--signal.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/signal.c b/signal.c
index 694661457b..5803f8f0b9 100644
--- a/signal.c
+++ b/signal.c
@@ -554,7 +554,7 @@ typedef RETSIGTYPE ruby_sigaction_t(int);
#endif
#ifdef USE_SIGALTSTACK
-int
+static int
rb_sigaltstack_size(void)
{
/* XXX: BSD_vfprintf() uses >1500KiB stack and x86-64 need >5KiB stack. */
@@ -577,19 +577,18 @@ rb_sigaltstack_size(void)
}
/* alternate stack for SIGSEGV */
-void
-rb_register_sigaltstack(rb_thread_t *th)
+void *
+rb_register_sigaltstack(void)
{
stack_t newSS, oldSS;
- if (!th->altstack)
- rb_bug("rb_register_sigaltstack: th->altstack not initialized\n");
-
- newSS.ss_sp = th->altstack;
newSS.ss_size = rb_sigaltstack_size();
+ newSS.ss_sp = xmalloc(newSS.ss_size);
newSS.ss_flags = 0;
sigaltstack(&newSS, &oldSS); /* ignore error. */
+
+ return newSS.ss_sp;
}
#endif /* USE_SIGALTSTACK */
@@ -1532,9 +1531,7 @@ Init_signal(void)
install_sighandler(SIGILL, (sighandler_t)sigill);
#endif
#ifdef SIGSEGV
-# ifdef USE_SIGALTSTACK
- rb_register_sigaltstack(GET_THREAD());
-# endif
+ RB_ALTSTACK_INIT(GET_VM()->main_altstack);
install_sighandler(SIGSEGV, (sighandler_t)sigsegv);
#endif
}