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) {
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);
static VALUE sig_list(void)
static void signal_exec(VALUE cmd, int safe, int sig)
const char * ruby_signal_name(int no)
void ruby_thread_stack_overflow(rb_thread_t *th)
void rb_bug(const char *fmt,...)
static VALUE trap(int sig, sighandler_t func, VALUE command)
rb_atomic_t ruby_atomic_exchange(rb_atomic_t *ptr, rb_atomic_t val)
#define GetProcPtr(obj, ptr)
static VALUE interrupt_init(int argc, VALUE *argv, VALUE self)
static void rb_enable_interrupt(void)
void rb_threadptr_signal_raise(rb_thread_t *th, int sig)
SSL_METHOD *(* func)(void)
RETSIGTYPE ruby_sigaction_t(int)
void rb_signal_exec(rb_thread_t *th, int sig)
#define ruby_enable_coredump
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_ary_new3(long n,...)
void ruby_default_signal(int sig)
static VALUE esignal_signo(VALUE self)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
RETSIGTYPE(* sighandler_t)(int)
VALUE rb_check_to_integer(VALUE, const char *)
static sighandler_t trap_handler(VALUE *cmd, int sig)
const char * rb_obj_classname(VALUE)
static VALUE sig_signame(VALUE recv, VALUE signo)
sighandler_t posix_signal(int signum, sighandler_t handler)
int ruby_disable_gc_stress
static int reserved_signal_p(int signo)
void rb_thread_wakeup_timer_thread(void)
static RETSIGTYPE sighandler(int sig)
VALUE rb_iv_get(VALUE, const char *)
int pthread_sigmask(int how, const sigset_t *set, sigset_t *oset)
static void install_sighandler(int signum, sighandler_t handler)
static const struct signals siglist[]
rb_atomic_t cnt[RUBY_NSIG]
static sighandler_t default_handler(int sig)
static VALUE sig_trap(int argc, VALUE *argv)
static int signm2signo(const char *nm)
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
VALUE rb_sprintf(const char *format,...)
VALUE rb_iv_set(VALUE, const char *, VALUE)
struct rb_vm_struct::@130 trap_list[RUBY_NSIG]
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static const char * signo2signm(int no)
static void rb_disable_interrupt(void)
static struct @116 signal_buff
void rb_bug_errno(const char *mesg, int errno_arg)
void rb_alias(VALUE, ID, ID)
VALUE rb_call_super(int, const VALUE *)
VALUE rb_str_new_cstr(const char *)
int rb_sigaltstack_size(void)
void rb_sys_fail(const char *mesg)
int rb_get_next_signal(void)
VALUE rb_f_kill(int argc, VALUE *argv)
rb_atomic_t ruby_atomic_compare_and_swap(rb_atomic_t *ptr, rb_atomic_t cmp, rb_atomic_t newval)
#define CHECK_STACK_OVERFLOW()
#define rb_check_arity(argc, min, max)
#define UNLIMITED_ARGUMENTS
sighandler_t signal(int signum, sighandler_t handler)
unsigned long interrupt_mask
VALUE rb_block_proc(void)
void ruby_sig_finalize(void)
VALUE rb_check_string_type(VALUE)
int rb_signal_buff_size(void)
static VALUE esignal_init(int argc, VALUE *argv, VALUE self)
VALUE rb_eval_cmd(VALUE, VALUE, int)
#define SafeStringValue(v)
static int trap_signm(VALUE vsig)
const char * rb_id2name(ID id)
#define StringValuePtr(v)
#define ruby_signal(sig, handler)
VALUE rb_define_module(const char *name)
VALUE rb_hash_aset(VALUE, VALUE, VALUE)
static rb_thread_t * GET_THREAD(void)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_new2(const char *)
void rb_threadptr_signal_exit(rb_thread_t *th)