KernelState::GetKernelModule

This commit is contained in:
Dr. Chat 2015-07-05 17:27:25 -05:00
parent 8adbc2cd0c
commit 870aa092bb
4 changed files with 28 additions and 20 deletions

View File

@ -275,13 +275,9 @@ X_STATUS Emulator::LaunchStfsContainer(std::wstring path) {
X_STATUS Emulator::CompleteLaunch(const std::wstring& path,
const std::string& module_path) {
// Allow xam to request module loads.
auto xam_module = kernel_state_->GetModule("xam.xex");
auto xam = kernel::object_ref<kernel::XamModule>(
reinterpret_cast<kernel::XamModule*>(xam_module.release()));
auto xboxkrnl_module = kernel_state_->GetModule("xboxkrnl.exe");
auto xboxkrnl = kernel::object_ref<kernel::XboxkrnlModule>(
reinterpret_cast<kernel::XboxkrnlModule*>(xboxkrnl_module.release()));
auto xam = kernel_state()->GetKernelModule<kernel::XamModule>("xam.xex");
auto xboxkrnl =
kernel_state()->GetKernelModule<kernel::XboxkrnlModule>("xboxkrnl.exe");
int result = 0;
auto next_module = module_path;

View File

@ -161,6 +161,18 @@ bool KernelState::IsKernelModule(const char* name) {
return false;
}
object_ref<XKernelModule> KernelState::GetKernelModule(const char* name) {
assert_true(IsKernelModule(name));
for (auto kernel_module : kernel_modules_) {
if (kernel_module->Matches(name)) {
return retain_object(kernel_module.get());
}
}
return nullptr;
}
object_ref<XModule> KernelState::GetModule(const char* name) {
if (!name) {
// NULL name = self.

View File

@ -112,15 +112,23 @@ class KernelState {
void UnregisterModule(XModule* module);
bool IsKernelModule(const char* name);
object_ref<XModule> GetModule(const char* name);
object_ref<XUserModule> GetExecutableModule();
void SetExecutableModule(object_ref<XUserModule> module);
object_ref<XUserModule> LoadUserModule(const char* name);
object_ref<XKernelModule> GetKernelModule(const char* name);
template <typename T>
object_ref<XKernelModule> LoadKernelModule() {
auto kernel_module = object_ref<XKernelModule>(new T(emulator_, this));
LoadKernelModule(kernel_module);
return kernel_module;
}
object_ref<XUserModule> LoadUserModule(const char* name);
template <typename T>
object_ref<T> GetKernelModule(const char* name) {
auto module = GetKernelModule(name);
return object_ref<T>(reinterpret_cast<T*>(module.release()));
}
// Terminates a title: Unloads all modules, and kills all guest threads.
void TerminateTitle(bool from_guest_thread = false);

View File

@ -93,9 +93,7 @@ SHIM_CALL XamGetExecutionId_shim(PPCContext* ppc_context,
}
dword_result_t XamLoaderSetLaunchData(lpvoid_t data, dword_t size) {
auto xam_module = kernel_state()->GetModule("xam.xex");
auto xam = kernel::object_ref<kernel::XamModule>(
reinterpret_cast<kernel::XamModule*>(xam_module.release()));
auto xam = kernel_state()->GetKernelModule<kernel::XamModule>("xam.xex");
auto& loader_data = xam->loader_data();
if (loader_data.launch_data_ptr) {
@ -114,9 +112,7 @@ dword_result_t XamLoaderSetLaunchData(lpvoid_t data, dword_t size) {
DECLARE_XAM_EXPORT(XamLoaderSetLaunchData, ExportTag::kSketchy);
dword_result_t XamLoaderGetLaunchDataSize(lpdword_t size_ptr) {
auto xam_module = kernel_state()->GetModule("xam.xex");
auto xam = kernel::object_ref<kernel::XamModule>(
reinterpret_cast<kernel::XamModule*>(xam_module.release()));
auto xam = kernel_state()->GetKernelModule<kernel::XamModule>("xam.xex");
*size_ptr = xam->loader_data().launch_data_size;
@ -126,9 +122,7 @@ DECLARE_XAM_EXPORT(XamLoaderGetLaunchDataSize, ExportTag::kSketchy);
dword_result_t XamLoaderGetLaunchData(lpvoid_t buffer_ptr,
dword_t buffer_size) {
auto xam_module = kernel_state()->GetModule("xam.xex");
auto xam = kernel::object_ref<kernel::XamModule>(
reinterpret_cast<kernel::XamModule*>(xam_module.release()));
auto xam = kernel_state()->GetKernelModule<kernel::XamModule>("xam.xex");
auto& loader_data = xam->loader_data();
if (loader_data.launch_data_ptr) {
@ -146,9 +140,7 @@ dword_result_t XamLoaderGetLaunchData(lpvoid_t buffer_ptr,
DECLARE_XAM_EXPORT(XamLoaderGetLaunchData, ExportTag::kSketchy);
void XamLoaderLaunchTitle(lpstring_t raw_name, dword_t flags) {
auto xam_module = kernel_state()->GetModule("xam.xex");
auto xam = kernel::object_ref<kernel::XamModule>(
reinterpret_cast<kernel::XamModule*>(xam_module.release()));
auto xam = kernel_state()->GetKernelModule<kernel::XamModule>("xam.xex");
auto& loader_data = xam->loader_data();
loader_data.launch_flags = flags;