Register user-modules with the kernel in UserModule::Restore
This commit is contained in:
parent
2855036f72
commit
bb5fd73b9e
|
@ -159,6 +159,31 @@ void KernelState::RegisterModule(XModule* module) {}
|
||||||
|
|
||||||
void KernelState::UnregisterModule(XModule* module) {}
|
void KernelState::UnregisterModule(XModule* module) {}
|
||||||
|
|
||||||
|
bool KernelState::RegisterUserModule(object_ref<UserModule> module) {
|
||||||
|
auto lock = global_critical_region_.Acquire();
|
||||||
|
|
||||||
|
for (auto user_module : user_modules_) {
|
||||||
|
if (user_module->path() == module->path()) {
|
||||||
|
// Already loaded.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
user_modules_.push_back(module);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KernelState::UnregisterUserModule(UserModule* module) {
|
||||||
|
auto lock = global_critical_region_.Acquire();
|
||||||
|
|
||||||
|
for (auto it = user_modules_.begin(); it != user_modules_.end(); it++) {
|
||||||
|
if ((*it)->path() == module->path()) {
|
||||||
|
user_modules_.erase(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool KernelState::IsKernelModule(const char* name) {
|
bool KernelState::IsKernelModule(const char* name) {
|
||||||
if (!name) {
|
if (!name) {
|
||||||
// Executing module isn't a kernel module.
|
// Executing module isn't a kernel module.
|
||||||
|
|
|
@ -120,6 +120,8 @@ class KernelState {
|
||||||
|
|
||||||
void RegisterModule(XModule* module);
|
void RegisterModule(XModule* module);
|
||||||
void UnregisterModule(XModule* module);
|
void UnregisterModule(XModule* module);
|
||||||
|
bool RegisterUserModule(object_ref<UserModule> module);
|
||||||
|
void UnregisterUserModule(UserModule* module);
|
||||||
bool IsKernelModule(const char* name);
|
bool IsKernelModule(const char* name);
|
||||||
object_ref<XModule> GetModule(const char* name, bool user_only = false);
|
object_ref<XModule> GetModule(const char* name, bool user_only = false);
|
||||||
|
|
||||||
|
|
|
@ -325,14 +325,19 @@ object_ref<UserModule> UserModule::Restore(KernelState* kernel_state,
|
||||||
// XModule::Save took care of this earlier...
|
// XModule::Save took care of this earlier...
|
||||||
// TODO: Find a nicer way to represent that here.
|
// TODO: Find a nicer way to represent that here.
|
||||||
if (!module->RestoreObject(stream)) {
|
if (!module->RestoreObject(stream)) {
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = module->LoadFromFile(path);
|
auto result = module->LoadFromFile(path);
|
||||||
if (XFAILED(result)) {
|
if (XFAILED(result)) {
|
||||||
XELOGD("UserModule::Restore LoadFromFile(%s) FAILED - code %.8X",
|
XELOGD("UserModule::Restore LoadFromFile(%s) FAILED - code %.8X",
|
||||||
path.c_str(), result);
|
path.c_str(), result);
|
||||||
return false;
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!kernel_state->RegisterUserModule(retain_object(module))) {
|
||||||
|
// Already loaded?
|
||||||
|
assert_always();
|
||||||
}
|
}
|
||||||
|
|
||||||
return object_ref<UserModule>(module);
|
return object_ref<UserModule>(module);
|
||||||
|
|
|
@ -114,7 +114,7 @@ bool XModule::Save(ByteStream* stream) {
|
||||||
object_ref<XModule> XModule::Restore(KernelState* kernel_state,
|
object_ref<XModule> XModule::Restore(KernelState* kernel_state,
|
||||||
ByteStream* stream) {
|
ByteStream* stream) {
|
||||||
if (stream->Read<uint32_t>() != 'XMOD') {
|
if (stream->Read<uint32_t>() != 'XMOD') {
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto path = stream->Read<std::string>();
|
auto path = stream->Read<std::string>();
|
||||||
|
@ -123,6 +123,10 @@ object_ref<XModule> XModule::Restore(KernelState* kernel_state,
|
||||||
// Can only save user modules at the moment, so just redirect.
|
// Can only save user modules at the moment, so just redirect.
|
||||||
// TODO: Find a way to call RestoreObject here before UserModule::Restore.
|
// TODO: Find a way to call RestoreObject here before UserModule::Restore.
|
||||||
auto module = UserModule::Restore(kernel_state, stream, path);
|
auto module = UserModule::Restore(kernel_state, stream, path);
|
||||||
|
if (!module) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
XELOGD("XModule %.8X (%s)", module->handle(), module->path_.c_str());
|
XELOGD("XModule %.8X (%s)", module->handle(), module->path_.c_str());
|
||||||
|
|
||||||
module->hmodule_ptr_ = hmodule_ptr;
|
module->hmodule_ptr_ = hmodule_ptr;
|
||||||
|
|
Loading…
Reference in New Issue