Browse files

Handle stack reset case in checking stack size

In the CAPI we also do stack checks so we need to make sure that we
handle the case where the stack size was reset. Also make sure we
check for interrupts here.
  • Loading branch information...
1 parent 75090fb commit 5db3ec42bfd8297a90294e1d2635220197b6c01f @dbussink dbussink committed Oct 19, 2012
Showing with 22 additions and 12 deletions.
  1. +14 −3 vm/capi/capi.cpp
  2. +1 −5 vm/state.cpp
  3. +7 −4 vm/state.hpp
View
17 vm/capi/capi.cpp
@@ -138,6 +138,17 @@ namespace rubinius {
return map[type];
}
+ bool capi_check_interrupts(STATE, CallFrame* call_frame, void* end) {
+ if(!state->check_stack(call_frame, end)) {
+ return false;
+ }
+
+ if(unlikely(state->vm()->check_local_interrupts)) {
+ if(!state->process_async(call_frame)) return false;
+ }
+ return true;
+ }
+
/**
* Common implementation for rb_funcall*
*/
@@ -191,7 +202,7 @@ namespace rubinius {
Object** args, Object* block)
{
int marker = 0;
- if(!env->state()->check_stack(env->current_call_frame(), &marker)) {
+ if(!capi_check_interrupts(env->state(), env->current_call_frame(), &marker)) {
env->current_ep()->return_to(env);
}
@@ -281,7 +292,7 @@ namespace rubinius {
size_t arg_count, Object** arg_vals)
{
int marker = 0;
- if(!env->state()->check_stack(env->current_call_frame(), &marker)) {
+ if(!capi_check_interrupts(env->state(), env->current_call_frame(), &marker)) {
env->current_ep()->return_to(env);
}
@@ -333,7 +344,7 @@ namespace rubinius {
size_t arg_count, Object** args)
{
int marker = 0;
- if(!env->state()->check_stack(env->current_call_frame(), &marker)) {
+ if(!capi_check_interrupts(env->state(), env->current_call_frame(), &marker)) {
env->current_ep()->return_to(env);
}
View
6 vm/state.cpp
@@ -63,11 +63,7 @@ namespace rubinius {
// If this is true, stack_limit_ was just changed to get our attention, reset
// it now.
- if(vm_->stack_limit_ == vm_->stack_start_) {
- vm_->reset_stack_limit();
- } else {
- if(!check_stack(call_frame, end)) return false;
- }
+ if(!check_stack(call_frame, end)) return false;
if(unlikely(vm_->check_local_interrupts)) {
if(!process_async(call_frame)) return false;
View
11 vm/state.hpp
@@ -90,11 +90,14 @@ namespace rubinius {
bool check_stack(CallFrame* call_frame, void* end) {
// @TODO assumes stack growth direction
- if(unlikely(reinterpret_cast<uintptr_t>(end) < vm_->stack_limit_)) {
- raise_stack_error(call_frame);
- return false;
+ if(vm_->stack_limit_ == vm_->stack_start_) {
+ vm_->reset_stack_limit();
+ } else {
+ if(unlikely(reinterpret_cast<uintptr_t>(end) < vm_->stack_limit_)) {
+ raise_stack_error(call_frame);
+ return false;
+ }
}
-
return true;
}

0 comments on commit 5db3ec4

Please sign in to comment.