Allow new-style export registration.

This commit is contained in:
Ben Vanik
2015-05-31 17:54:44 -07:00
parent 08770a4ec0
commit ce3359389b
10 changed files with 69 additions and 35 deletions

View File

@@ -417,9 +417,8 @@ uint64_t UndefinedCallExtern(void* raw_context, uint64_t symbol_info_ptr) {
}
void X64Emitter::CallExtern(const hir::Instr* instr,
const FunctionInfo* symbol_info) {
if (!symbol_info->extern_handler()) {
CallNative(UndefinedCallExtern, reinterpret_cast<uint64_t>(symbol_info));
} else if (symbol_info->behavior() == FunctionBehavior::kBuiltin) {
if (symbol_info->behavior() == FunctionBehavior::kBuiltin &&
symbol_info->builtin_handler()) {
// rcx = context
// rdx = target host function
// r8 = arg0
@@ -433,7 +432,8 @@ void X64Emitter::CallExtern(const hir::Instr* instr,
ReloadECX();
ReloadEDX();
// rax = host return
} else if (symbol_info->behavior() == FunctionBehavior::kExtern) {
} else if (symbol_info->behavior() == FunctionBehavior::kExtern &&
symbol_info->extern_handler()) {
// rcx = context
// rdx = target host function
mov(rdx, reinterpret_cast<uint64_t>(symbol_info->extern_handler()));
@@ -444,6 +444,8 @@ void X64Emitter::CallExtern(const hir::Instr* instr,
ReloadECX();
ReloadEDX();
// rax = host return
} else {
CallNative(UndefinedCallExtern, reinterpret_cast<uint64_t>(symbol_info));
}
}

View File

@@ -19,22 +19,20 @@ ExportResolver::ExportResolver() {}
ExportResolver::~ExportResolver() {}
void ExportResolver::RegisterTable(const std::string& library_name,
Export* exports, const size_t count) {
tables_.emplace_back(library_name, exports, count);
void ExportResolver::RegisterTable(
const std::string& library_name,
const std::vector<xe::cpu::Export*>* exports) {
tables_.emplace_back(library_name, exports);
}
Export* ExportResolver::GetExportByOrdinal(const std::string& library_name,
uint16_t ordinal) {
for (const auto& table : tables_) {
if (table.name == library_name || table.simple_name == library_name) {
// TODO(benvanik): binary search?
for (size_t n = 0; n < table.count; n++) {
if (table.exports[n].ordinal == ordinal) {
return &table.exports[n];
}
if (ordinal > table.exports->size()) {
return nullptr;
}
return nullptr;
return table.exports->at(ordinal);
}
}
return nullptr;

View File

@@ -89,8 +89,8 @@ class ExportResolver {
ExportResolver();
~ExportResolver();
void RegisterTable(const std::string& library_name, Export* exports,
const size_t count);
void RegisterTable(const std::string& library_name,
const std::vector<Export*>* exports);
Export* GetExportByOrdinal(const std::string& library_name, uint16_t ordinal);
@@ -105,10 +105,9 @@ class ExportResolver {
struct ExportTable {
std::string name;
std::string simple_name; // without extension
Export* exports;
size_t count;
ExportTable(const std::string& name, Export* exports, size_t count)
: name(name), exports(exports), count(count) {
const std::vector<Export*>* exports;
ExportTable(const std::string& name, const std::vector<Export*>* exports)
: name(name), exports(exports) {
auto dot_pos = name.find_last_of('.');
if (dot_pos != std::string::npos) {
simple_name = name.substr(0, dot_pos);

View File

@@ -234,8 +234,13 @@ bool XexModule::SetupLibraryImports(const xe_xex2_import_library_t* library) {
FunctionInfo::ExternHandler handler = 0;
if (kernel_export) {
handler =
(FunctionInfo::ExternHandler)kernel_export->function_data.shim;
if (kernel_export->function_data.trampoline) {
handler = (FunctionInfo::ExternHandler)
kernel_export->function_data.trampoline;
} else {
handler =
(FunctionInfo::ExternHandler)kernel_export->function_data.shim;
}
} else {
handler = UndefinedImport;
}