VM: new method context::address_to_error

db4
Björn Lindqvist 2015-08-03 23:48:08 +02:00
parent 504be0c7cb
commit a7757eed41
3 changed files with 22 additions and 14 deletions

View File

@ -42,6 +42,23 @@ void context::fill_stack_seg(cell top_ptr, segment* seg, cell pattern) {
#endif #endif
} }
vm_error_type context::address_to_error(cell addr) {
if (datastack_seg->underflow_p(addr))
return ERROR_DATASTACK_UNDERFLOW;
if (datastack_seg->overflow_p(addr))
return ERROR_DATASTACK_OVERFLOW;
if (retainstack_seg->underflow_p(addr))
return ERROR_RETAINSTACK_UNDERFLOW;
if (retainstack_seg->overflow_p(addr))
return ERROR_RETAINSTACK_OVERFLOW;
/* These are flipped because the callstack grows downwards. */
if (callstack_seg->underflow_p(addr))
return ERROR_CALLSTACK_OVERFLOW;
if (callstack_seg->overflow_p(addr))
return ERROR_CALLSTACK_UNDERFLOW;
return ERROR_MEMORY;
}
void context::reset() { void context::reset() {
reset_datastack(); reset_datastack();
reset_retainstack(); reset_retainstack();

View File

@ -49,6 +49,7 @@ struct context {
void reset(); void reset();
void fix_stacks(); void fix_stacks();
void fill_stack_seg(cell top_ptr, segment* seg, cell pattern); void fill_stack_seg(cell top_ptr, segment* seg, cell pattern);
vm_error_type address_to_error(cell addr);
cell peek() { return *(cell*)datastack; } cell peek() { return *(cell*)datastack; }

View File

@ -117,20 +117,10 @@ void factor_vm::verify_memory_protection_error(cell addr) {
void factor_vm::memory_protection_error(cell pc, cell addr) { void factor_vm::memory_protection_error(cell pc, cell addr) {
if (code->safepoint_p(addr)) if (code->safepoint_p(addr))
safepoint.handle_safepoint(this, pc); safepoint.handle_safepoint(this, pc);
else if (ctx->datastack_seg->underflow_p(addr)) else {
general_error(ERROR_DATASTACK_UNDERFLOW, false_object, false_object); vm_error_type type = ctx->address_to_error(addr);
else if (ctx->datastack_seg->overflow_p(addr)) general_error(type, from_unsigned_cell(addr), false_object);
general_error(ERROR_DATASTACK_OVERFLOW, false_object, false_object); }
else if (ctx->retainstack_seg->underflow_p(addr))
general_error(ERROR_RETAINSTACK_UNDERFLOW, false_object, false_object);
else if (ctx->retainstack_seg->overflow_p(addr))
general_error(ERROR_RETAINSTACK_OVERFLOW, false_object, false_object);
else if (ctx->callstack_seg->underflow_p(addr))
general_error(ERROR_CALLSTACK_OVERFLOW, false_object, false_object);
else if (ctx->callstack_seg->overflow_p(addr))
general_error(ERROR_CALLSTACK_UNDERFLOW, false_object, false_object);
else
general_error(ERROR_MEMORY, from_unsigned_cell(addr), false_object);
} }
/* Allocates memory */ /* Allocates memory */