VM: renaming verify_memory_protection_error to set_memory_protection_error

and sets the signal_fault_addr and signal_fault_pc in the function.
char-rename
Björn Lindqvist 2016-09-22 01:49:12 +02:00
parent 65a2281188
commit a0df88f20b
5 changed files with 20 additions and 23 deletions

View File

@ -98,17 +98,19 @@ void factor_vm::not_implemented_error() {
general_error(ERROR_NOT_IMPLEMENTED, false_object, false_object);
}
void factor_vm::verify_memory_protection_error(cell addr) {
void factor_vm::set_memory_protection_error(cell fault_addr, cell fault_pc) {
// Called from the OS-specific top halves of the signal handlers to
// make sure it's safe to dispatch to memory_signal_handler_impl.
if (fatal_erroring_p)
fa_diddly_atal_error();
if (faulting_p && !code->safepoint_p(addr))
fatal_error("Double fault", addr);
if (faulting_p && !code->safepoint_p(fault_addr))
fatal_error("Double fault", fault_addr);
else if (fep_p)
fatal_error("Memory protection fault during low-level debugger", addr);
fatal_error("Memory protection fault during low-level debugger", fault_addr);
else if (atomic::load(&current_gc_p))
fatal_error("Memory protection fault during gc", addr);
fatal_error("Memory protection fault during gc", fault_addr);
signal_fault_addr = fault_addr;
signal_fault_pc = fault_pc;
}
// Allocates memory

View File

@ -36,9 +36,8 @@ void factor_vm::call_fault_handler(exception_type_t exception,
cell handler = 0;
if (exception == EXC_BAD_ACCESS) {
signal_fault_addr = MACH_EXC_STATE_FAULT(exc_state);
signal_fault_pc = (cell)MACH_PROGRAM_COUNTER(thread_state);
verify_memory_protection_error(signal_fault_addr);
set_memory_protection_error(MACH_EXC_STATE_FAULT(exc_state),
(cell)MACH_PROGRAM_COUNTER(thread_state));
handler = (cell)factor::memory_signal_handler_impl;
} else if (exception == EXC_ARITHMETIC && code != MACH_EXC_INTEGER_DIV) {
signal_fpu_status = fpu_status(mach_fpu_status(float_state));

View File

@ -100,18 +100,11 @@ segment::segment(cell size_, bool executable_p) {
segment::~segment() {
int pagesize = getpagesize();
int retval = munmap((void*)(start - pagesize), pagesize + size + pagesize);
int retval = munmap((void*)(start - pagesize), 2 * pagesize + size);
if (retval)
fatal_error("Segment deallocation failed", 0);
}
void factor_vm::dispatch_signal(void* uap, void(handler)()) {
dispatch_signal_handler((cell*)&UAP_STACK_POINTER(uap),
(cell*)&UAP_PROGRAM_COUNTER(uap),
(cell)FUNCTION_CODE_POINTER(handler));
UAP_SET_TOC_POINTER(uap, (cell)FUNCTION_TOC_POINTER(handler));
}
void factor_vm::start_sampling_profiler_timer() {
struct itimerval timer;
memset((void*)&timer, 0, sizeof(struct itimerval));
@ -126,14 +119,19 @@ void factor_vm::end_sampling_profiler_timer() {
setitimer(ITIMER_REAL, &timer, NULL);
}
void factor_vm::dispatch_signal(void* uap, void(handler)()) {
dispatch_signal_handler((cell*)&UAP_STACK_POINTER(uap),
(cell*)&UAP_PROGRAM_COUNTER(uap),
(cell)FUNCTION_CODE_POINTER(handler));
UAP_SET_TOC_POINTER(uap, (cell)FUNCTION_TOC_POINTER(handler));
}
void memory_signal_handler(int signal, siginfo_t* siginfo, void* uap) {
cell fault_addr = (cell)siginfo->si_addr;
cell fault_pc = (cell)UAP_PROGRAM_COUNTER(uap);
factor_vm* vm = current_vm();
vm->verify_memory_protection_error(fault_addr);
vm->signal_fault_addr = fault_addr;
vm->signal_fault_pc = fault_pc;
vm->set_memory_protection_error(fault_addr, fault_pc);
vm->dispatch_signal(uap, factor::memory_signal_handler_impl);
}

View File

@ -196,9 +196,7 @@ LONG factor_vm::exception_handler(PEXCEPTION_RECORD e, void* frame, PCONTEXT c,
void* dispatch) {
switch (e->ExceptionCode) {
case EXCEPTION_ACCESS_VIOLATION:
signal_fault_addr = e->ExceptionInformation[1];
signal_fault_pc = c->EIP;
verify_memory_protection_error(signal_fault_addr);
set_memory_protection_error(e->ExceptionInformation[1], c->EIP);
dispatch_signal_handler((cell*)&c->ESP, (cell*)&c->EIP,
(cell)factor::memory_signal_handler_impl);
break;

View File

@ -199,7 +199,7 @@ struct factor_vm {
void general_error(vm_error_type error, cell arg1, cell arg2);
void type_error(cell type, cell tagged);
void not_implemented_error();
void verify_memory_protection_error(cell addr);
void set_memory_protection_error(cell fault_addr, cell fault_pc);
void divide_by_zero_error();
void primitive_unimplemented();