* vm_core.h, eval_intern.h (CHECK_STACK_OVERFLOW): move

CHECK_STACK_OVERFLOW() to vm_core.h and rename to
  CHECK_VM_STACK_OVERFLOW().
  This change is only move and rename.
* tool/instruction.rb: catch up above changes.
* vm.c, vm_insnhelper.c: ditto.
* vm_insnhelper.c (vm_stackoverflow): add a function to unify
  raising vm stackoverflow exception.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2012-12-25 09:57:07 +00:00
Родитель febab308c8
Коммит 270fbd9c05
7 изменённых файлов: 40 добавлений и 20 удалений

Просмотреть файл

@ -1,3 +1,17 @@
Tue Dec 25 18:53:35 2012 Koichi Sasada <ko1@atdot.net>
* vm_core.h, eval_intern.h (CHECK_STACK_OVERFLOW): move
CHECK_STACK_OVERFLOW() to vm_core.h and rename to
CHECK_VM_STACK_OVERFLOW().
This change is only move and rename.
* tool/instruction.rb: catch up above changes.
* vm.c, vm_insnhelper.c: ditto.
* vm_insnhelper.c (vm_stackoverflow): add a function to unify
raising vm stackoverflow exception.
Tue Dec 25 16:16:54 2012 Koichi Sasada <ko1@atdot.net>
* vm_core.h (RUBY_VM_THREAD_VM_STACK_SIZE): change default

Просмотреть файл

@ -153,12 +153,6 @@ enum ruby_tag_type {
#define SCOPE_CHECK(f) (rb_vm_cref()->nd_visi == (f))
#define SCOPE_SET(f) (rb_vm_cref()->nd_visi = (f))
#define CHECK_STACK_OVERFLOW(cfp, margin) do \
if ((VALUE *)((char *)(((VALUE *)(cfp)->sp) + (margin)) + sizeof(rb_control_frame_t)) >= ((VALUE *)(cfp))) { \
rb_exc_raise(sysstack_error); \
} \
while (0)
void rb_thread_cleanup(void);
void rb_thread_wait_other_threads(void);

Просмотреть файл

@ -692,7 +692,7 @@ class RubyVM
n = 0
push_ba.each {|pushs| n += pushs.length}
commit " CHECK_STACK_OVERFLOW(REG_CFP, #{n});" if n > 0
commit " CHECK_VM_STACK_OVERFLOW(REG_CFP, #{n});" if n > 0
push_ba.each{|pushs|
pushs.each{|r|
commit " PUSH(SCREG(#{r}));"
@ -842,7 +842,7 @@ class RubyVM
each_footer_stack_val(insn){|v|
n += 1 unless v[2]
}
commit " CHECK_STACK_OVERFLOW(REG_CFP, #{n});" if n > 0
commit " CHECK_VM_STACK_OVERFLOW(REG_CFP, #{n});" if n > 0
each_footer_stack_val(insn){|v|
if v[2]
commit " SCREG(#{v[2]}) = #{v[1]};"

6
vm.c
Просмотреть файл

@ -143,7 +143,7 @@ vm_set_top_stack(rb_thread_t * th, VALUE iseqval)
}
/* for return */
CHECK_STACK_OVERFLOW(th->cfp, iseq->local_size + iseq->stack_max);
CHECK_VM_STACK_OVERFLOW(th->cfp, iseq->local_size + iseq->stack_max);
vm_push_frame(th, iseq, VM_FRAME_MAGIC_TOP | VM_FRAME_FLAG_FINISH,
th->top_self, rb_cObject, VM_ENVVAL_BLOCK_PTR(0),
iseq->iseq_encoded, th->cfp->sp, iseq->local_size, 0);
@ -155,7 +155,7 @@ vm_set_eval_stack(rb_thread_t * th, VALUE iseqval, const NODE *cref, rb_block_t
rb_iseq_t *iseq;
GetISeqPtr(iseqval, iseq);
CHECK_STACK_OVERFLOW(th->cfp, iseq->local_size + iseq->stack_max);
CHECK_VM_STACK_OVERFLOW(th->cfp, iseq->local_size + iseq->stack_max);
vm_push_frame(th, iseq, VM_FRAME_MAGIC_EVAL | VM_FRAME_FLAG_FINISH,
base_block->self, base_block->klass,
VM_ENVVAL_PREV_EP_PTR(base_block->ep), iseq->iseq_encoded,
@ -612,7 +612,7 @@ invoke_block_from_c(rb_thread_t *th, const rb_block_t *block,
VM_FRAME_MAGIC_LAMBDA : VM_FRAME_MAGIC_BLOCK;
cfp = th->cfp;
CHECK_STACK_OVERFLOW(cfp, argc + iseq->stack_max);
CHECK_VM_STACK_OVERFLOW(cfp, argc + iseq->stack_max);
for (i=0; i<argc; i++) {
cfp->sp[i] = argv[i];

Просмотреть файл

@ -853,6 +853,12 @@ int rb_autoloading_value(VALUE mod, ID id, VALUE* value);
#define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack]
#define CHECK_VM_STACK_OVERFLOW(cfp, margin) do \
if ((VALUE *)((char *)(((VALUE *)(cfp)->sp) + (margin)) + sizeof(rb_control_frame_t)) >= ((VALUE *)(cfp))) { \
vm_stackoverflow(); \
} \
while (0)
/* for thread */
#if RUBY_VM_THREAD_MODEL == 2

Просмотреть файл

@ -156,7 +156,7 @@ vm_call0_body(rb_thread_t* th, rb_call_info_t *ci, const VALUE *argv)
rb_control_frame_t *reg_cfp = th->cfp;
int i;
CHECK_STACK_OVERFLOW(reg_cfp, ci->argc + 1);
CHECK_VM_STACK_OVERFLOW(reg_cfp, ci->argc + 1);
*reg_cfp->sp++ = ci->recv;
for (i = 0; i < ci->argc; i++) {
@ -1212,7 +1212,7 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char
}
/* kick */
CHECK_STACK_OVERFLOW(th->cfp, iseq->stack_max);
CHECK_VM_STACK_OVERFLOW(th->cfp, iseq->stack_max);
result = vm_exec(th);
}
TH_POP_TAG();

Просмотреть файл

@ -24,6 +24,12 @@
static rb_control_frame_t *vm_get_ruby_level_caller_cfp(rb_thread_t *th, rb_control_frame_t *cfp);
static void
vm_stackoverflow(void)
{
rb_exc_raise(sysstack_error);
}
static inline rb_control_frame_t *
vm_push_frame(rb_thread_t *th,
const rb_iseq_t *iseq,
@ -41,7 +47,7 @@ vm_push_frame(rb_thread_t *th,
/* check stack overflow */
if ((void *)(sp + local_size) >= (void *)cfp) {
rb_exc_raise(sysstack_error);
vm_stackoverflow();
}
th->cfp = cfp;
@ -1048,7 +1054,7 @@ vm_caller_setup_args(const rb_thread_t *th, rb_control_frame_t *cfp, rb_call_inf
ptr = RARRAY_PTR(tmp);
cfp->sp -= 1;
CHECK_STACK_OVERFLOW(cfp, len);
CHECK_VM_STACK_OVERFLOW(cfp, len);
for (i = 0; i < len; i++) {
*cfp->sp++ = ptr[i];
@ -1209,7 +1215,7 @@ vm_call_iseq_setup_normal(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info
rb_iseq_t *iseq = ci->me->def->body.iseq;
VALUE *sp = argv + iseq->arg_size;
CHECK_STACK_OVERFLOW(cfp, iseq->stack_max);
CHECK_VM_STACK_OVERFLOW(cfp, iseq->stack_max);
/* clear local variables */
for (i = 0; i < iseq->local_size - iseq->arg_size; i++) {
@ -1236,7 +1242,7 @@ vm_call_iseq_setup_tailcall(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_in
cfp = th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp); /* pop cf */
CHECK_STACK_OVERFLOW(cfp, iseq->stack_max);
CHECK_VM_STACK_OVERFLOW(cfp, iseq->stack_max);
RUBY_VM_CHECK_INTS(th);
sp_orig = sp = cfp->sp;
@ -1633,7 +1639,7 @@ vm_call_method_missing(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_inf
ci_entry.me = rb_method_entry(CLASS_OF(ci_entry.recv), idMethodMissing, &ci_entry.defined_class);
/* shift arguments: m(a, b, c) #=> method_missing(:m, a, b, c) */
CHECK_STACK_OVERFLOW(reg_cfp, 1);
CHECK_VM_STACK_OVERFLOW(reg_cfp, 1);
if (ci->argc > 0) {
MEMMOVE(argv+1, argv, VALUE, ci->argc);
}
@ -2090,7 +2096,7 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq,
argc == 1 && !NIL_P(ary = rb_check_array_type(arg0))) { /* rhs is only an array */
th->mark_stack_len = argc = RARRAY_LENINT(ary);
CHECK_STACK_OVERFLOW(th->cfp, argc);
CHECK_VM_STACK_OVERFLOW(th->cfp, argc);
MEMCPY(argv, RARRAY_PTR(ary), VALUE, argc);
}
@ -2208,7 +2214,7 @@ vm_invoke_block(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_info_t *ci
VALUE * const rsp = GET_SP() - ci->argc;
SET_SP(rsp);
CHECK_STACK_OVERFLOW(GET_CFP(), iseq->stack_max);
CHECK_VM_STACK_OVERFLOW(GET_CFP(), iseq->stack_max);
opt_pc = vm_yield_setup_args(th, iseq, ci->argc, rsp, 0, block_proc_is_lambda(block->proc));
vm_push_frame(th, iseq, VM_FRAME_MAGIC_BLOCK, block->self,