From cc2d21f4115e60ee0de1a7d2fdb7ac8e08a71dce Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Mon, 29 Jul 2024 13:09:16 +0000 Subject: [PATCH] WOW64: Resolve the wine unix call dispatcher at runtime --- Source/Windows/WOW64/Module.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/Windows/WOW64/Module.cpp b/Source/Windows/WOW64/Module.cpp index 6135669f6..5837b669e 100644 --- a/Source/Windows/WOW64/Module.cpp +++ b/Source/Windows/WOW64/Module.cpp @@ -103,6 +103,8 @@ std::mutex ThreadCreationMutex; // Map of TIDs to their FEX thread state, `ThreadCreationMutex` must be locked when accessing std::unordered_map Threads; +decltype(__wine_unix_call_dispatcher) WineUnixCall; + std::pair GetThreadTLS(HANDLE Thread) { THREAD_BASIC_INFORMATION Info; const NTSTATUS Err = NtQueryInformationThread(Thread, ThreadBasicInformation, &Info, sizeof(Info), nullptr); @@ -365,7 +367,7 @@ public: ReturnRSP += sizeof(StackLayout); Context::UnlockJITContext(); - ReturnRAX = static_cast(__wine_unix_call(StackArgs->Handle, StackArgs->ID, ULongToPtr(StackArgs->Args))); + ReturnRAX = static_cast(WineUnixCall(StackArgs->Handle, StackArgs->ID, ULongToPtr(StackArgs->Args))); Context::LockJITContext(); } else if (Frame->State.rip == (uint64_t)BridgeInstrs::Syscall) { const uint64_t EntryRAX = Frame->State.gregs[FEXCore::X86State::REG_RAX]; @@ -445,6 +447,11 @@ void BTCpuProcessInit() { *reinterpret_cast(Addr) = 0x2ecd2ecd; BridgeInstrs::Syscall = Addr; BridgeInstrs::UnixCall = reinterpret_cast(reinterpret_cast(Addr) + 2); + + const auto Sym = GetProcAddress(GetModuleHandle("ntdll.dll"), "__wine_unix_call_dispatcher"); + if (Sym) { + WineUnixCall = *reinterpret_cast(Sym); + } } NTSTATUS BTCpuThreadInit() {