24 #if !defined(_WIN32) && !defined(HAVE_GCC_ATOMIC_BUILTINS)
45 #if defined(__BEOS__) || defined(__HAIKU__)
49 #ifdef HAVE_PTHREAD_SIGMASK
50 #define USE_TRAP_MASK 1
52 #define USE_TRAP_MASK 0
56 # define NSIG (_SIGMAX + 1)
148 {
"VTALRM", SIGVTALRM},
175 {
"DANGER", SIGDANGER},
178 {
"MIGRATE", SIGMIGRATE},
187 {
"RETRACT", SIGRETRACT},
204 if (strcmp(sigs->
signm, nm) == 0)
215 if (sigs->
signo == no)
245 if (!
NIL_P(sig)) argnum = 2;
248 if (argc < 1 || argnum < argc) {
254 if (signo < 0 || signo >
NSIG) {
272 if (strncmp(signm,
"SIG", 3) == 0) signm += 3;
354 #define killpg(pg, sig) kill(-(pg), (sig))
365 switch (
TYPE(argv[0])) {
382 if (strncmp(
"SIG", s, 3) == 0)
404 for (i=1; i<
argc; i++) {
410 for (i=1; i<
argc; i++) {
425 #define sighandler_t sh_t
429 #ifdef USE_SIGALTSTACK
431 #define SIGINFO_ARG , siginfo_t *info, void *ctx
439 #ifdef USE_SIGALTSTACK
444 stack_t newSS, oldSS;
447 rb_bug(
"rb_register_sigaltstack: th->altstack not initialized\n");
449 newSS.ss_sp = th->altstack;
453 sigaltstack(&newSS, &oldSS);
460 struct sigaction sigact, old;
463 rb_trap_accept_nativethreads[signum] = 0;
466 sigemptyset(&sigact.sa_mask);
467 #ifdef USE_SIGALTSTACK
469 sigact.sa_flags = SA_SIGINFO;
471 sigact.sa_handler = handler;
476 if (signum == SIGCHLD && handler == SIG_IGN)
477 sigact.sa_flags |= SA_NOCLDWAIT;
479 #if defined(SA_ONSTACK) && defined(USE_SIGALTSTACK)
480 if (signum == SIGSEGV || signum == SIGBUS)
481 sigact.sa_flags |= SA_ONSTACK;
483 if (sigaction(signum, &sigact, &old) < 0) {
484 if (errno != 0 && errno != EINVAL) {
488 return old.sa_handler;
498 #define ruby_signal(sig,handler) ( signal((sig),(handler)))
501 ruby_nativethread_signal(
int signum,
sighandler_t handler)
505 old =
signal(signum, handler);
506 rb_trap_accept_nativethreads[signum] = 1;
518 #if !defined(BSD_SIGNAL) && !defined(POSIX_SIGNAL)
530 static sigset_t trap_last_mask;
543 sigdelset(&mask, SIGVTALRM);
544 sigdelset(&mask, SIGSEGV);
582 #ifdef USE_SIGALTSTACK
584 check_stack_overflow(
const void *addr)
586 int ruby_stack_overflowed_p(
const rb_thread_t *,
const void *);
589 if (ruby_stack_overflowed_p(th, addr)) {
593 #define CHECK_STACK_OVERFLOW() check_stack_overflow(info->si_addr)
595 #define CHECK_STACK_OVERFLOW() (void)0
607 #if defined __APPLE__
615 static void ruby_abort(
void)
628 static int segv_received = 0;
635 char msg[] =
"SEGV received in SEGV handler\n";
636 write(2, msg,
sizeof(msg));
643 ruby_disable_gc_stress = 1;
644 rb_bug(
"Segmentation fault");
752 # ifdef USE_SIGALTSTACK
785 if (!
NIL_P(command)) {
793 if (strncmp(
RSTRING_PTR(command),
"SYSTEM_DEFAULT", 14) == 0) {
799 if (strncmp(
RSTRING_PTR(command),
"SIG_IGN", 7) == 0) {
804 else if (strncmp(
RSTRING_PTR(command),
"SIG_DFL", 7) == 0) {
809 else if (strncmp(
RSTRING_PTR(command),
"DEFAULT", 7) == 0) {
814 if (strncmp(
RSTRING_PTR(command),
"IGNORE", 6) == 0) {
819 if (strncmp(
RSTRING_PTR(command),
"EXIT", 4) == 0) {
840 switch (
TYPE(vsig)) {
843 if (sig < 0 || sig >=
NSIG) {
857 if (strncmp(
"SIG", s, 3) == 0)
860 if (sig == 0 && strcmp(s,
"EXIT") != 0)
878 if (oldfunc == SIG_IGN) oldcmd =
rb_str_new2(
"IGNORE");
891 sigdelset(&arg->mask, sig);
902 trap_last_mask = arg->mask;
952 if (argc < 1 || argc > 2) {
974 sigfillset(&fullmask);
1011 if (old != SIG_DFL) {
1016 #if defined(SIGCLD) || defined(SIGCHLD)
1018 init_sigchld(
int sig)
1026 sigfillset(&fullmask);
1031 if (oldfunc != SIG_DFL && oldfunc != SIG_IGN) {
1034 GET_VM()->trap_list[sig].cmd = 0;
1038 sigdelset(&mask, sig);
1040 trap_last_mask = mask;
1058 #ifndef RUBY_DEBUG_ENV
1059 #define ruby_enable_coredump 0
1133 if (!ruby_enable_coredump) {
1138 # ifdef USE_SIGALTSTACK
1149 init_sigchld(SIGCLD);
1150 #elif defined(SIGCHLD)
1151 init_sigchld(SIGCHLD);