24 #if !defined(_WIN32) && !defined(HAVE_GCC_ATOMIC_BUILTINS)
34 #if defined(__BEOS__) || defined(__HAIKU__)
38 #ifdef HAVE_PTHREAD_SIGMASK
39 #define USE_TRAP_MASK 1
41 #define USE_TRAP_MASK 0
45 # define NSIG (_SIGMAX + 1)
137 {
"VTALRM", SIGVTALRM},
164 {
"DANGER", SIGDANGER},
167 {
"MIGRATE", SIGMIGRATE},
176 {
"RETRACT", SIGRETRACT},
193 if (strcmp(sigs->
signm, nm) == 0)
204 if (sigs->
signo == no)
234 if (!
NIL_P(sig)) argnum = 2;
237 if (argc < 1 || argnum < argc) {
243 if (signo < 0 || signo >
NSIG) {
261 if (strncmp(signm,
"SIG", 3) == 0) signm += 3;
343 #define killpg(pg, sig) kill(-(pg), (sig))
354 switch (
TYPE(argv[0])) {
371 if (strncmp(
"SIG", s, 3) == 0)
393 for (i=1; i<
argc; i++) {
399 for (i=1; i<
argc; i++) {
414 #define sighandler_t sh_t
418 #ifdef USE_SIGALTSTACK
420 #define SIGINFO_ARG , siginfo_t *info, void *ctx
428 #ifdef USE_SIGALTSTACK
433 stack_t newSS, oldSS;
436 rb_bug(
"rb_register_sigaltstack: th->altstack not initialized\n");
438 newSS.ss_sp = th->altstack;
442 sigaltstack(&newSS, &oldSS);
449 struct sigaction sigact, old;
452 rb_trap_accept_nativethreads[signum] = 0;
455 sigemptyset(&sigact.sa_mask);
456 #ifdef USE_SIGALTSTACK
458 sigact.sa_flags = SA_SIGINFO;
460 sigact.sa_handler = handler;
465 if (signum == SIGCHLD && handler == SIG_IGN)
466 sigact.sa_flags |= SA_NOCLDWAIT;
468 #if defined(SA_ONSTACK) && defined(USE_SIGALTSTACK)
469 if (signum == SIGSEGV || signum == SIGBUS)
470 sigact.sa_flags |= SA_ONSTACK;
472 if (sigaction(signum, &sigact, &old) < 0) {
473 if (errno != 0 && errno != EINVAL) {
477 return old.sa_handler;
487 #define ruby_signal(sig,handler) ( signal((sig),(handler)))
490 ruby_nativethread_signal(
int signum,
sighandler_t handler)
494 old =
signal(signum, handler);
495 rb_trap_accept_nativethreads[signum] = 1;
507 #if !defined(BSD_SIGNAL) && !defined(POSIX_SIGNAL)
519 static sigset_t trap_last_mask;
532 sigdelset(&mask, SIGVTALRM);
533 sigdelset(&mask, SIGSEGV);
571 #ifdef USE_SIGALTSTACK
573 check_stack_overflow(
const void *addr)
575 int ruby_stack_overflowed_p(
const rb_thread_t *,
const void *);
578 if (ruby_stack_overflowed_p(th, addr)) {
582 #define CHECK_STACK_OVERFLOW() check_stack_overflow(info->si_addr)
584 #define CHECK_STACK_OVERFLOW() (void)0
596 #if defined __APPLE__
604 static void ruby_abort(
void)
617 static int segv_received = 0;
624 char msg[] =
"SEGV received in SEGV handler\n";
625 write(2, msg,
sizeof(msg));
632 ruby_disable_gc_stress = 1;
633 rb_bug(
"Segmentation fault");
741 # ifdef USE_SIGALTSTACK
774 if (!
NIL_P(command)) {
782 if (strncmp(
RSTRING_PTR(command),
"SYSTEM_DEFAULT", 14) == 0) {
788 if (strncmp(
RSTRING_PTR(command),
"SIG_IGN", 7) == 0) {
793 else if (strncmp(
RSTRING_PTR(command),
"SIG_DFL", 7) == 0) {
798 else if (strncmp(
RSTRING_PTR(command),
"DEFAULT", 7) == 0) {
803 if (strncmp(
RSTRING_PTR(command),
"IGNORE", 6) == 0) {
808 if (strncmp(
RSTRING_PTR(command),
"EXIT", 4) == 0) {
829 switch (
TYPE(vsig)) {
832 if (sig < 0 || sig >=
NSIG) {
846 if (strncmp(
"SIG", s, 3) == 0)
849 if (sig == 0 && strcmp(s,
"EXIT") != 0)
867 if (oldfunc == SIG_IGN) oldcmd =
rb_str_new2(
"IGNORE");
880 sigdelset(&arg->mask, sig);
891 trap_last_mask = arg->mask;
941 if (argc < 1 || argc > 2) {
963 sigfillset(&fullmask);
1000 if (old != SIG_DFL) {
1005 #if defined(SIGCLD) || defined(SIGCHLD)
1007 init_sigchld(
int sig)
1015 sigfillset(&fullmask);
1020 if (oldfunc != SIG_DFL && oldfunc != SIG_IGN) {
1023 GET_VM()->trap_list[sig].cmd = 0;
1027 sigdelset(&mask, sig);
1029 trap_last_mask = mask;
1047 #ifndef RUBY_DEBUG_ENV
1048 #define ruby_enable_coredump 0
1122 if (!ruby_enable_coredump) {
1127 # ifdef USE_SIGALTSTACK
1138 init_sigchld(SIGCLD);
1139 #elif defined(SIGCHLD)
1140 init_sigchld(SIGCHLD);