From f6f524b8148145c5b5b5ac0a79809df979069bc6 Mon Sep 17 00:00:00 2001 From: Gliniak Date: Sun, 11 Oct 2020 17:37:22 +0200 Subject: [PATCH] Implemented ExLoadedImageName --- src/xenia/kernel/kernel_state.cc | 11 +++++++++++ src/xenia/kernel/xboxkrnl/xboxkrnl_module.cc | 10 ++++++++++ src/xenia/kernel/xboxkrnl/xboxkrnl_module.h | 2 ++ 3 files changed, 23 insertions(+) diff --git a/src/xenia/kernel/kernel_state.cc b/src/xenia/kernel/kernel_state.cc index c0d2e3d20..9c5dcebc2 100644 --- a/src/xenia/kernel/kernel_state.cc +++ b/src/xenia/kernel/kernel_state.cc @@ -316,6 +316,17 @@ void KernelState::SetExecutableModule(object_ref module) { *variable_ptr = executable_module_->hmodule_ptr(); } + // Setup the kernel's ExLoadedImageName field + export_entry = processor()->export_resolver()->GetExportByOrdinal( + "xboxkrnl.exe", ordinals::ExLoadedImageName); + + if (export_entry) { + char* variable_ptr = + memory()->TranslateVirtual(export_entry->variable_ptr); + xe::string_util::copy_truncating( + variable_ptr, executable_module_->path(), + xboxkrnl::XboxkrnlModule::kExLoadedImageNameSize); + } // Spin up deferred dispatch worker. // TODO(benvanik): move someplace more appropriate (out of ctor, but around // here). diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_module.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_module.cc index b2aafe294..f6b9846e0 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_module.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_module.cc @@ -189,6 +189,16 @@ XboxkrnlModule::XboxkrnlModule(Emulator* emulator, KernelState* kernel_state) ordinals::XexExecutableModuleHandle, ppXexExecutableModuleHandle); + // ExLoadedImageName (char*) + // The full path to loaded image/xex including its name. + // Used usually in custom dashboards (Aurora) + // Todo(Gliniak): Confirm that official kernel always allocate space for this + // variable. + uint32_t ppExLoadedImageName = + memory_->SystemHeapAlloc(kExLoadedImageNameSize); + export_resolver_->SetVariableMapping( + "xboxkrnl.exe", ordinals::ExLoadedImageName, ppExLoadedImageName); + // ExLoadedCommandLine (char*) // The name of the xex. Not sure this is ever really used on real devices. // Perhaps it's how swap disc/etc data is sent? diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_module.h b/src/xenia/kernel/xboxkrnl/xboxkrnl_module.h index 5a817453c..39a9c95b2 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_module.h +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_module.h @@ -27,6 +27,8 @@ namespace xboxkrnl { class XboxkrnlModule : public KernelModule { public: + static constexpr size_t kExLoadedImageNameSize = 255 + 1; + XboxkrnlModule(Emulator* emulator, KernelState* kernel_state); virtual ~XboxkrnlModule();