diff --git a/Source/Windows/ARM64EC/Module.cpp b/Source/Windows/ARM64EC/Module.cpp index e60ae29a4..0afd3e16b 100644 --- a/Source/Windows/ARM64EC/Module.cpp +++ b/Source/Windows/ARM64EC/Module.cpp @@ -328,7 +328,7 @@ void LoadImageVolatileMetadata(const fextl::string& ModuleName, uint64_t Address } void HandleImageMap(uint64_t Address) { - fextl::string ModuleName = FEX::Windows::GetSectionFilePath(Address); + fextl::string ModuleName = fextl::string {FEX::Windows::BaseName(FEX::Windows::GetSectionFilePath(Address))}; LogMan::Msg::DFmt("Load module {}: {:X}", ModuleName, Address); FEX_CONFIG_OPT(VolatileMetadata, VOLATILEMETADATA); if (VolatileMetadata) { @@ -626,8 +626,8 @@ NTSTATUS ProcessInit() { InitSyscalls(); FEX::Windows::InitCRTProcess(); - const auto ExecutablePath = FEX::Windows::GetExecutableFilePath(); - FEX::Config::LoadConfig(ExecutablePath, _environ, FEX::ReadPortabilityInformation()); + const auto ExecutableName = FEX::Windows::BaseName(FEX::Windows::GetExecutableFilePath()); + FEX::Config::LoadConfig(fextl::string {ExecutableName}, _environ, FEX::ReadPortabilityInformation()); FEXCore::Config::ReloadMetaLayer(); FEX::Windows::Logging::Init(); @@ -688,8 +688,8 @@ NTSTATUS ProcessInit() { StatAllocHandler = fextl::make_unique(FEXCore::SHMStats::AppType::WIN_ARM64EC); } - if (StartupSleep() && (StartupSleepProcName().empty() || ExecutablePath == StartupSleepProcName())) { - LogMan::Msg::IFmt("[{}][{}] Sleeping for {} seconds", GetCurrentProcessId(), ExecutablePath, StartupSleep()); + if (StartupSleep() && (StartupSleepProcName().empty() || ExecutableName == StartupSleepProcName())) { + LogMan::Msg::IFmt("[{}][{}] Sleeping for {} seconds", GetCurrentProcessId(), ExecutableName, StartupSleep()); std::this_thread::sleep_for(std::chrono::seconds(StartupSleep())); } diff --git a/Source/Windows/Common/Module.h b/Source/Windows/Common/Module.h index 85e5a6994..2076e1f6f 100644 --- a/Source/Windows/Common/Module.h +++ b/Source/Windows/Common/Module.h @@ -6,7 +6,7 @@ #include namespace FEX::Windows { -fextl::string GetExecutableFilePath() { +inline fextl::string GetExecutableFilePath() { std::array Buf; UNICODE_STRING PathW {.Length = 0, .MaximumLength = Buf.size() * sizeof(WCHAR), .Buffer = Buf.data()}; @@ -19,16 +19,16 @@ fextl::string GetExecutableFilePath() { fextl::string Path(PathA.Buffer); RtlFreeAnsiString(&PathA); - return Path.substr(Path.find_last_of('\\') + 1); + return Path; } -fextl::string GetSectionFilePath(uint64_t Address) { +inline fextl::string GetSectionFilePath(uint64_t Address) { struct { MEMORY_SECTION_NAME Info; std::array PathW; } Buffer; - if (NtQueryVirtualMemory(GetCurrentProcess(), reinterpret_cast(Address), MemoryMappedFilenameInformation, &Buffer, sizeof(Buffer), NULL)) { + if (NtQueryVirtualMemory(NtCurrentProcess(), reinterpret_cast(Address), MemoryMappedFilenameInformation, &Buffer, sizeof(Buffer), NULL)) { return {}; } @@ -37,6 +37,10 @@ fextl::string GetSectionFilePath(uint64_t Address) { fextl::string Path(PathA.Buffer); RtlFreeAnsiString(&PathA); + return Path; +} + +inline std::string_view BaseName(std::string_view Path) { return Path.substr(Path.find_last_of('\\') + 1); } } // namespace FEX::Windows diff --git a/Source/Windows/WOW64/Module.cpp b/Source/Windows/WOW64/Module.cpp index c51f4f902..58ffc038e 100644 --- a/Source/Windows/WOW64/Module.cpp +++ b/Source/Windows/WOW64/Module.cpp @@ -187,7 +187,7 @@ void LoadImageVolatileMetadata(const fextl::string& ModuleName, uint64_t Address } void HandleImageMap(uint64_t Address) { - fextl::string ModuleName = FEX::Windows::GetSectionFilePath(Address); + fextl::string ModuleName = fextl::string {FEX::Windows::BaseName(FEX::Windows::GetSectionFilePath(Address))}; LogMan::Msg::DFmt("Load module {}: {:X}", ModuleName, Address); FEX_CONFIG_OPT(VolatileMetadata, VOLATILEMETADATA); if (VolatileMetadata) { @@ -508,8 +508,8 @@ public: void BTCpuProcessInit() { FEX::Windows::InitCRTProcess(); - const auto ExecutablePath = FEX::Windows::GetExecutableFilePath(); - FEX::Config::LoadConfig(ExecutablePath, _environ, FEX::ReadPortabilityInformation()); + const auto ExecutableName = FEX::Windows::BaseName(FEX::Windows::GetExecutableFilePath()); + FEX::Config::LoadConfig(fextl::string {ExecutableName}, _environ, FEX::ReadPortabilityInformation()); FEXCore::Config::ReloadMetaLayer(); FEX::Windows::Logging::Init(); @@ -582,8 +582,8 @@ void BTCpuProcessInit() { StatAllocHandler = fextl::make_unique(FEXCore::SHMStats::AppType::WIN_WOW64); } - if (StartupSleep() && (StartupSleepProcName().empty() || ExecutablePath == StartupSleepProcName())) { - LogMan::Msg::IFmt("[{}][{}] Sleeping for {} seconds", GetCurrentProcessId(), ExecutablePath, StartupSleep()); + if (StartupSleep() && (StartupSleepProcName().empty() || ExecutableName == StartupSleepProcName())) { + LogMan::Msg::IFmt("[{}][{}] Sleeping for {} seconds", GetCurrentProcessId(), ExecutableName, StartupSleep()); std::this_thread::sleep_for(std::chrono::seconds(StartupSleep())); } }