From 48bf3a9ab4566627f2078be04fe5a5216a409e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Wed, 23 Jul 2014 11:07:49 +0200 Subject: [PATCH] VM: moves the code that clears the roots to the same function that corrupts the stack --- vm/cpu-x86.cpp | 8 ++++++++ vm/errors.cpp | 11 ++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/vm/cpu-x86.cpp b/vm/cpu-x86.cpp index 85a8186d9f..c436afa57e 100644 --- a/vm/cpu-x86.cpp +++ b/vm/cpu-x86.cpp @@ -56,6 +56,14 @@ void factor_vm::dispatch_signal_handler(cell* sp, cell* pc, cell handler) { *pc = (cell)handler_word->entry_point; } + + /* Poking with the stack pointer, which the above code does, means + that pointers to stack-allocated objects will become + corrupted. Therefore the root vectors needs to be cleared because + their pointers to stack variables are now garbage. */ + data_roots.clear(); + bignum_roots.clear(); + code_roots.clear(); } } diff --git a/vm/errors.cpp b/vm/errors.cpp index 7e2a9d077b..6b2a108a2a 100644 --- a/vm/errors.cpp +++ b/vm/errors.cpp @@ -39,13 +39,6 @@ void out_of_memory() { /* Allocates memory */ void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_) { - /* If we got here from memory_protection_error(), then the stack - pointer has been fiddled with and the elements of these vectors, - which address stack-allocated objects, are bogus and needs to be - resetted. */ - data_roots.clear(); - bignum_roots.clear(); - code_roots.clear(); data_root arg1(arg1_, this); data_root arg2(arg2_, this); @@ -74,8 +67,8 @@ void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_) { arg1.value(), arg2.value()); ctx->push(error_object); - /* Clear the data roots again since arg1 and arg2's destructors - won't be called. */ + /* Clear the data roots since arg1 and arg2's destructors won't be + called. */ data_roots.clear(); /* The unwind-native-frames subprimitive will clear faulting_p