21 #if !defined(_WIN32) && !defined(HAVE_GCC_ATOMIC_BUILTINS)
31 #if defined(__BEOS__) || defined(__HAIKU__)
35 #ifdef HAVE_PTHREAD_SIGMASK
36 #define USE_TRAP_MASK 1
38 #define USE_TRAP_MASK 0
42 # define NSIG (_SIGMAX + 1)
134 {
"VTALRM", SIGVTALRM},
161 {
"DANGER", SIGDANGER},
164 {
"MIGRATE", SIGMIGRATE},
173 {
"RETRACT", SIGRETRACT},
190 if (strcmp(sigs->
signm, nm) == 0)
201 if (sigs->
signo == no)
231 if (!
NIL_P(sig)) argnum = 2;
234 if (argc < 1 || argnum < argc) {
240 if (signo < 0 || signo >
NSIG) {
258 if (strncmp(signm,
"SIG", 3) == 0) signm += 3;
340 #define killpg(pg, sig) kill(-(pg), (sig))
351 switch (
TYPE(argv[0])) {
368 if (strncmp(
"SIG", s, 3) == 0)
390 for (i=1; i<
argc; i++) {
396 for (i=1; i<
argc; i++) {
411 #define sighandler_t sh_t
415 #ifdef USE_SIGALTSTACK
417 #define SIGINFO_ARG , siginfo_t *info, void *ctx
425 #ifdef USE_SIGALTSTACK
430 stack_t newSS, oldSS;
433 rb_bug(
"rb_register_sigaltstack: th->altstack not initialized\n");
435 newSS.ss_sp = th->altstack;
439 sigaltstack(&newSS, &oldSS);
446 struct sigaction sigact, old;
449 rb_trap_accept_nativethreads[signum] = 0;
452 sigemptyset(&sigact.sa_mask);
453 #ifdef USE_SIGALTSTACK
455 sigact.sa_flags = SA_SIGINFO;
457 sigact.sa_handler = handler;
462 if (signum == SIGCHLD && handler == SIG_IGN)
463 sigact.sa_flags |= SA_NOCLDWAIT;
465 #if defined(SA_ONSTACK) && defined(USE_SIGALTSTACK)
466 if (signum == SIGSEGV || signum == SIGBUS)
467 sigact.sa_flags |= SA_ONSTACK;
469 if (sigaction(signum, &sigact, &old) < 0) {
470 if (errno != 0 && errno != EINVAL) {
474 return old.sa_handler;
484 #define ruby_signal(sig,handler) ( signal((sig),(handler)))
487 ruby_nativethread_signal(
int signum,
sighandler_t handler)
491 old =
signal(signum, handler);
492 rb_trap_accept_nativethreads[signum] = 1;
504 #if !defined(BSD_SIGNAL) && !defined(POSIX_SIGNAL)
516 static sigset_t trap_last_mask;
529 sigdelset(&mask, SIGVTALRM);
530 sigdelset(&mask, SIGSEGV);
576 #if defined __MACH__ && defined __APPLE__ && defined USE_SIGALTSTACK
577 int ruby_stack_overflowed_p(
const rb_thread_t *,
const void *);
580 if (ruby_stack_overflowed_p(th, info->si_addr)) {
589 static int segv_received = 0;
591 sigsegv(
int sig SIGINFO_ARG)
593 #ifdef USE_SIGALTSTACK
594 int ruby_stack_overflowed_p(
const rb_thread_t *,
const void *);
597 if (ruby_stack_overflowed_p(th, info->si_addr)) {
602 fprintf(stderr,
"SEGV received in SEGV handler\n");
608 ruby_disable_gc_stress = 1;
609 rb_bug(
"Segmentation fault");
718 # ifdef USE_SIGALTSTACK
751 if (!
NIL_P(command)) {
759 if (strncmp(
RSTRING_PTR(command),
"SYSTEM_DEFAULT", 14) == 0) {
765 if (strncmp(
RSTRING_PTR(command),
"SIG_IGN", 7) == 0) {
770 else if (strncmp(
RSTRING_PTR(command),
"SIG_DFL", 7) == 0) {
775 else if (strncmp(
RSTRING_PTR(command),
"DEFAULT", 7) == 0) {
780 if (strncmp(
RSTRING_PTR(command),
"IGNORE", 6) == 0) {
785 if (strncmp(
RSTRING_PTR(command),
"EXIT", 4) == 0) {
806 switch (
TYPE(vsig)) {
809 if (sig < 0 || sig >=
NSIG) {
823 if (strncmp(
"SIG", s, 3) == 0)
826 if (sig == 0 && strcmp(s,
"EXIT") != 0)
844 if (oldfunc == SIG_IGN) oldcmd =
rb_str_new2(
"IGNORE");
857 sigdelset(&arg->mask, sig);
868 trap_last_mask = arg->mask;
918 if (argc < 1 || argc > 2) {
940 sigfillset(&fullmask);
977 if (old != SIG_DFL) {
982 #if defined(SIGCLD) || defined(SIGCHLD)
984 init_sigchld(
int sig)
992 sigfillset(&fullmask);
997 if (oldfunc != SIG_DFL && oldfunc != SIG_IGN) {
1000 GET_VM()->trap_list[sig].cmd = 0;
1004 sigdelset(&mask, sig);
1006 trap_last_mask = mask;
1024 #ifndef RUBY_DEBUG_ENV
1025 #define ruby_enable_coredump 0
1099 if (!ruby_enable_coredump) {
1104 # ifdef USE_SIGALTSTACK
1115 init_sigchld(SIGCLD);
1116 #elif defined(SIGCHLD)
1117 init_sigchld(SIGCHLD);