14 #include "ruby/internal/config.h"
28 #ifdef HAVE_UCONTEXT_H
29 # include <ucontext.h>
36 #include "debug_counter.h"
37 #include "eval_intern.h"
39 #include "internal/error.h"
40 #include "internal/eval.h"
41 #include "internal/sanitizers.h"
42 #include "internal/signal.h"
43 #include "internal/string.h"
44 #include "internal/thread.h"
45 #include "ruby_atomic.h"
47 #include "ractor_core.h"
49 #ifdef NEED_RUBY_ATOMIC_OPS
70 #define FOREACH_SIGNAL(sig, offset) \
71 for (sig = siglist + (offset); sig < siglist + numberof(siglist); ++sig)
72 enum { LONGEST_SIGNAME = 7 };
74 char signm[LONGEST_SIGNAME + 1];
137 {
"CHLD", RUBY_SIGCHLD },
138 {
"CLD", RUBY_SIGCHLD },
156 {
"VTALRM", SIGVTALRM},
183 {
"DANGER", SIGDANGER},
186 {
"MIGRATE", SIGMIGRATE},
195 {
"RETRACT", SIGRETRACT},
205 static const char signame_prefix[] =
"SIG";
206 static const int signame_prefix_len = 3;
209 signm2signo(
VALUE *sig_ptr,
int negative,
int exit,
int *prefix_ptr)
212 VALUE vsig = *sig_ptr;
226 *sig_ptr = vsig = str;
231 if (memchr(nm,
'\0',
len)) {
235 if (
len > 0 && nm[0] ==
'-') {
243 if (
len >= prefix + signame_prefix_len) {
244 if (memcmp(nm + prefix, signame_prefix, signame_prefix_len) == 0)
245 prefix += signame_prefix_len;
247 if (
len <= (
long)prefix) {
251 if (prefix_ptr) *prefix_ptr = prefix;
252 nmlen =
len - prefix;
254 if (nmlen > LONGEST_SIGNAME)
goto unsupported;
255 FOREACH_SIGNAL(sigs, !exit) {
256 if (memcmp(sigs->signm, nm, nmlen) == 0 &&
257 sigs->signm[nmlen] ==
'\0') {
258 return negative ? -sigs->signo : sigs->signo;
263 if (prefix == signame_prefix_len) {
266 else if (prefix > signame_prefix_len) {
267 prefix -= signame_prefix_len;
275 prefix = signame_prefix_len;
278 prefix, signame_prefix, vsig);
287 FOREACH_SIGNAL(sigs, 0) {
288 if (sigs->signo == no)
311 const char *signame = signo2signm(
NUM2INT(signo));
312 if (!signame)
return Qnil;
319 return signo2signm(no);
323 rb_signo2signm(
int signo)
325 const char *
const signm = signo2signm(signo);
344 esignal_init(
int argc,
VALUE *argv,
VALUE self)
352 if (!
NIL_P(sig)) argnum = 2;
358 if (signo < 0 || signo > NSIG) {
365 sig = rb_signo2signm(signo);
370 signo = signm2signo(&sig, FALSE, FALSE, &prefix);
371 if (prefix != signame_prefix_len) {
389 esignal_signo(
VALUE self)
396 interrupt_init(
int argc,
VALUE *argv,
VALUE self)
405 void rb_malloc_info_show_results(
void);
406 #if defined(USE_SIGALTSTACK) || defined(_WIN32)
407 static void reset_sigmask(
int sig);
413 #if USE_DEBUG_COUNTER
414 rb_debug_counter_show_results(
"killed by signal.");
416 rb_malloc_info_show_results();
418 signal(sig, SIG_DFL);
419 #if defined(USE_SIGALTSTACK) || defined(_WIN32)
425 static void sighandler(
int sig);
426 static int signal_ignored(
int sig);
427 static void signal_enque(
int sig);
433 #define killpg(pg, sig) kill(-(pg), (sig))
446 sig = signm2signo(&str, TRUE, FALSE, NULL);
449 if (argc <= 1)
return INT2FIX(0);
453 for (i=1; i<argc; i++) {
454 if (killpg(
NUM2PIDT(argv[i]), sig) < 0)
459 const rb_pid_t
self = (GET_THREAD() == GET_VM()->ractor.main_thread) ? getpid() : -1;
462 for (i=1; i<argc; i++) {
465 if ((sig != 0) && (
self != -1) && (pid ==
self)) {
491 t = signal_ignored(sig);
493 if (t < 0 && kill(pid, sig))
501 else if (kill(pid, sig) < 0) {
506 rb_threadptr_check_signal(GET_VM()->ractor.main_thread);
519 #define sighandler_t ruby_sighandler_t
521 #ifdef USE_SIGALTSTACK
522 typedef void ruby_sigaction_t(
int, siginfo_t*,
void*);
523 #define SIGINFO_ARG , siginfo_t *info, void *ctx
524 #define SIGINFO_CTX ctx
526 typedef void ruby_sigaction_t(
int);
528 #define SIGINFO_CTX 0
531 #ifdef USE_SIGALTSTACK
533 #define RUBY_SIGALTSTACK_SIZE (16*1024)
536 rb_sigaltstack_size(
void)
538 int size = RUBY_SIGALTSTACK_SIZE;
542 int minsigstksz = (int)MINSIGSTKSZ;
543 if (size < minsigstksz)
547 #if defined(HAVE_SYSCONF) && defined(_SC_PAGE_SIZE)
550 pagesize = (int)sysconf(_SC_PAGE_SIZE);
559 static int rb_sigaltstack_size_value = 0;
562 rb_allocate_sigaltstack(
void)
565 if (!rb_sigaltstack_size_value) {
566 rb_sigaltstack_size_value = rb_sigaltstack_size();
568 altstack = malloc(rb_sigaltstack_size_value);
575 rb_register_sigaltstack(
void *altstack)
577 stack_t newSS, oldSS;
579 newSS.ss_size = rb_sigaltstack_size_value;
580 newSS.ss_sp = altstack;
583 sigaltstack(&newSS, &oldSS);
591 ruby_signal(
int signum, sighandler_t handler)
593 struct sigaction sigact, old;
596 rb_trap_accept_nativethreads[signum] = 0;
599 sigemptyset(&sigact.sa_mask);
600 #if defined(USE_SIGALTSTACK) && !defined(__wasm__)
601 if (handler == SIG_IGN || handler == SIG_DFL) {
602 sigact.sa_handler = handler;
606 sigact.sa_sigaction = (ruby_sigaction_t*)handler;
607 sigact.sa_flags = SA_SIGINFO;
610 sigact.sa_handler = handler;
615 #if defined(SA_ONSTACK) && defined(USE_SIGALTSTACK)
620 sigact.sa_flags |= SA_ONSTACK;
624 (void)VALGRIND_MAKE_MEM_DEFINED(&old,
sizeof(old));
625 if (sigaction(signum, &sigact, &old) < 0) {
628 if (old.sa_flags & SA_SIGINFO)
629 handler = (sighandler_t)old.sa_sigaction;
631 handler = old.sa_handler;
632 ASSUME(handler != SIG_ERR);
637 ruby_posix_signal(
int signum, sighandler_t handler)
639 return ruby_signal(signum, handler);
643 static inline sighandler_t
644 ruby_signal(
int signum, sighandler_t handler)
646 if (signum == SIGKILL) {
650 return signal(signum, handler);
654 #define ruby_signal(sig,handler) ( signal((sig),(handler)))
657 ruby_nativethread_signal(
int signum, sighandler_t handler)
661 old = signal(signum, handler);
662 rb_trap_accept_nativethreads[signum] = 1;
669 signal_ignored(
int sig)
673 struct sigaction old;
674 (void)VALGRIND_MAKE_MEM_DEFINED(&old,
sizeof(old));
675 if (sigaction(sig, NULL, &old) < 0)
return FALSE;
676 func = old.sa_handler;
678 sighandler_t old = signal(sig, SIG_DFL);
682 if (func == SIG_IGN)
return 1;
683 return func == sighandler ? 0 : -1;
687 signal_enque(
int sig)
689 ATOMIC_INC(signal_buff.cnt[sig]);
690 ATOMIC_INC(signal_buff.size);
696 int old_errnum =
errno;
699 rb_thread_wakeup_timer_thread(sig);
701 #if !defined(BSD_SIGNAL) && !defined(POSIX_SIGNAL)
702 ruby_signal(sig, sighandler);
709 rb_signal_buff_size(
void)
711 return signal_buff.size;
715 rb_disable_interrupt(
void)
717 #ifdef HAVE_PTHREAD_SIGMASK
720 pthread_sigmask(SIG_SETMASK, &mask, NULL);
725 rb_enable_interrupt(
void)
727 #ifdef HAVE_PTHREAD_SIGMASK
730 pthread_sigmask(SIG_SETMASK, &mask, NULL);
735 rb_get_next_signal(
void)
739 if (signal_buff.size != 0) {
740 for (i=1; i<RUBY_NSIG; i++) {
741 if (signal_buff.cnt[i] > 0) {
742 ATOMIC_DEC(signal_buff.cnt[i]);
743 ATOMIC_DEC(signal_buff.size);
752 #if defined SIGSEGV || defined SIGBUS || defined SIGILL || defined SIGFPE
753 static const char *received_signal;
754 # define clear_received_signal() do { \
755 if (GET_VM() != NULL) rb_gc_enable(); \
756 received_signal = 0; \
759 # define clear_received_signal() ((void)0)
762 #if defined(USE_SIGALTSTACK) || defined(_WIN32)
764 # if defined __HAIKU__
765 # define USE_UCONTEXT_REG 1
766 # elif !(defined(HAVE_UCONTEXT_H) && (defined __i386__ || defined __x86_64__ || defined __amd64__))
767 # elif defined __linux__
768 # define USE_UCONTEXT_REG 1
769 # elif defined __APPLE__
770 # define USE_UCONTEXT_REG 1
771 # elif defined __FreeBSD__
772 # define USE_UCONTEXT_REG 1
774 #if defined(HAVE_PTHREAD_SIGMASK)
775 # define ruby_sigunmask pthread_sigmask
776 #elif defined(HAVE_SIGPROCMASK)
777 # define ruby_sigunmask sigprocmask
780 reset_sigmask(
int sig)
782 #if defined(ruby_sigunmask)
785 clear_received_signal();
786 #if defined(ruby_sigunmask)
788 sigaddset(&mask, sig);
789 if (ruby_sigunmask(SIG_UNBLOCK, &mask, NULL)) {
795 # ifdef USE_UCONTEXT_REG
797 check_stack_overflow(
int sig,
const uintptr_t addr,
const ucontext_t *ctx)
799 const DEFINE_MCONTEXT_PTR(mctx, ctx);
800 # if defined __linux__
802 const greg_t sp = mctx->gregs[REG_RSP];
803 const greg_t bp = mctx->gregs[REG_RBP];
805 const greg_t sp = mctx->gregs[REG_ESP];
806 const greg_t bp = mctx->gregs[REG_EBP];
808 # elif defined __APPLE__
809 # include <AvailabilityMacros.h>
810 # if defined(MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
811 # define MCTX_SS_REG(reg) __ss.__##reg
813 # define MCTX_SS_REG(reg) ss.reg
815 # if defined(__LP64__)
816 const uintptr_t sp = mctx->MCTX_SS_REG(rsp);
817 const uintptr_t bp = mctx->MCTX_SS_REG(rbp);
819 const uintptr_t sp = mctx->MCTX_SS_REG(esp);
820 const uintptr_t bp = mctx->MCTX_SS_REG(ebp);
822 # elif defined __FreeBSD__
823 # if defined(__amd64__)
824 const __register_t sp = mctx->mc_rsp;
825 const __register_t bp = mctx->mc_rbp;
827 const __register_t sp = mctx->mc_esp;
828 const __register_t bp = mctx->mc_ebp;
830 # elif defined __HAIKU__
831 # if defined(__amd64__)
832 const unsigned long sp = mctx->rsp;
833 const unsigned long bp = mctx->rbp;
835 const unsigned long sp = mctx->esp;
836 const unsigned long bp = mctx->ebp;
839 enum {pagesize = 4096};
840 const uintptr_t sp_page = (uintptr_t)sp / pagesize;
841 const uintptr_t bp_page = (uintptr_t)bp / pagesize;
842 const uintptr_t fault_page = addr / pagesize;
846 if (sp_page == fault_page || sp_page == fault_page + 1 ||
847 (sp_page <= fault_page && fault_page <= bp_page)) {
850 int uplevel = roomof(pagesize,
sizeof(*ec->tag)) / 2;
851 while ((uintptr_t)ec->tag->buf / pagesize <= fault_page + 1) {
855 if ((crit = (!ec->tag->prev || !--uplevel)) != FALSE)
break;
856 ec->tag = ec->tag->prev;
859 rb_ec_stack_overflow(ec, crit);
864 check_stack_overflow(
int sig,
const void *addr)
866 int ruby_stack_overflowed_p(
const rb_thread_t *,
const void *);
868 if (ruby_stack_overflowed_p(th, addr)) {
870 rb_ec_stack_overflow(th->ec, FALSE);
876 # define CHECK_STACK_OVERFLOW() check_stack_overflow(sig, 0)
878 # define FAULT_ADDRESS info->si_addr
879 # ifdef USE_UCONTEXT_REG
880 # define CHECK_STACK_OVERFLOW_() check_stack_overflow(sig, (uintptr_t)FAULT_ADDRESS, ctx)
882 # define CHECK_STACK_OVERFLOW_() check_stack_overflow(sig, FAULT_ADDRESS)
884 # define MESSAGE_FAULT_ADDRESS " at %p", FAULT_ADDRESS
885 # define SIGNAL_FROM_USER_P() ((info)->si_code == SI_USER)
886 # define CHECK_STACK_OVERFLOW() (SIGNAL_FROM_USER_P() ? (void)0 : CHECK_STACK_OVERFLOW_())
889 # define CHECK_STACK_OVERFLOW() (void)0
891 #ifndef MESSAGE_FAULT_ADDRESS
892 # define MESSAGE_FAULT_ADDRESS
895 #if defined SIGSEGV || defined SIGBUS || defined SIGILL || defined SIGFPE
896 NOINLINE(
static void check_reserved_signal_(
const char *name,
size_t name_len,
int signo));
899 #define check_reserved_signal(name) check_reserved_signal_(name, sizeof(name)-1, sig)
903 static sighandler_t default_sigbus_handler;
904 NORETURN(
static ruby_sigaction_t sigbus);
907 sigbus(
int sig SIGINFO_ARG)
909 check_reserved_signal(
"BUS");
916 #if defined __APPLE__ || defined __linux__
917 CHECK_STACK_OVERFLOW();
919 rb_bug_for_fatal_signal(default_sigbus_handler, sig, SIGINFO_CTX,
"Bus Error" MESSAGE_FAULT_ADDRESS);
925 static sighandler_t default_sigsegv_handler;
926 NORETURN(
static ruby_sigaction_t sigsegv);
929 sigsegv(
int sig SIGINFO_ARG)
931 check_reserved_signal(
"SEGV");
932 CHECK_STACK_OVERFLOW();
933 rb_bug_for_fatal_signal(default_sigsegv_handler, sig, SIGINFO_CTX,
"Segmentation fault" MESSAGE_FAULT_ADDRESS);
939 static sighandler_t default_sigill_handler;
940 NORETURN(
static ruby_sigaction_t sigill);
943 sigill(
int sig SIGINFO_ARG)
945 check_reserved_signal(
"ILL");
946 #if defined __APPLE__ || defined __linux__
947 CHECK_STACK_OVERFLOW();
949 rb_bug_for_fatal_signal(default_sigill_handler, sig, SIGINFO_CTX,
"Illegal instruction" MESSAGE_FAULT_ADDRESS);
954 NORETURN(
static void ruby_abort(
void));
971 check_reserved_signal_(
const char *name,
size_t name_len,
int signo)
973 const char *prev = ATOMIC_PTR_EXCHANGE(received_signal, name);
976 ssize_t RB_UNUSED_VAR(err);
977 static const int stderr_fd = 2;
978 #define NOZ(name, str) name[sizeof(str)-1] = str
979 static const char NOZ(msg1,
" received in ");
980 static const char NOZ(msg2,
" handler\n");
985 # define W(str, len) \
986 iov[i++] = (struct iovec){.iov_base = (void *)(str), .iov_len = (len)}
988 # define W(str, len) err = write(stderr_fd, (str), (len))
991 #if __has_feature(address_sanitizer) || \
992 __has_feature(memory_sanitizer) || \
993 defined(HAVE_VALGRIND_MEMCHECK_H)
994 ruby_posix_signal(signo, SIG_DFL);
997 W(msg1,
sizeof(msg1));
998 W(prev, strlen(prev));
999 W(msg2,
sizeof(msg2));
1002 err = writev(stderr_fd, iov, i);
1007 if (GET_VM() != NULL) {
1008 rb_gc_disable_no_rest();
1013 #if defined SIGPIPE || defined SIGSYS
1015 sig_do_nothing(
int sig)
1021 signal_exec(
VALUE cmd,
int sig)
1024 volatile rb_atomic_t old_interrupt_mask = ec->interrupt_mask;
1025 enum ruby_tag_type state;
1036 ec->interrupt_mask |= TRAP_INTERRUPT_MASK;
1038 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1044 ec->interrupt_mask = old_interrupt_mask;
1048 EC_JUMP_TAG(ec, state);
1056 VALUE trap_exit = vm->trap_list.cmd[0];
1059 vm->trap_list.cmd[0] = 0;
1060 signal_exec(trap_exit, 0);
1069 VALUE cmd = vm->trap_list.cmd[sig];
1094 rb_threadptr_signal_raise(th, sig);
1098 else if (UNDEF_P(cmd)) {
1099 rb_threadptr_signal_exit(th);
1102 return signal_exec(cmd, sig);
1108 default_handler(
int sig)
1138 func = (sighandler_t)sigbus;
1143 func = (sighandler_t)sigsegv;
1148 func = sig_do_nothing;
1153 func = sig_do_nothing;
1165 trap_handler(
VALUE *cmd,
int sig)
1167 sighandler_t func = sighandler;
1179 if (!
NIL_P(command)) {
1191 func = default_handler(sig);
1198 if (memcmp(cptr,
"SYSTEM_DEFAULT", 14) == 0) {
1204 if (memcmp(cptr,
"SIG_IGN", 7) == 0) {
1207 else if (memcmp(cptr,
"SIG_DFL", 7) == 0) {
1210 else if (memcmp(cptr,
"DEFAULT", 7) == 0) {
1215 if (memcmp(cptr,
"IGNORE", 6) == 0) {
1220 if (memcmp(cptr,
"EXIT", 4) == 0) {
1228 GetProcPtr(*cmd, proc);
1237 trap_signm(
VALUE vsig)
1243 if (sig < 0 || sig >= NSIG) {
1248 sig = signm2signo(&vsig, FALSE, TRUE, NULL);
1254 trap(
int sig, sighandler_t func,
VALUE command)
1256 sighandler_t oldfunc;
1269 oldfunc = ruby_signal(sig, func);
1272 oldcmd = vm->trap_list.cmd[sig];
1276 if (oldfunc == SIG_IGN) oldcmd =
rb_str_new2(
"IGNORE");
1277 else if (oldfunc == SIG_DFL) oldcmd =
rb_str_new2(
"SYSTEM_DEFAULT");
1278 else if (oldfunc == sighandler) oldcmd =
rb_str_new2(
"DEFAULT");
1288 ACCESS_ONCE(
VALUE, vm->trap_list.cmd[sig]) = command;
1294 reserved_signal_p(
int signo)
1298 if (signo == SIGSEGV)
1302 if (signo == SIGBUS)
1306 if (signo == SIGILL)
1310 if (signo == SIGFPE)
1316 if (signo == SIGVTALRM)
1363 sig = trap_signm(argv[0]);
1364 if (reserved_signal_p(sig)) {
1365 const char *name = signo2signm(sig);
1378 func = trap_handler(&cmd, sig);
1383 cmd = rb_proc_isolate(cmd);
1386 return trap(sig, func, cmd);
1404 FOREACH_SIGNAL(sigs, 0) {
1410 #define INSTALL_SIGHANDLER(cond, signame, signum) do { \
1411 static const char failed[] = "failed to install "signame" handler"; \
1412 if (!(cond)) break; \
1413 if (reserved_signal_p(signum)) rb_bug(failed); \
1418 install_sighandler_core(
int signum, sighandler_t handler, sighandler_t *old_handler)
1422 old = ruby_signal(signum, handler);
1423 if (old == SIG_ERR)
return -1;
1425 *old_handler = (old == SIG_DFL || old == SIG_IGN) ? 0 : old;
1429 if (old != SIG_DFL) {
1430 ruby_signal(signum, old);
1436 # define install_sighandler(signum, handler) \
1437 INSTALL_SIGHANDLER(install_sighandler_core(signum, handler, NULL), #signum, signum)
1438 # define force_install_sighandler(signum, handler, old_handler) \
1439 INSTALL_SIGHANDLER(install_sighandler_core(signum, handler, old_handler), #signum, signum)
1444 sighandler_t oldfunc;
1446 oldfunc = ruby_signal(SIGINT, SIG_IGN);
1447 if (oldfunc == sighandler) {
1448 ruby_signal(SIGINT, SIG_DFL);
1452 int ruby_enable_coredump = 0;
1507 VM_ASSERT(GET_THREAD()->pending_interrupt_queue);
1510 rb_disable_interrupt();
1512 install_sighandler(SIGINT, sighandler);
1514 install_sighandler(SIGHUP, sighandler);
1517 install_sighandler(SIGQUIT, sighandler);
1520 install_sighandler(SIGTERM, sighandler);
1523 install_sighandler(SIGALRM, sighandler);
1526 install_sighandler(SIGUSR1, sighandler);
1529 install_sighandler(SIGUSR2, sighandler);
1532 if (!ruby_enable_coredump) {
1534 force_install_sighandler(SIGBUS, (sighandler_t)sigbus, &default_sigbus_handler);
1537 force_install_sighandler(SIGILL, (sighandler_t)sigill, &default_sigill_handler);
1540 RB_ALTSTACK_INIT(GET_VM()->main_altstack, rb_allocate_sigaltstack());
1541 force_install_sighandler(SIGSEGV, (sighandler_t)sigsegv, &default_sigsegv_handler);
1545 install_sighandler(SIGPIPE, sig_do_nothing);
1548 install_sighandler(SIGSYS, sig_do_nothing);
1552 install_sighandler(RUBY_SIGCHLD, sighandler);
1555 rb_enable_interrupt();
std::atomic< unsigned > rb_atomic_t
Type that is eligible for atomic operations.
VALUE rb_define_module(const char *name)
Defines a top-level module.
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for a module.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a method.
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
#define rb_str_new2
Old name of rb_str_new_cstr.
#define T_STRING
Old name of RUBY_T_STRING.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define UNREACHABLE_RETURN
Old name of RBIMPL_UNREACHABLE_RETURN.
#define FIX2INT
Old name of RB_FIX2INT.
#define ASSUME
Old name of RBIMPL_ASSUME.
#define rb_ary_new3
Old name of rb_ary_new_from_args.
#define Qtrue
Old name of RUBY_Qtrue.
#define NUM2INT
Old name of RB_NUM2INT.
#define INT2NUM
Old name of RB_INT2NUM.
#define Qnil
Old name of RUBY_Qnil.
#define NIL_P
Old name of RB_NIL_P.
#define IMMEDIATE_P
Old name of RB_IMMEDIATE_P.
#define FIXNUM_P
Old name of RB_FIXNUM_P.
#define SYMBOL_P
Old name of RB_SYMBOL_P.
void ruby_sig_finalize(void)
Clear signal handlers.
void rb_raise(VALUE exc_class, const char *fmt,...)
Exception entry point.
void rb_sys_fail(const char *mesg)
Converts a C errno into a Ruby exception, then raises it.
VALUE rb_eInterrupt
Interrupt exception.
VALUE rb_eArgError
ArgumentError exception.
void rb_bug_errno(const char *mesg, int errno_arg)
This is a wrapper of rb_bug() which automatically constructs appropriate message from the passed errn...
void rb_sys_fail_str(VALUE mesg)
Identical to rb_sys_fail(), except it takes the message in Ruby's String instead of C's.
VALUE rb_eSignal
SignalException exception.
VALUE rb_check_to_integer(VALUE val, const char *mid)
Identical to rb_check_convert_type(), except the return value type is fixed to rb_cInteger.
VALUE rb_call_super(int argc, const VALUE *argv)
This resembles ruby's super.
void rb_memerror(void)
Triggers out-of-memory error.
#define UNLIMITED_ARGUMENTS
This macro is used in conjunction with rb_check_arity().
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
void rb_interrupt(void)
Raises an instance of rb_eInterrupt.
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Inserts or replaces ("upsert"s) the objects into the given hash table.
VALUE rb_hash_new(void)
Creates a new, empty hash object.
VALUE rb_block_proc(void)
Constructs a Proc object from implicitly passed components.
VALUE rb_obj_is_proc(VALUE recv)
Queries if the given object is a proc.
void ruby_default_signal(int sig)
Pretends as if there was no custom signal handler.
const char * ruby_signal_name(int signo)
Queries the name of the signal.
VALUE rb_f_kill(int argc, const VALUE *argv)
Sends a signal ("kills") to processes.
VALUE rb_str_append(VALUE dst, VALUE src)
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
VALUE rb_str_subseq(VALUE str, long beg, long len)
Identical to rb_str_substr(), except the numbers are interpreted as byte offsets instead of character...
void rb_must_asciicompat(VALUE obj)
Asserts that the given string's encoding is (Ruby's definition of) ASCII compatible.
VALUE rb_check_string_type(VALUE obj)
Try converting an object to its stringised representation using its to_str method,...
VALUE rb_str_new_cstr(const char *ptr)
Identical to rb_str_new(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_thread_current(void)
Obtains the "current" thread.
VALUE rb_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
VALUE rb_ivar_get(VALUE obj, ID name)
Identical to rb_iv_get(), except it accepts the name as an ID instead of a C string.
void rb_alias(VALUE klass, ID dst, ID src)
Resembles alias.
VALUE rb_eval_cmd_kw(VALUE cmd, VALUE arg, int kw_splat)
This API is practically a variant of rb_proc_call_kw() now.
static ID rb_intern_const(const char *str)
This is a "tiny optimisation" over rb_intern().
VALUE rb_sym2str(VALUE symbol)
Obtain a frozen string representation of a symbol (not including the leading colon).
char * ptr
Pointer to the underlying memory region, of at least capa bytes.
int len
Length of the buffer.
static bool rb_ractor_shareable_p(VALUE obj)
Queries if multiple Ractors can share the passed object or not.
VALUE rb_sprintf(const char *fmt,...)
Ruby's extended sprintf(3).
#define NUM2PIDT
Converts an instance of rb_cNumeric into C's pid_t.
#define StringValue(v)
Ensures that the parameter object is a String.
#define RSTRING_GETMEM(str, ptrvar, lenvar)
Convenient macro to obtain the contents and length at once.
const char * rb_obj_classname(VALUE obj)
Queries the name of the class of the passed object.
#define errno
Ractor-aware version of errno.
#define RB_NO_KEYWORDS
Do not pass keywords.
#define _(args)
This was a transition path from K&R to ANSI.
uintptr_t VALUE
Type that represents a Ruby object.
static bool RB_SYMBOL_P(VALUE obj)
Queries if the object is an instance of rb_cSymbol.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.