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() (void)(ruby_disable_gc = 0, received_signal = 0)
756 # define clear_received_signal() ((void)0)
759 #if defined(USE_SIGALTSTACK) || defined(_WIN32)
761 # if defined __HAIKU__
762 # define USE_UCONTEXT_REG 1
763 # elif !(defined(HAVE_UCONTEXT_H) && (defined __i386__ || defined __x86_64__ || defined __amd64__))
764 # elif defined __linux__
765 # define USE_UCONTEXT_REG 1
766 # elif defined __APPLE__
767 # define USE_UCONTEXT_REG 1
768 # elif defined __FreeBSD__
769 # define USE_UCONTEXT_REG 1
771 #if defined(HAVE_PTHREAD_SIGMASK)
772 # define ruby_sigunmask pthread_sigmask
773 #elif defined(HAVE_SIGPROCMASK)
774 # define ruby_sigunmask sigprocmask
777 reset_sigmask(
int sig)
779 #if defined(ruby_sigunmask)
782 clear_received_signal();
783 #if defined(ruby_sigunmask)
785 sigaddset(&mask, sig);
786 if (ruby_sigunmask(SIG_UNBLOCK, &mask, NULL)) {
792 # ifdef USE_UCONTEXT_REG
794 check_stack_overflow(
int sig,
const uintptr_t addr,
const ucontext_t *ctx)
796 const DEFINE_MCONTEXT_PTR(mctx, ctx);
797 # if defined __linux__
799 const greg_t sp = mctx->gregs[REG_RSP];
800 const greg_t bp = mctx->gregs[REG_RBP];
802 const greg_t sp = mctx->gregs[REG_ESP];
803 const greg_t bp = mctx->gregs[REG_EBP];
805 # elif defined __APPLE__
806 # include <AvailabilityMacros.h>
807 # if defined(MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
808 # define MCTX_SS_REG(reg) __ss.__##reg
810 # define MCTX_SS_REG(reg) ss.reg
812 # if defined(__LP64__)
813 const uintptr_t sp = mctx->MCTX_SS_REG(rsp);
814 const uintptr_t bp = mctx->MCTX_SS_REG(rbp);
816 const uintptr_t sp = mctx->MCTX_SS_REG(esp);
817 const uintptr_t bp = mctx->MCTX_SS_REG(ebp);
819 # elif defined __FreeBSD__
820 # if defined(__amd64__)
821 const __register_t sp = mctx->mc_rsp;
822 const __register_t bp = mctx->mc_rbp;
824 const __register_t sp = mctx->mc_esp;
825 const __register_t bp = mctx->mc_ebp;
827 # elif defined __HAIKU__
828 # if defined(__amd64__)
829 const unsigned long sp = mctx->rsp;
830 const unsigned long bp = mctx->rbp;
832 const unsigned long sp = mctx->esp;
833 const unsigned long bp = mctx->ebp;
836 enum {pagesize = 4096};
837 const uintptr_t sp_page = (uintptr_t)sp / pagesize;
838 const uintptr_t bp_page = (uintptr_t)bp / pagesize;
839 const uintptr_t fault_page = addr / pagesize;
843 if (sp_page == fault_page || sp_page == fault_page + 1 ||
844 (sp_page <= fault_page && fault_page <= bp_page)) {
847 int uplevel = roomof(pagesize,
sizeof(*ec->tag)) / 2;
848 while ((uintptr_t)ec->tag->buf / pagesize <= fault_page + 1) {
852 if ((crit = (!ec->tag->prev || !--uplevel)) != FALSE)
break;
853 ec->tag = ec->tag->prev;
856 rb_ec_stack_overflow(ec, crit);
861 check_stack_overflow(
int sig,
const void *addr)
863 int ruby_stack_overflowed_p(
const rb_thread_t *,
const void *);
865 if (ruby_stack_overflowed_p(th, addr)) {
867 rb_ec_stack_overflow(th->ec, FALSE);
873 # define CHECK_STACK_OVERFLOW() check_stack_overflow(sig, 0)
875 # define FAULT_ADDRESS info->si_addr
876 # ifdef USE_UCONTEXT_REG
877 # define CHECK_STACK_OVERFLOW_() check_stack_overflow(sig, (uintptr_t)FAULT_ADDRESS, ctx)
879 # define CHECK_STACK_OVERFLOW_() check_stack_overflow(sig, FAULT_ADDRESS)
881 # define MESSAGE_FAULT_ADDRESS " at %p", FAULT_ADDRESS
882 # define SIGNAL_FROM_USER_P() ((info)->si_code == SI_USER)
883 # define CHECK_STACK_OVERFLOW() (SIGNAL_FROM_USER_P() ? (void)0 : CHECK_STACK_OVERFLOW_())
886 # define CHECK_STACK_OVERFLOW() (void)0
888 #ifndef MESSAGE_FAULT_ADDRESS
889 # define MESSAGE_FAULT_ADDRESS
892 #if defined SIGSEGV || defined SIGBUS || defined SIGILL || defined SIGFPE
893 NOINLINE(
static void check_reserved_signal_(
const char *name,
size_t name_len,
int signo));
896 #define check_reserved_signal(name) check_reserved_signal_(name, sizeof(name)-1, sig)
900 static sighandler_t default_sigbus_handler;
901 NORETURN(
static ruby_sigaction_t sigbus);
904 sigbus(
int sig SIGINFO_ARG)
906 check_reserved_signal(
"BUS");
913 #if defined __APPLE__ || defined __linux__
914 CHECK_STACK_OVERFLOW();
916 rb_bug_for_fatal_signal(default_sigbus_handler, sig, SIGINFO_CTX,
"Bus Error" MESSAGE_FAULT_ADDRESS);
922 static sighandler_t default_sigsegv_handler;
923 NORETURN(
static ruby_sigaction_t sigsegv);
926 sigsegv(
int sig SIGINFO_ARG)
928 check_reserved_signal(
"SEGV");
929 CHECK_STACK_OVERFLOW();
930 rb_bug_for_fatal_signal(default_sigsegv_handler, sig, SIGINFO_CTX,
"Segmentation fault" MESSAGE_FAULT_ADDRESS);
936 static sighandler_t default_sigill_handler;
937 NORETURN(
static ruby_sigaction_t sigill);
940 sigill(
int sig SIGINFO_ARG)
942 check_reserved_signal(
"ILL");
943 #if defined __APPLE__ || defined __linux__
944 CHECK_STACK_OVERFLOW();
946 rb_bug_for_fatal_signal(default_sigill_handler, sig, SIGINFO_CTX,
"Illegal instruction" MESSAGE_FAULT_ADDRESS);
951 NORETURN(
static void ruby_abort(
void));
968 check_reserved_signal_(
const char *name,
size_t name_len,
int signo)
970 const char *prev = ATOMIC_PTR_EXCHANGE(received_signal, name);
973 ssize_t RB_UNUSED_VAR(err);
974 static const int stderr_fd = 2;
975 #define NOZ(name, str) name[sizeof(str)-1] = str
976 static const char NOZ(msg1,
" received in ");
977 static const char NOZ(msg2,
" handler\n");
982 # define W(str, len) \
983 iov[i++] = (struct iovec){.iov_base = (void *)(str), .iov_len = (len)}
985 # define W(str, len) err = write(stderr_fd, (str), (len))
988 #if __has_feature(address_sanitizer) || \
989 __has_feature(memory_sanitizer) || \
990 defined(HAVE_VALGRIND_MEMCHECK_H)
991 ruby_posix_signal(signo, SIG_DFL);
994 W(msg1,
sizeof(msg1));
995 W(prev, strlen(prev));
996 W(msg2,
sizeof(msg2));
999 err = writev(stderr_fd, iov, i);
1004 ruby_disable_gc = 1;
1008 #if defined SIGPIPE || defined SIGSYS
1010 sig_do_nothing(
int sig)
1016 signal_exec(
VALUE cmd,
int sig)
1019 volatile rb_atomic_t old_interrupt_mask = ec->interrupt_mask;
1020 enum ruby_tag_type state;
1031 ec->interrupt_mask |= TRAP_INTERRUPT_MASK;
1033 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1039 ec->interrupt_mask = old_interrupt_mask;
1043 EC_JUMP_TAG(ec, state);
1051 VALUE trap_exit = vm->trap_list.cmd[0];
1054 vm->trap_list.cmd[0] = 0;
1055 signal_exec(trap_exit, 0);
1064 VALUE cmd = vm->trap_list.cmd[sig];
1089 rb_threadptr_signal_raise(th, sig);
1093 else if (UNDEF_P(cmd)) {
1094 rb_threadptr_signal_exit(th);
1097 return signal_exec(cmd, sig);
1103 default_handler(
int sig)
1133 func = (sighandler_t)sigbus;
1138 func = (sighandler_t)sigsegv;
1143 func = sig_do_nothing;
1148 func = sig_do_nothing;
1160 trap_handler(
VALUE *cmd,
int sig)
1162 sighandler_t func = sighandler;
1174 if (!
NIL_P(command)) {
1186 func = default_handler(sig);
1193 if (memcmp(cptr,
"SYSTEM_DEFAULT", 14) == 0) {
1199 if (memcmp(cptr,
"SIG_IGN", 7) == 0) {
1202 else if (memcmp(cptr,
"SIG_DFL", 7) == 0) {
1205 else if (memcmp(cptr,
"DEFAULT", 7) == 0) {
1210 if (memcmp(cptr,
"IGNORE", 6) == 0) {
1215 if (memcmp(cptr,
"EXIT", 4) == 0) {
1223 GetProcPtr(*cmd, proc);
1232 trap_signm(
VALUE vsig)
1238 if (sig < 0 || sig >= NSIG) {
1243 sig = signm2signo(&vsig, FALSE, TRUE, NULL);
1249 trap(
int sig, sighandler_t func,
VALUE command)
1251 sighandler_t oldfunc;
1264 oldfunc = ruby_signal(sig, func);
1267 oldcmd = vm->trap_list.cmd[sig];
1271 if (oldfunc == SIG_IGN) oldcmd =
rb_str_new2(
"IGNORE");
1272 else if (oldfunc == SIG_DFL) oldcmd =
rb_str_new2(
"SYSTEM_DEFAULT");
1273 else if (oldfunc == sighandler) oldcmd =
rb_str_new2(
"DEFAULT");
1283 ACCESS_ONCE(
VALUE, vm->trap_list.cmd[sig]) = command;
1289 reserved_signal_p(
int signo)
1293 if (signo == SIGSEGV)
1297 if (signo == SIGBUS)
1301 if (signo == SIGILL)
1305 if (signo == SIGFPE)
1311 if (signo == SIGVTALRM)
1358 sig = trap_signm(argv[0]);
1359 if (reserved_signal_p(sig)) {
1360 const char *name = signo2signm(sig);
1373 func = trap_handler(&cmd, sig);
1378 cmd = rb_proc_isolate(cmd);
1381 return trap(sig, func, cmd);
1399 FOREACH_SIGNAL(sigs, 0) {
1405 #define INSTALL_SIGHANDLER(cond, signame, signum) do { \
1406 static const char failed[] = "failed to install "signame" handler"; \
1407 if (!(cond)) break; \
1408 if (reserved_signal_p(signum)) rb_bug(failed); \
1413 install_sighandler_core(
int signum, sighandler_t handler, sighandler_t *old_handler)
1417 old = ruby_signal(signum, handler);
1418 if (old == SIG_ERR)
return -1;
1420 *old_handler = (old == SIG_DFL || old == SIG_IGN) ? 0 : old;
1424 if (old != SIG_DFL) {
1425 ruby_signal(signum, old);
1431 # define install_sighandler(signum, handler) \
1432 INSTALL_SIGHANDLER(install_sighandler_core(signum, handler, NULL), #signum, signum)
1433 # define force_install_sighandler(signum, handler, old_handler) \
1434 INSTALL_SIGHANDLER(install_sighandler_core(signum, handler, old_handler), #signum, signum)
1439 sighandler_t oldfunc;
1441 oldfunc = ruby_signal(SIGINT, SIG_IGN);
1442 if (oldfunc == sighandler) {
1443 ruby_signal(SIGINT, SIG_DFL);
1447 int ruby_enable_coredump = 0;
1502 VM_ASSERT(GET_THREAD()->pending_interrupt_queue);
1505 rb_disable_interrupt();
1507 install_sighandler(SIGINT, sighandler);
1509 install_sighandler(SIGHUP, sighandler);
1512 install_sighandler(SIGQUIT, sighandler);
1515 install_sighandler(SIGTERM, sighandler);
1518 install_sighandler(SIGALRM, sighandler);
1521 install_sighandler(SIGUSR1, sighandler);
1524 install_sighandler(SIGUSR2, sighandler);
1527 if (!ruby_enable_coredump) {
1529 force_install_sighandler(SIGBUS, (sighandler_t)sigbus, &default_sigbus_handler);
1532 force_install_sighandler(SIGILL, (sighandler_t)sigill, &default_sigill_handler);
1535 RB_ALTSTACK_INIT(GET_VM()->main_altstack, rb_allocate_sigaltstack());
1536 force_install_sighandler(SIGSEGV, (sighandler_t)sigsegv, &default_sigsegv_handler);
1540 install_sighandler(SIGPIPE, sig_do_nothing);
1543 install_sighandler(SIGSYS, sig_do_nothing);
1547 install_sighandler(RUBY_SIGCHLD, sighandler);
1550 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, 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 id)
Identical to rb_id2str(), except it takes an instance of rb_cSymbol rather than an ID.
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.