VM: refactoring, new function get_thread_pc() and simpler logic in exception_handler()

db4
Björn Lindqvist 2015-08-26 12:00:11 +02:00
parent 2a852915d2
commit 5a39631b4b
1 changed files with 21 additions and 22 deletions

View File

@ -228,20 +228,15 @@ LONG factor_vm::exception_handler(PEXCEPTION_RECORD e, void* frame, PCONTEXT c,
(cell)factor::synchronous_signal_handler_impl); (cell)factor::synchronous_signal_handler_impl);
break; break;
} }
return ExceptionContinueExecution; return ExceptionContinueExecution;
} }
VM_C_API LONG exception_handler(PEXCEPTION_RECORD e, void* frame, PCONTEXT c, VM_C_API LONG exception_handler(PEXCEPTION_RECORD e, void* frame, PCONTEXT c,
void* dispatch) { void* dispatch) {
if (factor_vm::fatal_erroring_p)
return ExceptionContinueSearch;
factor_vm* vm = current_vm_p(); factor_vm* vm = current_vm_p();
if (vm) if (factor_vm::fatal_erroring_p || !vm)
return vm->exception_handler(e, frame, c, dispatch);
else
return ExceptionContinueSearch; return ExceptionContinueSearch;
return vm->exception_handler(e, frame, c, dispatch);
} }
/* On Unix SIGINT (ctrl-c) automatically interrupts blocking io system /* On Unix SIGINT (ctrl-c) automatically interrupts blocking io system
@ -306,6 +301,21 @@ void unlock_console() {}
void close_console() {} void close_console() {}
cell get_thread_pc(THREADHANDLE th) {
DWORD suscount = SuspendThread(th);
FACTOR_ASSERT(suscount == 0);
CONTEXT context;
memset((void*)&context, 0, sizeof(CONTEXT));
context.ContextFlags = CONTEXT_CONTROL;
BOOL context_ok = GetThreadContext(th, &context);
FACTOR_ASSERT(context_ok);
suscount = ResumeThread(th);
FACTOR_ASSERT(suscount == 1);
return context.EIP;
}
void factor_vm::sampler_thread_loop() { void factor_vm::sampler_thread_loop() {
LARGE_INTEGER counter, new_counter, units_per_second; LARGE_INTEGER counter, new_counter, units_per_second;
DWORD ok; DWORD ok;
@ -328,22 +338,11 @@ void factor_vm::sampler_thread_loop() {
++samples; ++samples;
counter.QuadPart += units_per_second.QuadPart; counter.QuadPart += units_per_second.QuadPart;
} }
if (samples == 0)
continue;
if (samples > 0) { cell pc = get_thread_pc(thread);
DWORD suscount = SuspendThread(thread); safepoint.enqueue_samples(this, samples, pc, false);
FACTOR_ASSERT(suscount == 0);
CONTEXT context;
memset((void*)&context, 0, sizeof(CONTEXT));
context.ContextFlags = CONTEXT_CONTROL;
BOOL context_ok = GetThreadContext(thread, &context);
FACTOR_ASSERT(context_ok);
suscount = ResumeThread(thread);
FACTOR_ASSERT(suscount == 1);
safepoint.enqueue_samples(this, samples, context.EIP, false);
}
} }
} }