Fix a couple of API bugs dealing with modules
This commit is contained in:
parent
fcdd15d157
commit
8d4582a7a4
|
@ -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.
|
||||||
|
if (hmodule) {
|
||||||
auto ldr_data =
|
auto ldr_data =
|
||||||
kernel_memory()->TranslateVirtual<X_LDR_DATA_TABLE_ENTRY*>(hmodule);
|
kernel_memory()->TranslateVirtual<X_LDR_DATA_TABLE_ENTRY*>(hmodule);
|
||||||
ldr_data->load_count++;
|
ldr_data->load_count++;
|
||||||
|
}
|
||||||
|
|
||||||
SHIM_SET_MEM_32(hmodule_ptr, hmodule);
|
SHIM_SET_MEM_32(hmodule_ptr, hmodule);
|
||||||
|
|
||||||
|
@ -253,13 +256,16 @@ SHIM_CALL XexUnloadImage_shim(PPCContext* ppc_context,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Can't unload kernel modules from user code.
|
||||||
|
if (module->module_type() != XModule::ModuleType::kKernelModule) {
|
||||||
auto ldr_data =
|
auto ldr_data =
|
||||||
kernel_state->memory()->TranslateVirtual<X_LDR_DATA_TABLE_ENTRY*>(
|
kernel_state->memory()->TranslateVirtual<X_LDR_DATA_TABLE_ENTRY*>(
|
||||||
hmodule);
|
hmodule);
|
||||||
if (ldr_data->load_count-- <= 0) {
|
if (--ldr_data->load_count == 0) {
|
||||||
// No more references, free it.
|
// No more references, free it.
|
||||||
kernel_state->object_table()->RemoveHandle(module->handle());
|
kernel_state->object_table()->RemoveHandle(module->handle());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SHIM_SET_RETURN_32(X_STATUS_SUCCESS);
|
SHIM_SET_RETURN_32(X_STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue