22 #if defined(__native_client__) && defined(NACL_NEWLIB)
26 #ifdef NEED_RUBY_ATOMIC_OPS
47 #if defined(__BEOS__) || defined(__HAIKU__)
52 # define NSIG (_SIGMAX + 1)
144 {
"VTALRM", SIGVTALRM},
171 {
"DANGER", SIGDANGER},
174 {
"MIGRATE", SIGMIGRATE},
183 {
"RETRACT", SIGRETRACT},
200 if (strcmp(sigs->
signm, nm) == 0)
211 if (sigs->
signo == no)
261 if (!
NIL_P(sig)) argnum = 2;
267 if (signo < 0 || signo >
NSIG) {
285 if (strncmp(signm,
"SIG", 3) == 0) signm += 3;
367 #define killpg(pg, sig) kill(-(pg), (sig))
378 switch (
TYPE(argv[0])) {
395 if (strncmp(
"SIG", s, 3) == 0)
417 for (i=1; i<
argc; i++) {
423 for (i=1; i<
argc; i++) {
437 #define sighandler_t sh_t
441 #ifdef USE_SIGALTSTACK
443 #define SIGINFO_ARG , siginfo_t *info, void *ctx
449 #ifdef USE_SIGALTSTACK
456 if (size < MINSIGSTKSZ)
459 #if defined(HAVE_SYSCONF) && defined(_SC_PAGE_SIZE)
462 pagesize = (int)sysconf(_SC_PAGE_SIZE);
475 stack_t newSS, oldSS;
478 rb_bug(
"rb_register_sigaltstack: th->altstack not initialized\n");
480 newSS.ss_sp = th->altstack;
484 sigaltstack(&newSS, &oldSS);
492 struct sigaction sigact, old;
495 rb_trap_accept_nativethreads[signum] = 0;
498 sigemptyset(&sigact.sa_mask);
499 #ifdef USE_SIGALTSTACK
501 sigact.sa_flags = SA_SIGINFO;
503 sigact.sa_handler = handler;
508 if (signum == SIGCHLD && handler == SIG_IGN)
509 sigact.sa_flags |= SA_NOCLDWAIT;
511 #if defined(SA_ONSTACK) && defined(USE_SIGALTSTACK)
512 if (signum == SIGSEGV
517 sigact.sa_flags |= SA_ONSTACK;
519 if (sigaction(signum, &sigact, &old) < 0) {
520 if (errno != 0 && errno != EINVAL) {
524 return old.sa_handler;
534 #define ruby_signal(sig,handler) ( signal((sig),(handler)))
537 ruby_nativethread_signal(
int signum,
sighandler_t handler)
541 old =
signal(signum, handler);
542 rb_trap_accept_nativethreads[signum] = 1;
554 #if !defined(BSD_SIGNAL) && !defined(POSIX_SIGNAL)
572 #ifdef HAVE_PTHREAD_SIGMASK
582 #ifdef HAVE_PTHREAD_SIGMASK
608 #ifdef USE_SIGALTSTACK
610 check_stack_overflow(
const void *addr)
612 int ruby_stack_overflowed_p(
const rb_thread_t *,
const void *);
615 if (ruby_stack_overflowed_p(th, addr)) {
619 #define CHECK_STACK_OVERFLOW() check_stack_overflow(info->si_addr)
621 #define CHECK_STACK_OVERFLOW() (void)0
633 #if defined __APPLE__
641 static void ruby_abort(
void)
654 static int segv_received = 0;
662 char msg[] =
"SEGV received in SEGV handler\n";
664 err = write(2, msg,
sizeof(msg));
671 ruby_disable_gc_stress = 1;
672 rb_bug(
"Segmentation fault");
680 volatile unsigned long old_interrupt_mask = cur_th->
interrupt_mask;
817 if (!
NIL_P(command)) {
825 if (strncmp(
RSTRING_PTR(command),
"SYSTEM_DEFAULT", 14) == 0) {
831 if (strncmp(
RSTRING_PTR(command),
"SIG_IGN", 7) == 0) {
836 else if (strncmp(
RSTRING_PTR(command),
"SIG_DFL", 7) == 0) {
841 else if (strncmp(
RSTRING_PTR(command),
"DEFAULT", 7) == 0) {
846 if (strncmp(
RSTRING_PTR(command),
"IGNORE", 6) == 0) {
851 if (strncmp(
RSTRING_PTR(command),
"EXIT", 4) == 0) {
873 switch (
TYPE(vsig)) {
876 if (sig < 0 || sig >=
NSIG) {
890 if (strncmp(
"SIG", s, 3) == 0)
893 if (sig == 0 && strcmp(s,
"EXIT") != 0)
915 if (oldfunc == SIG_IGN) oldcmd =
rb_str_new2(
"IGNORE");
935 if (signo == SIGSEGV)
953 if (signo == SIGVTALRM)
1023 return trap(sig, func, cmd);
1056 if (old != SIG_DFL) {
1062 #if defined(SIGCLD) || defined(SIGCHLD)
1064 init_sigchld(
int sig)
1070 if (oldfunc != SIG_DFL && oldfunc != SIG_IGN) {
1073 GET_VM()->trap_list[sig].cmd = 0;
1092 #ifndef RUBY_DEBUG_ENV
1093 #define ruby_enable_coredump 0
1168 if (!ruby_enable_coredump) {
1173 # ifdef USE_SIGALTSTACK
1184 init_sigchld(SIGCLD);
1185 #elif defined(SIGCHLD)
1186 init_sigchld(SIGCHLD);