Last bit of string cleanup. string.h finally gone.
This commit is contained in:
@@ -11,92 +11,87 @@
|
||||
|
||||
#include <poly/math.h>
|
||||
|
||||
using namespace xe;
|
||||
namespace xe {
|
||||
|
||||
ExportResolver::ExportResolver() {}
|
||||
|
||||
ExportResolver::ExportResolver() {
|
||||
}
|
||||
ExportResolver::~ExportResolver() {}
|
||||
|
||||
ExportResolver::~ExportResolver() {
|
||||
}
|
||||
|
||||
void ExportResolver::RegisterTable(
|
||||
const char* library_name, KernelExport* exports, const size_t count) {
|
||||
ExportTable table;
|
||||
xestrcpya(table.name, poly::countof(table.name), library_name);
|
||||
table.exports = exports;
|
||||
table.count = count;
|
||||
tables_.push_back(table);
|
||||
void ExportResolver::RegisterTable(const std::string& library_name,
|
||||
KernelExport* exports, const size_t count) {
|
||||
tables_.emplace_back(library_name, exports, count);
|
||||
|
||||
for (size_t n = 0; n < count; n++) {
|
||||
exports[n].is_implemented = false;
|
||||
exports[n].variable_ptr = 0;
|
||||
exports[n].function_data.shim_data = NULL;
|
||||
exports[n].function_data.shim = NULL;
|
||||
exports[n].function_data.shim_data = nullptr;
|
||||
exports[n].function_data.shim = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t ExportResolver::GetLibraryOrdinal(const char* library_name) {
|
||||
uint16_t ExportResolver::GetLibraryOrdinal(const std::string& library_name) {
|
||||
uint16_t n = 0;
|
||||
for (auto it = tables_.begin(); it != tables_.end(); ++it, n++) {
|
||||
if (!strcmp(library_name, it->name)) {
|
||||
for (const auto& table : tables_) {
|
||||
if (table.name != library_name) {
|
||||
return n;
|
||||
}
|
||||
++n;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
KernelExport* ExportResolver::GetExportByOrdinal(
|
||||
const uint16_t library_ordinal, const uint32_t ordinal) {
|
||||
auto& table = tables_[library_ordinal];
|
||||
KernelExport* ExportResolver::GetExportByOrdinal(const uint16_t library_ordinal,
|
||||
const uint32_t ordinal) {
|
||||
const 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;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
KernelExport* ExportResolver::GetExportByOrdinal(const char* library_name,
|
||||
const uint32_t ordinal) {
|
||||
for (std::vector<ExportTable>::iterator it = tables_.begin();
|
||||
it != tables_.end(); ++it) {
|
||||
if (!strcmp(library_name, it->name)) {
|
||||
KernelExport* ExportResolver::GetExportByOrdinal(
|
||||
const std::string& library_name, const uint32_t ordinal) {
|
||||
for (const auto& table : tables_) {
|
||||
if (table.name == library_name) {
|
||||
// TODO(benvanik): binary search?
|
||||
for (size_t n = 0; n < it->count; n++) {
|
||||
if (it->exports[n].ordinal == ordinal) {
|
||||
return &it->exports[n];
|
||||
for (size_t n = 0; n < table.count; n++) {
|
||||
if (table.exports[n].ordinal == ordinal) {
|
||||
return &table.exports[n];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
KernelExport* ExportResolver::GetExportByName(const char* library_name,
|
||||
const char* name) {
|
||||
KernelExport* ExportResolver::GetExportByName(const std::string& library_name,
|
||||
const std::string& name) {
|
||||
// TODO(benvanik): lookup by name.
|
||||
assert_always();
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ExportResolver::SetVariableMapping(const char* library_name,
|
||||
void ExportResolver::SetVariableMapping(const std::string& library_name,
|
||||
const uint32_t ordinal,
|
||||
uint32_t value) {
|
||||
KernelExport* kernel_export = GetExportByOrdinal(library_name, ordinal);
|
||||
auto kernel_export = GetExportByOrdinal(library_name, ordinal);
|
||||
assert_not_null(kernel_export);
|
||||
kernel_export->is_implemented = true;
|
||||
kernel_export->variable_ptr = value;
|
||||
}
|
||||
|
||||
void ExportResolver::SetFunctionMapping(
|
||||
const char* library_name, const uint32_t ordinal,
|
||||
void* shim_data, xe_kernel_export_shim_fn shim) {
|
||||
KernelExport* kernel_export = GetExportByOrdinal(library_name, ordinal);
|
||||
void ExportResolver::SetFunctionMapping(const std::string& library_name,
|
||||
const uint32_t ordinal, void* shim_data,
|
||||
xe_kernel_export_shim_fn shim) {
|
||||
auto kernel_export = GetExportByOrdinal(library_name, ordinal);
|
||||
assert_not_null(kernel_export);
|
||||
kernel_export->is_implemented = true;
|
||||
kernel_export->function_data.shim_data = shim_data;
|
||||
kernel_export->function_data.shim = shim;
|
||||
}
|
||||
|
||||
} // namespace xe
|
||||
|
||||
Reference in New Issue
Block a user