From 8b446de059200b32ae5cf39df135f7adcb2b113f Mon Sep 17 00:00:00 2001 From: Brendan Shanks Date: Fri, 17 Jul 2026 13:44:34 -0700 Subject: [PATCH 1/3] Windows: Use GetModuleHandleW() to avoid unnecessary string conversions --- Source/Tools/FEXOfflineCompiler/Main.cpp | 2 +- Source/Windows/ARM64EC/Module.cpp | 4 ++-- Source/Windows/Common/Logging.cpp | 2 +- Source/Windows/WOW64/Module.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Tools/FEXOfflineCompiler/Main.cpp b/Source/Tools/FEXOfflineCompiler/Main.cpp index e969af057..af3bb7723 100644 --- a/Source/Tools/FEXOfflineCompiler/Main.cpp +++ b/Source/Tools/FEXOfflineCompiler/Main.cpp @@ -413,7 +413,7 @@ static std::optional GenerateSingleCache(FEXCore::ExecutableFileInf #ifndef _WIN32 auto HostFeatures = FEX::FetchHostFeatures(); #else - const auto NtDll = GetModuleHandle("ntdll.dll"); + const auto NtDll = GetModuleHandleW(L"ntdll.dll"); const bool IsWine = !!GetProcAddress(NtDll, "wine_get_version"); auto HostFeatures = FEX::Windows::CPUFeatures::FetchHostFeatures( IsWine, Is64Bit ? FEXCore::HostFeatures::HostTypeEnum::Arm64ec : FEXCore::HostFeatures::HostTypeEnum::Wow64); diff --git a/Source/Windows/ARM64EC/Module.cpp b/Source/Windows/ARM64EC/Module.cpp index 6ceecd878..ab3e7a35e 100644 --- a/Source/Windows/ARM64EC/Module.cpp +++ b/Source/Windows/ARM64EC/Module.cpp @@ -268,7 +268,7 @@ void ParseWineSyscallNumbers(HMODULE NtDll) { void InitSyscalls() { // The ntdll exports called by GetModuleHandle/GetProcAddress aren't known to be patched before JIT init by any current // software so are safe to call, but if that changes the loader structures in the PEB could be parsed manually. - const auto NtDll = GetModuleHandle("ntdll.dll"); + const auto NtDll = GetModuleHandleW(L"ntdll.dll"); NtDllBase = reinterpret_cast(NtDll); const auto WineSyscallDispatcherPtr = reinterpret_cast(GetProcAddress(NtDll, "__wine_syscall_dispatcher")); @@ -593,7 +593,7 @@ NTSTATUS ProcessInit() { SignalDelegator = fextl::make_unique(); SyscallHandler = fextl::make_unique(); - const auto NtDll = GetModuleHandle("ntdll.dll"); + const auto NtDll = GetModuleHandleW(L"ntdll.dll"); const bool IsWine = !!GetProcAddress(NtDll, "wine_get_version"); OvercommitTracker.emplace(IsWine); diff --git a/Source/Windows/Common/Logging.cpp b/Source/Windows/Common/Logging.cpp index c8b0e826d..8980bda8d 100644 --- a/Source/Windows/Common/Logging.cpp +++ b/Source/Windows/Common/Logging.cpp @@ -39,7 +39,7 @@ void Init() { return; } - WineDbgOut = reinterpret_cast(GetProcAddress(GetModuleHandleA("ntdll.dll"), "__wine_dbg_output")); + WineDbgOut = reinterpret_cast(GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "__wine_dbg_output")); if (!WineDbgOut) { const auto Path = fextl::fmt::format("{}\\fex-{}.log", getenv("LOCALAPPDATA"), GetCurrentProcessId()); LogFile = fopen(Path.c_str(), "a"); diff --git a/Source/Windows/WOW64/Module.cpp b/Source/Windows/WOW64/Module.cpp index f62302315..515a553b7 100644 --- a/Source/Windows/WOW64/Module.cpp +++ b/Source/Windows/WOW64/Module.cpp @@ -527,7 +527,7 @@ void BTCpuProcessInit() { SignalDelegator = fextl::make_unique(); SyscallHandler = fextl::make_unique(); - const auto NtDll = GetModuleHandle("ntdll.dll"); + const auto NtDll = GetModuleHandleW(L"ntdll.dll"); const bool IsWine = !!GetProcAddress(NtDll, "wine_get_version"); OvercommitTracker.emplace(IsWine); From 074743d6e886eb93bb49e6de3ad35005dc3cf2b2 Mon Sep 17 00:00:00 2001 From: Brendan Shanks Date: Wed, 22 Jul 2026 14:44:13 -0700 Subject: [PATCH 2/3] Windows: Explicitly use *A/*W Win32 functions --- Source/Windows/Common/FEXUnixLib.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Windows/Common/FEXUnixLib.cpp b/Source/Windows/Common/FEXUnixLib.cpp index 4b6652a2b..979782395 100644 --- a/Source/Windows/Common/FEXUnixLib.cpp +++ b/Source/Windows/Common/FEXUnixLib.cpp @@ -247,8 +247,8 @@ SHMSlotResult AllocateSHMSlots(void* SHMBase, uint32_t MapSize, uint32_t MaxSize } // Opaque handle path, doesn't support resizing. - auto handle = CreateFile(fextl::fmt::format("/dev/shm/fex-{}-stats", Illegal::linux_getpid()).c_str(), GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + auto handle = CreateFileA(fextl::fmt::format("/dev/shm/fex-{}-stats", Illegal::linux_getpid()).c_str(), GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); // Create the section mapping for the file handle for the full size. HANDLE SectionMapping; @@ -284,7 +284,7 @@ void DeleteSHMStatsFile() { } // Legacy Proton path. - DeleteFile(fextl::fmt::format("/dev/shm/fex-{}-stats", Illegal::linux_getpid()).c_str()); + DeleteFileA(fextl::fmt::format("/dev/shm/fex-{}-stats", Illegal::linux_getpid()).c_str()); } } // namespace FEX::Windows::UnixLib From 0ed0bc1dd555cd287e71b3e8a705c539bf8c9284 Mon Sep 17 00:00:00 2001 From: Brendan Shanks Date: Wed, 22 Jul 2026 15:02:03 -0700 Subject: [PATCH 3/3] CMake: Define UNICODE when building for Windows --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d848401c..63f75f100 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -195,6 +195,9 @@ if (ENABLE_GDB_SYMBOLS) endif() add_compile_definitions(_LARGEFILE64_SOURCE) +if (WIN32) + add_compile_definitions(UNICODE _UNICODE) +endif() set(CMAKE_CXX_STANDARD 20) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)