From 6f3b66af494e145cfa23a216e5663a772d570af4 Mon Sep 17 00:00:00 2001 From: maxjivi05 Date: Fri, 4 Dec 2026 18:49:17 -0500 Subject: [PATCH] Rebase the FEX patch series onto FEX-2612 --- docs/development/x86-64-steam-client.md | 7 +- ...7-cmake-install-code-without-depends.patch | 1 + ...signal-return-restores-syscall-state.patch | 4 +- ...gnal-handler-escape-frees-host-stack.patch | 20 +- .../0011-thunk-calls-mark-spilled-state.patch | 22 +- ...ignal-return-applies-guest-registers.patch | 12 +- .../0017-fd-exec-keeps-argv0-and-path.patch | 6 +- ...at-ptrace-seccomp-and-proc-emulation.patch | 286 +++++++----------- ...st-only-on-small-address-space-hosts.patch | 6 +- ...roc-status-seccomp-of-calling-thread.patch | 8 +- .../0024-read-host-status-directly.patch | 4 +- ...uest-memory-above-host-address-limit.patch | 22 +- ...t-cmdline-without-checkpoint-restore.patch | 4 +- ...tables-describe-the-container-procfs.patch | 14 +- 14 files changed, 177 insertions(+), 239 deletions(-) diff --git a/docs/development/x86-64-steam-client.md b/docs/development/x86-64-steam-client.md index ced25e4c70..d4d67c7687 100644 --- a/docs/development/x86-64-steam-client.md +++ b/docs/development/x86-64-steam-client.md @@ -216,9 +216,10 @@ alone would then read as an installed client. NullReferenceException, internal CLR errors). A writable mapping or mprotect now write-protects the overlapping part of any alias that is already executable, so the first write faults and invalidates. `FEX_SMCCHECKS=full` was the only workaround; no setting is needed with the patch. - - `0007-cmake-install-code-without-depends`: CMake 4.5 rejects the `DEPENDS` argument FEX passes to - `install(CODE ...)` for the guest thunk libraries, so builds with host thunks stopped at configure. - The guest libraries are external projects in the default build, which `install` already follows. + - `0007-cmake-install-code-without-depends` (`Fixed-upstream: FEX-2612`): CMake 4.5 rejects the + `DEPENDS` argument FEX passes to `install(CODE ...)` for the guest thunk libraries, so builds with + host thunks stopped at configure. The guest libraries are external projects in the default build, + which `install` already follows. - `0008-signal-return-restores-syscall-state`: a guest `rt_sigreturn` is a system call, so FEX's syscall stub marks every static register as spilled (`InSyscallInfo = 0xFFFF`). When the handler left RIP alone, the return resumed the interrupted JIT code without passing the stub's reset, and diff --git a/tools/fex/patches/0007-cmake-install-code-without-depends.patch b/tools/fex/patches/0007-cmake-install-code-without-depends.patch index 6752b40280..83c0e1fb82 100644 --- a/tools/fex/patches/0007-cmake-install-code-without-depends.patch +++ b/tools/fex/patches/0007-cmake-install-code-without-depends.patch @@ -1,3 +1,4 @@ +Fixed-upstream: FEX-2612 diff --git a/CMakeLists.txt b/CMakeLists.txt index 8976588..3ae54f4 100644 --- a/CMakeLists.txt diff --git a/tools/fex/patches/0008-signal-return-restores-syscall-state.patch b/tools/fex/patches/0008-signal-return-restores-syscall-state.patch index 6592a94550..327fe76a85 100644 --- a/tools/fex/patches/0008-signal-return-restores-syscall-state.patch +++ b/tools/fex/patches/0008-signal-return-restores-syscall-state.patch @@ -1,8 +1,8 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp -index b4c7b24..643185d 100644 +index 345f4d834..085ff00a2 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp -@@ -264,12 +264,13 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr +@@ -283,12 +283,13 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr auto Frame = Thread->CurrentFrame; if (Context->Flags & ArchHelpers::Context::ContextFlags::CONTEXT_FLAG_INJIT) { diff --git a/tools/fex/patches/0009-signal-handler-escape-frees-host-stack.patch b/tools/fex/patches/0009-signal-handler-escape-frees-host-stack.patch index fbeec5ec96..6af2b7eb33 100644 --- a/tools/fex/patches/0009-signal-handler-escape-frees-host-stack.patch +++ b/tools/fex/patches/0009-signal-handler-escape-frees-host-stack.patch @@ -1,5 +1,5 @@ diff --git a/Source/Tools/LinuxEmulation/ArchHelpers/MContext.h b/Source/Tools/LinuxEmulation/ArchHelpers/MContext.h -index 02bb6bf..2e72492 100644 +index 02bb6bfef..2e724929f 100644 --- a/Source/Tools/LinuxEmulation/ArchHelpers/MContext.h +++ b/Source/Tools/LinuxEmulation/ArchHelpers/MContext.h @@ -49,6 +49,11 @@ struct X86ContextBackup { @@ -27,10 +27,10 @@ index 02bb6bf..2e72492 100644 // Arm64 doesn't have a red zone diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp -index 643185d..53179c4 100644 +index 085ff00a2..5c79d1092 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp -@@ -136,6 +136,31 @@ void SignalDelegator::SpillSRA(FEXCore::Core::InternalThreadState* Thread, void* +@@ -155,6 +155,31 @@ void SignalDelegator::SpillSRA(FEXCore::Core::InternalThreadState* Thread, void* #endif } @@ -62,7 +62,7 @@ index 643185d..53179c4 100644 ArchHelpers::Context::ContextBackup* SignalDelegator::StoreThreadState(FEXCore::Core::InternalThreadState* Thread, int Signal, void* ucontext) { // We can end up getting a signal at any point in our host state // Jump to a handler that saves all state so we can safely return -@@ -249,6 +274,19 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr +@@ -268,6 +293,19 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr } OldSP = *reinterpret_cast(GuestSP); @@ -82,7 +82,7 @@ index 643185d..53179c4 100644 } uintptr_t NewSP = OldSP; -@@ -287,6 +325,7 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS +@@ -306,6 +344,7 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS auto ContextBackup = StoreThreadState(Thread, Signal, ucontext); auto Frame = Thread->CurrentFrame; @@ -90,7 +90,7 @@ index 643185d..53179c4 100644 // Ref count our faults // We use this to track if it is safe to clear cache -@@ -336,6 +375,8 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS +@@ -355,6 +394,8 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS uint64_t OldGuestSP = Frame->State.gregs[FEXCore::X86State::REG_RSP]; uint64_t NewGuestSP = OldGuestSP; @@ -99,7 +99,7 @@ index 643185d..53179c4 100644 // altstack is only used if the signal handler was setup with SA_ONSTACK if (GuestAction->sa_flags & SA_ONSTACK) { -@@ -345,6 +386,8 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS +@@ -364,6 +405,8 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS // Then that means we are hitting recursive signals and we need to walk back the stack correctly uint64_t AltStackBase = reinterpret_cast(GuestStack->ss_sp); uint64_t AltStackEnd = AltStackBase + GuestStack->ss_size; @@ -108,7 +108,7 @@ index 643185d..53179c4 100644 if (OldGuestSP >= AltStackBase && OldGuestSP <= AltStackEnd) { // We are already in the alt stack, the rest of the code will handle adjusting this } else { -@@ -353,6 +396,40 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS +@@ -372,6 +415,40 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS } } @@ -149,7 +149,7 @@ index 643185d..53179c4 100644 // siginfo_t siginfo_t* HostSigInfo = reinterpret_cast(info); -@@ -491,6 +568,8 @@ bool SignalDelegator::HandleSignalPause(FEXCore::Core::InternalThreadState* Thre +@@ -510,6 +587,8 @@ bool SignalDelegator::HandleSignalPause(FEXCore::Core::InternalThreadState* Thre // Our ref counting doesn't matter anymore Thread->CurrentFrame->SignalHandlerRefCounter = 0; @@ -159,7 +159,7 @@ index 643185d..53179c4 100644 // Set the new PC if (CTX->IsAddressInCodeBuffer(Thread, ArchHelpers::Context::GetPc(ucontext))) { diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h -index dfcd4b0..e4a86a9 100644 +index 0f45cf68d..408cddf71 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h @@ -83,6 +83,9 @@ struct ThreadStateObject : public FEXCore::Allocator::FEXAllocOperators { diff --git a/tools/fex/patches/0011-thunk-calls-mark-spilled-state.patch b/tools/fex/patches/0011-thunk-calls-mark-spilled-state.patch index 626c726b59..cebe184aa2 100644 --- a/tools/fex/patches/0011-thunk-calls-mark-spilled-state.patch +++ b/tools/fex/patches/0011-thunk-calls-mark-spilled-state.patch @@ -1,7 +1,8 @@ diff --git a/FEXCore/Source/Interface/Core/Core.cpp b/FEXCore/Source/Interface/Core/Core.cpp +index 1946dc946..9f04358c5 100644 --- a/FEXCore/Source/Interface/Core/Core.cpp +++ b/FEXCore/Source/Interface/Core/Core.cpp -@@ -383,7 +383,11 @@ +@@ -383,7 +383,11 @@ bool ContextImpl::InitCore() { } void ContextImpl::HandleCallback(FEXCore::Core::InternalThreadState* Thread, uint64_t RIP) { @@ -15,9 +16,10 @@ diff --git a/FEXCore/Source/Interface/Core/Core.cpp b/FEXCore/Source/Interface/C void ContextImpl::ExecuteThread(FEXCore::Core::InternalThreadState* Thread) { diff --git a/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp b/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp +index ae3ed51e4..c5e656d2c 100644 --- a/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp +++ b/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp -@@ -305,6 +305,9 @@ +@@ -306,6 +306,9 @@ DEF_OP(Thunk) { PushDynamicRegs(TMP1); @@ -27,7 +29,7 @@ diff --git a/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp b/FEXCore/Source/In mov(ARMEmitter::Size::i64Bit, ARMEmitter::Reg::r0, GetReg(Op->ArgPtr)); InsertNamedThunkRelocation(ARMEmitter::Reg::r2, Op->ThunkNameHash); -@@ -320,6 +323,8 @@ +@@ -321,6 +324,8 @@ DEF_OP(Thunk) { FillStaticRegs({ .NZCV = false, }); @@ -37,9 +39,10 @@ diff --git a/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp b/FEXCore/Source/In DEF_OP(ValidateCode) { diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp +index 5c79d1092..e8e04b056 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp -@@ -107,6 +107,10 @@ +@@ -126,6 +126,10 @@ void SignalDelegator::SpillSRA(FEXCore::Core::InternalThreadState* Thread, void* #ifdef ARCHITECTURE_arm64 Thread->CurrentFrame->State.rip = CTX->RestoreRIPFromHostPC(Thread, ArchHelpers::Context::GetPc(ucontext)); @@ -50,7 +53,7 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp b/Sou for (size_t i = 0; i < Config.SRAGPRCount; i++) { const uint8_t SRAIdxMap = Config.SRAGPRMapping[i]; if (IgnoreMask & (1U << SRAIdxMap)) { -@@ -301,12 +305,10 @@ +@@ -320,12 +324,10 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr if (Context->UContextLocation) { auto Frame = Thread->CurrentFrame; @@ -67,7 +70,7 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp b/Sou if (Is64BitMode) { RestoreFrame_x64(Thread, Context, Frame, ucontext); -@@ -361,6 +363,9 @@ +@@ -380,6 +382,9 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS ContextBackup->InSyscallInfo = Thread->CurrentFrame->InSyscallInfo; Thread->CurrentFrame->InSyscallInfo = 0; } else { @@ -78,9 +81,10 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp b/Sou // This is likely to cause issues but in some cases it isn't fatal // This can also happen if we have put a signal on hold, then we just reenabled the signal diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp +index fa6260954..e5d92e7c5 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp -@@ -131,7 +131,7 @@ +@@ -131,7 +131,7 @@ void SignalDelegator::RestoreFrame_x64(FEXCore::Core::InternalThreadState* Threa if (Context->OriginalRIP != guest_uctx->uc_mcontext.gregs[FEXCore::x86_64::FEX_REG_RIP] || Context->FaultToTopAndGeneratedException) { // Restore previous `InSyscallInfo` structure. @@ -89,7 +93,7 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFram // Hack! Go back to the top of the dispatcher top // This is only safe inside the JIT rather than anything outside of it -@@ -211,7 +211,7 @@ +@@ -211,7 +211,7 @@ void SignalDelegator::RestoreFrame_ia32(FEXCore::Core::InternalThreadState* Thre // If the guest modified the RIP then we need to take special precautions here if (Context->OriginalRIP != guest_uctx->sc.ip || Context->FaultToTopAndGeneratedException) { // Restore previous `InSyscallInfo` structure. @@ -98,7 +102,7 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFram // Hack! Go back to the top of the dispatcher top // This is only safe inside the JIT rather than anything outside of it -@@ -290,7 +290,7 @@ +@@ -290,7 +290,7 @@ void SignalDelegator::RestoreRTFrame_ia32(FEXCore::Core::InternalThreadState* Th if (Context->OriginalRIP != guest_uctx->uc.uc_mcontext.gregs[FEXCore::x86::FEX_REG_EIP] || Context->FaultToTopAndGeneratedException) { // Restore previous `InSyscallInfo` structure. diff --git a/tools/fex/patches/0012-signal-return-applies-guest-registers.patch b/tools/fex/patches/0012-signal-return-applies-guest-registers.patch index d97a75bee3..09c8398310 100644 --- a/tools/fex/patches/0012-signal-return-applies-guest-registers.patch +++ b/tools/fex/patches/0012-signal-return-applies-guest-registers.patch @@ -1,7 +1,8 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h +index 9e6820bf6..43898e700 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h -@@ -263,6 +263,8 @@ +@@ -266,6 +266,8 @@ private: FEXCore::Core::CpuStateFrame* Frame, void* ucontext); void RestoreRTFrame_ia32(FEXCore::Core::InternalThreadState* Thread, ArchHelpers::Context::ContextBackup* Context, FEXCore::Core::CpuStateFrame* Frame, void* ucontext); @@ -11,9 +12,10 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h b/Sourc ///< Setup the signal frame for x64. uint64_t SetupFrame_x64(FEXCore::Core::InternalThreadState* Thread, ArchHelpers::Context::ContextBackup* ContextBackup, diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp +index e5d92e7c5..38dc524f1 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp -@@ -122,6 +122,32 @@ +@@ -122,6 +122,32 @@ static void SetXStateInfo(T* xstate, bool is_avx_enabled) { } } @@ -46,7 +48,7 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFram void SignalDelegator::RestoreFrame_x64(FEXCore::Core::InternalThreadState* Thread, ArchHelpers::Context::ContextBackup* Context, FEXCore::Core::CpuStateFrame* Frame, void* ucontext) { auto* guest_uctx = reinterpret_cast(Context->UContextLocation); -@@ -202,6 +228,27 @@ +@@ -202,6 +228,27 @@ void SignalDelegator::RestoreFrame_x64(FEXCore::Core::InternalThreadState* Threa const auto modulo_i = (i + CurrentOffset) % 8; memcpy(&Frame->State.mm[modulo_i], &fpstate->_st[i], sizeof(Frame->State.mm[0])); } @@ -74,7 +76,7 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFram } } -@@ -280,6 +327,17 @@ +@@ -280,6 +327,17 @@ void SignalDelegator::RestoreFrame_ia32(FEXCore::Core::InternalThreadState* Thre const auto modulo_i = (i + CurrentOffset) % 8; memcpy(&Frame->State.mm[modulo_i], &fpstate->_st[i], 10); } @@ -92,7 +94,7 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFram } } -@@ -359,6 +417,17 @@ +@@ -359,6 +417,17 @@ void SignalDelegator::RestoreRTFrame_ia32(FEXCore::Core::InternalThreadState* Th const auto modulo_i = (i + CurrentOffset) % 8; memcpy(&Frame->State.mm[modulo_i], &fpstate->_st[i], 10); } diff --git a/tools/fex/patches/0017-fd-exec-keeps-argv0-and-path.patch b/tools/fex/patches/0017-fd-exec-keeps-argv0-and-path.patch index 2192b9b0af..9bdad1cebd 100644 --- a/tools/fex/patches/0017-fd-exec-keeps-argv0-and-path.patch +++ b/tools/fex/patches/0017-fd-exec-keeps-argv0-and-path.patch @@ -1,8 +1,8 @@ diff --git a/Source/Tools/FEXInterpreter/FEXInterpreter.cpp b/Source/Tools/FEXInterpreter/FEXInterpreter.cpp -index 2881ad9..abc84f3 100644 +index dd2c18303..e7e88f8f2 100644 --- a/Source/Tools/FEXInterpreter/FEXInterpreter.cpp +++ b/Source/Tools/FEXInterpreter/FEXInterpreter.cpp -@@ -518,7 +518,7 @@ int main(int argc, char** argv, char** const envp) { +@@ -524,7 +524,7 @@ int main(int argc, char** argv, char** const envp) { FEXCore::Config::Set(FEXCore::Config::CONFIG_APP_CONFIG_NAME, Program.ProgramName); } else { // Anonymous program. @@ -12,7 +12,7 @@ index 2881ad9..abc84f3 100644 } } else { diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp -index a7a432b..4a77d87 100644 +index a7a432bbd..4a77d8716 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp @@ -441,7 +441,7 @@ uint64_t ExecveHandler(FEXCore::Core::CpuStateFrame* Frame, const char* pathname diff --git a/tools/fex/patches/0021-anticheat-ptrace-seccomp-and-proc-emulation.patch b/tools/fex/patches/0021-anticheat-ptrace-seccomp-and-proc-emulation.patch index f39ddc2790..0f49522f22 100644 --- a/tools/fex/patches/0021-anticheat-ptrace-seccomp-and-proc-emulation.patch +++ b/tools/fex/patches/0021-anticheat-ptrace-seccomp-and-proc-emulation.patch @@ -18,10 +18,10 @@ index 61385d2c3..b515a4a02 100644 Utils/ForcedAssert.cpp Utils/LogManager.cpp diff --git a/FEXCore/Source/Interface/Config/Config.json.in b/FEXCore/Source/Interface/Config/Config.json.in -index 602b2a50d..5f59684e4 100644 +index 6bd89a1e5..860bd4429 100644 --- a/FEXCore/Source/Interface/Config/Config.json.in +++ b/FEXCore/Source/Interface/Config/Config.json.in -@@ -602,6 +602,62 @@ +@@ -604,6 +604,62 @@ "\tfull: Validate code before every run (slow)" ] }, @@ -84,14 +84,14 @@ index 602b2a50d..5f59684e4 100644 "TSOEnabled": { "Type": "bool", "Default": "true", -@@ -689,6 +745,16 @@ +@@ -691,6 +747,16 @@ "Should only be used for applications that have issues with this set." ] }, + "EnableCPUIDFaulting": { + "Type": "bool", + "Default": "false", -+ "AffectsCodeGen": "true", ++ "AffectsCodeGen": "false", + "Desc": [ + "Honour ARCH_SET_CPUID. When a guest thread calls arch_prctl(ARCH_SET_CPUID, 0), CPUID from that", + "thread raises a #GP (SIGSEGV, si_code SI_KERNEL) like Linux with a CPUID-faulting CPU, instead of", @@ -102,10 +102,10 @@ index 602b2a50d..5f59684e4 100644 "Type": "uint32", "Default": "0", diff --git a/FEXCore/Source/Interface/Context/Context.h b/FEXCore/Source/Interface/Context/Context.h -index 9b91055bd..aa39b26d2 100644 +index cce4d5113..24118405d 100644 --- a/FEXCore/Source/Interface/Context/Context.h +++ b/FEXCore/Source/Interface/Context/Context.h -@@ -223,8 +223,12 @@ public: +@@ -224,8 +224,12 @@ public: void OnCodeBufferAllocated(const std::shared_ptr&) override; void ClearCodeCache(FEXCore::Core::InternalThreadState* Thread, bool NewCodeBuffer = true) override; @@ -120,14 +120,6 @@ index 9b91055bd..aa39b26d2 100644 FEXCore::Utils::WritePriorityMutex::Mutex& GetCodeInvalidationMutex() override { return CodeInvalidationMutex; } -@@ -354,6 +358,7 @@ public: - FEX_CONFIG_OPT(SingleStepConfig, SINGLESTEP); - FEX_CONFIG_OPT(GdbServer, GDBSERVER); - FEX_CONFIG_OPT(Is64BitMode, IS64BIT_MODE); -+ FEX_CONFIG_OPT(EnableCPUIDFaulting, ENABLECPUIDFAULTING); - FEX_CONFIG_OPT(TSOEnabled, TSOENABLED); - FEX_CONFIG_OPT(VectorTSOEnabled, VECTORTSOENABLED); - FEX_CONFIG_OPT(MemcpySetTSOEnabled, MEMCPYSETTSOENABLED); diff --git a/FEXCore/Source/Interface/Core/Core.cpp b/FEXCore/Source/Interface/Core/Core.cpp index 9f04358c5..02d9a280a 100644 --- a/FEXCore/Source/Interface/Core/Core.cpp @@ -336,20 +328,20 @@ index 3c78b22da..d903216c1 100644 LiveGuestHash = XXH3_128bits_digest(&HashState); LastFootprintHashed = CurrentFootprint; diff --git a/FEXCore/Source/Interface/Core/DiskCache.h b/FEXCore/Source/Interface/Core/DiskCache.h -index 4899cd250..85b4ec02a 100644 +index 0bd3c21e4..0f1490cba 100644 --- a/FEXCore/Source/Interface/Core/DiskCache.h +++ b/FEXCore/Source/Interface/Core/DiskCache.h @@ -249,7 +249,7 @@ namespace DiskCache { // The current version of the diskcache. // This must be changed any time codegen changes occur! // Be aware of the impact of changing this frequently! -- static constexpr uint16_t FormatVersion = 43; -+ static constexpr uint16_t FormatVersion = 0x8000 | (1 << 8) | 43; +- static constexpr uint16_t FormatVersion = 52; ++ static constexpr uint16_t FormatVersion = 0x8000 | (1 << 8) | 52; static constexpr uint32_t LOOKUP_KEY_MAX_BUCKET_DEPTH = 500; diff --git a/FEXCore/Source/Interface/Core/Frontend.cpp b/FEXCore/Source/Interface/Core/Frontend.cpp -index 8d1d8db47..47b465b2a 100644 +index 94e4ac522..18cda8889 100644 --- a/FEXCore/Source/Interface/Core/Frontend.cpp +++ b/FEXCore/Source/Interface/Core/Frontend.cpp @@ -19,6 +19,7 @@ $end_info$ @@ -431,7 +423,7 @@ index 8d1d8db47..47b465b2a 100644 } // Skip the number of decoded bytes regardless to get instruction size. -@@ -870,7 +894,7 @@ Decoder::DecodedBlockStatus Decoder::DecodeInstructionImpl(uint64_t PC) { +@@ -881,7 +905,7 @@ Decoder::DecodedBlockStatus Decoder::DecodeInstructionImpl(uint64_t PC) { for (;;) { if (InstructionSize >= MAX_INST_SIZE) { @@ -440,7 +432,7 @@ index 8d1d8db47..47b465b2a 100644 } uint8_t Op = ReadByte(); switch (Op) { -@@ -1097,11 +1121,12 @@ void Decoder::DecodeREXIfValid(int8_t ExpectedOffset) { +@@ -1108,11 +1132,12 @@ void Decoder::DecodeREXIfValid(int8_t ExpectedOffset) { Decoder::DecodedBlockStatus Decoder::DecodeInstruction(uint64_t PC) { // Will be set if DecodeInstructionImpl tries to read non-executable memory HitNonExecutableRange = false; @@ -454,7 +446,7 @@ index 8d1d8db47..47b465b2a 100644 // Put an invalid instruction in the stream so the core can raise SIGILL if hit // Error while decoding instruction. We don't know the table or instruction size DecodeInst->TableInfo = nullptr; -@@ -1123,6 +1148,10 @@ Decoder::DecodedBlockStatus Decoder::DecodeInstruction(uint64_t PC) { +@@ -1134,6 +1159,10 @@ Decoder::DecodedBlockStatus Decoder::DecodeInstruction(uint64_t PC) { return DecodedBlockStatus::BAD_RELOCATION; } @@ -465,7 +457,7 @@ index 8d1d8db47..47b465b2a 100644 return ErrorDuringDecoding; } else if (!DecodeInst->TableInfo || (DecodeInst->TableInfo->Type == TYPE_INST && !DecodeInst->TableInfo->OpcodeDispatcher.OpDispatch)) { // If there wasn't an error during decoding but we have no dispatcher for the instruction then claim invalid instruction. -@@ -1682,6 +1711,7 @@ void Decoder::DecodeLoop(const uint8_t* _InstStream, uint64_t GuestSizePause) { +@@ -1693,6 +1722,7 @@ void Decoder::DecodeLoop(const uint8_t* _InstStream, uint64_t GuestSizePause) { BlockIt->BlockStatus == DecodedBlockStatus::BREAKPOINT_3 ? "Breakpoint" : BlockIt->BlockStatus == DecodedBlockStatus::INVALID_INST ? "Invalid" : BlockIt->BlockStatus == DecodedBlockStatus::NOEXEC_INST ? "NoExec" : @@ -503,7 +495,7 @@ index ade14bc44..6d279b22c 100644 uint32_t HitBreakpoint {~0U}; diff --git a/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp b/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp -index 09437a1ea..06890a8b5 100644 +index c5e656d2c..7b9c15b61 100644 --- a/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp +++ b/FEXCore/Source/Interface/Core/JIT/BranchOps.cpp @@ -195,6 +195,21 @@ DEF_OP(ExitFunction) { @@ -529,7 +521,7 @@ index 09437a1ea..06890a8b5 100644 // First try to pop from the call-ret stack, otherwise follow the normal path (but ending in a ret) ldp(TMP1, TMP2, REG_CALLRET_SP, 0x10); diff --git a/FEXCore/Source/Interface/Core/JIT/JIT.cpp b/FEXCore/Source/Interface/Core/JIT/JIT.cpp -index 435afed5e..459b0a6ce 100644 +index fa9c8c880..777b4b51d 100644 --- a/FEXCore/Source/Interface/Core/JIT/JIT.cpp +++ b/FEXCore/Source/Interface/Core/JIT/JIT.cpp @@ -862,6 +862,7 @@ CPUBackend::CompiledCode Arm64JITCore::EmitJITCode(uint64_t Entry, uint64_t Size @@ -541,10 +533,10 @@ index 435afed5e..459b0a6ce 100644 // Prepare restart via long jump in case branch encoding fails. diff --git a/FEXCore/Source/Interface/Core/JIT/JITClass.h b/FEXCore/Source/Interface/Core/JIT/JITClass.h -index 980a83237..42d86b43f 100644 +index 55286855f..684ac9d9d 100644 --- a/FEXCore/Source/Interface/Core/JIT/JITClass.h +++ b/FEXCore/Source/Interface/Core/JIT/JITClass.h -@@ -82,6 +82,7 @@ private: +@@ -86,6 +86,7 @@ private: // In the rare case when those assumptions are broken, FEX needs to safely restart the JIT. RestartOptions RestartControl {}; bool RequiresFarARM64Jumps {}; @@ -553,11 +545,11 @@ index 980a83237..42d86b43f 100644 uint32_t SSANodeMultiplier {24}; diff --git a/FEXCore/Source/Interface/Core/JIT/MiscOps.cpp b/FEXCore/Source/Interface/Core/JIT/MiscOps.cpp -index 137c99c60..8ea457ec1 100644 +index d15ef9aee..bc1fb9c19 100644 --- a/FEXCore/Source/Interface/Core/JIT/MiscOps.cpp +++ b/FEXCore/Source/Interface/Core/JIT/MiscOps.cpp -@@ -107,6 +107,42 @@ DEF_OP(Break) { - } +@@ -86,6 +86,34 @@ DEF_OP(Break) { + br(TMP1); } +DEF_OP(BreakErrorCode) { @@ -584,15 +576,7 @@ index 137c99c60..8ea457ec1 100644 + str(TMP1, STATE, offsetof(FEXCore::Core::CpuStateFrame, SynchronousFaultData)); + str(ARMEmitter::XReg::zr, STATE, offsetof(FEXCore::Core::CpuStateFrame, SynchronousFaultData) + 8); + -+ if (CTX->HostFeatures.ProcessFeatures.SupportsFaultFreeSynchronousFaults) { -+ ldr(TMP1, STATE, offsetof(FEXCore::Core::CpuStateFrame, Pointers.GuestSignal_SynchronousFault)); -+ } else { -+ switch (Op->Reason.Signal) { -+ case Core::FAULT_SIGILL: ldr(TMP1, STATE, offsetof(FEXCore::Core::CpuStateFrame, Pointers.GuestSignal_SIGILL)); break; -+ case Core::FAULT_SIGSEGV: ldr(TMP1, STATE, offsetof(FEXCore::Core::CpuStateFrame, Pointers.GuestSignal_SIGSEGV)); break; -+ default: ldr(TMP1, STATE, offsetof(FEXCore::Core::CpuStateFrame, Pointers.GuestSignal_SIGTRAP)); break; -+ } -+ } ++ ldr(TMP1, STATE, offsetof(FEXCore::Core::CpuStateFrame, Pointers.GuestSignal_SynchronousFault)); + br(TMP1); +} + @@ -647,7 +631,7 @@ index 391d48560..228d03969 100644 // Returns true if new pages are marked as containing code bool AddBlockExecutableRange(FEXCore::Core::InternalThreadState* Thread, auto& Addresses, uint64_t Start, uint64_t Length) { diff --git a/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp b/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp -index 1a0366398..40dd2b2e0 100644 +index 356fc3bb1..27491cea4 100644 --- a/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp +++ b/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp @@ -138,6 +138,31 @@ void OpDispatchBuilder::IRETOp(OpcodeArgs) { @@ -736,7 +720,7 @@ index 1a0366398..40dd2b2e0 100644 // The loads here also load the selector, NOT the base if (ToSeg) { -@@ -1281,8 +1335,7 @@ void OpDispatchBuilder::MOVSegOp(OpcodeArgs, bool ToSeg) { +@@ -1283,8 +1337,7 @@ void OpDispatchBuilder::MOVSegOp(OpcodeArgs, bool ToSeg) { _StoreContextGPR(OpSize::i16Bit, Src, offsetof(FEXCore::Core::CPUState, gs_idx)); UpdatePrefixFromSegment(Src, FEXCore::X86Tables::DecodeFlags::FLAG_GS_PREFIX); } else { @@ -746,7 +730,7 @@ index 1a0366398..40dd2b2e0 100644 } break; case FEXCore::X86State::REG_RSP: // FS -@@ -1291,8 +1344,7 @@ void OpDispatchBuilder::MOVSegOp(OpcodeArgs, bool ToSeg) { +@@ -1293,8 +1346,7 @@ void OpDispatchBuilder::MOVSegOp(OpcodeArgs, bool ToSeg) { _StoreContextGPR(OpSize::i16Bit, Src, offsetof(FEXCore::Core::CPUState, fs_idx)); UpdatePrefixFromSegment(Src, FEXCore::X86Tables::DecodeFlags::FLAG_FS_PREFIX); } else { @@ -756,7 +740,7 @@ index 1a0366398..40dd2b2e0 100644 } break; default: UnimplementedOp(Op); return; -@@ -1319,19 +1371,11 @@ void OpDispatchBuilder::MOVSegOp(OpcodeArgs, bool ToSeg) { +@@ -1321,19 +1373,11 @@ void OpDispatchBuilder::MOVSegOp(OpcodeArgs, bool ToSeg) { break; case FEXCore::X86State::REG_RBP: // GS case FEXCore::X86State::REG_R13: // GS @@ -778,45 +762,11 @@ index 1a0366398..40dd2b2e0 100644 break; default: UnimplementedOp(Op); return; } -@@ -1373,6 +1417,33 @@ void OpDispatchBuilder::CPUIDOp(OpcodeArgs) { - Ref Src = LoadGPRRegister(X86State::REG_RAX); - Ref Leaf = LoadGPRRegister(X86State::REG_RCX); - -+ if (CTX->Config.EnableCPUIDFaulting()) { -+ auto FaultBlock = CreateNewCodeBlockAfter(GetCurrentBlock()); -+ auto ContinueBlock = CreateNewCodeBlockAfter(FaultBlock); -+ -+ auto Fault = _LoadContextGPR(OpSize::i32Bit, offsetof(FEXCore::Core::CpuStateFrame, CPUIDFault)); -+ auto CondJump_ = CondJump(Fault, CondClass::EQ); -+ SetTrueJumpTarget(CondJump_, ContinueBlock); -+ SetFalseJumpTarget(CondJump_, FaultBlock); -+ -+ SetCurrentCodeBlock(FaultBlock); -+ StartNewBlock(); -+ -+ auto NewRIP = GetRelocatedPC(Op, -Op->InstSize); -+ _StoreContextGPR(GetGPROpSize(), NewRIP, offsetof(FEXCore::Core::CPUState, rip)); -+ -+ IR::BreakDefinition Reason {}; -+ Reason.ErrorRegister = 0; -+ Reason.Signal = Core::FAULT_SIGSEGV; -+ Reason.TrapNumber = X86State::X86_TRAPNO_GP; -+ Reason.si_code = 0x80; -+ BlockSetRIP = true; -+ Break(Reason); -+ -+ SetCurrentCodeBlock(ContinueBlock); -+ StartNewBlock(); -+ } -+ - Ref RAX = _AllocateGPR(false); - Ref RBX = _AllocateGPR(false); - Ref RCX = _AllocateGPR(false); diff --git a/FEXCore/Source/Interface/Core/OpcodeDispatcher.h b/FEXCore/Source/Interface/Core/OpcodeDispatcher.h -index 4477c7266..f6f65209a 100644 +index d3e523d9b..601db6009 100644 --- a/FEXCore/Source/Interface/Core/OpcodeDispatcher.h +++ b/FEXCore/Source/Interface/Core/OpcodeDispatcher.h -@@ -214,6 +214,10 @@ public: +@@ -216,6 +216,10 @@ public: } return _Break(Reason, RelocatedPC); } @@ -827,7 +777,7 @@ index 4477c7266..f6f65209a 100644 IRPair Thunk(Ref ArgPtr, SHA256Sum ThunkNameHash) { FlushRegisterCache(); return _Thunk(ArgPtr, ThunkNameHash); -@@ -415,6 +419,7 @@ public: +@@ -417,6 +421,7 @@ public: void XCHGRAXOp(OpcodeArgs); void SAHFOp(OpcodeArgs); void LAHFOp(OpcodeArgs); @@ -835,7 +785,7 @@ index 4477c7266..f6f65209a 100644 void MOVSegOp(OpcodeArgs, bool ToSeg); void FLAGControlOp(OpcodeArgs); void MOVOffsetOp(OpcodeArgs); -@@ -1906,8 +1911,8 @@ private: +@@ -1974,8 +1979,8 @@ private: // An exception should still be raised after an instruction that unsets TF, leave the unblocked bit set but unset // the TF bit to cause such behaviour. The handling code at the start of the next block will then unset the // unblocked bit before raising the exception. @@ -847,7 +797,7 @@ index 4477c7266..f6f65209a 100644 } else { _StoreContextGPR(OpSize::i8Bit, Value, ARRAY_OFFSETOF(FEXCore::Core::CPUState, flags, BitOffset)); diff --git a/FEXCore/Source/Interface/IR/IR.json b/FEXCore/Source/Interface/IR/IR.json -index 16c29e759..34122804b 100644 +index 4b79cf35c..0c01f580d 100644 --- a/FEXCore/Source/Interface/IR/IR.json +++ b/FEXCore/Source/Interface/IR/IR.json @@ -324,6 +324,12 @@ @@ -864,12 +814,12 @@ index 16c29e759..34122804b 100644 "HasSideEffects": true }, diff --git a/FEXCore/Source/Interface/IR/IREmitter.cpp b/FEXCore/Source/Interface/IR/IREmitter.cpp -index f305ad3e8..40b02b33d 100644 +index 6c8ed5d11..d8fd1431e 100644 --- a/FEXCore/Source/Interface/IR/IREmitter.cpp +++ b/FEXCore/Source/Interface/IR/IREmitter.cpp -@@ -22,7 +22,8 @@ static bool IsFragmentExit(FEXCore::IR::IROps Op) { - case OP_THREADREMOVECODEENTRY: +@@ -23,7 +23,8 @@ static bool IsFragmentExit(FEXCore::IR::IROps Op) { case OP_SYSCALL: + case OP_CPUID: case OP_EXITFUNCTION: - case OP_BREAK: return true; + case OP_BREAK: @@ -930,10 +880,10 @@ index 000000000..aaa7a80cf +#endif +} diff --git a/FEXCore/include/FEXCore/Core/Context.h b/FEXCore/include/FEXCore/Core/Context.h -index 8aa448e2e..865d292fd 100644 +index 7e1d30770..854c5ce1c 100644 --- a/FEXCore/include/FEXCore/Core/Context.h +++ b/FEXCore/include/FEXCore/Core/Context.h -@@ -140,9 +140,11 @@ public: +@@ -141,9 +141,11 @@ public: virtual void FlushAndCloseCodeMap() = 0; FEX_DEFAULT_VISIBILITY virtual void ClearCodeCache(FEXCore::Core::InternalThreadState* Thread, bool NewCodeBuffer = true) = 0; @@ -948,10 +898,10 @@ index 8aa448e2e..865d292fd 100644 FEX_DEFAULT_VISIBILITY virtual void diff --git a/FEXCore/include/FEXCore/Core/CoreState.h b/FEXCore/include/FEXCore/Core/CoreState.h -index c1cb5f03c..deb3b7a69 100644 +index 7c02605f5..98ba8e150 100644 --- a/FEXCore/include/FEXCore/Core/CoreState.h +++ b/FEXCore/include/FEXCore/Core/CoreState.h -@@ -274,6 +274,11 @@ struct alignas(64) CPUState { +@@ -282,6 +282,11 @@ struct alignas(64) CPUState { // TODO: This should be moved to the frontend. constexpr static uint32_t DEFAULT_USER_CS = 6; @@ -963,15 +913,6 @@ index c1cb5f03c..deb3b7a69 100644 // Follows encoding of the TI bit in segment selector encoding. constexpr static uint32_t SEGMENT_ARRAY_INDEX_GDT = 0; -@@ -463,6 +468,8 @@ struct CpuStateFrame { - - uint32_t SignalHandlerRefCounter {}; - -+ uint32_t CPUIDFault {}; -+ - InternalThreadState* Thread; - - #ifdef _WIN32 diff --git a/FEXCore/include/FEXCore/HLE/SyscallHandler.h b/FEXCore/include/FEXCore/HLE/SyscallHandler.h index 0ba0218e3..89e36d52e 100644 --- a/FEXCore/include/FEXCore/HLE/SyscallHandler.h @@ -1022,10 +963,10 @@ index c5844fe10..d646c6a2f 100644 // Ensure 16-byte alignment to take advantage of ARM single-copy atomicity. diff --git a/Source/Tools/FEXInterpreter/FEXInterpreter.cpp b/Source/Tools/FEXInterpreter/FEXInterpreter.cpp -index 1bc6ca92a..79f47aa2d 100644 +index e7e88f8f2..26b8186c8 100644 --- a/Source/Tools/FEXInterpreter/FEXInterpreter.cpp +++ b/Source/Tools/FEXInterpreter/FEXInterpreter.cpp -@@ -595,8 +595,7 @@ int main(int argc, char** argv, char** const envp) { +@@ -602,8 +602,7 @@ int main(int argc, char** argv, char** const envp) { // Create a thread without a RIP or stack pointer setup initially. auto ParentThread = SyscallHandler->TM.CreateThread(); SyscallHandler->TM.TrackThread(ParentThread); @@ -1086,7 +1027,7 @@ index 715a8f132..3f02104ea 100644 LinuxSyscalls/Seccomp/SeccompEmulator.cpp LinuxSyscalls/Seccomp/BPFEmitter.cpp diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp -index 83e90c27e..1b2396b01 100644 +index 2095d4dc5..eb12945e4 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp @@ -10,6 +10,7 @@ $end_info$ @@ -1106,7 +1047,7 @@ index 83e90c27e..1b2396b01 100644 #include #include #include -@@ -592,6 +595,10 @@ EmulatedFDManager::EmulatedFDManager(FEXCore::Context::Context* ctx) +@@ -593,6 +596,10 @@ EmulatedFDManager::EmulatedFDManager(FEXCore::Context::Context* ctx) FDReadCreators[procAuxv] = &EmulatedFDManager::ProcAuxv; FDReadCreators["/proc/self/auxv"] = &EmulatedFDManager::ProcAuxv; @@ -1117,7 +1058,7 @@ index 83e90c27e..1b2396b01 100644 if (ThreadsConfig > 1) { cpus_online = fextl::fmt::format("0-{}", ThreadsConfig - 1); } else { -@@ -601,6 +608,20 @@ EmulatedFDManager::EmulatedFDManager(FEXCore::Context::Context* ctx) +@@ -602,6 +609,20 @@ EmulatedFDManager::EmulatedFDManager(FEXCore::Context::Context* ctx) EmulatedFDManager::~EmulatedFDManager() {} @@ -1138,7 +1079,7 @@ index 83e90c27e..1b2396b01 100644 int32_t EmulatedFDManager::Open(const char* pathname, int flags, uint32_t mode) { auto Creator = FDReadCreators.end(); if (pathname) { -@@ -608,12 +629,148 @@ int32_t EmulatedFDManager::Open(const char* pathname, int flags, uint32_t mode) +@@ -609,12 +630,148 @@ int32_t EmulatedFDManager::Open(const char* pathname, int flags, uint32_t mode) } if (Creator == FDReadCreators.end()) { @@ -2795,10 +2736,10 @@ index 000000000..b6b433eca +void StartSamplingProfiler(FEX::HLE::SignalDelegator* Signals, uint32_t Hz, bool AllThreads, bool External = false); +} diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.cpp -index 7b0e9f91c..d2626fd8f 100644 +index a7dcd128d..830ae3721 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.cpp -@@ -120,6 +120,16 @@ $end_info$ +@@ -119,6 +119,16 @@ $end_info$ // TRACE_syscall // - ptrace unsupported @@ -2815,7 +2756,7 @@ index 7b0e9f91c..d2626fd8f 100644 namespace FEX::HLE { uint64_t SeccompEmulator::Handle(FEXCore::Core::CpuStateFrame* Frame, uint32_t Op, uint32_t flags, void* arg) { // If seccomp isn't enabled then say so. -@@ -315,6 +325,60 @@ void SeccompEmulator::DeserializeFilters(FEXCore::Core::CpuStateFrame* Frame, in +@@ -314,6 +324,60 @@ void SeccompEmulator::DeserializeFilters(FEXCore::Core::CpuStateFrame* Frame, in close(FD); } @@ -2876,16 +2817,16 @@ index 7b0e9f91c..d2626fd8f 100644 SeccompEmulator::ExecuteFilterResult SeccompEmulator::ExecuteFilter(FEXCore::Core::CpuStateFrame* Frame, uint64_t JITPC, FEX::HLE::SyscallArguments* Args) { if (!HasFilter(Frame)) { -@@ -325,6 +389,8 @@ SeccompEmulator::ExecuteFilter(FEXCore::Core::CpuStateFrame* Frame, uint64_t JIT - auto Thread = FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame); - const uint64_t RIP = Thread->Thread->CTX->RestoreRIPFromHostPC(Frame->Thread, JITPC); +@@ -330,6 +394,8 @@ SeccompEmulator::ExecuteFilter(FEXCore::Core::CpuStateFrame* Frame, uint64_t JIT + ::prctl(PR_SET_NO_NEW_PRIVS, 1L, 0, 0, 0); + } + const uint64_t PostSyscallRIP = RIP + 2; + const auto Arch = Is64BitMode() ? AUDIT_ARCH_X86_64 : AUDIT_ARCH_I386; bool ShouldLog {}; uint32_t SeccompResult {}; -@@ -429,18 +495,9 @@ SeccompEmulator::ExecuteFilter(FEXCore::Core::CpuStateFrame* Frame, uint64_t JIT +@@ -425,18 +491,9 @@ SeccompEmulator::ExecuteFilter(FEXCore::Core::CpuStateFrame* Frame, uint64_t JIT break; } case SECCOMP_RET_TRAP: { @@ -2906,7 +2847,7 @@ index 7b0e9f91c..d2626fd8f 100644 } case SECCOMP_RET_ERRNO: { // errno return is clamped. -@@ -620,7 +677,8 @@ uint64_t SeccompEmulator::SetModeFilter(FEXCore::Core::CpuStateFrame* Frame, uin +@@ -671,7 +728,8 @@ uint64_t SeccompEmulator::SetModeFilter(FEXCore::Core::CpuStateFrame* Frame, uin return -EINVAL; } @@ -2916,7 +2857,7 @@ index 7b0e9f91c..d2626fd8f 100644 return -EFAULT; } -@@ -629,12 +687,22 @@ uint64_t SeccompEmulator::SetModeFilter(FEXCore::Core::CpuStateFrame* Frame, uin +@@ -680,12 +738,22 @@ uint64_t SeccompEmulator::SetModeFilter(FEXCore::Core::CpuStateFrame* Frame, uin return -EACCES; } @@ -2941,7 +2882,7 @@ index 7b0e9f91c..d2626fd8f 100644 auto lk = FEXCore::MaskSignalsAndLockMutex(FilterMutex); diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.h -index b10f664ed..2d58f79c0 100644 +index a4c7b70e0..31b489216 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.h +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.h @@ -61,6 +61,8 @@ public: @@ -2953,19 +2894,18 @@ index b10f664ed..2d58f79c0 100644 bool HasFilter(FEXCore::Core::CpuStateFrame* Frame) const { auto Thread = FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame); return !Thread->Filters.empty(); -@@ -98,6 +100,10 @@ private: - - static void DumpProgram(const sock_fprog* prog); - +@@ -101,6 +103,9 @@ private: + const sock_fprog* GetStrictModeFilter() const; + void KillProcess(ThreadStateObject* Thread); + void KillThread(FEXCore::Core::CpuStateFrame* Thread); + void QueueTrapSignal(FEX::HLE::ThreadStateObject* Thread, int Code, uint32_t Errno, uint64_t PostSyscallRIP, uint64_t SyscallNumber, + uint32_t Arch); + void ForceExitSignal(FEX::HLE::ThreadStateObject* Thread, int Signal); -+ + // Multiple filter instruction count penalty. // When multiple filters are installed there is a penalty per filter counted towards the maximum number of instructions. - constexpr static size_t BPF_MULTIFILTERPENALTY = 4; diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp -index 77f124a94..efe49dbf1 100644 +index e8e04b056..c6ef3fe04 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp @@ -8,6 +8,8 @@ $end_info$ @@ -2977,7 +2917,7 @@ index 77f124a94..efe49dbf1 100644 #include #include -@@ -200,6 +202,10 @@ ArchHelpers::Context::ContextBackup* SignalDelegator::StoreThreadState(FEXCore:: +@@ -219,6 +221,10 @@ ArchHelpers::Context::ContextBackup* SignalDelegator::StoreThreadState(FEXCore:: Context->UContextLocation = 0; Context->SigInfoLocation = 0; Context->InSyscallInfo = 0; @@ -2988,7 +2928,7 @@ index 77f124a94..efe49dbf1 100644 // Store fault to top status and then reset it Context->FaultToTopAndGeneratedException = Thread->CurrentFrame->SynchronousFaultData.FaultToTopAndGeneratedException; -@@ -208,6 +214,8 @@ ArchHelpers::Context::ContextBackup* SignalDelegator::StoreThreadState(FEXCore:: +@@ -227,6 +233,8 @@ ArchHelpers::Context::ContextBackup* SignalDelegator::StoreThreadState(FEXCore:: return Context; } @@ -2997,7 +2937,7 @@ index 77f124a94..efe49dbf1 100644 void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thread, void* ucontext, RestoreType Type) { uint64_t OldSP {}; if (Type == RestoreType::TYPE_PAUSE) [[unlikely]] { -@@ -296,8 +304,38 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr +@@ -315,8 +323,38 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr uintptr_t NewSP = OldSP; auto Context = reinterpret_cast(NewSP); @@ -3036,7 +2976,7 @@ index 77f124a94..efe49dbf1 100644 // Reset the guest state memcpy(&Thread->CurrentFrame->State, &Context->GuestState, sizeof(FEXCore::Core::CPUState)); -@@ -324,7 +362,36 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr +@@ -343,7 +381,36 @@ void SignalDelegator::RestoreThreadState(FEXCore::Core::InternalThreadState* Thr bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadState* Thread, int Signal, void* info, void* ucontext, GuestSigAction* GuestAction, stack_t* GuestStack) { @@ -3073,7 +3013,7 @@ index 77f124a94..efe49dbf1 100644 auto Frame = Thread->CurrentFrame; auto& SignalInfo = FEX::HLE::ThreadManager::GetStateObjectFromFEXCoreThread(Thread)->SignalInfo; -@@ -363,8 +430,13 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS +@@ -382,8 +449,13 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS ContextBackup->InSyscallInfo = Thread->CurrentFrame->InSyscallInfo; Thread->CurrentFrame->InSyscallInfo = 0; } else { @@ -3089,7 +3029,7 @@ index 77f124a94..efe49dbf1 100644 if (!IsAddressInDispatcher(OldPC)) { // This is likely to cause issues but in some cases it isn't fatal -@@ -443,6 +515,14 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS +@@ -462,6 +534,14 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS if (Is64BitMode) { NewGuestSP = SetupFrame_x64(Thread, ContextBackup, Frame, Signal, HostSigInfo, ucontext, GuestAction, GuestStack, NewGuestSP, eflags); @@ -3104,7 +3044,7 @@ index 77f124a94..efe49dbf1 100644 } else { const bool SigInfoFrame = (GuestAction->sa_flags & SA_SIGINFO) == SA_SIGINFO; if (SigInfoFrame) { -@@ -464,8 +544,8 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS +@@ -483,8 +563,8 @@ bool SignalDelegator::HandleDispatcherGuestSignal(FEXCore::Core::InternalThreadS // This way signal handlers always go back to their original operating mode. // Doesn't matter for 32-bit processes as they can only be 32-bit, but does // matter for 64-bit processes as they could have potentially installed a 32-bit code segment. @@ -3115,7 +3055,7 @@ index 77f124a94..efe49dbf1 100644 Frame->State.cs_cached = Frame->State.CalculateGDTBase(*Frame->State.GetSegmentFromIndex(Frame->State, Frame->State.cs_idx)); Frame->State.ss_cached = Frame->State.CalculateGDTBase(*Frame->State.GetSegmentFromIndex(Frame->State, Frame->State.ss_idx)); -@@ -671,7 +751,7 @@ bool SignalDelegator::HandleFrontendSIGSEGV(FEXCore::Core::InternalThreadState* +@@ -690,7 +770,7 @@ bool SignalDelegator::HandleFrontendSIGSEGV(FEXCore::Core::InternalThreadState* auto SigInfo = *static_cast(Info); if (FaultSafeUserMemAccess::TryHandleSafeFault(Signal, SigInfo, UContext)) { @@ -3124,7 +3064,7 @@ index 77f124a94..efe49dbf1 100644 } #ifdef ARCHITECTURE_arm64 -@@ -695,10 +775,21 @@ bool SignalDelegator::HandleFrontendSIGSEGV(FEXCore::Core::InternalThreadState* +@@ -714,10 +794,21 @@ bool SignalDelegator::HandleFrontendSIGSEGV(FEXCore::Core::InternalThreadState* void SignalDelegator::HandleGuestSignal(FEX::HLE::ThreadStateObject* ThreadObject, int Signal, void* Info, void* UContext) { auto Thread = ThreadObject->Thread; @@ -3146,7 +3086,7 @@ index 77f124a94..efe49dbf1 100644 if (Signal == SIGSEGV && SigInfo.si_code == SEGV_ACCERR && SigInfo.si_addr == reinterpret_cast(&Thread->InterruptFaultPage)) { if (!MustDeferSignal) { // We just reached the end of the outermost signal-deferring section and faulted to check for pending signals. -@@ -762,6 +853,8 @@ void SignalDelegator::HandleGuestSignal(FEX::HLE::ThreadStateObject* ThreadObjec +@@ -781,6 +872,8 @@ void SignalDelegator::HandleGuestSignal(FEX::HLE::ThreadStateObject* ThreadObjec // This allows us to maintain the expected signal mask through the guest signal handling and then all the way back again sigmask_val[0] = GetNewSigMask(Signal); @@ -3155,7 +3095,7 @@ index 77f124a94..efe49dbf1 100644 // Now update the faulting page permissions so it will fault on write. mprotect(reinterpret_cast(&Thread->InterruptFaultPage), sizeof(Thread->InterruptFaultPage), PROT_NONE); -@@ -774,6 +867,7 @@ void SignalDelegator::HandleGuestSignal(FEX::HLE::ThreadStateObject* ThreadObjec +@@ -793,6 +886,7 @@ void SignalDelegator::HandleGuestSignal(FEX::HLE::ThreadStateObject* ThreadObjec // This signal is masked, must defer until the guest updates the signal mask. // Add it to the pending signal list ThreadObject->SignalInfo.PendingSignals |= 1ULL << (Signal - 1); @@ -3163,7 +3103,7 @@ index 77f124a94..efe49dbf1 100644 return; } -@@ -795,6 +889,21 @@ void SignalDelegator::HandleGuestSignal(FEX::HLE::ThreadStateObject* ThreadObjec +@@ -814,6 +908,21 @@ void SignalDelegator::HandleGuestSignal(FEX::HLE::ThreadStateObject* ThreadObjec if (Handler.GuestHandler && Handler.GuestHandler(Thread, Signal, &SigInfo, UContext, &Handler.GuestAction, &ThreadObject->SignalInfo.GuestAltStack)) { uint64_t NewMask = GetNewSigMask(Signal); @@ -3185,7 +3125,7 @@ index 77f124a94..efe49dbf1 100644 // Update our host signal mask so we don't hit race conditions with signals // This allows us to maintain the expected signal mask through the guest signal handling and then all the way back again -@@ -942,6 +1051,30 @@ void SignalDelegator::UninstallHostHandler(int Signal) { +@@ -961,6 +1070,30 @@ void SignalDelegator::UninstallHostHandler(int Signal) { ::syscall(SYS_rt_sigaction, Signal, &SignalHandler.OldAction, nullptr, 8); } @@ -3216,7 +3156,7 @@ index 77f124a94..efe49dbf1 100644 void SignalDelegator::QueueSignal(pid_t tgid, pid_t tid, int Signal, siginfo_t* info, bool IgnoreMask) { bool WasIgnored {}; bool WasMasked {}; -@@ -976,11 +1109,34 @@ void SignalDelegator::QueueSignal(pid_t tgid, pid_t tid, int Signal, siginfo_t* +@@ -995,11 +1128,34 @@ void SignalDelegator::QueueSignal(pid_t tgid, pid_t tid, int Signal, siginfo_t* } } @@ -3251,7 +3191,7 @@ index 77f124a94..efe49dbf1 100644 // Signal zero isn't real HostHandlers[0].Installed = true; -@@ -1143,23 +1299,36 @@ void SignalDelegator::RegisterTLSState(FEX::HLE::ThreadStateObject* Thread) { +@@ -1162,23 +1318,36 @@ void SignalDelegator::RegisterTLSState(FEX::HLE::ThreadStateObject* Thread) { } } @@ -3295,7 +3235,7 @@ index 77f124a94..efe49dbf1 100644 void SignalDelegator::FrontendRegisterHostSignalHandler(int Signal, bool Required) { // Linux signal handlers are per-process rather than per thread // Multiple threads could be calling in to this -@@ -1302,6 +1471,7 @@ static void CheckForPendingSignals(const FEX::HLE::ThreadStateObject* Thread) { +@@ -1321,6 +1490,7 @@ static void CheckForPendingSignals(const FEX::HLE::ThreadStateObject* Thread) { if (PendingSignals != 0) { for (int i = 0; i < 64; ++i) { if (PendingSignals & (1ULL << i)) { @@ -3303,7 +3243,7 @@ index 77f124a94..efe49dbf1 100644 FHU::Syscalls::tgkill(Thread->ThreadInfo.PID, Thread->ThreadInfo.TID, i + 1); // We might not even return here which is spooky } -@@ -1342,6 +1512,9 @@ uint64_t SignalDelegator::GuestSigProcMask(FEX::HLE::ThreadStateObject* Thread, +@@ -1361,6 +1531,9 @@ uint64_t SignalDelegator::GuestSigProcMask(FEX::HLE::ThreadStateObject* Thread, } ::syscall(SYS_rt_sigprocmask, SIG_SETMASK, &HostMask, nullptr, 8); @@ -3314,10 +3254,10 @@ index 77f124a94..efe49dbf1 100644 if (oldset) { diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h -index c52832d73..e558ced19 100644 +index 43898e700..0d5b5597d 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h -@@ -62,6 +62,8 @@ public: +@@ -65,6 +65,8 @@ public: void RegisterTLSState(FEX::HLE::ThreadStateObject* Thread); void UninstallTLSState(FEX::HLE::ThreadStateObject* Thread); @@ -3326,7 +3266,7 @@ index c52832d73..e558ced19 100644 /** * @brief Registers a signal handler for the host to handle a signal -@@ -106,6 +108,10 @@ public: +@@ -109,6 +111,10 @@ public: void UninstallHostHandler(int Signal); void QueueSignal(pid_t tgid, pid_t tid, int Signal, siginfo_t* info, bool IgnoreMask); @@ -3337,7 +3277,7 @@ index c52832d73..e558ced19 100644 void SetVDSOSymbols() { // Get symbols from VDSO. VDSOPointers = FEX::VDSO::GetVDSOSymbols(); -@@ -184,6 +190,8 @@ private: +@@ -187,6 +193,8 @@ private: FEXCore::Context::Context* CTX; FEX_CONFIG_OPT(Is64BitMode, IS64BIT_MODE); @@ -3347,7 +3287,7 @@ index c52832d73..e558ced19 100644 FEX_CONFIG_OPT(HalfBarrierTSOEnabled, HALFBARRIERTSOENABLED); diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp -index 65f847a5e..aa72957fa 100644 +index 38dc524f1..87199e10c 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp @@ -7,6 +7,7 @@ $end_info$ @@ -3554,7 +3494,7 @@ index 65f847a5e..aa72957fa 100644 guest_uctx->uc_mcontext.gregs[FEXCore::x86_64::FEX_REG_EFL] = eflags; // This stores the CS/GS/FS selectors. It ALSO stores the SS selector in the top 16 bits...For some reason. // Despite the naming, the endianness is swapped from what you'd expect. -@@ -572,6 +646,9 @@ uint64_t SignalDelegator::SetupFrame_x64(FEXCore::Core::InternalThreadState* Thr +@@ -568,6 +642,9 @@ uint64_t SignalDelegator::SetupFrame_x64(FEXCore::Core::InternalThreadState* Thr guest_uctx->uc_stack.ss_sp = GuestStack->ss_sp; guest_uctx->uc_stack.ss_size = GuestStack->ss_size; @@ -3564,7 +3504,7 @@ index 65f847a5e..aa72957fa 100644 // Apparently RAX is always set to zero in case of badly misbehaving C applications and variadics. Frame->State.gregs[FEXCore::X86State::REG_RAX] = 0; Frame->State.gregs[FEXCore::X86State::REG_RDI] = Signal; -@@ -647,7 +724,7 @@ uint64_t SignalDelegator::SetupFrame_ia32(FEXCore::Core::InternalThreadState* Th +@@ -643,7 +720,7 @@ uint64_t SignalDelegator::SetupFrame_ia32(FEXCore::Core::InternalThreadState* Th guest_uctx->sc.err = ConvertSignalToError(ucontext, Signal, HostSigInfo); } @@ -3573,7 +3513,7 @@ index 65f847a5e..aa72957fa 100644 guest_uctx->sc.flags = eflags; guest_uctx->sc.sp_at_signal = 0; -@@ -783,7 +860,8 @@ uint64_t SignalDelegator::SetupRTFrame_ia32(FEXCore::Core::InternalThreadState* +@@ -779,7 +856,8 @@ uint64_t SignalDelegator::SetupRTFrame_ia32(FEXCore::Core::InternalThreadState* guest_uctx->uc.uc_mcontext.gregs[FEXCore::x86::FEX_REG_ERR] = ConvertSignalToError(ucontext, Signal, HostSigInfo); } @@ -4241,7 +4181,7 @@ index 2c3edeef1..5ce7ee8bd 100644 REGISTER_SYSCALL_IMPL(rseq, [](FEXCore::Core::CpuStateFrame* Frame, struct rseq* rseq, uint32_t rseq_len, int flags, uint32_t sig) -> uint64_t { // We don't support this diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp -index 0a51b98a3..de6daa958 100644 +index 068fee23e..5f4a60480 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp @@ -8,6 +8,7 @@ $end_info$ @@ -4265,7 +4205,7 @@ index 0a51b98a3..de6daa958 100644 ARG_TO_STR(idtype_t, "%u") namespace FEX::HLE { -@@ -492,6 +499,30 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { +@@ -500,6 +507,30 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { return FEX::HLE::_SyscallHandler->SeccompEmulator.Handle(Frame, Operation, 0, reinterpret_cast(arg3)); } case PR_GET_SECCOMP: return FEX::HLE::_SyscallHandler->SeccompEmulator.GetSeccomp(Frame); @@ -4296,7 +4236,7 @@ index 0a51b98a3..de6daa958 100644 case PR_GET_AUXV: { if (arg4 || arg5) { return -EINVAL; -@@ -524,6 +555,7 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { +@@ -532,6 +563,7 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { return -EPERM; } Frame->State.gs_cached = addr; @@ -4304,7 +4244,7 @@ index 0a51b98a3..de6daa958 100644 Result = 0; break; case 0x1002: // ARCH_SET_FS -@@ -532,25 +564,26 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { +@@ -540,22 +572,27 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { return -EPERM; } Frame->State.fs_cached = addr; @@ -4325,22 +4265,18 @@ index 0a51b98a3..de6daa958 100644 Result = -EINVAL; // We don't support CET, return EINVAL break; case 0x1011: // ARCH_GET_CPUID -- return 1; -- break; -- case 0x1012: // ARCH_SET_CPUID -- return -ENODEV; // Claim we don't support faulting on CPUID -- break; -+ return FEX::HLE::_SyscallHandler->TM.EnableCPUIDFaulting() ? (Frame->CPUIDFault == 0) : 1; -+ case 0x1012: ++ if (!FEX::HLE::_SyscallHandler->TM.EnableCPUIDFaulting()) { ++ return 1; ++ } + return (Frame->State.CoreFlags & FEXCore::Core::CoreFlagsEnum::CPUID_ENABLED) == FEXCore::Core::CoreFlagsEnum::CPUID_ENABLED ? 1 : 0; + case 0x1012: // ARCH_SET_CPUID + if (!FEX::HLE::_SyscallHandler->TM.EnableCPUIDFaulting()) { + return -ENODEV; + } -+ Frame->CPUIDFault = addr ? 0 : 1; -+ return 0; - default: - LogMan::Msg::EFmt("Unknown prctl: 0x{:x}", code); - Result = -EINVAL; -@@ -571,6 +604,7 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { + if (addr == 0) { + // Disable CPUID (thus enabling CPUID faulting) + Frame->State.CoreFlags = Frame->State.CoreFlags & ~FEXCore::Core::CoreFlagsEnum::CPUID_ENABLED; +@@ -584,6 +621,7 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { // Save telemetry if we're exiting. FEX::HLE::_SyscallHandler->GetSignalDelegator()->SaveTelemetry(); FEX::HLE::_SyscallHandler->TM.CleanupForExit(); @@ -4583,7 +4519,7 @@ index 5d6c850d8..f9e85a26f 100644 InvalidateCodeRangeIfNecessary(Thread, reinterpret_cast(addr), len, false); diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp -index 69e10b3d2..e13cb1ca9 100644 +index 8e7d466ed..2e59f2fb5 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp @@ -1,6 +1,7 @@ @@ -4611,7 +4547,7 @@ index 69e10b3d2..e13cb1ca9 100644 uint64_t ThreadManager::SetSignalMask(uint64_t Mask) { ::syscall(SYSCALL_DEF(rt_sigprocmask), SIG_SETMASK, &Mask, &Mask, 8); return Mask; -@@ -196,6 +207,16 @@ ThreadManager::CreateThread(const FEXCore::Core::CPUState* NewThreadState, uint6 +@@ -197,6 +208,16 @@ ThreadManager::CreateThread(const FEXCore::Core::CPUState* NewThreadState, uint6 Frame->State.callret_sp = ThreadStateObject->GetCallRetStackInfo().DefaultLocation; ThreadStateObject->Thread->FrontendPtr = ThreadStateObject; @@ -4628,7 +4564,7 @@ index 69e10b3d2..e13cb1ca9 100644 if (ProfileStats()) { ThreadStateObject->Thread->ThreadStats = Stat.AllocateSlot(ThreadStateObject->ThreadInfo.TID); } -@@ -221,8 +242,8 @@ ThreadManager::CreateThread(const FEXCore::Core::CPUState* NewThreadState, uint6 +@@ -222,8 +243,8 @@ ThreadManager::CreateThread(const FEXCore::Core::CPUState* NewThreadState, uint6 } } else { // Without any thread data to inherit, setup the default gdt. @@ -4639,7 +4575,7 @@ index 69e10b3d2..e13cb1ca9 100644 auto GDT = FEXCore::Core::CPUState::GetSegmentFromIndex(Frame->State, Frame->State.cs_idx); FEXCore::Core::CPUState::SetGDTBase(GDT, 0); FEXCore::Core::CPUState::SetGDTLimit(GDT, 0xF'FFFFU); -@@ -236,11 +257,20 @@ ThreadManager::CreateThread(const FEXCore::Core::CPUState* NewThreadState, uint6 +@@ -237,6 +258,14 @@ ThreadManager::CreateThread(const FEXCore::Core::CPUState* NewThreadState, uint6 GDT->L = 0; // L = Long Mode = 32-bit GDT->D = 1; // D = Default Operand Size = 32-bit } @@ -4654,14 +4590,8 @@ index 69e10b3d2..e13cb1ca9 100644 } if (InheritThread) { - FEX::HLE::_SyscallHandler->SeccompEmulator.InheritSeccompFilters(InheritThread, ThreadStateObject); - ThreadStateObject->persona = InheritThread->persona; -+ Frame->CPUIDFault = InheritThread->Thread->CurrentFrame->CPUIDFault; - } else { - ThreadStateObject->persona = ::personality(0xffffffff); - } diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h -index e4a86a946..c5bfe3c25 100644 +index 408cddf71..0a46703ca 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h @@ -15,6 +15,7 @@ $end_info$ @@ -4680,9 +4610,9 @@ index e4a86a946..c5bfe3c25 100644 stack_t GuestAltStack { .ss_sp = nullptr, .ss_flags = SS_DISABLE, // By default the guest alt stack is disabled -@@ -92,6 +94,27 @@ struct ThreadStateObject : public FEXCore::Allocator::FEXAllocOperators { - uint32_t SeccompMode {SECCOMP_MODE_DISABLED}; +@@ -93,6 +95,27 @@ struct ThreadStateObject : public FEXCore::Allocator::FEXAllocOperators { fextl::vector Filters {}; + std::atomic PrctlSetPending {false}; + uint64_t SeccompTrapRIP {}; + @@ -4708,7 +4638,7 @@ index e4a86a946..c5bfe3c25 100644 // personality emulation. uint32_t persona {}; -@@ -189,6 +212,11 @@ public: +@@ -190,6 +213,11 @@ public: return static_cast(Thread->FrontendPtr); } @@ -4720,7 +4650,7 @@ index e4a86a946..c5bfe3c25 100644 FEX::HLE::ThreadStateObject* CreateThread(const FEXCore::Core::CPUState* NewThreadState = nullptr, uint64_t ParentTID = 0, FEX::HLE::ThreadStateObject* InheritThread = nullptr); void TrackThread(FEX::HLE::ThreadStateObject* Thread) { -@@ -219,29 +247,38 @@ public: +@@ -220,29 +248,38 @@ public: } void InvalidateGuestCodeRange(FEXCore::Core::InternalThreadState* CallingThread, uint64_t Start, uint64_t Length) { @@ -4765,7 +4695,7 @@ index e4a86a946..c5bfe3c25 100644 } // Callback while holding the locks. -@@ -253,6 +290,20 @@ public: +@@ -254,6 +291,20 @@ public: } private: diff --git a/tools/fex/patches/0022-proc-maps-guest-only-on-small-address-space-hosts.patch b/tools/fex/patches/0022-proc-maps-guest-only-on-small-address-space-hosts.patch index c86203eb3f..0d62f092d4 100644 --- a/tools/fex/patches/0022-proc-maps-guest-only-on-small-address-space-hosts.patch +++ b/tools/fex/patches/0022-proc-maps-guest-only-on-small-address-space-hosts.patch @@ -4,7 +4,7 @@ Subject: [PATCH] List only guest mappings in /proc//maps on hosts below 47 Builds on StonkGuy's /proc emulation from https://github.com/StonkGuy/FEX (eac-2611, MIT). diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp -index 1b2396b01..156e3964c 100644 +index eb12945e4..65b0521c9 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp @@ -17,7 +17,11 @@ $end_info$ @@ -33,7 +33,7 @@ index 1b2396b01..156e3964c 100644 #include #include #include -@@ -608,6 +616,37 @@ EmulatedFDManager::EmulatedFDManager(FEXCore::Context::Context* ctx) +@@ -609,6 +617,37 @@ EmulatedFDManager::EmulatedFDManager(FEXCore::Context::Context* ctx) EmulatedFDManager::~EmulatedFDManager() {} @@ -71,7 +71,7 @@ index 1b2396b01..156e3964c 100644 static bool IsProcMapsPath(const char* Path) { if (strncmp(Path, "/proc/", 6) != 0) { return false; -@@ -660,14 +699,56 @@ int32_t EmulatedFDManager::ProcMaps(FEXCore::Context::Context* ctx, int32_t fd, +@@ -661,14 +700,56 @@ int32_t EmulatedFDManager::ProcMaps(FEXCore::Context::Context* ctx, int32_t fd, ::close(HostFD); constexpr uint64_t X86_64TaskSizeMax = (1ULL << 47) - 4096; diff --git a/tools/fex/patches/0023-proc-status-seccomp-of-calling-thread.patch b/tools/fex/patches/0023-proc-status-seccomp-of-calling-thread.patch index 5d76391bd5..d0550e8db0 100644 --- a/tools/fex/patches/0023-proc-status-seccomp-of-calling-thread.patch +++ b/tools/fex/patches/0023-proc-status-seccomp-of-calling-thread.patch @@ -11,10 +11,10 @@ Builds on StonkGuy's anti-cheat emulation from https://github.com/StonkGuy/FEX ( 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp -index 156e3964c..c1a91d122 100644 +index 65b0521c9..ce36b988b 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp -@@ -796,7 +796,11 @@ int32_t EmulatedFDManager::ProcStatus(FEXCore::Context::Context* ctx, int32_t fd +@@ -797,7 +797,11 @@ int32_t EmulatedFDManager::ProcStatus(FEXCore::Context::Context* ctx, int32_t fd Buf[Len] = '\0'; uint32_t SeccompMode = SECCOMP_MODE_DISABLED; @@ -28,10 +28,10 @@ index 156e3964c..c1a91d122 100644 } diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h -index c5bfe3c25..657de6ceb 100644 +index 0a46703ca..9c5f9f1c2 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h -@@ -289,6 +289,16 @@ public: +@@ -290,6 +290,16 @@ public: return &Threads; } diff --git a/tools/fex/patches/0024-read-host-status-directly.patch b/tools/fex/patches/0024-read-host-status-directly.patch index 931c6b2e4f..8a5268c7e7 100644 --- a/tools/fex/patches/0024-read-host-status-directly.patch +++ b/tools/fex/patches/0024-read-host-status-directly.patch @@ -59,7 +59,7 @@ index dae3d3bcc..c0f3eb3ed 100644 + } // namespace FHU::Syscalls diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp -index c1a91d122..49adaaa66 100644 +index ce36b988b..19bfc814f 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp @@ -14,6 +14,7 @@ $end_info$ @@ -70,7 +70,7 @@ index c1a91d122..49adaaa66 100644 #include #include #include -@@ -784,7 +785,7 @@ int32_t EmulatedFDManager::ProcStatus(FEXCore::Context::Context* ctx, int32_t fd +@@ -785,7 +786,7 @@ int32_t EmulatedFDManager::ProcStatus(FEXCore::Context::Context* ctx, int32_t fd char Buf[8192]; ssize_t Len = 0; { diff --git a/tools/fex/patches/0027-fixed-guest-memory-above-host-address-limit.patch b/tools/fex/patches/0027-fixed-guest-memory-above-host-address-limit.patch index 6ec5cf2392..4ec889351c 100644 --- a/tools/fex/patches/0027-fixed-guest-memory-above-host-address-limit.patch +++ b/tools/fex/patches/0027-fixed-guest-memory-above-host-address-limit.patch @@ -26,7 +26,7 @@ Builds on StonkGuy's anti-cheat emulation from https://github.com/StonkGuy/FEX ( create mode 100644 Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.h diff --git a/Source/Tools/LinuxEmulation/CMakeLists.txt b/Source/Tools/LinuxEmulation/CMakeLists.txt -index 3f02104..acf4c4c 100644 +index 3f02104ea..acf4c4c13 100644 --- a/Source/Tools/LinuxEmulation/CMakeLists.txt +++ b/Source/Tools/LinuxEmulation/CMakeLists.txt @@ -18,6 +18,7 @@ add_library(LinuxEmulation STATIC @@ -39,7 +39,7 @@ index 3f02104..acf4c4c 100644 LinuxSyscalls/SyscallsVMATracking.cpp diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.cpp new file mode 100644 -index 0000000..13f9e70 +index 000000000..13f9e70e9 --- /dev/null +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.cpp @@ -0,0 +1,2546 @@ @@ -2591,7 +2591,7 @@ index 0000000..13f9e70 +} // namespace FEX::HLE::GuestHighMemory diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.h new file mode 100644 -index 0000000..28341bf +index 000000000..28341bf50 --- /dev/null +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/GuestHighMemory.h @@ -0,0 +1,65 @@ @@ -2661,7 +2661,7 @@ index 0000000..28341bf +void ReleaseThread(FEX::HLE::ThreadStateObject* Thread); +} // namespace FEX::HLE::GuestHighMemory diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp -index efe49db..e8723e8 100644 +index c6ef3fe04..22a5a7f36 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp @@ -7,6 +7,7 @@ $end_info$ @@ -2672,7 +2672,7 @@ index efe49db..e8723e8 100644 #include "LinuxSyscalls/Syscalls.h" #include "LinuxSyscalls/PtraceEmu.h" #include "LinuxSyscalls/SignalTrace.h" -@@ -748,6 +749,10 @@ uint64_t SignalDelegator::GetNewSigMask(int Signal) const { +@@ -767,6 +768,10 @@ uint64_t SignalDelegator::GetNewSigMask(int Signal) const { } bool SignalDelegator::HandleFrontendSIGSEGV(FEXCore::Core::InternalThreadState* Thread, int Signal, void* Info, void* UContext) { @@ -2684,7 +2684,7 @@ index efe49db..e8723e8 100644 if (FaultSafeUserMemAccess::TryHandleSafeFault(Signal, SigInfo, UContext)) { diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp -index 607ab0b..5e684c4 100644 +index 607ab0b97..5e684c4c7 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp @@ -16,6 +16,7 @@ $end_info$ @@ -2763,7 +2763,7 @@ index 607ab0b..5e684c4 100644 #ifdef DEBUG_STRACE Strace(Frame, Result); diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Memory.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Memory.cpp -index 9397c9e..6095bf3 100644 +index 9397c9eb4..6095bf37f 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Memory.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Memory.cpp @@ -5,12 +5,19 @@ tags: LinuxSyscalls|syscalls-shared @@ -2817,7 +2817,7 @@ index 9397c9e..6095bf3 100644 if (Result != -1) { diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp -index f9e85a2..3326a90 100644 +index f9e85a26f..3326a90fd 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/SyscallsSMCTracking.cpp @@ -21,6 +21,7 @@ $end_info$ @@ -2985,7 +2985,7 @@ index f9e85a2..3326a90 100644 TrackMprotect(Thread, addr, len, prot); diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp -index e13cb1c..49df38c 100644 +index 2e59f2fb5..ee28680a7 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp @@ -1,6 +1,7 @@ @@ -3005,10 +3005,10 @@ index e13cb1c..49df38c 100644 FEX::HLE::_SyscallHandler->SeccompEmulator.FreeSeccompFilters(Thread); diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h -index 657de6c..4aa2080 100644 +index 9c5f9f1c2..e43dfc79c 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h -@@ -103,6 +103,40 @@ struct ThreadStateObject : public FEXCore::Allocator::FEXAllocOperators { +@@ -104,6 +104,40 @@ struct ThreadStateObject : public FEXCore::Allocator::FEXAllocOperators { bool Enabled; } SyscallUserDispatch {}; diff --git a/tools/fex/patches/0028-guest-cmdline-without-checkpoint-restore.patch b/tools/fex/patches/0028-guest-cmdline-without-checkpoint-restore.patch index d9417ac604..899b071568 100644 --- a/tools/fex/patches/0028-guest-cmdline-without-checkpoint-restore.patch +++ b/tools/fex/patches/0028-guest-cmdline-without-checkpoint-restore.patch @@ -14,10 +14,10 @@ argument area and argv points there, which needs no privilege. 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Source/Tools/FEXInterpreter/ELFCodeLoader.h b/Source/Tools/FEXInterpreter/ELFCodeLoader.h -index cebf1f5..f21d755 100644 +index b1a72d227..6d2157365 100644 --- a/Source/Tools/FEXInterpreter/ELFCodeLoader.h +++ b/Source/Tools/FEXInterpreter/ELFCodeLoader.h -@@ -855,13 +855,34 @@ public: +@@ -874,13 +874,34 @@ public: int r = prctl(PR_SET_MM, PR_SET_MM_MAP, &map, sizeof(map), 0L); if (r != 0) { diff --git a/tools/fex/patches/0029-proc-mount-tables-describe-the-container-procfs.patch b/tools/fex/patches/0029-proc-mount-tables-describe-the-container-procfs.patch index 9f93ebe139..61cf5004df 100644 --- a/tools/fex/patches/0029-proc-mount-tables-describe-the-container-procfs.patch +++ b/tools/fex/patches/0029-proc-mount-tables-describe-the-container-procfs.patch @@ -15,7 +15,7 @@ mountinfo now list the proc mount without the host instance's access options 2 files changed, 170 insertions(+), 61 deletions(-) diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp -index 49adaaa..a7a4f1d 100644 +index 19bfc814f..85f1b3e15 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/EmulatedFiles/EmulatedFiles.cpp @@ -37,6 +37,7 @@ $end_info$ @@ -26,7 +26,7 @@ index 49adaaa..a7a4f1d 100644 #include #include #include -@@ -648,6 +649,149 @@ static bool IsHostArchModule(const char* Path, fextl::unordered_map