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