Fix a couple of API bugs dealing with modules

This commit is contained in:
Dr. Chat 2015-07-05 13:27:48 -05:00
parent fcdd15d157
commit 8d4582a7a4
1 changed files with 15 additions and 9 deletions

View File

@ -221,6 +221,7 @@ SHIM_CALL XexLoadImage_shim(PPCContext* ppc_context,
if (module) {
// Existing module found.
hmodule = module->hmodule_ptr();
result = X_STATUS_SUCCESS;
} else {
// Not found; attempt to load as a user module.
auto user_module = kernel_state->LoadUserModule(module_name);
@ -232,9 +233,11 @@ SHIM_CALL XexLoadImage_shim(PPCContext* ppc_context,
}
// Increment the module's load count.
if (hmodule) {
auto ldr_data =
kernel_memory()->TranslateVirtual<X_LDR_DATA_TABLE_ENTRY*>(hmodule);
ldr_data->load_count++;
}
SHIM_SET_MEM_32(hmodule_ptr, hmodule);
@ -253,13 +256,16 @@ SHIM_CALL XexUnloadImage_shim(PPCContext* ppc_context,
return;
}
// Can't unload kernel modules from user code.
if (module->module_type() != XModule::ModuleType::kKernelModule) {
auto ldr_data =
kernel_state->memory()->TranslateVirtual<X_LDR_DATA_TABLE_ENTRY*>(
hmodule);
if (ldr_data->load_count-- <= 0) {
if (--ldr_data->load_count == 0) {
// No more references, free it.
kernel_state->object_table()->RemoveHandle(module->handle());
}
}
SHIM_SET_RETURN_32(X_STATUS_SUCCESS);
}