From b5f7e91bdcc43e8ff51f91b236a2ee89ad8379dc Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 27 Mar 2010 07:45:11 -0400 Subject: [PATCH] vm: report callstack overflow --- basis/debugger/debugger.factor | 8 ++++++-- core/kernel/kernel-tests.factor | 4 ++++ vm/errors.cpp | 6 ++++++ vm/errors.hpp | 2 ++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/basis/debugger/debugger.factor b/basis/debugger/debugger.factor index c34a50190f..d10fd4f73a 100644 --- a/basis/debugger/debugger.factor +++ b/basis/debugger/debugger.factor @@ -120,6 +120,8 @@ HOOK: signal-error. os ( obj -- ) : datastack-overflow. ( obj -- ) "Data" stack-overflow. ; : retainstack-underflow. ( obj -- ) "Retain" stack-underflow. ; : retainstack-overflow. ( obj -- ) "Retain" stack-overflow. ; +: callstack-underflow. ( obj -- ) "Call" stack-underflow. ; +: callstack-overflow. ( obj -- ) "Call" stack-overflow. ; : memory-error. ( error -- ) "Memory protection fault at address " write third .h ; @@ -153,8 +155,10 @@ PREDICATE: vm-error < array { 11 [ datastack-overflow. ] } { 12 [ retainstack-underflow. ] } { 13 [ retainstack-overflow. ] } - { 14 [ memory-error. ] } - { 15 [ fp-trap-error. ] } + { 13 [ callstack-underflow. ] } + { 14 [ callstack-overflow. ] } + { 15 [ memory-error. ] } + { 16 [ fp-trap-error. ] } } ; inline M: vm-error summary drop "VM error" ; diff --git a/core/kernel/kernel-tests.factor b/core/kernel/kernel-tests.factor index ca8aa8286b..bf16d9439f 100644 --- a/core/kernel/kernel-tests.factor +++ b/core/kernel/kernel-tests.factor @@ -46,6 +46,10 @@ IN: kernel.tests [ ] [ :c ] unit-test +: overflow-c ( -- ) overflow-c overflow-c ; + +[ overflow-c ] [ { "kernel-error" 14 f f } = ] must-fail-with + [ -7 ] must-fail [ 3 ] [ t 3 and ] unit-test diff --git a/vm/errors.cpp b/vm/errors.cpp index d0c72989a3..21dff5a475 100755 --- a/vm/errors.cpp +++ b/vm/errors.cpp @@ -87,6 +87,8 @@ void factor_vm::not_implemented_error() void factor_vm::memory_protection_error(cell addr, stack_frame *stack) { + /* Retain and call stack underflows are not supposed to happen */ + if(ctx->datastack_seg->underflow_p(addr)) general_error(ERROR_DATASTACK_UNDERFLOW,false_object,false_object,stack); else if(ctx->datastack_seg->overflow_p(addr)) @@ -95,6 +97,10 @@ void factor_vm::memory_protection_error(cell addr, stack_frame *stack) general_error(ERROR_RETAINSTACK_UNDERFLOW,false_object,false_object,stack); else if(ctx->retainstack_seg->overflow_p(addr)) general_error(ERROR_RETAINSTACK_OVERFLOW,false_object,false_object,stack); + else if(ctx->callstack_seg->underflow_p(addr)) + general_error(ERROR_CALLSTACK_UNDERFLOW,false_object,false_object,stack); + else if(ctx->callstack_seg->overflow_p(addr)) + general_error(ERROR_CALLSTACK_OVERFLOW,false_object,false_object,stack); else general_error(ERROR_MEMORY,allot_cell(addr),false_object,stack); } diff --git a/vm/errors.hpp b/vm/errors.hpp index 0ce5957aef..34a23bd46d 100755 --- a/vm/errors.hpp +++ b/vm/errors.hpp @@ -18,6 +18,8 @@ enum vm_error_type ERROR_DATASTACK_OVERFLOW, ERROR_RETAINSTACK_UNDERFLOW, ERROR_RETAINSTACK_OVERFLOW, + ERROR_CALLSTACK_UNDERFLOW, + ERROR_CALLSTACK_OVERFLOW, ERROR_MEMORY, ERROR_FP_TRAP, };