16#ifdef HAVE_SYS_PRCTL_H
24#include "internal/error.h"
25#include "internal/eval.h"
31#include "internal/variable.h"
53#define id_cause ruby_static_id_cause
55#define exception_error GET_VM()->special_exceptions[ruby_error_reenter]
60#define CLASS_OR_MODULE_P(obj) \
61 (!SPECIAL_CONST_P(obj) && \
62 (BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE))
83#if defined(__linux__) && defined(PR_SET_THP_DISABLE)
84 prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0);
95 GET_VM()->running = 1;
113 error_print(GET_EC());
133 void *
volatile iseq = 0;
168 rb_ec_scheduler_finalize(ec);
175 rb_ec_exec_end_proc(ec);
215 return rb_ec_cleanup(GET_EC(), ex);
227 volatile int step = 0;
258 if (ex == 0) ex =
state;
262 sysex = error_handle(ec, ex);
265 for (nerr = 0; nerr <
numberof(errs); ++nerr) {
275 sysex = sysexit_status(
err);
357 if (status) *status = s;
371 rb_ec_cleanup(ec, 0);
375 return rb_ec_cleanup(ec, rb_ec_exec_node(ec, n));
383 return rb_ec_exec_node(GET_EC(), n);
407 while (cref && CREF_NEXT(cref)) {
408 VALUE klass = CREF_CLASS(cref);
409 if (!CREF_PUSHED_BY_EVAL(cref) &&
413 cref = CREF_NEXT(cref);
453 klass = CREF_CLASS(cref);
454 if (!CREF_PUSHED_BY_EVAL(cref) &&
461 cref = CREF_NEXT(cref);
521static VALUE get_errinfo(
void);
522#define get_ec_errinfo(ec) rb_ec_get_errinfo(ec)
530 CONST_ID(id_true_cause,
"true_cause");
541 if (!
NIL_P(cause) && cause != exc) {
582 if (!nocircular && !
NIL_P(*cause) && *cause !=
Qundef && *cause != mesg) {
599 const char *
const volatile file0 =
file;
602 volatile int state = 0;
613 exc_setup_cause(mesg, cause);
618 set_backtrace(mesg, at);
624 if (
state)
goto fatal;
696 mesg = exc_setup_message(ec, mesg, &cause);
697 setup_exception(ec, tag, mesg, cause);
715 mesg = make_exception(1, &mesg,
FALSE);
731 mesg = make_exception(1, &mesg,
FALSE);
754 if (RB_TYPE_P(opt,
T_HASH)) {
838 if (isstr &&!
NIL_P(exc)) {
861 set_backtrace(mesg,
argv[2]);
1019 result = (*b_proc) (data1);
1041 while ((eclass = va_arg(ap,
VALUE)) != 0) {
1052 result = (*r_proc) (data2, ec->
errinfo);
1162 result = (*b_proc) (data1);
1218 return frame_func_id(GET_EC()->cfp);
1235 return frame_called_id(GET_EC()->cfp);
1250prev_frame_callee(
void)
1253 if (!prev_cfp)
return 0;
1254 return frame_called_id(prev_cfp);
1258prev_frame_func(
void)
1261 if (!prev_cfp)
return 0;
1262 return frame_func_id(prev_cfp);
1272rb_frame_last_func(
void)
1278 while (!(mid = frame_func_id(cfp)) &&
1280 !RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(ec, cfp)));
1297rb_mod_append_features(
VALUE module,
VALUE include)
1318 ID id_append_features, id_included;
1320 CONST_ID(id_append_features,
"append_features");
1324 for (i = 0; i <
argc; i++)
1346rb_mod_prepend_features(
VALUE module,
VALUE prepend)
1367 ID id_prepend_features, id_prepended;
1369 CONST_ID(id_prepend_features,
"prepend_features");
1370 CONST_ID(id_prepended,
"prepended");
1373 for (i = 0; i <
argc; i++)
1383ensure_class_or_module(
VALUE obj)
1387 "wrong argument type %"PRIsVALUE" (expected Class or Module)",
1393hidden_identity_hash_new(
void)
1397 RBASIC_CLEAR_CLASS(hash);
1402refinement_superclass(
VALUE superclass)
1404 if (RB_TYPE_P(superclass,
T_MODULE)) {
1420 VALUE iclass, c, superclass = klass;
1422 ensure_class_or_module(klass);
1424 if (
NIL_P(CREF_REFINEMENTS(cref))) {
1425 CREF_REFINEMENTS_SET(cref, hidden_identity_hash_new());
1428 if (CREF_OMOD_SHARED(cref)) {
1429 CREF_REFINEMENTS_SET(cref,
rb_hash_dup(CREF_REFINEMENTS(cref)));
1430 CREF_OMOD_SHARED_UNSET(cref);
1434 while (c && RB_TYPE_P(c,
T_ICLASS)) {
1435 if (
RBASIC(c)->klass == module) {
1444 superclass = refinement_superclass(superclass);
1451 while (module && module != klass) {
1465 rb_using_refinement(cref, klass, module);
1473 VALUE super, module, refinements;
1477 using_module_recursive(cref, super);
1485 module =
RBASIC(klass)->klass;
1493 CONST_ID(id_refinements,
"__refinements__");
1494 refinements =
rb_attr_get(module, id_refinements);
1495 if (
NIL_P(refinements))
return;
1507 using_module_recursive(cref, module);
1513rb_refinement_module_get_refined_class(
VALUE module)
1515 ID id_refined_class;
1517 CONST_ID(id_refined_class,
"__refined_class__");
1522add_activated_refinement(
VALUE activated_refinements,
1525 VALUE iclass, c, superclass = klass;
1529 while (c && RB_TYPE_P(c,
T_ICLASS)) {
1530 if (
RBASIC(c)->klass == refinement) {
1538 superclass = refinement_superclass(superclass);
1542 while (refinement && refinement != klass) {
1564 ID id_refinements, id_activated_refinements,
1565 id_refined_class, id_defined_at;
1566 VALUE refinements, activated_refinements;
1577 ensure_class_or_module(klass);
1578 CONST_ID(id_refinements,
"__refinements__");
1579 refinements =
rb_attr_get(module, id_refinements);
1580 if (
NIL_P(refinements)) {
1581 refinements = hidden_identity_hash_new();
1584 CONST_ID(id_activated_refinements,
"__activated_refinements__");
1585 activated_refinements =
rb_attr_get(module, id_activated_refinements);
1586 if (
NIL_P(activated_refinements)) {
1587 activated_refinements = hidden_identity_hash_new();
1589 activated_refinements);
1592 if (
NIL_P(refinement)) {
1593 VALUE superclass = refinement_superclass(klass);
1595 RCLASS_SET_SUPER(refinement, superclass);
1597 CONST_ID(id_refined_class,
"__refined_class__");
1599 CONST_ID(id_defined_at,
"__defined_at__");
1602 add_activated_refinement(activated_refinements, klass, refinement);
1609ignored_block(
VALUE module,
const char *klass)
1611 const char *anon =
"";
1614 anon =
", maybe for Module.new";
1616 rb_warn(
"%s""using doesn't call the given block""%s.", klass, anon);
1632 if (prev_frame_func()) {
1634 "Module#using is not permitted in methods");
1636 if (prev_cfp && prev_cfp->
self != self) {
1640 ignored_block(module,
"Module#");
1650 CONST_ID(id_defined_at,
"__defined_at__");
1684rb_mod_s_used_modules(
VALUE _)
1690 if (!
NIL_P(CREF_REFINEMENTS(cref))) {
1693 cref = CREF_NEXT(cref);
1798 ID id_extend_object, id_extended;
1800 CONST_ID(id_extend_object,
"extend_object");
1804 for (i = 0; i <
argc; i++)
1828 rb_warning(
"main.include in the wrapped load is effective only in wrapper module");
1852 ignored_block(module,
"main.");
1865 if (VM_FRAME_RUBYFRAME_P(cfp)) {
1883 const VALUE *
ptr = errinfo_place(ec);
1901 return get_errinfo();
1913 return GET_EC()->errinfo;
1930 GET_EC()->errinfo =
err;
1952 set_backtrace(
err, val);
1968 ID fname = prev_frame_func();
1990 ID fname = prev_frame_callee();
2011f_current_dirname(
VALUE _)
2034f_global_variables(
VALUE _)
2111 rb_mod_s_used_modules, 0);
2123 "include", top_include, -1);
2125 "using", top_using, 1);
2135 id_signo = rb_intern_const(
"signo");
VALUE rb_ary_push(VALUE ary, VALUE item)
#define UNREACHABLE_RETURN
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
#define rb_define_private_method(klass, mid, func, arity)
Defines klass#mid and makes it private.
#define rb_define_global_function(mid, func, arity)
Defines rb_mKernel #mid.
void rb_obj_call_init_kw(VALUE obj, int argc, const VALUE *argv, int kw_splat)
VALUE rb_ec_get_errinfo(const rb_execution_context_t *ec)
void rb_raise_jump(VALUE, VALUE)
#define get_ec_errinfo(ec)
void rb_ec_clear_all_trace_func(const rb_execution_context_t *ec)
VALUE rb_f_raise(int argc, VALUE *argv)
void rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec)
VALUE rb_vrescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2, va_list args)
An equivalent of rescue clause.
#define CLASS_OR_MODULE_P(obj)
int rb_keyword_given_p(void)
int rb_vm_cframe_keyword_p(const rb_control_frame_t *cfp)
#define warn_print_str(x)
#define unknown_longjmp_status(status)
int rb_ec_set_raised(rb_execution_context_t *ec)
VALUE rb_ec_backtrace_object(const rb_execution_context_t *ec)
#define INTERNAL_EXCEPTION_P(exc)
#define EC_JUMP_TAG(ec, st)
void rb_vm_localjump_error(const char *, VALUE, int)
#define rb_ec_raised_clear(ec)
#define PASS_PASSED_BLOCK_HANDLER()
int rb_ec_reset_raised(rb_execution_context_t *ec)
rb_cref_t * rb_vm_cref_replace_with_duplicated_cref(void)
rb_cref_t * rb_vm_cref(void)
#define SAVE_ROOT_JMPBUF(th, stmt)
#define RUBY_EVENT_C_RETURN
VALUE rb_file_dirname(VALUE fname)
void rb_objspace_call_finalizer(rb_objspace_t *objspace)
#define STACK_UPPER(x, a, b)
void rb_include_module(VALUE klass, VALUE module)
void rb_extend_object(VALUE obj, VALUE module)
Extend the object with the module.
void rb_prepend_module(VALUE klass, VALUE module)
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
VALUE rb_include_class_new(VALUE module, VALUE super)
VALUE rb_module_new(void)
void rb_class_modify_check(VALUE klass)
Asserts that klass is not a frozen class.
ID rb_frame_callee(void)
The name of the current method.
ID rb_frame_this_func(void)
The original name of the current method.
void rb_need_block(void)
Declares that the current method needs a block.
void rb_undef_method(VALUE klass, const char *name)
int rb_block_given_p(void)
Determines if the current method is given a block.
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
void ruby_stop(int ex)
Calls ruby_cleanup() and exits the process.
int ruby_exec_node(void *n)
Runs the given compiled source.
int ruby_setup(void)
Initializes the VM and builtin libraries.
void ruby_finalize(void)
Runs the VM finalization processes.
void ruby_init_stack(volatile VALUE *)
void * ruby_process_options(int, char **)
void ruby_prog_init(void)
Defines built-in variables.
int ruby_cleanup(volatile int ex)
Destructs the VM.
void ruby_sig_finalize(void)
VALUE rb_get_backtrace(VALUE exc)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_rescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2,...)
An equivalent of rescue clause.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
VALUE rb_ident_hash_new(void)
void rb_interrupt(void)
Raises an Interrupt exception.
void rb_frozen_error_raise(VALUE frozen_obj, const char *fmt,...)
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *pstate)
Protects a function call from potential global escapes from the function.
VALUE rb_make_exception(int argc, const VALUE *argv)
Make an Exception object from the list of arguments in a manner similar to Kernel#raise.
void rb_exc_fatal(VALUE mesg)
Raises a fatal error in the current thread.
void rb_warn(const char *fmt,...)
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
VALUE rb_rescue(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2)
An equivalent of rescue clause.
VALUE rb_ensure(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*e_proc)(VALUE), VALUE data2)
An equivalent to ensure clause.
VALUE rb_errinfo(void)
The current exception in the current thread.
void rb_jump_tag(int tag)
Continues the exception caught by rb_protect() and rb_eval_string_protect().
VALUE rb_eSystemCallError
void rb_warning(const char *fmt,...)
VALUE rb_cClass
Class class.
VALUE rb_mKernel
Kernel module.
VALUE rb_cObject
Object class.
void rb_obj_call_init(VALUE obj, int argc, const VALUE *argv)
Calls initialize method of obj with the given arguments.
VALUE rb_obj_class(VALUE)
VALUE rb_obj_dup(VALUE)
Equivalent to Object#dup in Ruby.
VALUE rb_cBasicObject
BasicObject class.
VALUE rb_cModule
Module class.
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Determines if obj is a kind of c.
void ruby_init(void)
Calls ruby_setup() and check error.
int ruby_executable_node(void *n, int *status)
Checks the return value of ruby_options().
void rb_hash_foreach(VALUE hash, rb_foreach_func *func, VALUE farg)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
VALUE rb_hash_lookup(VALUE hash, VALUE key)
VALUE rb_hash_dup(VALUE hash)
#define THROW_DATA_P(err)
Thin wrapper to ruby/config.h.
VALUE rb_funcallv_kw(VALUE, ID, int, const VALUE *, int)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
#define UNLIMITED_ARGUMENTS
void rb_error_arity(int, int, int)
void ruby_default_signal(int)
#define rb_exc_new_cstr(exc, str)
VALUE rb_check_string_type(VALUE)
VALUE rb_obj_as_string(VALUE)
VALUE rb_f_trace_var(int, const VALUE *)
VALUE rb_const_list(void *)
VALUE rb_ivar_get(VALUE, ID)
VALUE rb_f_untrace_var(int, const VALUE *)
VALUE rb_ivar_defined(VALUE, ID)
VALUE rb_mod_constants(int, const VALUE *, VALUE)
VALUE rb_attr_get(VALUE, ID)
void * rb_mod_const_of(VALUE, void *)
void * rb_mod_const_at(VALUE, void *)
VALUE rb_ivar_set(VALUE, ID, VALUE)
VALUE rb_f_global_variables(void)
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
ID rb_intern(const char *)
int ruby_vm_destruct(ruby_vm_t *vm)
Internal header aggregating init functions.
void Init_eval_method(void)
void Init_vm_objects(void)
Internal header for Class.
#define RCLASS_REFINED_CLASS(c)
Internal header for Hash.
Internal header for Object.
Internal header for Thread.
void rb_gvar_ractor_local(const char *name)
VALUE rb_search_class_path(VALUE)
#define RUBY_DTRACE_HOOK(name, arg)
VALUE rb_vm_top_self(void)
VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements)
const char * rb_source_location_cstr(int *pline)
VALUE rb_current_realfilepath(void)
void rb_vm_encoded_insn_data_table_init(void)
#define MEMCPY(p1, p2, type, n)
void rb_clear_method_cache_all(void)
void rb_define_virtual_variable(const char *q, type *w, void_type *e)
Define a function-backended global variable.
void rb_ractor_terminate_all(void)
#define RMODULE_IS_REFINEMENT
#define RMODULE_IS_OVERLAID
#define RB_OBJ_WRITE(a, slot, b)
WB for new reference from ‘a’ to ‘b’.
const char * rb_obj_classname(VALUE)
#define ATOMIC_VALUE_EXCHANGE(var, val)
Internal header for Scheduler.
VALUE rb_scheduler_set(VALUE scheduler)
void rb_vm_trap_exit(rb_vm_t *vm)
VALUE rb_sprintf(const char *,...)
struct rb_method_definition_struct *const def
struct rb_ensure_list * next
struct rb_ensure_entry entry
rb_ensure_list_t * ensure_list
struct rb_vm_protect_tag * protect_tag
enum rb_iseq_constant_body::iseq_type type
struct rb_iseq_constant_body * body
rb_execution_context_t * ec
struct rb_vm_protect_tag * prev
void rb_threadptr_check_signal(rb_thread_t *mth)
void rb_threadptr_unlock_all_locking_mutexes(rb_thread_t *th)
void rb_thread_stop_timer_thread(void)
void rb_threadptr_interrupt(rb_thread_t *th)
VALUE rb_iseq_eval_main(const rb_iseq_t *iseq)
VALUE rb_vm_frame_block_handler(const rb_control_frame_t *cfp)
void rb_vm_rewind_cfp(rb_execution_context_t *ec, rb_control_frame_t *cfp)
const rb_callable_method_entry_t * rb_vm_frame_method_entry(const rb_control_frame_t *cfp)
void rb_vm_pop_frame(rb_execution_context_t *ec)
#define VM_ENV_INDEX_LAST_LVAR
#define rb_vm_register_special_exception(sp, e, m)
@ block_handler_type_iseq
#define EXEC_EVENT_HOOK(ec_, flag_, self_, id_, called_id_, klass_, data_)
#define RUBY_VM_CHECK_INTS(ec)
#define RUBY_VM_VALID_CONTROL_FRAME_P(cfp, ecfp)
#define VM_BLOCK_HANDLER_NONE
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)