Better handling of undefined imports.

This commit is contained in:
Ben Vanik 2013-12-15 15:26:12 -08:00
parent f2348301ea
commit 9fdacebf2d
2 changed files with 39 additions and 18 deletions

View File

@ -20,6 +20,8 @@ namespace cpu {
class XenonRuntime;
using PPCContext = alloy::frontend::ppc::PPCContext;
class XenonThreadState : public alloy::runtime::ThreadState {
public:
@ -27,7 +29,7 @@ public:
size_t stack_size, uint64_t thread_state_address);
virtual ~XenonThreadState();
alloy::frontend::ppc::PPCContext* context() const { return context_; }
PPCContext* context() const { return context_; }
private:
size_t stack_size_;
@ -38,7 +40,7 @@ private:
uint64_t thread_state_address_;
// NOTE: must be 64b aligned for SSE ops.
alloy::frontend::ppc::PPCContext* context_;
PPCContext* context_;
};

View File

@ -19,6 +19,13 @@ using namespace alloy::runtime;
using namespace xe::cpu;
namespace {
void UndefinedImport(PPCContext* ppc_state, void* arg0, void* arg1) {
XELOGE("call to undefined kernel import");
}
}
XexModule::XexModule(
XenonRuntime* runtime) :
runtime_(runtime),
@ -119,20 +126,22 @@ int XexModule::SetupLibraryImports(const xe_xex2_import_library_t* library) {
var_info->set_status(SymbolInfo::STATUS_DEFINED);
// Grab, if available.
uint32_t* slot = (uint32_t*)(membase + info->value_address);
if (kernel_export->type == KernelExport::Function) {
// Not exactly sure what this should be...
// TODO(benvanik): find out what import variables are.
XELOGW("kernel import variable not defined");
} else {
if (kernel_export->is_implemented) {
// Implemented - replace with pointer.
*slot = XESWAP32BE(kernel_export->variable_ptr);
if (kernel_export) {
uint32_t* slot = (uint32_t*)(membase + info->value_address);
if (kernel_export->type == KernelExport::Function) {
// Not exactly sure what this should be...
// TODO(benvanik): find out what import variables are.
XELOGW("kernel import variable not defined");
} else {
// Not implemented - write with a dummy value.
*slot = XESWAP32BE(0xD000BEEF | (kernel_export->ordinal & 0xFFF) << 16);
XELOGCPU("WARNING: imported a variable with no value: %s",
kernel_export->name);
if (kernel_export->is_implemented) {
// Implemented - replace with pointer.
*slot = XESWAP32BE(kernel_export->variable_ptr);
} else {
// Not implemented - write with a dummy value.
*slot = XESWAP32BE(0xD000BEEF | (kernel_export->ordinal & 0xFFF) << 16);
XELOGCPU("WARNING: imported a variable with no value: %s",
kernel_export->name);
}
}
}
@ -152,11 +161,21 @@ int XexModule::SetupLibraryImports(const xe_xex2_import_library_t* library) {
//fn->set_name(name);
fn_info->set_status(SymbolInfo::STATUS_DECLARED);
ExternFunction::Handler handler = 0;
void* handler_data = 0;
if (kernel_export) {
handler = (ExternFunction::Handler)kernel_export->function_data.shim;
handler_data = kernel_export->function_data.shim_data;
} else {
handler = (ExternFunction::Handler)UndefinedImport;
handler_data = this;
}
DefineFunction(fn_info);
Function* fn = new ExternFunction(
info->thunk_address,
(ExternFunction::Handler)kernel_export->function_data.shim,
kernel_export->function_data.shim_data,
info->thunk_address,
handler,
handler_data,
NULL);
fn_info->set_function(fn);
fn_info->set_status(SymbolInfo::STATUS_DEFINED);