Project

General

Profile

Bug #17949 ยป ruby-clang-setjmp-var_from_memory.patch

A sample usage of VAR_FROM_MEMORY. Never intended to be merged. - xtkoba (Tee KOBAYASHI), 06/12/2021 04:20 PM

View differences:

eval_intern.h
_tag.lock_rec = rb_ec_vm_lock_rec(_ec); \
#define EC_POP_TAG() \
_ec->tag = _tag.prev; \
_ec->tag = VAR_FROM_MEMORY(_tag).prev; \
} while (0)
#define EC_TMPPOP_TAG() \
_ec->tag = _tag.prev
_ec->tag = VAR_FROM_MEMORY(_tag).prev
#define EC_REPUSH_TAG() (void)(_ec->tag = &_tag)
-- a/eval.c
++ b/eval.c
......
SAVE_ROOT_JMPBUF(GET_THREAD(), iseq = ruby_process_options(argc, argv));
}
else {
VAR_FROM_MEMORY(ec);
rb_ec_clear_current_thread_trace_func(ec);
state = error_handle(ec, state);
iseq = (void *)INT2FIX(state);
......
rb_fiber_scheduler_set(Qnil);
}
else {
VAR_FROM_MEMORY(ec);
state = error_handle(ec, state);
}
EC_POP_TAG();
......
SAVE_ROOT_JMPBUF(th, rb_ractor_terminate_all());
}
else {
VAR_FROM_MEMORY(ec);
switch (step) {
case 0: goto step_0;
case 1: goto step_1;
......
}
if (!NIL_P(mesg)) {
VAR_FROM_MEMORY(ec);
ec->errinfo = mesg;
}
......
}
warn_print_str(e);
}
else {
VAR_FROM_MEMORY(ec);
}
EC_POP_TAG();
if (state == TAG_FATAL && ec->errinfo == exception_error) {
ec->errinfo = mesg;
......
goto fatal;
}
VAR_FROM_MEMORY(tag);
if (tag != TAG_FATAL) {
RUBY_DTRACE_HOOK(RAISE, rb_obj_classname(ec->errinfo));
EXEC_EVENT_HOOK(ec, RUBY_EVENT_RAISE, ec->cfp->self, 0, 0, 0, mesg);
......
/* escape from r_proc */
if (state == TAG_RETRY) {
state = TAG_NONE;
VAR_FROM_MEMORY(b_proc);
VAR_FROM_MEMORY(data1);
ec->errinfo = Qnil;
result = Qfalse;
goto retry_entry;
......
result = Qnil;
/* reuses args when raised again after retrying in r_proc */
VAR_FROM_MEMORY(args);
va_copy(ap, args);
while ((eclass = va_arg(ap, VALUE)) != 0) {
if (rb_obj_is_kind_of(ec->errinfo, eclass)) {
......
if (handle) {
state = TAG_NONE;
VAR_FROM_MEMORY(r_proc);
VAR_FROM_MEMORY(data2);
if (r_proc) {
result = (*r_proc) (data2, ec->errinfo);
}
......
SAVE_ROOT_JMPBUF(rb_ec_thread_ptr(ec), result = (*proc) (data));
}
else {
VAR_FROM_MEMORY(pstate);
VAR_FROM_MEMORY(protect_tag);
VAR_FROM_MEMORY(org_jmpbuf);
rb_vm_rewind_cfp(ec, cfp);
}
MEMCPY(&rb_ec_thread_ptr(ec)->root_jmpbuf, &org_jmpbuf, rb_jmpbuf_t, 1);
......
if ((state = EC_EXEC_TAG()) == TAG_NONE) {
result = (*b_proc) (data1);
}
else {
VAR_FROM_MEMORY(ensure_list);
}
EC_POP_TAG();
errinfo = ec->errinfo;
if (!NIL_P(errinfo) && !RB_TYPE_P(errinfo, T_OBJECT)) {
-- a/eval_jump.c
++ b/eval_jump.c
......
exec_end_procs_chain(&end_procs, &ec->errinfo);
}
else {
VAR_FROM_MEMORY(ec);
EC_TMPPOP_TAG();
error_handle(ec, state);
if (!NIL_P(ec->errinfo)) errinfo = ec->errinfo;
-- a/gc.c
++ b/gc.c
......
EC_PUSH_TAG(ec);
state = EC_EXEC_TAG();
if (state != TAG_NONE) {
VAR_FROM_MEMORY(table);
++saved.finished; /* skip failed finalizer */
}
for (i = saved.finished;
-- a/load.c
++ b/load.c
......
if (state == TAG_NONE) {
load_iseq_eval(ec, fname);
}
else {
VAR_FROM_MEMORY(th);
}
EC_POP_TAG();
#if !defined __GNUC__
......
if ((state = EC_EXEC_TAG()) == TAG_NONE) {
rb_load(fname, wrap);
}
else {
VAR_FROM_MEMORY(pstate);
}
EC_POP_TAG();
if (state != TAG_NONE) *pstate = state;
......
}
}
}
else {
VAR_FROM_MEMORY(ec);
VAR_FROM_MEMORY(fname);
VAR_FROM_MEMORY(exception);
VAR_FROM_MEMORY(path);
}
EC_POP_TAG();
rb_thread_t *th2 = rb_ec_thread_ptr(ec);
-- a/thread.c
++ b/thread.c
......
SAVE_ROOT_JMPBUF(th, thread_do_start(th));
}
else {
VAR_FROM_MEMORY(th);
VAR_FROM_MEMORY(ractor_main_th);
errinfo = th->ec->errinfo;
if (state == TAG_FATAL) {
......
saved_errno = errno;
}, ubf_select, wfd->th, FALSE);
}
else {
VAR_FROM_MEMORY(wfd);
}
EC_POP_TAG();
/*
......
RUBY_VM_CHECK_INTS_BLOCKING(wfd.th->ec);
} while (wait_retryable(&result, lerrno, to, end));
}
else {
VAR_FROM_MEMORY(wfd);
}
EC_POP_TAG();
RB_VM_LOCK_ENTER();
......
if ((state = EC_EXEC_TAG()) == TAG_NONE) {
ret = (*func)(obj, arg, FALSE);
}
else {
VAR_FROM_MEMORY(sym);
VAR_FROM_MEMORY(p);
}
EC_POP_TAG();
if (!recursive_pop(p.list, p.obj, p.pairid)) {
goto invalid;
-- a/vm.c
++ b/vm.c
......
goto vm_loop_start; /* fallback to the VM */
}
else {
VAR_FROM_MEMORY(ec);
result = ec->errinfo;
rb_ec_raised_reset(ec, RAISED_STACKOVERFLOW);
while ((result = vm_exec_handle_exception(ec, state, result, &initial)) == Qundef) {
-- a/vm_backtrace.c
++ b/vm_backtrace.c
......
if ((state = EC_EXEC_TAG()) == TAG_NONE) {
result = (*func)(&dbg_context, data);
}
else {
VAR_FROM_MEMORY(ec);
}
EC_POP_TAG();
/* invalidate bindings? */
-- a/vm_eval.c
++ b/vm_eval.c
......
retval = (*it_proc) (data1);
}
else if (state == TAG_BREAK || state == TAG_RETRY) {
VAR_FROM_MEMORY(it_proc);
VAR_FROM_MEMORY(data1);
VAR_FROM_MEMORY(ifunc);
VAR_FROM_MEMORY(ec);
VAR_FROM_MEMORY(cfp);
const struct vm_throw_data *const err = (struct vm_throw_data *)ec->errinfo;
const rb_control_frame_t *const escape_cfp = THROW_DATA_CATCH_FRAME(err);
......
SDR(); fprintf(stderr, "%p, %p\n", (void *)cfp, (void *)escape_cfp);
}
}
else {
VAR_FROM_MEMORY(ec);
}
EC_POP_TAG();
if (state) {
......
state = 0;
}
EC_POP_TAG();
VAR_FROM_MEMORY(stateptr);
if (stateptr)
*stateptr = state;
-- a/vm_trace.c
++ b/vm_trace.c
......
if ((state = EC_EXEC_TAG()) == TAG_NONE) {
exec_hooks_body(ec, list, trace_arg);
}
else {
VAR_FROM_MEMORY(ec);
VAR_FROM_MEMORY(list);
}
EC_POP_TAG();
exec_hooks_postcheck(ec, list);
......
result = (*func)(arg);
}
else {
VAR_FROM_MEMORY(ec);
VAR_FROM_MEMORY(dummy_trace_arg);
(void)*&vm; /* suppress "clobbered" warning */
}
EC_POP_TAG();
......
(pjob.func)(pjob.data);
}
}
else {
VAR_FROM_MEMORY(vm);
VAR_FROM_MEMORY(ec);
VAR_FROM_MEMORY(block_mask);
VAR_FROM_MEMORY(tmp);
}
EC_POP_TAG();
}
/* restore POSTPONED_JOB mask */
    (1-1/1)