mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-06 19:00:17 +02:00
Merge pull request #3276 from bylaws/f1
Improvements for WOW64 compat with newer wine
This commit is contained in:
3 files changed
+32
-9
No files matched your search
@@ -22,12 +22,13 @@ EXPORTS
|
||||
Wow64PassExceptionToGuest @16
|
||||
Wow64PrepareForDebuggerAttach @17 PRIVATE
|
||||
Wow64PrepareForException @18
|
||||
Wow64RaiseException @19
|
||||
Wow64ShallowThunkAllocObjectAttributes32TO64_FNC @20 PRIVATE
|
||||
Wow64ShallowThunkAllocSecurityQualityOfService32TO64_FNC @21 PRIVATE
|
||||
Wow64ShallowThunkSIZE_T32TO64 @22 PRIVATE
|
||||
Wow64ShallowThunkSIZE_T64TO32 @23 PRIVATE
|
||||
Wow64SuspendLocalThread @24
|
||||
Wow64SystemServiceEx @25
|
||||
Wow64ValidateUserCallTarget @26 PRIVATE
|
||||
Wow64ValidateUserCallTargetFilter @27 PRIVATE
|
||||
Wow64ProcessPendingCrossProcessItems @19
|
||||
Wow64RaiseException @20
|
||||
Wow64ShallowThunkAllocObjectAttributes32TO64_FNC @21 PRIVATE
|
||||
Wow64ShallowThunkAllocSecurityQualityOfService32TO64_FNC @22 PRIVATE
|
||||
Wow64ShallowThunkSIZE_T32TO64 @23 PRIVATE
|
||||
Wow64ShallowThunkSIZE_T64TO32 @24 PRIVATE
|
||||
Wow64SuspendLocalThread @25 PRIVATE
|
||||
Wow64SystemServiceEx @26
|
||||
Wow64ValidateUserCallTarget @27 PRIVATE
|
||||
Wow64ValidateUserCallTargetFilter @28 PRIVATE
|
||||
@@ -35,6 +35,7 @@ $end_info$
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <utility>
|
||||
#include <unordered_set>
|
||||
#include <ntstatus.h>
|
||||
#include <windef.h>
|
||||
#include <winternl.h>
|
||||
@@ -94,6 +95,7 @@ namespace {
|
||||
SYSTEM_CPU_INFORMATION CpuInfo{};
|
||||
|
||||
std::mutex ThreadSuspendLock;
|
||||
std::unordered_set<DWORD> InitializedWOWThreads; // Set of TIDs, `ThreadSuspendLock` must be locked when accessing
|
||||
|
||||
std::pair<NTSTATUS, TLS> GetThreadTLS(HANDLE Thread) {
|
||||
THREAD_BASIC_INFORMATION Info;
|
||||
@@ -460,6 +462,7 @@ public:
|
||||
const uint64_t EntryRAX = Frame->State.gregs[FEXCore::X86State::REG_RAX];
|
||||
|
||||
Context::UnlockJITContext();
|
||||
Wow64ProcessPendingCrossProcessItems();
|
||||
ReturnRAX = static_cast<uint64_t>(Wow64SystemServiceEx(static_cast<UINT>(EntryRAX),
|
||||
reinterpret_cast<UINT *>(ReturnRSP + 4)));
|
||||
Context::LockJITContext();
|
||||
@@ -554,6 +557,8 @@ void BTCpuProcessInit() {
|
||||
NTSTATUS BTCpuThreadInit() {
|
||||
GetTLS().ThreadState() = CTX->CreateThread(nullptr, 0);
|
||||
|
||||
std::scoped_lock Lock(ThreadSuspendLock);
|
||||
InitializedWOWThreads.emplace(GetCurrentThreadId());
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -563,6 +568,17 @@ NTSTATUS BTCpuThreadTerm(HANDLE Thread) {
|
||||
return Err;
|
||||
}
|
||||
|
||||
{
|
||||
THREAD_BASIC_INFORMATION Info;
|
||||
if (NTSTATUS Err = NtQueryInformationThread(Thread, ThreadBasicInformation, &Info, sizeof(Info), nullptr); Err) {
|
||||
return Err;
|
||||
}
|
||||
|
||||
const auto ThreadTID = reinterpret_cast<uint64_t>(Info.ClientId.UniqueThread);
|
||||
std::scoped_lock Lock(ThreadSuspendLock);
|
||||
InitializedWOWThreads.erase(ThreadTID);
|
||||
}
|
||||
|
||||
CTX->DestroyThread(TLS.ThreadState());
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
@@ -665,6 +681,11 @@ NTSTATUS BTCpuSuspendLocalThread(HANDLE Thread, ULONG *Count) {
|
||||
}
|
||||
|
||||
std::scoped_lock Lock(ThreadSuspendLock);
|
||||
|
||||
// If the thread hasn't yet been initialized, suspend it without special handling as it wont yet have entered the JIT
|
||||
if (!InitializedWOWThreads.contains(ThreadTID))
|
||||
return NtSuspendThread(Thread, Count);
|
||||
|
||||
// If CONTROL_IN_JIT is unset at this point, then it can never be set (and thus the JIT cannot be reentered) as
|
||||
// CONTROL_PAUSED has been set, as such, while this may redundantly request interrupts in rare cases it will never
|
||||
// miss them
|
||||
|
||||
@@ -90,6 +90,7 @@ typedef enum _MEMORY_INFORMATION_CLASS {
|
||||
} MEMORY_INFORMATION_CLASS;
|
||||
|
||||
NTSTATUS WINAPI Wow64SystemServiceEx(UINT,UINT*);
|
||||
void WINAPI Wow64ProcessPendingCrossProcessItems(void);
|
||||
|
||||
NTSTATUS WINAPI RtlWow64SetThreadContext(HANDLE,const WOW64_CONTEXT*);
|
||||
NTSTATUS WINAPI RtlWow64GetThreadContext(HANDLE,WOW64_CONTEXT*);
|
||||
|
||||
Reference in new issue
Block a user