VM: always clear the data and retainstack in general_error because they might contain uninitialized values (#1187)

db4
Björn Lindqvist 2014-12-04 19:13:23 +01:00 committed by John Benediktsson
parent 348bd85824
commit 378f208025
3 changed files with 8 additions and 18 deletions

View File

@ -39,16 +39,6 @@ void context::reset() {
reset_context_objects(); reset_context_objects();
} }
void context::fix_stacks() {
if (datastack + sizeof(cell) < datastack_seg->start ||
datastack + stack_reserved >= datastack_seg->end)
reset_datastack();
if (retainstack + sizeof(cell) < retainstack_seg->start ||
retainstack + stack_reserved >= retainstack_seg->end)
reset_retainstack();
}
context::~context() { context::~context() {
delete datastack_seg; delete datastack_seg;
delete retainstack_seg; delete retainstack_seg;

View File

@ -47,7 +47,6 @@ struct context {
void reset_callstack(); void reset_callstack();
void reset_context_objects(); void reset_context_objects();
void reset(); void reset();
void fix_stacks();
void scrub_stacks(gc_info* info, cell index); void scrub_stacks(gc_info* info, cell index);
cell peek() { return *(cell*)datastack; } cell peek() { return *(cell*)datastack; }

View File

@ -44,17 +44,19 @@ void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_) {
faulting_p = true; faulting_p = true;
/* If we had an underflow or overflow, data or retain stack /* If we had an underflow or overflow, data or retain stack pointers
pointers might be out of bounds, so fix them before allocating might be out of bounds, or some of their slots might be
anything */ uninitialized, so reset them before allocating anything. */
ctx->fix_stacks(); ctx->reset_datastack();
ctx->reset_retainstack();
/* If error was thrown during heap scan, we re-enable the GC */ /* If error was thrown during heap scan, we re-enable the GC */
gc_off = false; gc_off = false;
cell error_handler = special_objects[ERROR_HANDLER_QUOT];
/* If the error handler is set, we rewind any C stack frames and /* If the error handler is set, we rewind any C stack frames and
pass the error to user-space. */ pass the error to user-space. */
if (!current_gc && to_boolean(special_objects[ERROR_HANDLER_QUOT])) { if (!current_gc && to_boolean(error_handler)) {
#ifdef FACTOR_DEBUG #ifdef FACTOR_DEBUG
/* Doing a GC here triggers all kinds of funny errors */ /* Doing a GC here triggers all kinds of funny errors */
primitive_compact_gc(); primitive_compact_gc();
@ -72,8 +74,7 @@ void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_) {
/* The unwind-native-frames subprimitive will clear faulting_p /* The unwind-native-frames subprimitive will clear faulting_p
if it was successfully reached. */ if it was successfully reached. */
unwind_native_frames(special_objects[ERROR_HANDLER_QUOT], unwind_native_frames(error_handler, ctx->callstack_top);
ctx->callstack_top);
} /* Error was thrown in early startup before error handler is set, so just } /* Error was thrown in early startup before error handler is set, so just
crash. */ crash. */
else { else {