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; class XenonRuntime;
using PPCContext = alloy::frontend::ppc::PPCContext;
class XenonThreadState : public alloy::runtime::ThreadState { class XenonThreadState : public alloy::runtime::ThreadState {
public: public:
@ -27,7 +29,7 @@ public:
size_t stack_size, uint64_t thread_state_address); size_t stack_size, uint64_t thread_state_address);
virtual ~XenonThreadState(); virtual ~XenonThreadState();
alloy::frontend::ppc::PPCContext* context() const { return context_; } PPCContext* context() const { return context_; }
private: private:
size_t stack_size_; size_t stack_size_;
@ -38,7 +40,7 @@ private:
uint64_t thread_state_address_; uint64_t thread_state_address_;
// NOTE: must be 64b aligned for SSE ops. // 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; using namespace xe::cpu;
namespace {
void UndefinedImport(PPCContext* ppc_state, void* arg0, void* arg1) {
XELOGE("call to undefined kernel import");
}
}
XexModule::XexModule( XexModule::XexModule(
XenonRuntime* runtime) : XenonRuntime* runtime) :
runtime_(runtime), runtime_(runtime),
@ -119,20 +126,22 @@ int XexModule::SetupLibraryImports(const xe_xex2_import_library_t* library) {
var_info->set_status(SymbolInfo::STATUS_DEFINED); var_info->set_status(SymbolInfo::STATUS_DEFINED);
// Grab, if available. // Grab, if available.
uint32_t* slot = (uint32_t*)(membase + info->value_address); if (kernel_export) {
if (kernel_export->type == KernelExport::Function) { uint32_t* slot = (uint32_t*)(membase + info->value_address);
// Not exactly sure what this should be... if (kernel_export->type == KernelExport::Function) {
// TODO(benvanik): find out what import variables are. // Not exactly sure what this should be...
XELOGW("kernel import variable not defined"); // TODO(benvanik): find out what import variables are.
} else { XELOGW("kernel import variable not defined");
if (kernel_export->is_implemented) {
// Implemented - replace with pointer.
*slot = XESWAP32BE(kernel_export->variable_ptr);
} else { } else {
// Not implemented - write with a dummy value. if (kernel_export->is_implemented) {
*slot = XESWAP32BE(0xD000BEEF | (kernel_export->ordinal & 0xFFF) << 16); // Implemented - replace with pointer.
XELOGCPU("WARNING: imported a variable with no value: %s", *slot = XESWAP32BE(kernel_export->variable_ptr);
kernel_export->name); } 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->set_name(name);
fn_info->set_status(SymbolInfo::STATUS_DECLARED); 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); DefineFunction(fn_info);
Function* fn = new ExternFunction( Function* fn = new ExternFunction(
info->thunk_address, info->thunk_address,
(ExternFunction::Handler)kernel_export->function_data.shim, handler,
kernel_export->function_data.shim_data, handler_data,
NULL); NULL);
fn_info->set_function(fn); fn_info->set_function(fn);
fn_info->set_status(SymbolInfo::STATUS_DEFINED); fn_info->set_status(SymbolInfo::STATUS_DEFINED);