VM: better error message in case factor_vm::store_external_address fails

db4
Björn Lindqvist 2015-01-28 14:40:12 +00:00
parent 434e4ef4b7
commit f5dc4afb2e
2 changed files with 52 additions and 34 deletions

View File

@ -181,8 +181,7 @@ cell factor_vm::compute_dlsym_address(array* parameters, cell index) {
return (cell)undefined_symbol; return (cell)undefined_symbol;
} }
default: default:
critical_error("Bad symbol specifier in compute_dlsym_address", symbol); return -1;
return (cell)undefined_symbol;
} }
} }
@ -219,8 +218,7 @@ cell factor_vm::compute_dlsym_toc_address(array* parameters, cell index) {
return (cell)undefined_toc; return (cell)undefined_toc;
} }
default: default:
critical_error("Bad symbol specifier in compute_dlsym_toc_address", symbol); return -1;
return (cell)undefined_toc;
} }
} }
#endif #endif
@ -229,54 +227,70 @@ cell factor_vm::compute_vm_address(cell arg) {
return (cell)this + untag_fixnum(arg); return (cell)this + untag_fixnum(arg);
} }
void factor_vm::store_external_address(instruction_operand op) { cell factor_vm::lookup_external_address(relocation_type rel_type,
code_block* compiled = op.compiled; code_block *compiled,
array* parameters = array* parameters,
(to_boolean(compiled->parameters) ? untag<array>(compiled->parameters) cell index) {
: NULL); switch (rel_type) {
cell index = op.index;
switch (op.rel_type()) {
case RT_DLSYM: case RT_DLSYM:
op.store_value(compute_dlsym_address(parameters, index)); return compute_dlsym_address(parameters, index);
break;
case RT_THIS: case RT_THIS:
op.store_value(compiled->entry_point()); return compiled->entry_point();
break;
case RT_MEGAMORPHIC_CACHE_HITS: case RT_MEGAMORPHIC_CACHE_HITS:
op.store_value((cell)&dispatch_stats.megamorphic_cache_hits); return (cell)&dispatch_stats.megamorphic_cache_hits;
break;
case RT_VM: case RT_VM:
op.store_value(compute_vm_address(array_nth(parameters, index))); return compute_vm_address(array_nth(parameters, index));
break;
case RT_CARDS_OFFSET: case RT_CARDS_OFFSET:
op.store_value(cards_offset); return cards_offset;
break;
case RT_DECKS_OFFSET: case RT_DECKS_OFFSET:
op.store_value(decks_offset); return decks_offset;
break;
#ifdef WINDOWS #ifdef WINDOWS
case RT_EXCEPTION_HANDLER: case RT_EXCEPTION_HANDLER:
op.store_value((cell)&factor::exception_handler); return (cell)&factor::exception_handler;
break;
#endif #endif
#ifdef FACTOR_PPC #ifdef FACTOR_PPC
case RT_DLSYM_TOC: case RT_DLSYM_TOC:
op.store_value(compute_dlsym_toc_address(parameters, index)); return compute_dlsym_toc_address(parameters, index);
break;
#endif #endif
case RT_INLINE_CACHE_MISS: case RT_INLINE_CACHE_MISS:
op.store_value((cell)&factor::inline_cache_miss); return (cell)&factor::inline_cache_miss;
break;
case RT_SAFEPOINT: case RT_SAFEPOINT:
op.store_value((cell)code->safepoint_page); return (cell)code->safepoint_page;
break;
default: default:
critical_error("Bad rel type in store_external_address()", op.rel_type()); return -1;
break;
} }
} }
void factor_vm::store_external_address(instruction_operand op) {
code_block* compiled = op.compiled;
array* parameters = to_boolean(compiled->parameters)
? untag<array>(compiled->parameters)
: NULL;
cell index = op.index;
relocation_type rel_type = op.rel_type();
cell ext_addr = lookup_external_address(rel_type,
compiled,
parameters,
index);
if (ext_addr == (cell)-1) {
ostringstream ss;
print_obj(ss, compiled->owner);
ss << ": ";
cell arg;
if (rel_type == RT_DLSYM || rel_type == RT_DLSYM_TOC) {
ss << "Bad symbol specifier in store_external_address";
arg = array_nth(parameters, index);
} else {
ss << "Bad rel type in store_external_address";
arg = rel_type;
}
critical_error(ss.str().c_str(), arg);
}
op.store_value(ext_addr);
}
cell factor_vm::compute_here_address(cell arg, cell offset, cell factor_vm::compute_here_address(cell arg, cell offset,
code_block* compiled) { code_block* compiled) {
fixnum n = untag_fixnum(arg); fixnum n = untag_fixnum(arg);

View File

@ -576,6 +576,10 @@ struct factor_vm {
#endif #endif
cell compute_vm_address(cell arg); cell compute_vm_address(cell arg);
void store_external_address(instruction_operand op); void store_external_address(instruction_operand op);
cell lookup_external_address(relocation_type rel_type,
code_block* compiled,
array* parameters,
cell index);
cell compute_here_address(cell arg, cell offset, code_block* compiled); cell compute_here_address(cell arg, cell offset, code_block* compiled);
void initialize_code_block(code_block* compiled, cell literals); void initialize_code_block(code_block* compiled, cell literals);
void initialize_code_block(code_block* compiled); void initialize_code_block(code_block* compiled);