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
|
|
|
|
|
|
|
|
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;
|
|
|
|
XEIGNORE(xestrcpya(table.name, XECOUNT(table.name), library_name));
|
|
|
|
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;
|
|
|
|
exports[n].function_data.impl = NULL;
|
|
|
|
}
|
2013-01-13 07:25:41 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2013-01-30 09:35:08 +00:00
|
|
|
if (!xestrcmpa(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.
|
|
|
|
XEASSERTALWAYS();
|
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);
|
|
|
|
XEASSERTNOTNULL(kernel_export);
|
|
|
|
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,
|
|
|
|
void* shim_data, xe_kernel_export_shim_fn shim,
|
|
|
|
xe_kernel_export_impl_fn impl) {
|
2013-01-28 11:03:37 +00:00
|
|
|
KernelExport* kernel_export = GetExportByOrdinal(library_name, ordinal);
|
|
|
|
XEASSERTNOTNULL(kernel_export);
|
|
|
|
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;
|
|
|
|
kernel_export->function_data.impl = impl;
|
|
|
|
}
|