From d0fbcced57ad41e707511e1dd34710a364b31891 Mon Sep 17 00:00:00 2001 From: svc64 Date: Sat, 5 Aug 2023 14:25:41 +0300 Subject: [PATCH] Put ThreadUid in the execution context classes --- src/ARMeilleure/State/ExecutionContext.cs | 2 ++ src/Ryujinx.Cpu/AppleHv/HvExecutionContext.cs | 7 +++++++ src/Ryujinx.Cpu/AppleHv/HvExecutionContextShadow.cs | 2 ++ src/Ryujinx.Cpu/AppleHv/HvExecutionContextVcpu.cs | 2 ++ src/Ryujinx.Cpu/AppleHv/IHvExecutionContext.cs | 2 +- src/Ryujinx.Cpu/IExecutionContext.cs | 5 +++++ src/Ryujinx.Cpu/Jit/JitExecutionContext.cs | 7 +++++++ src/Ryujinx.HLE/Debugger/Debugger.cs | 7 +++---- .../HOS/Kernel/Process/ProcessExecutionContext.cs | 2 ++ src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs | 1 + 10 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/ARMeilleure/State/ExecutionContext.cs b/src/ARMeilleure/State/ExecutionContext.cs index 2d57df725..e4e9cd0e1 100644 --- a/src/ARMeilleure/State/ExecutionContext.cs +++ b/src/ARMeilleure/State/ExecutionContext.cs @@ -71,6 +71,8 @@ namespace ARMeilleure.State public bool IsAarch32 { get; set; } + public ulong ThreadUid { get; set; } + internal ExecutionMode ExecutionMode { get diff --git a/src/Ryujinx.Cpu/AppleHv/HvExecutionContext.cs b/src/Ryujinx.Cpu/AppleHv/HvExecutionContext.cs index 63b4b2edc..33549237f 100644 --- a/src/Ryujinx.Cpu/AppleHv/HvExecutionContext.cs +++ b/src/Ryujinx.Cpu/AppleHv/HvExecutionContext.cs @@ -48,6 +48,13 @@ namespace Ryujinx.Cpu.AppleHv set => _impl.Fpsr = value; } + /// + public ulong ThreadUid + { + get => _impl.ThreadUid; + set => _impl.ThreadUid = value; + } + /// public bool IsAarch32 { diff --git a/src/Ryujinx.Cpu/AppleHv/HvExecutionContextShadow.cs b/src/Ryujinx.Cpu/AppleHv/HvExecutionContextShadow.cs index b9cc08fb2..034795f08 100644 --- a/src/Ryujinx.Cpu/AppleHv/HvExecutionContextShadow.cs +++ b/src/Ryujinx.Cpu/AppleHv/HvExecutionContextShadow.cs @@ -18,6 +18,8 @@ namespace Ryujinx.Cpu.AppleHv public bool IsAarch32 { get; set; } + public ulong ThreadUid { get; set; } + private readonly ulong[] _x; private readonly V128[] _v; diff --git a/src/Ryujinx.Cpu/AppleHv/HvExecutionContextVcpu.cs b/src/Ryujinx.Cpu/AppleHv/HvExecutionContextVcpu.cs index c581698b9..690a5f30d 100644 --- a/src/Ryujinx.Cpu/AppleHv/HvExecutionContextVcpu.cs +++ b/src/Ryujinx.Cpu/AppleHv/HvExecutionContextVcpu.cs @@ -21,6 +21,8 @@ namespace Ryujinx.Cpu.AppleHv // This is only valid while debugging is enabled. public ulong DebugPc { get; set; } + public ulong ThreadUid { get; set; } + static HvExecutionContextVcpu() { // .NET does not support passing vectors by value, so we need to pass a pointer and use a native diff --git a/src/Ryujinx.Cpu/AppleHv/IHvExecutionContext.cs b/src/Ryujinx.Cpu/AppleHv/IHvExecutionContext.cs index f12ba9dfc..17be8cc45 100644 --- a/src/Ryujinx.Cpu/AppleHv/IHvExecutionContext.cs +++ b/src/Ryujinx.Cpu/AppleHv/IHvExecutionContext.cs @@ -15,7 +15,7 @@ namespace Ryujinx.Cpu.AppleHv uint Fpcr { get; set; } uint Fpsr { get; set; } - + ulong ThreadUid { get; set; } ulong GetX(int index); void SetX(int index, ulong value); diff --git a/src/Ryujinx.Cpu/IExecutionContext.cs b/src/Ryujinx.Cpu/IExecutionContext.cs index 927ba120d..b44c4f318 100644 --- a/src/Ryujinx.Cpu/IExecutionContext.cs +++ b/src/Ryujinx.Cpu/IExecutionContext.cs @@ -46,6 +46,11 @@ namespace Ryujinx.Cpu /// bool IsAarch32 { get; set; } + /// + /// Thread UID. + /// + public ulong ThreadUid { get; set; } + /// /// Indicates whenever the CPU is still running code. /// diff --git a/src/Ryujinx.Cpu/Jit/JitExecutionContext.cs b/src/Ryujinx.Cpu/Jit/JitExecutionContext.cs index fda9e54cb..2f3e0d59b 100644 --- a/src/Ryujinx.Cpu/Jit/JitExecutionContext.cs +++ b/src/Ryujinx.Cpu/Jit/JitExecutionContext.cs @@ -53,6 +53,13 @@ namespace Ryujinx.Cpu.Jit set => _impl.IsAarch32 = value; } + /// + public ulong ThreadUid + { + get => _impl.ThreadUid; + set => _impl.ThreadUid = value; + } + /// public bool Running => _impl.Running; diff --git a/src/Ryujinx.HLE/Debugger/Debugger.cs b/src/Ryujinx.HLE/Debugger/Debugger.cs index 0a2c43b16..63e540b2a 100644 --- a/src/Ryujinx.HLE/Debugger/Debugger.cs +++ b/src/Ryujinx.HLE/Debugger/Debugger.cs @@ -45,7 +45,6 @@ namespace Ryujinx.HLE.Debugger private ulong[] GetThreadIds() => Device.System.DebugGetApplicationProcess().DebugGetThreadUids(); private Ryujinx.Cpu.IExecutionContext GetThread(ulong threadUid) => Device.System.DebugGetApplicationProcess().DebugGetThreadContext(threadUid); private Ryujinx.Cpu.IExecutionContext[] GetThreads() => GetThreadIds().Select(x => GetThread(x)).ToArray(); - private ulong? GetThreadUid(Ryujinx.Cpu.IExecutionContext thread) => GetThreadIds().Where(x => GetThread(x) == thread).First(); private IVirtualMemoryManager GetMemory() => Device.System.DebugGetApplicationProcess().CpuMemory; private void InvalidateCacheRegion(ulong address, ulong size) => Device.System.DebugGetApplicationProcess().InvalidateCacheRegion(address, size); @@ -394,7 +393,7 @@ namespace Ryujinx.HLE.Debugger { if (threadId == 0) { - threadId = GetThreadUid(GetThreads().First()); + threadId = GetThreads().First().ThreadUid; } switch (op) @@ -502,12 +501,12 @@ namespace Ryujinx.HLE.Debugger } ctx.DebugStep(); - Reply($"T00thread:{GetThreadUid(ctx):x};"); + Reply($"T00thread:{ctx.ThreadUid:x};"); } private void CommandIsAlive(ulong? threadId) { - if (GetThreads().Any(x => GetThreadUid(x) == threadId)) + if (GetThreads().Any(x => x.ThreadUid == threadId)) { ReplyOK(); } diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessExecutionContext.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessExecutionContext.cs index f9718280e..2cfdbd687 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessExecutionContext.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessExecutionContext.cs @@ -17,6 +17,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public bool IsAarch32 { get => false; set { } } + public ulong ThreadUid { get; set; } + public bool Running { get; private set; } = true; private readonly ulong[] _x = new ulong[32]; diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs index 835bf5d40..4e71faf01 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs @@ -204,6 +204,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading Context.TpidrroEl0 = (long)_tlsAddress; ThreadUid = KernelContext.NewThreadUid(); + Context.ThreadUid = ThreadUid; HostThread.Name = customThreadStart != null ? $"HLE.OsThread.{ThreadUid}" : $"HLE.GuestThread.{ThreadUid}";