2013-01-13 07:25:41 +00:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* Xenia : Xbox 360 Emulator Research Project *
|
|
|
|
******************************************************************************
|
|
|
|
* Copyright 2013 Ben Vanik. All rights reserved. *
|
|
|
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2013-10-24 03:42:24 +00:00
|
|
|
#include <xenia/export_resolver.h>
|
2013-01-13 07:25:41 +00:00
|
|
|
|
2014-08-17 00:58:33 +00:00
|
|
|
#include <poly/math.h>
|
2013-01-13 07:25:41 +00:00
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
using namespace xe;
|
|
|
|
|
|
|
|
|
|
|
|
ExportResolver::ExportResolver() {
|
2013-01-13 07:25:41 +00:00
|
|
|
}
|
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
ExportResolver::~ExportResolver() {
|
2013-01-13 07:25:41 +00:00
|
|
|
}
|
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
void ExportResolver::RegisterTable(
|
|
|
|
const char* library_name, KernelExport* exports, const size_t count) {
|
|
|
|
ExportTable table;
|
2014-08-17 00:58:33 +00:00
|
|
|
xestrcpya(table.name, poly::countof(table.name), library_name);
|
2013-01-20 09:13:59 +00:00
|
|
|
table.exports = exports;
|
|
|
|
table.count = count;
|
|
|
|
tables_.push_back(table);
|
2013-01-28 11:03:37 +00:00
|
|
|
|
|
|
|
for (size_t n = 0; n < count; n++) {
|
|
|
|
exports[n].is_implemented = false;
|
|
|
|
exports[n].variable_ptr = 0;
|
2013-01-28 20:36:39 +00:00
|
|
|
exports[n].function_data.shim_data = NULL;
|
2013-01-28 11:03:37 +00:00
|
|
|
exports[n].function_data.shim = NULL;
|
|
|
|
}
|
2013-01-13 07:25:41 +00:00
|
|
|
}
|
|
|
|
|
2014-01-30 08:22:55 +00:00
|
|
|
uint16_t ExportResolver::GetLibraryOrdinal(const char* library_name) {
|
|
|
|
uint16_t n = 0;
|
|
|
|
for (auto it = tables_.begin(); it != tables_.end(); ++it, n++) {
|
2014-08-16 09:30:23 +00:00
|
|
|
if (!strcmp(library_name, it->name)) {
|
2014-01-30 08:22:55 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
KernelExport* ExportResolver::GetExportByOrdinal(
|
|
|
|
const uint16_t library_ordinal, const uint32_t ordinal) {
|
|
|
|
auto& table = tables_[library_ordinal];
|
|
|
|
// TODO(benvanik): binary search?
|
|
|
|
for (size_t n = 0; n < table.count; n++) {
|
|
|
|
if (table.exports[n].ordinal == ordinal) {
|
|
|
|
return &table.exports[n];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
KernelExport* ExportResolver::GetExportByOrdinal(const char* library_name,
|
|
|
|
const uint32_t ordinal) {
|
|
|
|
for (std::vector<ExportTable>::iterator it = tables_.begin();
|
|
|
|
it != tables_.end(); ++it) {
|
2014-08-16 09:30:23 +00:00
|
|
|
if (!strcmp(library_name, it->name)) {
|
2013-01-20 09:13:59 +00:00
|
|
|
// TODO(benvanik): binary search?
|
|
|
|
for (size_t n = 0; n < it->count; n++) {
|
|
|
|
if (it->exports[n].ordinal == ordinal) {
|
|
|
|
return &it->exports[n];
|
2013-01-13 07:25:41 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-20 09:13:59 +00:00
|
|
|
return NULL;
|
2013-01-13 07:25:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
KernelExport* ExportResolver::GetExportByName(const char* library_name,
|
|
|
|
const char* name) {
|
|
|
|
// TODO(benvanik): lookup by name.
|
2014-07-12 23:51:52 +00:00
|
|
|
assert_always();
|
2013-01-13 07:25:41 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2013-01-28 11:03:37 +00:00
|
|
|
|
|
|
|
void ExportResolver::SetVariableMapping(const char* library_name,
|
|
|
|
const uint32_t ordinal,
|
|
|
|
uint32_t value) {
|
|
|
|
KernelExport* kernel_export = GetExportByOrdinal(library_name, ordinal);
|
2014-07-12 23:51:52 +00:00
|
|
|
assert_not_null(kernel_export);
|
2013-01-28 11:03:37 +00:00
|
|
|
kernel_export->is_implemented = true;
|
|
|
|
kernel_export->variable_ptr = value;
|
|
|
|
}
|
|
|
|
|
2013-01-28 20:36:39 +00:00
|
|
|
void ExportResolver::SetFunctionMapping(
|
|
|
|
const char* library_name, const uint32_t ordinal,
|
2014-08-16 05:31:44 +00:00
|
|
|
void* shim_data, xe_kernel_export_shim_fn shim) {
|
2013-01-28 11:03:37 +00:00
|
|
|
KernelExport* kernel_export = GetExportByOrdinal(library_name, ordinal);
|
2014-07-12 23:51:52 +00:00
|
|
|
assert_not_null(kernel_export);
|
2013-01-28 11:03:37 +00:00
|
|
|
kernel_export->is_implemented = true;
|
2013-01-28 20:36:39 +00:00
|
|
|
kernel_export->function_data.shim_data = shim_data;
|
2013-01-28 11:03:37 +00:00
|
|
|
kernel_export->function_data.shim = shim;
|
|
|
|
}
|