[Kernel] Implemented XexLoadImageFromMemory

This commit is contained in:
Hyper
2024-08-26 22:13:27 +01:00
committed by Radosław Gliński
parent 1a9ff8fe67
commit a867320a87
5 changed files with 84 additions and 7 deletions

View File

@@ -443,7 +443,7 @@ object_ref<UserModule> KernelState::LoadUserModule(
// See if we've already loaded it
for (auto& existing_module : user_modules_) {
if (existing_module->path() == path) {
if (existing_module->Matches(path)) {
return existing_module;
}
}
@@ -466,6 +466,39 @@ object_ref<UserModule> KernelState::LoadUserModule(
return module;
}
object_ref<UserModule> KernelState::LoadUserModuleFromMemory(
const std::string_view raw_name, const void* addr, const size_t length) {
auto name = xe::utf8::find_base_name_from_guest_path(raw_name);
object_ref<UserModule> module;
{
auto global_lock = global_critical_region_.Acquire();
// See if we've already loaded it
for (auto& existing_module : user_modules_) {
if (existing_module->Matches(name)) {
return existing_module;
}
}
global_lock.unlock();
// Module wasn't loaded, so load it.
module = object_ref<UserModule>(new UserModule(this));
X_STATUS status = module->LoadFromMemoryNamed(name, addr, length);
if (XFAILED(status)) {
object_table()->ReleaseHandle(module->handle());
return nullptr;
}
global_lock.lock();
// Putting into the listing automatically retains.
user_modules_.push_back(module);
}
return module;
}
X_RESULT KernelState::FinishLoadingUserModule(
const object_ref<UserModule> module, bool call_entry) {
// TODO(Gliniak): Apply custom patches here