Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

signal.c
Go to the documentation of this file.
1 /**********************************************************************
2
3 signal.c -
4
5 $Author$
6 created at: Tue Dec 20 10:13:44 JST 1994
7
8 Copyright (C) 1993-2007 Yukihiro Matsumoto
9 Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
10 Copyright (C) 2000 Information-technology Promotion Agency, Japan
11
12 **********************************************************************/
13
14 #include "internal.h"
15 #include "vm_core.h"
16 #include <signal.h>
17 #include <stdio.h>
18 #include <errno.h>
19 #include "ruby_atomic.h"
20 #include "eval_intern.h"
21 #ifdef HAVE_UNISTD_H
22 # include <unistd.h>
23 #endif
24 #ifdef HAVE_SYS_UIO_H
25 #include <sys/uio.h>
26 #endif
27 #ifdef HAVE_UCONTEXT_H
28 #include <ucontext.h>
29 #endif
30
31 #ifdef HAVE_VALGRIND_MEMCHECK_H
32 # include <valgrind/memcheck.h>
33 # ifndef VALGRIND_MAKE_MEM_DEFINED
34 # define VALGRIND_MAKE_MEM_DEFINED(p, n) VALGRIND_MAKE_READABLE((p), (n))
35 # endif
36 # ifndef VALGRIND_MAKE_MEM_UNDEFINED
37 # define VALGRIND_MAKE_MEM_UNDEFINED(p, n) VALGRIND_MAKE_WRITABLE((p), (n))
38 # endif
39 #else
40 # define VALGRIND_MAKE_MEM_DEFINED(p, n) 0
41 # define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0
42 #endif
43
44 #ifdef NEED_RUBY_ATOMIC_OPS
45 rb_atomic_t
46 ruby_atomic_exchange(rb_atomic_t *ptr, rb_atomic_t val)
47 {
48 rb_atomic_t old = *ptr;
49 *ptr = val;
50 return old;
51 }
52
53 rb_atomic_t
54 ruby_atomic_compare_and_swap(rb_atomic_t *ptr, rb_atomic_t cmp,
55 rb_atomic_t newval)
56 {
57 rb_atomic_t old = *ptr;
58 if (old == cmp) {
59 *ptr = newval;
60 }
61 return old;
62 }
63 #endif
64
65 #define FOREACH_SIGNAL(sig, offset) \
66 for (sig = siglist + (offset); sig < siglist + numberof(siglist); ++sig)
67 enum { LONGEST_SIGNAME = 7 }; /* MIGRATE and RETRACT */
68 static const struct signals {
69 char signm[LONGEST_SIGNAME + 1];
70 int signo;
71 } siglist [] = {
72 {"EXIT", 0},
73 #ifdef SIGHUP
74 {"HUP", SIGHUP},
75 #endif
76 {"INT", SIGINT},
77 #ifdef SIGQUIT
78 {"QUIT", SIGQUIT},
79 #endif
80 #ifdef SIGILL
81 {"ILL", SIGILL},
82 #endif
83 #ifdef SIGTRAP
84 {"TRAP", SIGTRAP},
85 #endif
86 #ifdef SIGABRT
87 {"ABRT", SIGABRT},
88 #endif
89 #ifdef SIGIOT
90 {"IOT", SIGIOT},
91 #endif
92 #ifdef SIGEMT
93 {"EMT", SIGEMT},
94 #endif
95 #ifdef SIGFPE
96 {"FPE", SIGFPE},
97 #endif
98 #ifdef SIGKILL
99 {"KILL", SIGKILL},
100 #endif
101 #ifdef SIGBUS
102 {"BUS", SIGBUS},
103 #endif
104 #ifdef SIGSEGV
105 {"SEGV", SIGSEGV},
106 #endif
107 #ifdef SIGSYS
108 {"SYS", SIGSYS},
109 #endif
110 #ifdef SIGPIPE
111 {"PIPE", SIGPIPE},
112 #endif
113 #ifdef SIGALRM
114 {"ALRM", SIGALRM},
115 #endif
116 #ifdef SIGTERM
117 {"TERM", SIGTERM},
118 #endif
119 #ifdef SIGURG
120 {"URG", SIGURG},
121 #endif
122 #ifdef SIGSTOP
123 {"STOP", SIGSTOP},
124 #endif
125 #ifdef SIGTSTP
126 {"TSTP", SIGTSTP},
127 #endif
128 #ifdef SIGCONT
129 {"CONT", SIGCONT},
130 #endif
131 #if RUBY_SIGCHLD
132 {"CHLD", RUBY_SIGCHLD },
133 {"CLD", RUBY_SIGCHLD },
134 #endif
135 #ifdef SIGTTIN
136 {"TTIN", SIGTTIN},
137 #endif
138 #ifdef SIGTTOU
139 {"TTOU", SIGTTOU},
140 #endif
141 #ifdef SIGIO
142 {"IO", SIGIO},
143 #endif
144 #ifdef SIGXCPU
145 {"XCPU", SIGXCPU},
146 #endif
147 #ifdef SIGXFSZ
148 {"XFSZ", SIGXFSZ},
149 #endif
150 #ifdef SIGVTALRM
151 {"VTALRM", SIGVTALRM},
152 #endif
153 #ifdef SIGPROF
154 {"PROF", SIGPROF},
155 #endif
156 #ifdef SIGWINCH
157 {"WINCH", SIGWINCH},
158 #endif
159 #ifdef SIGUSR1
160 {"USR1", SIGUSR1},
161 #endif
162 #ifdef SIGUSR2
163 {"USR2", SIGUSR2},
164 #endif
165 #ifdef SIGLOST
166 {"LOST", SIGLOST},
167 #endif
168 #ifdef SIGMSG
169 {"MSG", SIGMSG},
170 #endif
171 #ifdef SIGPWR
172 {"PWR", SIGPWR},
173 #endif
174 #ifdef SIGPOLL
175 {"POLL", SIGPOLL},
176 #endif
177 #ifdef SIGDANGER
178 {"DANGER", SIGDANGER},
179 #endif
180 #ifdef SIGMIGRATE
181 {"MIGRATE", SIGMIGRATE},
182 #endif
183 #ifdef SIGPRE
184 {"PRE", SIGPRE},
185 #endif
186 #ifdef SIGGRANT
187 {"GRANT", SIGGRANT},
188 #endif
189 #ifdef SIGRETRACT
190 {"RETRACT", SIGRETRACT},
191 #endif
192 #ifdef SIGSOUND
193 {"SOUND", SIGSOUND},
194 #endif
195 #ifdef SIGINFO
196 {"INFO", SIGINFO},
197 #endif
198 };
199
200 static const char signame_prefix[] = "SIG";
201 static const int signame_prefix_len = 3;
202
203 static int
204 signm2signo(VALUE *sig_ptr, int negative, int exit, int *prefix_ptr)
205 {
206 const struct signals *sigs;
207 VALUE vsig = *sig_ptr;
208 const char *nm;
209 long len, nmlen;
210 int prefix = 0;
211
212 if (RB_SYMBOL_P(vsig)) {
213 *sig_ptr = vsig = rb_sym2str(vsig);
214 }
215 else if (!RB_TYPE_P(vsig, T_STRING)) {
216 VALUE str = rb_check_string_type(vsig);
217 if (NIL_P(str)) {
218 rb_raise(rb_eArgError, "bad signal type %s",
219 rb_obj_classname(vsig));
220 }
221 *sig_ptr = vsig = str;
222 }
223
224 rb_must_asciicompat(vsig);
225 RSTRING_GETMEM(vsig, nm, len);
226 if (memchr(nm, '\0', len)) {
227 rb_raise(rb_eArgError, "signal name with null byte");
228 }
229
230 if (len > 0 && nm[0] == '-') {
231 if (!negative)
232 rb_raise(rb_eArgError, "negative signal name: % "PRIsVALUE, vsig);
233 prefix = 1;
234 }
235 else {
236 negative = 0;
237 }
238 if (len >= prefix + signame_prefix_len) {
239 if (memcmp(nm + prefix, signame_prefix, signame_prefix_len) == 0)
240 prefix += signame_prefix_len;
241 }
242 if (len <= (long)prefix) {
243 unsupported:
244 if (prefix == signame_prefix_len) {
245 prefix = 0;
246 }
247 else if (prefix > signame_prefix_len) {
248 prefix -= signame_prefix_len;
249 len -= prefix;
250 vsig = rb_str_subseq(vsig, prefix, len);
251 prefix = 0;
252 }
253 else {
254 len -= prefix;
255 vsig = rb_str_subseq(vsig, prefix, len);
256 prefix = signame_prefix_len;
257 }
258 rb_raise(rb_eArgError, "unsupported signal `%.*s%"PRIsVALUE"'",
259 prefix, signame_prefix, vsig);
260 }
261
262 if (prefix_ptr) *prefix_ptr = prefix;
263 nmlen = len - prefix;
264 nm += prefix;
265 if (nmlen > LONGEST_SIGNAME) goto unsupported;
266 FOREACH_SIGNAL(sigs, !exit) {
267 if (memcmp(sigs->signm, nm, nmlen) == 0 &&
268 sigs->signm[nmlen] == '\0') {
269 return negative ? -sigs->signo : sigs->signo;
270 }
271 }
272 goto unsupported;
273 }
274
275 static const char*
276 signo2signm(int no)
277 {
278 const struct signals *sigs;
279
280 FOREACH_SIGNAL(sigs, 0) {
281 if (sigs->signo == no)
282 return sigs->signm;
283 }
284 return 0;
285 }
286
287 /*
288 * call-seq:
289 * Signal.signame(signo) -> string or nil
290 *
291 * Convert signal number to signal name.
292 * Returns +nil+ if the signo is an invalid signal number.
293 *
294 * Signal.trap("INT") { |signo| puts Signal.signame(signo) }
295 * Process.kill("INT", 0)
296 *
297 * <em>produces:</em>
298 *
299 * INT
300 */
301 static VALUE
302 sig_signame(VALUE recv, VALUE signo)
303 {
304 const char *signame = signo2signm(NUM2INT(signo));
305 if (!signame) return Qnil;
306 return rb_str_new_cstr(signame);
307 }
308
309 const char *
310 ruby_signal_name(int no)
311 {
312 return signo2signm(no);
313 }
314
315 static VALUE
316 rb_signo2signm(int signo)
317 {
318 const char *const signm = signo2signm(signo);
319 if (signm) {
320 return rb_sprintf("SIG%s", signm);
321 }
322 else {
323 return rb_sprintf("SIG%u", signo);
324 }
325 }
326
327 /*
328 * call-seq:
329 * SignalException.new(sig_name) -> signal_exception
330 * SignalException.new(sig_number [, name]) -> signal_exception
331 *
332 * Construct a new SignalException object. +sig_name+ should be a known
333 * signal name.
334 */
335
336 static VALUE
337 esignal_init(int argc, VALUE *argv, VALUE self)
338 {
339 int argnum = 1;
340 VALUE sig = Qnil;
341 int signo;
342
343 if (argc > 0) {
344 sig = rb_check_to_integer(argv[0], "to_int");
345 if (!NIL_P(sig)) argnum = 2;
346 else sig = argv[0];
347 }
348 rb_check_arity(argc, 1, argnum);
349 if (argnum == 2) {
350 signo = NUM2INT(sig);
351 if (signo < 0 || signo > NSIG) {
352 rb_raise(rb_eArgError, "invalid signal number (%d)", signo);
353 }
354 if (argc > 1) {
355 sig = argv[1];
356 }
357 else {
358 sig = rb_signo2signm(signo);
359 }
360 }
361 else {
362 int prefix;
363 signo = signm2signo(&sig, FALSE, FALSE, &prefix);
364 if (prefix != signame_prefix_len) {
365 sig = rb_str_append(rb_str_new_cstr("SIG"), sig);
366 }
367 }
368 rb_call_super(1, &sig);
369 rb_ivar_set(self, id_signo, INT2NUM(signo));
370
371 return self;
372 }
373
374 /*
375 * call-seq:
376 * signal_exception.signo -> num
377 *
378 * Returns a signal number.
379 */
380
381 static VALUE
382 esignal_signo(VALUE self)
383 {
384 return rb_ivar_get(self, id_signo);
385 }
386
387 /* :nodoc: */
388 static VALUE
389 interrupt_init(int argc, VALUE *argv, VALUE self)
390 {
391 VALUE args[2];
392
393 args[0] = INT2FIX(SIGINT);
394 args[1] = rb_check_arity(argc, 0, 1) ? argv[0] : Qnil;
395 return rb_call_super(2, args);
396 }
397
398 #include "debug_counter.h"
399 void rb_malloc_info_show_results(void); /* gc.c */
400
401 void
402 ruby_default_signal(int sig)
403 {
404 #if USE_DEBUG_COUNTER
405 rb_debug_counter_show_results("killed by signal.");
406 #endif
407 rb_malloc_info_show_results();
408
409 signal(sig, SIG_DFL);
410 raise(sig);
411 }
412
413 static RETSIGTYPE sighandler(int sig);
414 static int signal_ignored(int sig);
415 static void signal_enque(int sig);
416
417 VALUE
418 rb_f_kill(int argc, const VALUE *argv)
419 {
420 #ifndef HAVE_KILLPG
421 #define killpg(pg, sig) kill(-(pg), (sig))
422 #endif
423 int sig;
424 int i;
425 VALUE str;
426
427 rb_check_arity(argc, 2, UNLIMITED_ARGUMENTS);
428
429 if (FIXNUM_P(argv[0])) {
430 sig = FIX2INT(argv[0]);
431 }
432 else {
433 str = argv[0];
434 sig = signm2signo(&str, TRUE, FALSE, NULL);
435 }
436
437 if (argc <= 1) return INT2FIX(0);
438
439 if (sig < 0) {
440 sig = -sig;
441 for (i=1; i<argc; i++) {
442 if (killpg(NUM2PIDT(argv[i]), sig) < 0)
443 rb_sys_fail(0);
444 }
445 }
446 else {
447 const rb_pid_t self = (GET_THREAD() == GET_VM()->main_thread) ? getpid() : -1;
448 int wakeup = 0;
449
450 for (i=1; i<argc; i++) {
451 rb_pid_t pid = NUM2PIDT(argv[i]);
452
453 if ((sig != 0) && (self != -1) && (pid == self)) {
454 int t;
455 /*
456 * When target pid is self, many caller assume signal will be
457 * delivered immediately and synchronously.
458 */
459 switch (sig) {
460 case SIGSEGV:
461 #ifdef SIGBUS
462 case SIGBUS:
463 #endif
464 #ifdef SIGKILL
465 case SIGKILL:
466 #endif
467 #ifdef SIGILL
468 case SIGILL:
469 #endif
470 #ifdef SIGFPE
471 case SIGFPE:
472 #endif
473 #ifdef SIGSTOP
474 case SIGSTOP:
475 #endif
476 kill(pid, sig);
477 break;
478 default:
479 t = signal_ignored(sig);
480 if (t) {
481 if (t < 0 && kill(pid, sig))
482 rb_sys_fail(0);
483 break;
484 }
485 signal_enque(sig);
486 wakeup = 1;
487 }
488 }
489 else if (kill(pid, sig) < 0) {
490 rb_sys_fail(0);
491 }
492 }
493 if (wakeup) {
494 rb_threadptr_check_signal(GET_VM()->main_thread);
495 }
496 }
497 rb_thread_execute_interrupts(rb_thread_current());
498
499 return INT2FIX(i-1);
500 }
501
502 static struct {
503 rb_atomic_t cnt[RUBY_NSIG];
504 rb_atomic_t size;
505 } signal_buff;
506 #if RUBY_SIGCHLD
507 volatile unsigned int ruby_nocldwait;
508 #endif
509
510 #define sighandler_t ruby_sighandler_t
511
512 #ifdef USE_SIGALTSTACK
513 typedef void ruby_sigaction_t(int, siginfo_t*, void*);
514 #define SIGINFO_ARG , siginfo_t *info, void *ctx
515 #define SIGINFO_CTX ctx
516 #else
517 typedef RETSIGTYPE ruby_sigaction_t(int);
518 #define SIGINFO_ARG
519 #define SIGINFO_CTX 0
520 #endif
521
522 #ifdef USE_SIGALTSTACK
523 static int
524 rb_sigaltstack_size(void)
525 {
526 /* XXX: BSD_vfprintf() uses >1500KiB stack and x86-64 need >5KiB stack. */
527 int size = 16*1024;
528
529 #ifdef MINSIGSTKSZ
530 {
531 int minsigstksz = (int)MINSIGSTKSZ;
532 if (size < minsigstksz)
533 size = minsigstksz;
534 }
535 #endif
536 #if defined(HAVE_SYSCONF) && defined(_SC_PAGE_SIZE)
537 {
538 int pagesize;
539 pagesize = (int)sysconf(_SC_PAGE_SIZE);
540 if (size < pagesize)
541 size = pagesize;
542 }
543 #endif
544
545 return size;
546 }
547
548 /* alternate stack for SIGSEGV */
549 void *
550 rb_register_sigaltstack(void)
551 {
552 stack_t newSS, oldSS;
553
554 newSS.ss_size = rb_sigaltstack_size();
555 newSS.ss_sp = xmalloc(newSS.ss_size);
556 newSS.ss_flags = 0;
557
558 sigaltstack(&newSS, &oldSS); /* ignore error. */
559
560 return newSS.ss_sp;
561 }
562 #endif /* USE_SIGALTSTACK */
563
564 #ifdef POSIX_SIGNAL
565 static sighandler_t
566 ruby_signal(int signum, sighandler_t handler)
567 {
568 struct sigaction sigact, old;
569
570 #if 0
571 rb_trap_accept_nativethreads[signum] = 0;
572 #endif
573
574 sigemptyset(&sigact.sa_mask);
575 #ifdef USE_SIGALTSTACK
576 if (handler == SIG_IGN || handler == SIG_DFL) {
577 sigact.sa_handler = handler;
578 sigact.sa_flags = 0;
579 }
580 else {
581 sigact.sa_sigaction = (ruby_sigaction_t*)handler;
582 sigact.sa_flags = SA_SIGINFO;
583 }
584 #else
585 sigact.sa_handler = handler;
586 sigact.sa_flags = 0;
587 #endif
588
589 switch (signum) {
590 #if RUBY_SIGCHLD
591 case RUBY_SIGCHLD:
592 if (handler == SIG_IGN) {
593 ruby_nocldwait = 1;
594 # ifdef USE_SIGALTSTACK
595 if (sigact.sa_flags & SA_SIGINFO) {
596 sigact.sa_sigaction = (ruby_sigaction_t*)sighandler;
597 }
598 else {
599 sigact.sa_handler = sighandler;
600 }
601 # else
602 sigact.sa_handler = handler;
603 sigact.sa_flags = 0;
604 # endif
605 }
606 else {
607 ruby_nocldwait = 0;
608 }
609 break;
610 #endif
611 #if defined(SA_ONSTACK) && defined(USE_SIGALTSTACK)
612 case SIGSEGV:
613 #ifdef SIGBUS
614 case SIGBUS:
615 #endif
616 sigact.sa_flags |= SA_ONSTACK;
617 break;
618 #endif
619 }
620 (void)VALGRIND_MAKE_MEM_DEFINED(&old, sizeof(old));
621 if (sigaction(signum, &sigact, &old) < 0) {
622 return SIG_ERR;
623 }
624 if (old.sa_flags & SA_SIGINFO)
625 handler = (sighandler_t)old.sa_sigaction;
626 else
627 handler = old.sa_handler;
628 ASSUME(handler != SIG_ERR);
629 return handler;
630 }
631
632 sighandler_t
633 posix_signal(int signum, sighandler_t handler)
634 {
635 return ruby_signal(signum, handler);
636 }
637
638 #elif defined _WIN32
639 static inline sighandler_t
640 ruby_signal(int signum, sighandler_t handler)
641 {
642 if (signum == SIGKILL) {
643 errno = EINVAL;
644 return SIG_ERR;
645 }
646 return signal(signum, handler);
647 }
648
649 #else /* !POSIX_SIGNAL */
650 #define ruby_signal(sig,handler) (/* rb_trap_accept_nativethreads[(sig)] = 0,*/ signal((sig),(handler)))
651 #if 0 /* def HAVE_NATIVETHREAD */
652 static sighandler_t
653 ruby_nativethread_signal(int signum, sighandler_t handler)
654 {
655 sighandler_t old;
656
657 old = signal(signum, handler);
658 rb_trap_accept_nativethreads[signum] = 1;
659 return old;
660 }
661 #endif
662 #endif
663
664 static int
665 signal_ignored(int sig)
666 {
667 sighandler_t func;
668 #ifdef POSIX_SIGNAL
669 struct sigaction old;
670 (void)VALGRIND_MAKE_MEM_DEFINED(&old, sizeof(old));
671 if (sigaction(sig, NULL, &old) < 0) return FALSE;
672 func = old.sa_handler;
673 #else
674 sighandler_t old = signal(sig, SIG_DFL);
675 signal(sig, old);
676 func = old;
677 #endif
678 if (func == SIG_IGN) return 1;
679 return func == sighandler ? 0 : -1;
680 }
681
682 static void
683 signal_enque(int sig)
684 {
685 ATOMIC_INC(signal_buff.cnt[sig]);
686 ATOMIC_INC(signal_buff.size);
687 }
688
689 #if RUBY_SIGCHLD
690 static rb_atomic_t sigchld_hit;
691 /* destructive getter than simple predicate */
692 # define GET_SIGCHLD_HIT() ATOMIC_EXCHANGE(sigchld_hit, 0)
693 #else
694 # define GET_SIGCHLD_HIT() 0
695 #endif
696
697 static RETSIGTYPE
698 sighandler(int sig)
699 {
700 int old_errnum = errno;
701
702 /* the VM always needs to handle SIGCHLD for rb_waitpid */
703 if (sig == RUBY_SIGCHLD) {
704 #if RUBY_SIGCHLD
705 rb_vm_t *vm = GET_VM();
706 ATOMIC_EXCHANGE(sigchld_hit, 1);
707
708 /* avoid spurious wakeup in main thread iff nobody uses trap(:CHLD) */
709 if (vm && ACCESS_ONCE(VALUE, vm->trap_list.cmd[sig])) {
710 signal_enque(sig);
711 }
712 #endif
713 }
714 else {
715 signal_enque(sig);
716 }
717 rb_thread_wakeup_timer_thread(sig);
718 #if !defined(BSD_SIGNAL) && !defined(POSIX_SIGNAL)
719 ruby_signal(sig, sighandler);
720 #endif
721
722 errno = old_errnum;
723 }
724
725 int
726 rb_signal_buff_size(void)
727 {
728 return signal_buff.size;
729 }
730
731 #if HAVE_PTHREAD_H
732 #include <pthread.h>
733 #endif
734
735 static void
736 rb_disable_interrupt(void)
737 {
738 #ifdef HAVE_PTHREAD_SIGMASK
739 sigset_t mask;
740 sigfillset(&mask);
741 pthread_sigmask(SIG_SETMASK, &mask, NULL);
742 #endif
743 }
744
745 static void
746 rb_enable_interrupt(void)
747 {
748 #ifdef HAVE_PTHREAD_SIGMASK
749 sigset_t mask;
750 sigemptyset(&mask);
751 pthread_sigmask(SIG_SETMASK, &mask, NULL);
752 #endif
753 }
754
755 int
756 rb_get_next_signal(void)
757 {
758 int i, sig = 0;
759
760 if (signal_buff.size != 0) {
761 for (i=1; i<RUBY_NSIG; i++) {
762 if (signal_buff.cnt[i] > 0) {
763 ATOMIC_DEC(signal_buff.cnt[i]);
764 ATOMIC_DEC(signal_buff.size);
765 sig = i;
766 break;
767 }
768 }
769 }
770 return sig;
771 }
772
773 #if defined SIGSEGV || defined SIGBUS || defined SIGILL || defined SIGFPE
774 static const char *received_signal;
775 # define clear_received_signal() (void)(ruby_disable_gc = 0, received_signal = 0)
776 #else
777 # define clear_received_signal() ((void)0)
778 #endif
779
780 #if defined(USE_SIGALTSTACK) || defined(_WIN32)
781 NORETURN(void rb_ec_stack_overflow(rb_execution_context_t *ec, int crit));
782 # if defined __HAIKU__
783 # define USE_UCONTEXT_REG 1
784 # elif !(defined(HAVE_UCONTEXT_H) && (defined __i386__ || defined __x86_64__ || defined __amd64__))
785 # elif defined __linux__
786 # define USE_UCONTEXT_REG 1
787 # elif defined __APPLE__
788 # define USE_UCONTEXT_REG 1
789 # elif defined __FreeBSD__
790 # define USE_UCONTEXT_REG 1
791 # endif
792 #if defined(HAVE_PTHREAD_SIGMASK)
793 # define ruby_sigunmask pthread_sigmask
794 #elif defined(HAVE_SIGPROCMASK)
795 # define ruby_sigunmask sigprocmask
796 #endif
797 static void
798 reset_sigmask(int sig)
799 {
800 #if defined(ruby_sigunmask)
801 sigset_t mask;
802 #endif
803 clear_received_signal();
804 #if defined(ruby_sigunmask)
805 sigemptyset(&mask);
806 sigaddset(&mask, sig);
807 if (ruby_sigunmask(SIG_UNBLOCK, &mask, NULL)) {
808 rb_bug_errno(STRINGIZE(ruby_sigunmask)":unblock", errno);
809 }
810 #endif
811 }
812
813 # ifdef USE_UCONTEXT_REG
814 static void
815 check_stack_overflow(int sig, const uintptr_t addr, const ucontext_t *ctx)
816 {
817 const DEFINE_MCONTEXT_PTR(mctx, ctx);
818 # if defined __linux__
819 # if defined REG_RSP
820 const greg_t sp = mctx->gregs[REG_RSP];
821 const greg_t bp = mctx->gregs[REG_RBP];
822 # else
823 const greg_t sp = mctx->gregs[REG_ESP];
824 const greg_t bp = mctx->gregs[REG_EBP];
825 # endif
826 # elif defined __APPLE__
827 # if __DARWIN_UNIX03
828 # define MCTX_SS_REG(reg) __ss.__##reg
829 # else
830 # define MCTX_SS_REG(reg) ss.reg
831 # endif
832 # if defined(__LP64__)
833 const uintptr_t sp = mctx->MCTX_SS_REG(rsp);
834 const uintptr_t bp = mctx->MCTX_SS_REG(rbp);
835 # else
836 const uintptr_t sp = mctx->MCTX_SS_REG(esp);
837 const uintptr_t bp = mctx->MCTX_SS_REG(ebp);
838 # endif
839 # elif defined __FreeBSD__
840 # if defined(__amd64__)
841 const __register_t sp = mctx->mc_rsp;
842 const __register_t bp = mctx->mc_rbp;
843 # else
844 const __register_t sp = mctx->mc_esp;
845 const __register_t bp = mctx->mc_ebp;
846 # endif
847 # elif defined __HAIKU__
848 # if defined(__amd64__)
849 const unsigned long sp = mctx->rsp;
850 const unsigned long bp = mctx->rbp;
851 # else
852 const unsigned long sp = mctx->esp;
853 const unsigned long bp = mctx->ebp;
854 # endif
855 # endif
856 enum {pagesize = 4096};
857 const uintptr_t sp_page = (uintptr_t)sp / pagesize;
858 const uintptr_t bp_page = (uintptr_t)bp / pagesize;
859 const uintptr_t fault_page = addr / pagesize;
860
861 /* SP in ucontext is not decremented yet when `push` failed, so
862 * the fault page can be the next. */
863 if (sp_page == fault_page || sp_page == fault_page + 1 ||
864 (sp_page <= fault_page && fault_page <= bp_page)) {
865 rb_execution_context_t *ec = GET_EC();
866 int crit = FALSE;
867 if ((uintptr_t)ec->tag->buf / pagesize <= fault_page + 1) {
868 /* drop the last tag if it is close to the fault,
869 * otherwise it can cause stack overflow again at the same
870 * place. */
871 ec->tag = ec->tag->prev;
872 crit = TRUE;
873 }
874 reset_sigmask(sig);
875 rb_ec_stack_overflow(ec, crit);
876 }
877 }
878 # else
879 static void
880 check_stack_overflow(int sig, const void *addr)
881 {
882 int ruby_stack_overflowed_p(const rb_thread_t *, const void *);
883 rb_thread_t *th = GET_THREAD();
884 if (ruby_stack_overflowed_p(th, addr)) {
885 reset_sigmask(sig);
886 rb_ec_stack_overflow(th->ec, FALSE);
887 }
888 }
889 # endif
890 # ifdef _WIN32
891 # define CHECK_STACK_OVERFLOW() check_stack_overflow(sig, 0)
892 # else
893 # define FAULT_ADDRESS info->si_addr
894 # ifdef USE_UCONTEXT_REG
895 # define CHECK_STACK_OVERFLOW() check_stack_overflow(sig, (uintptr_t)FAULT_ADDRESS, ctx)
896 # else
897 # define CHECK_STACK_OVERFLOW() check_stack_overflow(sig, FAULT_ADDRESS)
898 # endif
899 # define MESSAGE_FAULT_ADDRESS " at %p", FAULT_ADDRESS
900 # endif
901 #else
902 # define CHECK_STACK_OVERFLOW() (void)0
903 #endif
904 #ifndef MESSAGE_FAULT_ADDRESS
905 # define MESSAGE_FAULT_ADDRESS
906 #endif
907
908 #if defined SIGSEGV || defined SIGBUS || defined SIGILL || defined SIGFPE
909 NOINLINE(static void check_reserved_signal_(const char *name, size_t name_len));
910 /* noinine to reduce stack usage in signal handers */
911
912 #define check_reserved_signal(name) check_reserved_signal_(name, sizeof(name)-1)
913
914 #ifdef SIGBUS
915
916 static sighandler_t default_sigbus_handler;
917 NORETURN(static ruby_sigaction_t sigbus);
918
919 static RETSIGTYPE
920 sigbus(int sig SIGINFO_ARG)
921 {
922 check_reserved_signal("BUS");
923 /*
924 * Mac OS X makes KERN_PROTECTION_FAILURE when thread touch guard page.
925 * and it's delivered as SIGBUS instead of SIGSEGV to userland. It's crazy
926 * wrong IMHO. but anyway we have to care it. Sigh.
927 */
928 /* Seems Linux also delivers SIGBUS. */
929 #if defined __APPLE__ || defined __linux__
930 CHECK_STACK_OVERFLOW();
931 #endif
932 rb_bug_for_fatal_signal(default_sigbus_handler, sig, SIGINFO_CTX, "Bus Error" MESSAGE_FAULT_ADDRESS);
933 }
934 #endif
935
936 #ifdef SIGSEGV
937
938 static sighandler_t default_sigsegv_handler;
939 NORETURN(static ruby_sigaction_t sigsegv);
940
941 static RETSIGTYPE
942 sigsegv(int sig SIGINFO_ARG)
943 {
944 check_reserved_signal("SEGV");
945 CHECK_STACK_OVERFLOW();
946 rb_bug_for_fatal_signal(default_sigsegv_handler, sig, SIGINFO_CTX, "Segmentation fault" MESSAGE_FAULT_ADDRESS);
947 }
948 #endif
949
950 #ifdef SIGILL
951
952 static sighandler_t default_sigill_handler;
953 NORETURN(static ruby_sigaction_t sigill);
954
955 static RETSIGTYPE
956 sigill(int sig SIGINFO_ARG)
957 {
958 check_reserved_signal("ILL");
959 #if defined __APPLE__
960 CHECK_STACK_OVERFLOW();
961 #endif
962 rb_bug_for_fatal_signal(default_sigill_handler, sig, SIGINFO_CTX, "Illegal instruction" MESSAGE_FAULT_ADDRESS);
963 }
964 #endif
965
966 #ifndef __sun
967 NORETURN(static void ruby_abort(void));
968 #endif
969
970 static void
971 ruby_abort(void)
972 {
973 #ifdef __sun
974 /* Solaris's abort() is async signal unsafe. Of course, it is not
975 * POSIX compliant.
976 */
977 raise(SIGABRT);
978 #else
979 abort();
980 #endif
981 }
982
983 static void
984 check_reserved_signal_(const char *name, size_t name_len)
985 {
986 const char *prev = ATOMIC_PTR_EXCHANGE(received_signal, name);
987
988 if (prev) {
989 ssize_t RB_UNUSED_VAR(err);
990 #define NOZ(name, str) name[sizeof(str)-1] = str
991 static const char NOZ(msg1, " received in ");
992 static const char NOZ(msg2, " handler\n");
993
994 #ifdef HAVE_WRITEV
995 struct iovec iov[4];
996
997 iov[0].iov_base = (void *)name;
998 iov[0].iov_len = name_len;
999 iov[1].iov_base = (void *)msg1;
1000 iov[1].iov_len = sizeof(msg1);
1001 iov[2].iov_base = (void *)prev;
1002 iov[2].iov_len = strlen(prev);
1003 iov[3].iov_base = (void *)msg2;
1004 iov[3].iov_len = sizeof(msg2);
1005 err = writev(2, iov, 4);
1006 #else
1007 err = write(2, name, name_len);
1008 err = write(2, msg1, sizeof(msg1));
1009 err = write(2, prev, strlen(prev));
1010 err = write(2, msg2, sizeof(msg2));
1011 #endif
1012 ruby_abort();
1013 }
1014
1015 ruby_disable_gc = 1;
1016 }
1017 #endif
1018
1019 #if defined SIGPIPE || defined SIGSYS
1020 static RETSIGTYPE
1021 sig_do_nothing(int sig)
1022 {
1023 }
1024 #endif
1025
1026 static int
1027 signal_exec(VALUE cmd, int sig)
1028 {
1029 rb_execution_context_t *ec = GET_EC();
1030 volatile rb_atomic_t old_interrupt_mask = ec->interrupt_mask;
1031 enum ruby_tag_type state;
1032
1033 /*
1034 * workaround the following race:
1035 * 1. signal_enque queues signal for execution
1036 * 2. user calls trap(sig, "IGNORE"), setting SIG_IGN
1037 * 3. rb_signal_exec runs on queued signal
1038 */
1039 if (IMMEDIATE_P(cmd))
1040 return FALSE;
1041
1042 ec->interrupt_mask |= TRAP_INTERRUPT_MASK;
1043 EC_PUSH_TAG(ec);
1044 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1045 VALUE signum = INT2NUM(sig);
1046 rb_eval_cmd_kw(cmd, rb_ary_new3(1, signum), RB_NO_KEYWORDS);
1047 }
1048 EC_POP_TAG();
1049 ec = GET_EC();
1050 ec->interrupt_mask = old_interrupt_mask;
1051
1052 if (state) {
1053 /* XXX: should be replaced with rb_threadptr_pending_interrupt_enque() */
1054 EC_JUMP_TAG(ec, state);
1055 }
1056 return TRUE;
1057 }
1058
1059 void
1060 rb_vm_trap_exit(rb_vm_t *vm)
1061 {
1062 VALUE trap_exit = vm->trap_list.cmd[0];
1063
1064 if (trap_exit) {
1065 vm->trap_list.cmd[0] = 0;
1066 signal_exec(trap_exit, 0);
1067 }
1068 }
1069
1070 void ruby_waitpid_all(rb_vm_t *); /* process.c */
1071
1072 void
1073 ruby_sigchld_handler(rb_vm_t *vm)
1074 {
1075 if (SIGCHLD_LOSSY || GET_SIGCHLD_HIT()) {
1076 ruby_waitpid_all(vm);
1077 }
1078 }
1079
1080 /* returns true if a trap handler was run, false otherwise */
1081 int
1082 rb_signal_exec(rb_thread_t *th, int sig)
1083 {
1084 rb_vm_t *vm = GET_VM();
1085 VALUE cmd = vm->trap_list.cmd[sig];
1086
1087 if (cmd == 0) {
1088 switch (sig) {
1089 case SIGINT:
1090 rb_interrupt();
1091 break;
1092 #ifdef SIGHUP
1093 case SIGHUP:
1094 #endif
1095 #ifdef SIGQUIT
1096 case SIGQUIT:
1097 #endif
1098 #ifdef SIGTERM
1099 case SIGTERM:
1100 #endif
1101 #ifdef SIGALRM
1102 case SIGALRM:
1103 #endif
1104 #ifdef SIGUSR1
1105 case SIGUSR1:
1106 #endif
1107 #ifdef SIGUSR2
1108 case SIGUSR2:
1109 #endif
1110 rb_threadptr_signal_raise(th, sig);
1111 break;
1112 }
1113 }
1114 else if (cmd == Qundef) {
1115 rb_threadptr_signal_exit(th);
1116 }
1117 else {
1118 return signal_exec(cmd, sig);
1119 }
1120 return FALSE;
1121 }
1122
1123 static sighandler_t
1124 default_handler(int sig)
1125 {
1126 sighandler_t func;
1127 switch (sig) {
1128 case SIGINT:
1129 #ifdef SIGHUP
1130 case SIGHUP:
1131 #endif
1132 #ifdef SIGQUIT
1133 case SIGQUIT:
1134 #endif
1135 #ifdef SIGTERM
1136 case SIGTERM:
1137 #endif
1138 #ifdef SIGALRM
1139 case SIGALRM:
1140 #endif
1141 #ifdef SIGUSR1
1142 case SIGUSR1:
1143 #endif
1144 #ifdef SIGUSR2
1145 case SIGUSR2:
1146 #endif
1147 #if RUBY_SIGCHLD
1148 case RUBY_SIGCHLD:
1149 #endif
1150 func = sighandler;
1151 break;
1152 #ifdef SIGBUS
1153 case SIGBUS:
1154 func = (sighandler_t)sigbus;
1155 break;
1156 #endif
1157 #ifdef SIGSEGV
1158 case SIGSEGV:
1159 func = (sighandler_t)sigsegv;
1160 break;
1161 #endif
1162 #ifdef SIGPIPE
1163 case SIGPIPE:
1164 func = sig_do_nothing;
1165 break;
1166 #endif
1167 #ifdef SIGSYS
1168 case SIGSYS:
1169 func = sig_do_nothing;
1170 break;
1171 #endif
1172 default:
1173 func = SIG_DFL;
1174 break;
1175 }
1176
1177 return func;
1178 }
1179
1180 static sighandler_t
1181 trap_handler(VALUE *cmd, int sig)
1182 {
1183 sighandler_t func = sighandler;
1184 VALUE command;
1185
1186 if (NIL_P(*cmd)) {
1187 func = SIG_IGN;
1188 }
1189 else {
1190 command = rb_check_string_type(*cmd);
1191 if (NIL_P(command) && SYMBOL_P(*cmd)) {
1192 command = rb_sym2str(*cmd);
1193 if (!command) rb_raise(rb_eArgError, "bad handler");
1194 }
1195 if (!NIL_P(command)) {
1196 const char *cptr;
1197 long len;
1198 StringValue(command);
1199 *cmd = command;
1200 RSTRING_GETMEM(command, cptr, len);
1201 switch (len) {
1202 case 0:
1203 goto sig_ign;
1204 break;
1205 case 14:
1206 if (memcmp(cptr, "SYSTEM_DEFAULT", 14) == 0) {
1207 if (sig == RUBY_SIGCHLD) {
1208 goto sig_dfl;
1209 }
1210 func = SIG_DFL;
1211 *cmd = 0;
1212 }
1213 break;
1214 case 7:
1215 if (memcmp(cptr, "SIG_IGN", 7) == 0) {
1216 sig_ign:
1217 func = SIG_IGN;
1218 *cmd = Qtrue;
1219 }
1220 else if (memcmp(cptr, "SIG_DFL", 7) == 0) {
1221 sig_dfl:
1222 func = default_handler(sig);
1223 *cmd = 0;
1224 }
1225 else if (memcmp(cptr, "DEFAULT", 7) == 0) {
1226 goto sig_dfl;
1227 }
1228 break;
1229 case 6:
1230 if (memcmp(cptr, "IGNORE", 6) == 0) {
1231 goto sig_ign;
1232 }
1233 break;
1234 case 4:
1235 if (memcmp(cptr, "EXIT", 4) == 0) {
1236 *cmd = Qundef;
1237 }
1238 break;
1239 }
1240 }
1241 else {
1242 rb_proc_t *proc;
1243 GetProcPtr(*cmd, proc);
1244 (void)proc;
1245 }
1246 }
1247
1248 return func;
1249 }
1250
1251 static int
1252 trap_signm(VALUE vsig)
1253 {
1254 int sig = -1;
1255
1256 if (FIXNUM_P(vsig)) {
1257 sig = FIX2INT(vsig);
1258 if (sig < 0 || sig >= NSIG) {
1259 rb_raise(rb_eArgError, "invalid signal number (%d)", sig);
1260 }
1261 }
1262 else {
1263 sig = signm2signo(&vsig, FALSE, TRUE, NULL);
1264 }
1265 return sig;
1266 }
1267
1268 static VALUE
1269 trap(int sig, sighandler_t func, VALUE command)
1270 {
1271 sighandler_t oldfunc;
1272 VALUE oldcmd;
1273 rb_vm_t *vm = GET_VM();
1274
1275 /*
1276 * Be careful. ruby_signal() and trap_list.cmd[sig] must be changed
1277 * atomically. In current implementation, we only need to don't call
1278 * RUBY_VM_CHECK_INTS().
1279 */
1280 if (sig == 0) {
1281 oldfunc = SIG_ERR;
1282 }
1283 else {
1284 oldfunc = ruby_signal(sig, func);
1285 if (oldfunc == SIG_ERR) rb_sys_fail_str(rb_signo2signm(sig));
1286 }
1287 oldcmd = vm->trap_list.cmd[sig];
1288 switch (oldcmd) {
1289 case 0:
1290 case Qtrue:
1291 if (oldfunc == SIG_IGN) oldcmd = rb_str_new2("IGNORE");
1292 else if (oldfunc == SIG_DFL) oldcmd = rb_str_new2("SYSTEM_DEFAULT");
1293 else if (oldfunc == sighandler) oldcmd = rb_str_new2("DEFAULT");
1294 else oldcmd = Qnil;
1295 break;
1296 case Qnil:
1297 break;
1298 case Qundef:
1299 oldcmd = rb_str_new2("EXIT");
1300 break;
1301 }
1302
1303 ACCESS_ONCE(VALUE, vm->trap_list.cmd[sig]) = command;
1304
1305 return oldcmd;
1306 }
1307
1308 static int
1309 reserved_signal_p(int signo)
1310 {
1311 /* Synchronous signal can't deliver to main thread */
1312 #ifdef SIGSEGV
1313 if (signo == SIGSEGV)
1314 return 1;
1315 #endif
1316 #ifdef SIGBUS
1317 if (signo == SIGBUS)
1318 return 1;
1319 #endif
1320 #ifdef SIGILL
1321 if (signo == SIGILL)
1322 return 1;
1323 #endif
1324 #ifdef SIGFPE
1325 if (signo == SIGFPE)
1326 return 1;
1327 #endif
1328
1329 /* used ubf internal see thread_pthread.c. */
1330 #ifdef SIGVTALRM
1331 if (signo == SIGVTALRM)
1332 return 1;
1333 #endif
1334
1335 return 0;
1336 }
1337
1338 /*
1339 * call-seq:
1340 * Signal.trap( signal, command ) -> obj
1341 * Signal.trap( signal ) {| | block } -> obj
1342 *
1343 * Specifies the handling of signals. The first parameter is a signal
1344 * name (a string such as ``SIGALRM'', ``SIGUSR1'', and so on) or a
1345 * signal number. The characters ``SIG'' may be omitted from the
1346 * signal name. The command or block specifies code to be run when the
1347 * signal is raised.
1348 * If the command is the string ``IGNORE'' or ``SIG_IGN'', the signal
1349 * will be ignored.
1350 * If the command is ``DEFAULT'' or ``SIG_DFL'', the Ruby's default handler
1351 * will be invoked.
1352 * If the command is ``EXIT'', the script will be terminated by the signal.
1353 * If the command is ``SYSTEM_DEFAULT'', the operating system's default
1354 * handler will be invoked.
1355 * Otherwise, the given command or block will be run.
1356 * The special signal name ``EXIT'' or signal number zero will be
1357 * invoked just prior to program termination.
1358 * trap returns the previous handler for the given signal.
1359 *
1360 * Signal.trap(0, proc { puts "Terminating: #{$$}" })
1361 * Signal.trap("CLD") { puts "Child died" }
1362 * fork && Process.wait
1363 *
1364 * produces:
1365 * Terminating: 27461
1366 * Child died
1367 * Terminating: 27460
1368 */
1369 static VALUE
1370 sig_trap(int argc, VALUE *argv, VALUE _)
1371 {
1372 int sig;
1373 sighandler_t func;
1374 VALUE cmd;
1375
1376 rb_check_arity(argc, 1, 2);
1377
1378 sig = trap_signm(argv[0]);
1379 if (reserved_signal_p(sig)) {
1380 const char *name = signo2signm(sig);
1381 if (name)
1382 rb_raise(rb_eArgError, "can't trap reserved signal: SIG%s", name);
1383 else
1384 rb_raise(rb_eArgError, "can't trap reserved signal: %d", sig);
1385 }
1386
1387 if (argc == 1) {
1388 cmd = rb_block_proc();
1389 func = sighandler;
1390 }
1391 else {
1392 cmd = argv[1];
1393 func = trap_handler(&cmd, sig);
1394 }
1395
1396 return trap(sig, func, cmd);
1397 }
1398
1399 /*
1400 * call-seq:
1401 * Signal.list -> a_hash
1402 *
1403 * Returns a list of signal names mapped to the corresponding
1404 * underlying signal numbers.
1405 *
1406 * Signal.list #=> {"EXIT"=>0, "HUP"=>1, "INT"=>2, "QUIT"=>3, "ILL"=>4, "TRAP"=>5, "IOT"=>6, "ABRT"=>6, "FPE"=>8, "KILL"=>9, "BUS"=>7, "SEGV"=>11, "SYS"=>31, "PIPE"=>13, "ALRM"=>14, "TERM"=>15, "URG"=>23, "STOP"=>19, "TSTP"=>20, "CONT"=>18, "CHLD"=>17, "CLD"=>17, "TTIN"=>21, "TTOU"=>22, "IO"=>29, "XCPU"=>24, "XFSZ"=>25, "VTALRM"=>26, "PROF"=>27, "WINCH"=>28, "USR1"=>10, "USR2"=>12, "PWR"=>30, "POLL"=>29}
1407 */
1408 static VALUE
1409 sig_list(VALUE _)
1410 {
1411 VALUE h = rb_hash_new();
1412 const struct signals *sigs;
1413
1414 FOREACH_SIGNAL(sigs, 0) {
1415 rb_hash_aset(h, rb_fstring_cstr(sigs->signm), INT2FIX(sigs->signo));
1416 }
1417 return h;
1418 }
1419
1420 #define INSTALL_SIGHANDLER(cond, signame, signum) do { \
1421 static const char failed[] = "failed to install "signame" handler"; \
1422 if (!(cond)) break; \
1423 if (reserved_signal_p(signum)) rb_bug(failed); \
1424 perror(failed); \
1425 } while (0)
1426 static int
1427 install_sighandler_core(int signum, sighandler_t handler, sighandler_t *old_handler)
1428 {
1429 sighandler_t old;
1430
1431 old = ruby_signal(signum, handler);
1432 if (old == SIG_ERR) return -1;
1433 if (old_handler) {
1434 *old_handler = (old == SIG_DFL || old == SIG_IGN) ? 0 : old;
1435 }
1436 else {
1437 /* signal handler should be inherited during exec. */
1438 if (old != SIG_DFL) {
1439 ruby_signal(signum, old);
1440 }
1441 }
1442 return 0;
1443 }
1444
1445 # define install_sighandler(signum, handler) \
1446 INSTALL_SIGHANDLER(install_sighandler_core(signum, handler, NULL), #signum, signum)
1447 # define force_install_sighandler(signum, handler, old_handler) \
1448 INSTALL_SIGHANDLER(install_sighandler_core(signum, handler, old_handler), #signum, signum)
1449
1450 #if RUBY_SIGCHLD
1451 static int
1452 init_sigchld(int sig)
1453 {
1454 sighandler_t oldfunc;
1455 sighandler_t func = sighandler;
1456
1457 oldfunc = ruby_signal(sig, SIG_DFL);
1458 if (oldfunc == SIG_ERR) return -1;
1459 ruby_signal(sig, func);
1460 ACCESS_ONCE(VALUE, GET_VM()->trap_list.cmd[sig]) = 0;
1461
1462 return 0;
1463 }
1464
1465 # define init_sigchld(signum) \
1466 INSTALL_SIGHANDLER(init_sigchld(signum), #signum, signum)
1467 #endif
1468
1469 void
1470 ruby_sig_finalize(void)
1471 {
1472 sighandler_t oldfunc;
1473
1474 oldfunc = ruby_signal(SIGINT, SIG_IGN);
1475 if (oldfunc == sighandler) {
1476 ruby_signal(SIGINT, SIG_DFL);
1477 }
1478 }
1479
1480
1481 int ruby_enable_coredump = 0;
1482
1483 /*
1484 * Many operating systems allow signals to be sent to running
1485 * processes. Some signals have a defined effect on the process, while
1486 * others may be trapped at the code level and acted upon. For
1487 * example, your process may trap the USR1 signal and use it to toggle
1488 * debugging, and may use TERM to initiate a controlled shutdown.
1489 *
1490 * pid = fork do
1491 * Signal.trap("USR1") do
1492 * $debug = !$debug
1493 * puts "Debug now: #$debug"
1494 * end
1495 * Signal.trap("TERM") do
1496 * puts "Terminating..."
1497 * shutdown()
1498 * end
1499 * # . . . do some work . . .
1500 * end
1501 *
1502 * Process.detach(pid)
1503 *
1504 * # Controlling program:
1505 * Process.kill("USR1", pid)
1506 * # ...
1507 * Process.kill("USR1", pid)
1508 * # ...
1509 * Process.kill("TERM", pid)
1510 *
1511 * produces:
1512 * Debug now: true
1513 * Debug now: false
1514 * Terminating...
1515 *
1516 * The list of available signal names and their interpretation is
1517 * system dependent. Signal delivery semantics may also vary between
1518 * systems; in particular signal delivery may not always be reliable.
1519 */
1520 void
1521 Init_signal(void)
1522 {
1523 VALUE mSignal = rb_define_module("Signal");
1524
1525 rb_define_global_function("trap", sig_trap, -1);
1526 rb_define_module_function(mSignal, "trap", sig_trap, -1);
1527 rb_define_module_function(mSignal, "list", sig_list, 0);
1528 rb_define_module_function(mSignal, "signame", sig_signame, 1);
1529
1530 rb_define_method(rb_eSignal, "initialize", esignal_init, -1);
1531 rb_define_method(rb_eSignal, "signo", esignal_signo, 0);
1532 rb_alias(rb_eSignal, rb_intern_const("signm"), rb_intern_const("message"));
1533 rb_define_method(rb_eInterrupt, "initialize", interrupt_init, -1);
1534
1535 /* At this time, there is no subthread. Then sigmask guarantee atomics. */
1536 rb_disable_interrupt();
1537
1538 install_sighandler(SIGINT, sighandler);
1539 #ifdef SIGHUP
1540 install_sighandler(SIGHUP, sighandler);
1541 #endif
1542 #ifdef SIGQUIT
1543 install_sighandler(SIGQUIT, sighandler);
1544 #endif
1545 #ifdef SIGTERM
1546 install_sighandler(SIGTERM, sighandler);
1547 #endif
1548 #ifdef SIGALRM
1549 install_sighandler(SIGALRM, sighandler);
1550 #endif
1551 #ifdef SIGUSR1
1552 install_sighandler(SIGUSR1, sighandler);
1553 #endif
1554 #ifdef SIGUSR2
1555 install_sighandler(SIGUSR2, sighandler);
1556 #endif
1557
1558 if (!ruby_enable_coredump) {
1559 #ifdef SIGBUS
1560 force_install_sighandler(SIGBUS, (sighandler_t)sigbus, &default_sigbus_handler);
1561 #endif
1562 #ifdef SIGILL
1563 force_install_sighandler(SIGILL, (sighandler_t)sigill, &default_sigill_handler);
1564 #endif
1565 #ifdef SIGSEGV
1566 RB_ALTSTACK_INIT(GET_VM()->main_altstack);
1567 force_install_sighandler(SIGSEGV, (sighandler_t)sigsegv, &default_sigsegv_handler);
1568 #endif
1569 }
1570 #ifdef SIGPIPE
1571 install_sighandler(SIGPIPE, sig_do_nothing);
1572 #endif
1573 #ifdef SIGSYS
1574 install_sighandler(SIGSYS, sig_do_nothing);
1575 #endif
1576
1577 #if RUBY_SIGCHLD
1578 init_sigchld(RUBY_SIGCHLD);
1579 #endif
1580
1581 rb_enable_interrupt();
1582 }
1583
1584 #if defined(HAVE_GRANTPT)
1585 extern int grantpt(int);
1586 #else
1587 static int
1588 fake_grantfd(int masterfd)
1589 {
1590 errno = ENOSYS;
1591 return -1;
1592 }
1593 #define grantpt(fd) fake_grantfd(fd)
1594 #endif
1595
1596 int
1597 rb_grantpt(int masterfd)
1598 {
1599 if (RUBY_SIGCHLD) {
1600 rb_vm_t *vm = GET_VM();
1601 int ret, e;
1602
1603 /*
1604 * Prevent waitpid calls from Ruby by taking waitpid_lock.
1605 * Pedantically, grantpt(3) is undefined if a non-default
1606 * SIGCHLD handler is defined, but preventing conflicting
1607 * waitpid calls ought to be sufficient.
1608 *
1609 * We could install the default sighandler temporarily, but that
1610 * could cause SIGCHLD to be missed by other threads. Blocking
1611 * SIGCHLD won't work here, either, unless we stop and restart
1612 * timer-thread (as only timer-thread sees SIGCHLD), but that
1613 * seems like overkill.
1614 */
1615 rb_nativethread_lock_lock(&vm->waitpid_lock);
1616 {
1617 ret = grantpt(masterfd); /* may spawn `pt_chown' and wait on it */
1618 if (ret < 0) e = errno;
1619 }
1620 rb_nativethread_lock_unlock(&vm->waitpid_lock);
1621
1622 if (ret < 0) errno = e;
1623 return ret;
1624 }
1625 else {
1626 return grantpt(masterfd);
1627 }
1628 }
sigaltstack
Definition: rb_mjit_min_header-2.7.0.h:2300
SIGTSTP
#define SIGTSTP
Definition: rb_mjit_min_header-2.7.0.h:2266
VALGRIND_MAKE_MEM_DEFINED
#define VALGRIND_MAKE_MEM_DEFINED(p, n)
Definition: signal.c:40
SIGIOT
#define SIGIOT
Definition: rb_mjit_min_header-2.7.0.h:2254
sig
int sig
Definition: rb_mjit_min_header-2.7.0.h:10422
void
void
Definition: rb_mjit_min_header-2.7.0.h:13273
TRUE
#define TRUE
Definition: nkf.h:175
ruby_waitpid_all
void ruby_waitpid_all(rb_vm_t *)
Definition: process.c:1029
RSTRING_GETMEM
#define RSTRING_GETMEM(str, ptrvar, lenvar)
Definition: ruby.h:1018
rb_nativethread_lock_unlock
void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock)
Definition: thread.c:451
ATOMIC_INC
#define ATOMIC_INC(var)
Definition: ruby_atomic.h:132
rb_str_new2
#define rb_str_new2
Definition: intern.h:903
FIX2INT
#define FIX2INT(x)
Definition: ruby.h:717
rb_hash_new
VALUE rb_hash_new(void)
Definition: hash.c:1501
ATOMIC_PTR_EXCHANGE
#define ATOMIC_PTR_EXCHANGE(var, val)
Definition: ruby_atomic.h:186
SIGSTOP
#define SIGSTOP
Definition: rb_mjit_min_header-2.7.0.h:2265
siginfo_t
Definition: rb_mjit_min_header-2.7.0.h:2112
ENOSYS
#define ENOSYS
Definition: rb_mjit_min_header-2.7.0.h:11017
ruby_signal
#define ruby_signal(sig, handler)
Definition: signal.c:650
SIGLOST
#define SIGLOST
Definition: rb_mjit_min_header-2.7.0.h:2279
sigaction
Definition: rb_mjit_min_header-2.7.0.h:2225
INT2FIX
#define INT2FIX(i)
Definition: ruby.h:263
bp
#define bp()
Definition: internal.h:1445
rb_threadptr_signal_exit
void rb_threadptr_signal_exit(rb_thread_t *th)
Definition: thread.c:2334
rb_bug_errno
void rb_bug_errno(const char *mesg, int errno_arg)
Definition: error.c:667
NORETURN
#define NORETURN(x)
Definition: defines.h:528
SIGFPE
#define SIGFPE
Definition: rb_mjit_min_header-2.7.0.h:2256
pthread_sigmask
int pthread_sigmask(int, const sigset_t *, sigset_t *)
rb_nativethread_lock_lock
void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock)
Definition: thread.c:445
VALUE
unsigned long VALUE
Definition: ruby.h:102
GET_VM
#define GET_VM()
Definition: vm_core.h:1764
rb_eArgError
VALUE rb_eArgError
Definition: error.c:923
ucontext_t
ucontext_t
Definition: rb_mjit_min_header-2.7.0.h:2335
RB_TYPE_P
#define RB_TYPE_P(obj, type)
Definition: ruby.h:560
rb_intern_const
#define rb_intern_const(str)
Definition: ruby.h:1879
rb_thread_current
VALUE rb_thread_current(void)
Definition: thread.c:2676
int
__inline__ int
Definition: rb_mjit_min_header-2.7.0.h:2839
rb_define_module
VALUE rb_define_module(const char *name)
Definition: class.c:772
old
VALUE ID VALUE old
Definition: rb_mjit_min_header-2.7.0.h:16133
rb_f_kill
VALUE rb_f_kill(int argc, const VALUE *argv)
Definition: signal.c:418
SIGCONT
#define SIGCONT
Definition: rb_mjit_min_header-2.7.0.h:2267
rb_define_global_function
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1787
rb_call_super
VALUE rb_call_super(int, const VALUE *)
Definition: vm_eval.c:306
EC_JUMP_TAG
#define EC_JUMP_TAG(ec, st)
Definition: eval_intern.h:184
rb_eSignal
VALUE rb_eSignal
Definition: error.c:917
Init_signal
void Init_signal(void)
Definition: signal.c:1521
StringValue
use StringValue() instead")))
ruby_sigchld_handler
void ruby_sigchld_handler(rb_vm_t *vm)
Definition: signal.c:1073
rb_execution_context_struct::tag
struct rb_vm_tag * tag
Definition: vm_core.h:849
rb_check_string_type
VALUE rb_check_string_type(VALUE)
Definition: string.c:2314
rb_vm_tag::prev
struct rb_vm_tag * prev
Definition: vm_core.h:803
Qundef
#define Qundef
Definition: ruby.h:470
rb_signal_buff_size
int rb_signal_buff_size(void)
Definition: signal.c:726
SIG_IGN
#define SIG_IGN
Definition: rb_mjit_min_header-2.7.0.h:2341
SIGXFSZ
#define SIGXFSZ
Definition: rb_mjit_min_header-2.7.0.h:2275
rb_define_method
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1551
GET_EC
#define GET_EC()
Definition: vm_core.h:1766
SIGWINCH
#define SIGWINCH
Definition: rb_mjit_min_header-2.7.0.h:2278
INT2NUM
#define INT2NUM(x)
Definition: ruby.h:1609
ptr
struct RIMemo * ptr
Definition: debug.c:74
rb_vm_trap_exit
void rb_vm_trap_exit(rb_vm_t *vm)
Definition: signal.c:1060
uintptr_t
unsigned int uintptr_t
Definition: win32.h:106
ruby_nocldwait
#define ruby_nocldwait
Definition: process.c:1025
ssize_t
_ssize_t ssize_t
Definition: rb_mjit_min_header-2.7.0.h:1329
SIGHUP
#define SIGHUP
Definition: rb_mjit_min_header-2.7.0.h:2248
ruby_default_signal
void ruby_default_signal(int sig)
Definition: signal.c:402
rb_ary_new3
#define rb_ary_new3
Definition: intern.h:104
NULL
#define NULL
Definition: _sdbm.c:101
exit
void exit(int __status) __attribute__((__noreturn__))
force_install_sighandler
#define force_install_sighandler(signum, handler, old_handler)
Definition: signal.c:1447
PRIsVALUE
#define PRIsVALUE
Definition: ruby.h:166
sysconf
long sysconf(int __name)
strlen
size_t strlen(const char *)
signal
_sig_func_ptr signal(int, _sig_func_ptr)
rb_bug_for_fatal_signal
void rb_bug_for_fatal_signal(ruby_sighandler_t default_sighandler, int sig, const void *ctx, const char *fmt,...)
Definition: error.c:649
rb_thread_struct::ec
rb_execution_context_t * ec
Definition: vm_core.h:915
RB_UNUSED_VAR
#define RB_UNUSED_VAR(x)
Definition: ruby.h:591
SIGBUS
#define SIGBUS
Definition: rb_mjit_min_header-2.7.0.h:2258
posix_signal
#define posix_signal
Definition: rb_mjit_min_header-2.7.0.h:6022
ASSUME
#define ASSUME(x)
Definition: ruby.h:52
rb_check_arity
#define rb_check_arity
Definition: intern.h:347
rb_vm_tag::buf
rb_jmpbuf_t buf
Definition: vm_core.h:802
SIGQUIT
#define SIGQUIT
Definition: rb_mjit_min_header-2.7.0.h:2250
ruby_atomic_compare_and_swap
rb_atomic_t ruby_atomic_compare_and_swap(rb_atomic_t *ptr, rb_atomic_t cmp, rb_atomic_t newval)
Definition: signal.c:54
UNLIMITED_ARGUMENTS
#define UNLIMITED_ARGUMENTS
Definition: intern.h:57
SIGPIPE
#define SIGPIPE
Definition: rb_mjit_min_header-2.7.0.h:2261
rb_raise
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2669
grantpt
#define grantpt(fd)
Definition: signal.c:1593
rb_ivar_get
VALUE rb_ivar_get(VALUE, ID)
Definition: variable.c:1070
id_signo
#define id_signo
Definition: internal.h:1587
SIGINFO_ARG
#define SIGINFO_ARG
Definition: signal.c:518
SIG_UNBLOCK
#define SIG_UNBLOCK
Definition: rb_mjit_min_header-2.7.0.h:2307
rb_alias
void rb_alias(VALUE, ID, ID)
Definition: vm_method.c:1581
rb_fstring_cstr
#define rb_fstring_cstr(str)
Definition: rb_mjit_min_header-2.7.0.h:7718
sighandler_t
#define sighandler_t
Definition: signal.c:510
rb_threadptr_check_signal
void rb_threadptr_check_signal(rb_thread_t *mth)
Definition: thread.c:4318
sigaddset
int sigaddset(sigset_t *, const int)
EC_POP_TAG
#define EC_POP_TAG()
Definition: eval_intern.h:137
rb_thread_execute_interrupts
void rb_thread_execute_interrupts(VALUE th)
Definition: thread.c:2284
GET_SIGCHLD_HIT
#define GET_SIGCHLD_HIT()
Definition: signal.c:694
rb_must_asciicompat
void rb_must_asciicompat(VALUE)
Definition: string.c:2166
NSIG
#define NSIG
Definition: vm_core.h:103
crit
int crit
Definition: rb_mjit_min_header-2.7.0.h:12246
sighandler_t
_sig_func_ptr sighandler_t
Definition: rb_mjit_min_header-2.7.0.h:2339
sigaltstack::ss_flags
int ss_flags
Definition: rb_mjit_min_header-2.7.0.h:2302
sigemptyset
int sigemptyset(sigset_t *)
RB_SYMBOL_P
#define RB_SYMBOL_P(x)
Definition: ruby.h:408
SIGUSR1
#define SIGUSR1
Definition: rb_mjit_min_header-2.7.0.h:2281
NOINLINE
#define NOINLINE(x)
Definition: defines.h:45
clear_received_signal
#define clear_received_signal()
Definition: signal.c:777
i
uint32_t i
Definition: rb_mjit_min_header-2.7.0.h:5464
sigset_t
__sigset_t sigset_t
Definition: rb_mjit_min_header-2.7.0.h:1262
rb_check_to_integer
VALUE rb_check_to_integer(VALUE, const char *)
Tries to convert val into Integer.
Definition: object.c:2999
mask
enum @11::@13::@14 mask
SIGEMT
#define SIGEMT
Definition: rb_mjit_min_header-2.7.0.h:2255
RUBY_NSIG
#define RUBY_NSIG
Definition: vm_core.h:106
SIGTTOU
#define SIGTTOU
Definition: rb_mjit_min_header-2.7.0.h:2271
SIGCHLD_LOSSY
#define SIGCHLD_LOSSY
Definition: vm_core.h:120
SIGINFO_CTX
#define SIGINFO_CTX
Definition: signal.c:519
SIGXCPU
#define SIGXCPU
Definition: rb_mjit_min_header-2.7.0.h:2274
MINSIGSTKSZ
#define MINSIGSTKSZ
Definition: rb_mjit_min_header-2.7.0.h:2245
ruby_enable_coredump
int ruby_enable_coredump
Definition: signal.c:1481
SIGSEGV
#define SIGSEGV
Definition: rb_mjit_min_header-2.7.0.h:2259
SIGSYS
#define SIGSYS
Definition: rb_mjit_min_header-2.7.0.h:2260
SIGUSR2
#define SIGUSR2
Definition: rb_mjit_min_header-2.7.0.h:2282
EC_EXEC_TAG
#define EC_EXEC_TAG()
Definition: eval_intern.h:181
RUBY_SIGCHLD
#define RUBY_SIGCHLD
Definition: vm_core.h:113
SIG_DFL
#define SIG_DFL
Definition: rb_mjit_min_header-2.7.0.h:2340
cnt
rb_atomic_t cnt[RUBY_NSIG]
Definition: signal.c:503
rb_get_next_signal
int rb_get_next_signal(void)
Definition: signal.c:756
ATOMIC_DEC
#define ATOMIC_DEC(var)
Definition: ruby_atomic.h:133
vm_core.h
rb_malloc_info_show_results
void rb_malloc_info_show_results(void)
Definition: gc.c:9979
rb_sys_fail
void rb_sys_fail(const char *mesg)
Definition: error.c:2793
rb_register_sigaltstack
void * rb_register_sigaltstack(void)
rb_interrupt
void rb_interrupt(void)
Raises an Interrupt exception.
Definition: eval.c:696
SIGURG
#define SIGURG
Definition: rb_mjit_min_header-2.7.0.h:2264
rb_eval_cmd_kw
VALUE rb_eval_cmd_kw(VALUE, VALUE, int)
Definition: vm_eval.c:1799
FALSE
#define FALSE
Definition: nkf.h:174
FIXNUM_P
#define FIXNUM_P(f)
Definition: ruby.h:396
sigaltstack
int sigaltstack(const stack_t *__restrict, stack_t *__restrict)
iovec::iov_base
void * iov_base
Definition: win32.h:226
rb_vm_struct::cmd
VALUE cmd[RUBY_NSIG]
Definition: vm_core.h:626
SIG_ERR
#define SIG_ERR
Definition: rb_mjit_min_header-2.7.0.h:2342
kill
int kill(int, int)
Definition: win32.c:4789
memcmp
int memcmp(const void *s1, const void *s2, size_t len)
Definition: memcmp.c:7
rb_str_new_cstr
#define rb_str_new_cstr(str)
Definition: rb_mjit_min_header-2.7.0.h:6117
getpid
pid_t getpid(void)
rb_thread_wakeup_timer_thread
void rb_thread_wakeup_timer_thread(int)
EINVAL
#define EINVAL
Definition: rb_mjit_min_header-2.7.0.h:10959
GetProcPtr
#define GetProcPtr(obj, ptr)
Definition: vm_core.h:1046
SIGPOLL
#define SIGPOLL
Definition: rb_mjit_min_header-2.7.0.h:2273
ruby_atomic_exchange
rb_atomic_t ruby_atomic_exchange(rb_atomic_t *ptr, rb_atomic_t val)
Definition: signal.c:46
ACCESS_ONCE
#define ACCESS_ONCE(type, x)
Definition: internal.h:223
SA_ONSTACK
#define SA_ONSTACK
Definition: rb_mjit_min_header-2.7.0.h:2238
rb_debug_counter_show_results
void rb_debug_counter_show_results(const char *msg)
Definition: debug_counter.c:116
DEFINE_MCONTEXT_PTR
#define DEFINE_MCONTEXT_PTR(mc, uc)
Definition: rb_mjit_min_header-2.7.0.h:431
rb_grantpt
int rb_grantpt(int masterfd)
Definition: signal.c:1597
rb_define_module_function
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
Definition: class.c:1771
iovec
Definition: win32.h:225
SIGINT
#define SIGINT
Definition: win32.h:481
rb_str_append
VALUE rb_str_append(VALUE, VALUE)
Definition: string.c:2965
CHECK_STACK_OVERFLOW
#define CHECK_STACK_OVERFLOW()
Definition: signal.c:902
internal.h
RB_ALTSTACK_INIT
#define RB_ALTSTACK_INIT(var)
Definition: vm_core.h:141
abort
void abort(void) __attribute__((__noreturn__))
argv
char ** argv
Definition: ruby.c:223
ruby_sig_finalize
void ruby_sig_finalize(void)
Definition: signal.c:1470
xmalloc
#define xmalloc
Definition: defines.h:211
rb_sprintf
VALUE rb_sprintf(const char *format,...)
Definition: sprintf.c:1197
rb_vm_struct::trap_list
struct rb_vm_struct::@184 trap_list
SIGVTALRM
#define SIGVTALRM
Definition: rb_mjit_min_header-2.7.0.h:2276
rb_str_subseq
VALUE rb_str_subseq(VALUE, long, long)
Definition: string.c:2474
SIGABRT
#define SIGABRT
Definition: rb_mjit_min_header-2.7.0.h:2253
SIGTERM
#define SIGTERM
Definition: rb_mjit_min_header-2.7.0.h:2263
SIGTTIN
#define SIGTTIN
Definition: rb_mjit_min_header-2.7.0.h:2270
SIGTRAP
#define SIGTRAP
Definition: rb_mjit_min_header-2.7.0.h:2252
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
GET_THREAD
#define GET_THREAD()
Definition: vm_core.h:1765
ruby_disable_gc
int ruby_disable_gc
Definition: gc.c:1001
SIG_SETMASK
#define SIG_SETMASK
Definition: rb_mjit_min_header-2.7.0.h:2305
debug_counter.h
rb_hash_aset
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Definition: hash.c:2779
ATOMIC_EXCHANGE
#define ATOMIC_EXCHANGE(var, val)
Definition: ruby_atomic.h:135
NIL_P
#define NIL_P(v)
Definition: ruby.h:482
FOREACH_SIGNAL
#define FOREACH_SIGNAL(sig, offset)
Definition: signal.c:65
TAG_NONE
#define TAG_NONE
Definition: vm_core.h:197
rb_execution_context_struct::interrupt_mask
rb_atomic_t interrupt_mask
Definition: vm_core.h:854
argc
int argc
Definition: ruby.c:222
rb_obj_classname
const char * rb_obj_classname(VALUE)
Definition: variable.c:289
rb_sys_fail_str
void rb_sys_fail_str(VALUE mesg)
Definition: error.c:2799
rb_ec_stack_overflow
MJIT_STATIC void rb_ec_stack_overflow(rb_execution_context_t *ec, int crit)
Definition: vm_insnhelper.c:67
SIGIO
#define SIGIO
Definition: rb_mjit_min_header-2.7.0.h:2272
SA_SIGINFO
#define SA_SIGINFO
Definition: rb_mjit_min_header-2.7.0.h:2236
RB_NO_KEYWORDS
#define RB_NO_KEYWORDS
Definition: ruby.h:1977
err
int err
Definition: win32.c:135
rb_signal_exec
int rb_signal_exec(rb_thread_t *th, int sig)
Definition: signal.c:1082
rb_vm_struct
Definition: vm_core.h:576
rb_threadptr_signal_raise
void rb_threadptr_signal_raise(rb_thread_t *th, int sig)
Definition: thread.c:2324
sigfillset
int sigfillset(sigset_t *)
sigaltstack::ss_size
size_t ss_size
Definition: rb_mjit_min_header-2.7.0.h:2303
SIGPROF
#define SIGPROF
Definition: rb_mjit_min_header-2.7.0.h:2277
_
#define _(args)
Definition: dln.h:28
EC_PUSH_TAG
#define EC_PUSH_TAG(ec)
Definition: eval_intern.h:130
Qtrue
#define Qtrue
Definition: ruby.h:468
errno
int errno
ruby_signal_name
const char * ruby_signal_name(int no)
Definition: signal.c:310
len
uint8_t len
Definition: escape.c:17
SYMBOL_P
#define SYMBOL_P(x)
Definition: ruby.h:413
RETSIGTYPE
#define RETSIGTYPE
Definition: rb_mjit_min_header-2.7.0.h:246
SIGALRM
#define SIGALRM
Definition: rb_mjit_min_header-2.7.0.h:2262
SIGKILL
#define SIGKILL
Definition: win32.h:484
ruby_atomic.h
rb_ivar_set
VALUE rb_ivar_set(VALUE, ID, VALUE)
Definition: variable.c:1300
T_STRING
#define T_STRING
Definition: ruby.h:528
rb_atomic_t
int rb_atomic_t
Definition: ruby_atomic.h:124
rb_pid_t
#define rb_pid_t
Definition: rb_mjit_min_header-2.7.0.h:99
rb_sym2str
VALUE rb_sym2str(VALUE)
Definition: symbol.c:784
_SC_PAGE_SIZE
#define _SC_PAGE_SIZE
Definition: rb_mjit_min_header-2.7.0.h:3372
TRAP_INTERRUPT_MASK
@ TRAP_INTERRUPT_MASK
Definition: vm_core.h:1833
eval_intern.h
size
rb_atomic_t size
Definition: signal.c:504
NUM2INT
#define NUM2INT(x)
Definition: ruby.h:715
Qnil
#define Qnil
Definition: ruby.h:469
ruby_sigaction_t
RETSIGTYPE ruby_sigaction_t(int)
Definition: signal.c:517
install_sighandler
#define install_sighandler(signum, handler)
Definition: signal.c:1445
h
size_t st_index_t h
Definition: rb_mjit_min_header-2.7.0.h:5462
MESSAGE_FAULT_ADDRESS
#define MESSAGE_FAULT_ADDRESS
Definition: signal.c:905
rb_eInterrupt
VALUE rb_eInterrupt
Definition: error.c:916
NUM2PIDT
#define NUM2PIDT(v)
Definition: ruby.h:357
write
_ssize_t write(int __fd, const void *__buf, size_t __nbyte)
rb_thread_struct
Definition: vm_core.h:910
rb_proc_t
Definition: vm_core.h:1049
STRINGIZE
#define STRINGIZE(expr)
Definition: defines.h:331
LONGEST_SIGNAME
@ LONGEST_SIGNAME
Definition: signal.c:67
ruby_tag_type
ruby_tag_type
Definition: vm_core.h:184
sigaltstack::ss_sp
void * ss_sp
Definition: rb_mjit_min_header-2.7.0.h:2301
SIGPWR
#define SIGPWR
Definition: rb_mjit_min_header-2.7.0.h:2280
SIGILL
#define SIGILL
Definition: rb_mjit_min_header-2.7.0.h:2251
sigaction
int sigaction(int, const struct sigaction *, struct sigaction *)
rb_vm_struct::waitpid_lock
rb_nativethread_lock_t waitpid_lock
Definition: vm_core.h:591
killpg
#define killpg(pg, sig)
IMMEDIATE_P
#define IMMEDIATE_P(x)
Definition: ruby.h:402
memchr
void * memchr(const void *, int, size_t)
name
const char * name
Definition: nkf.c:208
rb_execution_context_struct
Definition: vm_core.h:843
rb_block_proc
VALUE rb_block_proc(void)
Definition: proc.c:837