diff --git a/Ryujinx.Core/OsHle/CondVar.cs b/Ryujinx.Core/OsHle/CondVar.cs index f5fe3d292e..f1b846d08c 100644 --- a/Ryujinx.Core/OsHle/CondVar.cs +++ b/Ryujinx.Core/OsHle/CondVar.cs @@ -13,7 +13,7 @@ namespace Ryujinx.Core.OsHle private bool OwnsCondVarValue; - private List WaitingThreads; + private List WaitingThreads; public CondVar(Process Process, long CondVarAddress, long Timeout) { @@ -21,10 +21,10 @@ namespace Ryujinx.Core.OsHle this.CondVarAddress = CondVarAddress; this.Timeout = Timeout; - WaitingThreads = new List(); + WaitingThreads = new List(); } - public bool WaitForSignal(HThread Thread) + public bool WaitForSignal(KThread Thread) { int Count = Process.Memory.ReadInt32(CondVarAddress); @@ -66,7 +66,7 @@ namespace Ryujinx.Core.OsHle return true; } - public void SetSignal(HThread Thread, int Count) + public void SetSignal(KThread Thread, int Count) { lock (WaitingThreads) { diff --git a/Ryujinx.Core/OsHle/GlobalStateTable.cs b/Ryujinx.Core/OsHle/GlobalStateTable.cs index 75173a4e44..ffc9f26270 100644 --- a/Ryujinx.Core/OsHle/GlobalStateTable.cs +++ b/Ryujinx.Core/OsHle/GlobalStateTable.cs @@ -1,4 +1,5 @@ using System.Collections.Concurrent; +using System.Collections.Generic; namespace Ryujinx.Core.OsHle { @@ -38,14 +39,24 @@ namespace Ryujinx.Core.OsHle return default(T); } - public bool Delete(Process Process, int Id) + public object Delete(Process Process, int Id) { if (DictByProcess.TryGetValue(Process, out IdDictionary Dict)) { return Dict.Delete(Id); } - return false; + return null; + } + + public ICollection DeleteProcess(Process Process) + { + if (DictByProcess.TryRemove(Process, out IdDictionary Dict)) + { + return Dict.Clear(); + } + + return null; } } } \ No newline at end of file diff --git a/Ryujinx.Core/OsHle/Handles/KProcessHandleTable.cs b/Ryujinx.Core/OsHle/Handles/KProcessHandleTable.cs index e753b02629..2c8098834e 100644 --- a/Ryujinx.Core/OsHle/Handles/KProcessHandleTable.cs +++ b/Ryujinx.Core/OsHle/Handles/KProcessHandleTable.cs @@ -1,8 +1,8 @@ -using System; +using System.Collections.Generic; namespace Ryujinx.Core.OsHle.Handles { - class KProcessHandleTable : IDisposable + class KProcessHandleTable { private IdDictionary Handles; @@ -13,14 +13,7 @@ namespace Ryujinx.Core.OsHle.Handles public int OpenHandle(object Obj) { - int h = Handles.Add(Obj); - - /*if (h == 0x1d) - { - throw new System.Exception("bad handle"); - }*/ - - return h; + return Handles.Add(Obj); } public T GetData(int Handle) @@ -28,38 +21,14 @@ namespace Ryujinx.Core.OsHle.Handles return Handles.GetData(Handle); } - public bool CloseHandle(int Handle) + public object CloseHandle(int Handle) { - object Data = Handles.GetData(Handle); - - if (Data is HTransferMem TMem) - { - TMem.Memory.Manager.Reprotect( - TMem.Position, - TMem.Size, - TMem.Perm); - } - return Handles.Delete(Handle); } - public void Dispose() + public ICollection Clear() { - Dispose(true); - } - - protected virtual void Dispose(bool Disposing) - { - if (Disposing) - { - foreach (object Obj in Handles) - { - if (Obj is IDisposable DisposableObj) - { - DisposableObj.Dispose(); - } - } - } + return Handles.Clear(); } } } \ No newline at end of file diff --git a/Ryujinx.Core/OsHle/Handles/KProcessScheduler.cs b/Ryujinx.Core/OsHle/Handles/KProcessScheduler.cs index b111607811..9575429838 100644 --- a/Ryujinx.Core/OsHle/Handles/KProcessScheduler.cs +++ b/Ryujinx.Core/OsHle/Handles/KProcessScheduler.cs @@ -5,15 +5,15 @@ using System.Threading; namespace Ryujinx.Core.OsHle.Handles { - public class KProcessScheduler : IDisposable + class KProcessScheduler : IDisposable { private class SchedulerThread : IDisposable { - public HThread Thread { get; private set; } + public KThread Thread { get; private set; } public AutoResetEvent WaitEvent { get; private set; } - public SchedulerThread(HThread Thread) + public SchedulerThread(KThread Thread) { this.Thread = Thread; @@ -95,7 +95,7 @@ namespace Ryujinx.Core.OsHle.Handles } } - private ConcurrentDictionary AllThreads; + private ConcurrentDictionary AllThreads; private ThreadQueue[] WaitingToRun; @@ -105,7 +105,7 @@ namespace Ryujinx.Core.OsHle.Handles public KProcessScheduler() { - AllThreads = new ConcurrentDictionary(); + AllThreads = new ConcurrentDictionary(); WaitingToRun = new ThreadQueue[4]; @@ -119,7 +119,7 @@ namespace Ryujinx.Core.OsHle.Handles SchedLock = new object(); } - public void StartThread(HThread Thread) + public void StartThread(KThread Thread) { lock (SchedLock) { @@ -164,7 +164,7 @@ namespace Ryujinx.Core.OsHle.Handles } } - public void Resume(HThread CurrThread) + public void Resume(KThread CurrThread) { SchedulerThread SchedThread; @@ -183,7 +183,7 @@ namespace Ryujinx.Core.OsHle.Handles TryResumingExecution(SchedThread); } - public bool WaitForSignal(HThread Thread, int Timeout = -1) + public bool WaitForSignal(KThread Thread, int Timeout = -1) { SchedulerThread SchedThread; @@ -230,7 +230,7 @@ namespace Ryujinx.Core.OsHle.Handles private void TryResumingExecution(SchedulerThread SchedThread) { - HThread Thread = SchedThread.Thread; + KThread Thread = SchedThread.Thread; lock (SchedLock) { @@ -249,7 +249,7 @@ namespace Ryujinx.Core.OsHle.Handles Logging.Debug($"{GetDbgThreadInfo(Thread)} resuming execution..."); } - public void Yield(HThread Thread) + public void Yield(KThread Thread) { SchedulerThread SchedThread; @@ -295,11 +295,11 @@ namespace Ryujinx.Core.OsHle.Handles } } - public void Signal(params HThread[] Threads) + public void Signal(params KThread[] Threads) { lock (SchedLock) { - foreach (HThread Thread in Threads) + foreach (KThread Thread in Threads) { if (AllThreads.TryGetValue(Thread, out SchedulerThread SchedThread)) { @@ -314,7 +314,7 @@ namespace Ryujinx.Core.OsHle.Handles } } - private string GetDbgThreadInfo(HThread Thread) + private string GetDbgThreadInfo(KThread Thread) { return $"Thread {Thread.ThreadId} (core {Thread.ProcessorId}) prio {Thread.Priority}"; } diff --git a/Ryujinx.Core/OsHle/Handles/HThread.cs b/Ryujinx.Core/OsHle/Handles/KThread.cs similarity index 79% rename from Ryujinx.Core/OsHle/Handles/HThread.cs rename to Ryujinx.Core/OsHle/Handles/KThread.cs index c631cedc6c..aa1b27bede 100644 --- a/Ryujinx.Core/OsHle/Handles/HThread.cs +++ b/Ryujinx.Core/OsHle/Handles/KThread.cs @@ -2,7 +2,7 @@ using ChocolArm64; namespace Ryujinx.Core.OsHle.Handles { - public class HThread + class KThread : KSynchronizationObject { public AThread Thread { get; private set; } @@ -11,7 +11,7 @@ namespace Ryujinx.Core.OsHle.Handles public int ThreadId => Thread.ThreadId; - public HThread(AThread Thread, int ProcessorId, int Priority) + public KThread(AThread Thread, int ProcessorId, int Priority) { this.Thread = Thread; this.ProcessorId = ProcessorId; diff --git a/Ryujinx.Core/OsHle/IdDictionary.cs b/Ryujinx.Core/OsHle/IdDictionary.cs index bd20f69b5e..0746ae81b1 100644 --- a/Ryujinx.Core/OsHle/IdDictionary.cs +++ b/Ryujinx.Core/OsHle/IdDictionary.cs @@ -1,12 +1,10 @@ -using Ryujinx.Core.OsHle.Handles; using System; -using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; namespace Ryujinx.Core.OsHle { - class IdDictionary : IEnumerable + class IdDictionary { private ConcurrentDictionary Objs; @@ -60,31 +58,25 @@ namespace Ryujinx.Core.OsHle return default(T); } - public bool Delete(int Id) + public object Delete(int Id) { if (Objs.TryRemove(Id, out object Obj)) { - if (Obj is IDisposable DisposableObj && !(Obj is KEvent)) - { - DisposableObj.Dispose(); - } - FreeIdHint = Id; - return true; + return Obj; } - return false; + return null; } - IEnumerator IEnumerable.GetEnumerator() + public ICollection Clear() { - return Objs.Values.GetEnumerator(); - } + ICollection Values = Objs.Values; - IEnumerator IEnumerable.GetEnumerator() - { - return Objs.Values.GetEnumerator(); + Objs.Clear(); + + return Values; } } } \ No newline at end of file diff --git a/Ryujinx.Core/OsHle/Ipc/IpcHandler.cs b/Ryujinx.Core/OsHle/Ipc/IpcHandler.cs index e6df6854a3..35a2535bee 100644 --- a/Ryujinx.Core/OsHle/Ipc/IpcHandler.cs +++ b/Ryujinx.Core/OsHle/Ipc/IpcHandler.cs @@ -13,8 +13,7 @@ namespace Ryujinx.Core.OsHle.Ipc AMemory Memory, KSession Session, IpcMessage Request, - long CmdPtr, - int HndId) + long CmdPtr) { IpcMessage Response = new IpcMessage(); diff --git a/Ryujinx.Core/OsHle/Mutex.cs b/Ryujinx.Core/OsHle/Mutex.cs index c619e12174..7a0e8b6cf5 100644 --- a/Ryujinx.Core/OsHle/Mutex.cs +++ b/Ryujinx.Core/OsHle/Mutex.cs @@ -16,7 +16,7 @@ namespace Ryujinx.Core.OsHle private object EnterWaitLock; - private ConcurrentQueue WaitingThreads; + private ConcurrentQueue WaitingThreads; public Mutex(Process Process, long MutexAddress, int OwnerThreadHandle) { @@ -27,10 +27,10 @@ namespace Ryujinx.Core.OsHle EnterWaitLock = new object(); - WaitingThreads = new ConcurrentQueue(); + WaitingThreads = new ConcurrentQueue(); } - public void WaitForLock(HThread RequestingThread, int RequestingThreadHandle) + public void WaitForLock(KThread RequestingThread, int RequestingThreadHandle) { AcquireMutexValue(); @@ -83,11 +83,11 @@ namespace Ryujinx.Core.OsHle ReleaseMutexValue(); - HThread[] UnlockedThreads = new HThread[WaitingThreads.Count]; + KThread[] UnlockedThreads = new KThread[WaitingThreads.Count]; int Index = 0; - while (WaitingThreads.TryDequeue(out HThread Thread)) + while (WaitingThreads.TryDequeue(out KThread Thread)) { UnlockedThreads[Index++] = Thread; } diff --git a/Ryujinx.Core/OsHle/Process.cs b/Ryujinx.Core/OsHle/Process.cs index cf909816b9..1846e576d3 100644 --- a/Ryujinx.Core/OsHle/Process.cs +++ b/Ryujinx.Core/OsHle/Process.cs @@ -5,6 +5,7 @@ using Ryujinx.Core.Loaders; using Ryujinx.Core.Loaders.Executables; using Ryujinx.Core.OsHle.Exceptions; using Ryujinx.Core.OsHle.Handles; +using Ryujinx.Core.OsHle.IpcServices.NvServices; using Ryujinx.Core.OsHle.Svc; using System; using System.Collections.Concurrent; @@ -41,11 +42,11 @@ namespace Ryujinx.Core.OsHle private ConcurrentDictionary TlsSlots; - private ConcurrentDictionary ThreadsByTpidr; + private ConcurrentDictionary ThreadsByTpidr; private List Executables; - private HThread MainThread; + private KThread MainThread; private long ImageBase; @@ -70,7 +71,7 @@ namespace Ryujinx.Core.OsHle TlsSlots = new ConcurrentDictionary(); - ThreadsByTpidr = new ConcurrentDictionary(); + ThreadsByTpidr = new ConcurrentDictionary(); Executables = new List(); @@ -132,7 +133,7 @@ namespace Ryujinx.Core.OsHle return false; } - MainThread = HandleTable.GetData(Handle); + MainThread = HandleTable.GetData(Handle); if (NeedsHbAbi) { @@ -186,7 +187,7 @@ namespace Ryujinx.Core.OsHle AThread Thread = new AThread(GetTranslator(), Memory, EntryPoint); - HThread ThreadHnd = new HThread(Thread, ProcessorId, Priority); + KThread ThreadHnd = new KThread(Thread, ProcessorId, Priority); int Handle = HandleTable.OpenHandle(ThreadHnd); @@ -311,9 +312,9 @@ namespace Ryujinx.Core.OsHle return (int)((Position - MemoryRegions.TlsPagesAddress) / TlsSize); } - public HThread GetThread(long Tpidr) + public KThread GetThread(long Tpidr) { - if (!ThreadsByTpidr.TryGetValue(Tpidr, out HThread Thread)) + if (!ThreadsByTpidr.TryGetValue(Tpidr, out KThread Thread)) { Logging.Error($"Thread with TPIDR 0x{Tpidr:x16} not found!"); } @@ -344,8 +345,20 @@ namespace Ryujinx.Core.OsHle } Disposed = true; - - HandleTable.Dispose(); + + foreach (object Obj in HandleTable.Clear()) + { + if (Obj is KSession Session) + { + Session.Dispose(); + } + } + + ServiceNvDrv.Fds.DeleteProcess(this); + + ServiceNvDrv.NvMaps.DeleteProcess(this); + + ServiceNvDrv.NvMapsById.DeleteProcess(this); Scheduler.Dispose(); diff --git a/Ryujinx.Core/OsHle/Services/IpcService.cs b/Ryujinx.Core/OsHle/Services/IpcService.cs index 8218592ea5..9dca811483 100644 --- a/Ryujinx.Core/OsHle/Services/IpcService.cs +++ b/Ryujinx.Core/OsHle/Services/IpcService.cs @@ -40,21 +40,6 @@ namespace Ryujinx.Core.OsHle.IpcServices IsDomain = false; } - private int Add(IIpcService Obj) - { - return DomainObjects.Add(Obj); - } - - private bool Delete(int Id) - { - return DomainObjects.Delete(Id); - } - - private IIpcService GetObject(int Id) - { - return DomainObjects.GetData(Id); - } - public void CallMethod(ServiceCtx Context) { IIpcService Service = this; @@ -140,5 +125,27 @@ namespace Ryujinx.Core.OsHle.IpcServices Context.Response.HandleDesc = IpcHandleDesc.MakeMove(Handle); } } + + private int Add(IIpcService Obj) + { + return DomainObjects.Add(Obj); + } + + private bool Delete(int Id) + { + object Obj = DomainObjects.Delete(Id); + + if (Obj is IDisposable DisposableObj) + { + DisposableObj.Dispose(); + } + + return Obj != null; + } + + private IIpcService GetObject(int Id) + { + return DomainObjects.GetData(Id); + } } } \ No newline at end of file diff --git a/Ryujinx.Core/OsHle/Services/Nv/ServiceNvDrv.cs b/Ryujinx.Core/OsHle/Services/Nv/ServiceNvDrv.cs index 97908ebd18..ef223772f5 100644 --- a/Ryujinx.Core/OsHle/Services/Nv/ServiceNvDrv.cs +++ b/Ryujinx.Core/OsHle/Services/Nv/ServiceNvDrv.cs @@ -18,7 +18,7 @@ namespace Ryujinx.Core.OsHle.IpcServices.NvServices private Dictionary<(string, int), ServiceProcessIoctl> IoctlCmds; - private static GlobalStateTable Fds; + public static GlobalStateTable Fds { get; private set; } public static GlobalStateTable NvMaps { get; private set; } public static GlobalStateTable NvMapsById { get; private set; } diff --git a/Ryujinx.Core/OsHle/Services/Vi/IHOSBinderDriver.cs b/Ryujinx.Core/OsHle/Services/Vi/IHOSBinderDriver.cs index f4745a7f0e..4c34200609 100644 --- a/Ryujinx.Core/OsHle/Services/Vi/IHOSBinderDriver.cs +++ b/Ryujinx.Core/OsHle/Services/Vi/IHOSBinderDriver.cs @@ -1,4 +1,5 @@ using ChocolArm64.Memory; +using Ryujinx.Core.OsHle.Handles; using Ryujinx.Core.OsHle.Ipc; using Ryujinx.Core.OsHle.IpcServices.Android; using Ryujinx.Graphics.Gal; @@ -13,6 +14,8 @@ namespace Ryujinx.Core.OsHle.IpcServices.Vi public override IReadOnlyDictionary Commands => m_Commands; + private KEvent ReleaseEvent; + private NvFlinger Flinger; public IHOSBinderDriver(IGalRenderer Renderer) @@ -24,7 +27,9 @@ namespace Ryujinx.Core.OsHle.IpcServices.Vi { 2, GetNativeHandle } }; - Flinger = new NvFlinger(Renderer); + ReleaseEvent = new KEvent(); + + Flinger = new NvFlinger(Renderer, ReleaseEvent); } public long TransactParcel(ServiceCtx Context) @@ -56,7 +61,9 @@ namespace Ryujinx.Core.OsHle.IpcServices.Vi int Id = Context.RequestData.ReadInt32(); uint Unk = Context.RequestData.ReadUInt32(); - Context.Response.HandleDesc = IpcHandleDesc.MakeMove(0xbadcafe); + int Handle = Context.Process.HandleTable.OpenHandle(ReleaseEvent); + + Context.Response.HandleDesc = IpcHandleDesc.MakeMove(Handle); return 0; } @@ -70,6 +77,8 @@ namespace Ryujinx.Core.OsHle.IpcServices.Vi { if (Disposing) { + ReleaseEvent.Dispose(); + Flinger.Dispose(); } } diff --git a/Ryujinx.Core/OsHle/Services/Vi/NvFlinger.cs b/Ryujinx.Core/OsHle/Services/Vi/NvFlinger.cs index d4c6dada9f..3a7a2ee62d 100644 --- a/Ryujinx.Core/OsHle/Services/Vi/NvFlinger.cs +++ b/Ryujinx.Core/OsHle/Services/Vi/NvFlinger.cs @@ -1,4 +1,5 @@ using ChocolArm64.Memory; +using Ryujinx.Core.OsHle.Handles; using Ryujinx.Core.OsHle.IpcServices.NvServices; using Ryujinx.Graphics.Gal; using System; @@ -17,6 +18,10 @@ namespace Ryujinx.Core.OsHle.IpcServices.Android private Dictionary<(string, int), ServiceProcessParcel> Commands; + private KEvent ReleaseEvent; + + private IGalRenderer Renderer; + private const int BufferQueueCount = 0x40; private const int BufferQueueMask = BufferQueueCount - 1; @@ -55,8 +60,6 @@ namespace Ryujinx.Core.OsHle.IpcServices.Android public GbpBuffer Data; } - private IGalRenderer Renderer; - private BufferEntry[] BufferQueue; private ManualResetEvent WaitBufferFree; @@ -69,7 +72,7 @@ namespace Ryujinx.Core.OsHle.IpcServices.Android private bool KeepRunning; - public NvFlinger(IGalRenderer Renderer) + public NvFlinger(IGalRenderer Renderer, KEvent ReleaseEvent) { Commands = new Dictionary<(string, int), ServiceProcessParcel>() { @@ -83,8 +86,9 @@ namespace Ryujinx.Core.OsHle.IpcServices.Android { ("android.gui.IGraphicBufferProducer", 0xb), GbpDisconnect }, { ("android.gui.IGraphicBufferProducer", 0xe), GbpPreallocBuffer } }; - - this.Renderer = Renderer; + + this.Renderer = Renderer; + this.ReleaseEvent = ReleaseEvent; BufferQueue = new BufferEntry[0x40]; @@ -293,6 +297,8 @@ namespace Ryujinx.Core.OsHle.IpcServices.Android BufferQueue[Slot].State = BufferState.Free; + ReleaseEvent.Handle.Set(); + WaitBufferFree.Set(); return; @@ -377,6 +383,8 @@ namespace Ryujinx.Core.OsHle.IpcServices.Android Interlocked.Decrement(ref RenderQueueCount); + ReleaseEvent.Handle.Set(); + lock (WaitBufferFree) { WaitBufferFree.Set(); diff --git a/Ryujinx.Core/OsHle/Svc/SvcSystem.cs b/Ryujinx.Core/OsHle/Svc/SvcSystem.cs index a1f133ef2a..96bef5e474 100644 --- a/Ryujinx.Core/OsHle/Svc/SvcSystem.cs +++ b/Ryujinx.Core/OsHle/Svc/SvcSystem.cs @@ -35,7 +35,28 @@ namespace Ryujinx.Core.OsHle.Svc { int Handle = (int)ThreadState.X0; - Process.HandleTable.CloseHandle(Handle); + object Obj = Process.HandleTable.CloseHandle(Handle); + + if (Obj == null) + { + Logging.Warn($"Tried to CloseHandle on invalid handle 0x{Handle:x8}!"); + + ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidHandle); + + return; + } + + if (Obj is KSession Session) + { + Session.Dispose(); + } + else if (Obj is HTransferMem TMem) + { + TMem.Memory.Manager.Reprotect( + TMem.Position, + TMem.Size, + TMem.Perm); + } ThreadState.X0 = 0; } @@ -66,7 +87,7 @@ namespace Ryujinx.Core.OsHle.Svc int HandlesCount = (int)ThreadState.X2; long Timeout = (long)ThreadState.X3; - HThread CurrThread = Process.GetThread(ThreadState.Tpidr); + KThread CurrThread = Process.GetThread(ThreadState.Tpidr); WaitHandle[] Handles = new WaitHandle[HandlesCount]; @@ -142,32 +163,21 @@ namespace Ryujinx.Core.OsHle.Svc private void SvcSendSyncRequest(AThreadState ThreadState) { - SendSyncRequest(ThreadState, false); + SendSyncRequest(ThreadState, ThreadState.Tpidr, 0x100, (int)ThreadState.X0); } private void SvcSendSyncRequestWithUserBuffer(AThreadState ThreadState) { - SendSyncRequest(ThreadState, true); + SendSyncRequest( + ThreadState, + (long)ThreadState.X0, + (long)ThreadState.X1, + (int)ThreadState.X2); } - private void SendSyncRequest(AThreadState ThreadState, bool UserBuffer) + private void SendSyncRequest(AThreadState ThreadState, long CmdPtr, long Size, int Handle) { - long CmdPtr = ThreadState.Tpidr; - long Size = 0x100; - int Handle = 0; - - if (UserBuffer) - { - CmdPtr = (long)ThreadState.X0; - Size = (long)ThreadState.X1; - Handle = (int)ThreadState.X2; - } - else - { - Handle = (int)ThreadState.X0; - } - - HThread CurrThread = Process.GetThread(ThreadState.Tpidr); + KThread CurrThread = Process.GetThread(ThreadState.Tpidr); byte[] CmdData = AMemoryHelper.ReadBytes(Memory, CmdPtr, Size); @@ -179,14 +189,7 @@ namespace Ryujinx.Core.OsHle.Svc IpcMessage Cmd = new IpcMessage(CmdData, CmdPtr); - IpcHandler.IpcCall( - Ns, - Process, - Memory, - Session, - Cmd, - CmdPtr, - Handle); + IpcHandler.IpcCall(Ns, Process, Memory, Session, Cmd, CmdPtr); Thread.Yield(); diff --git a/Ryujinx.Core/OsHle/Svc/SvcThread.cs b/Ryujinx.Core/OsHle/Svc/SvcThread.cs index 231ee2a237..77cef44cc7 100644 --- a/Ryujinx.Core/OsHle/Svc/SvcThread.cs +++ b/Ryujinx.Core/OsHle/Svc/SvcThread.cs @@ -39,7 +39,7 @@ namespace Ryujinx.Core.OsHle.Svc { int Handle = (int)ThreadState.X0; - HThread Thread = Process.HandleTable.GetData(Handle); + KThread Thread = Process.HandleTable.GetData(Handle); if (Thread != null) { @@ -53,16 +53,18 @@ namespace Ryujinx.Core.OsHle.Svc private void SvcExitThread(AThreadState ThreadState) { - HThread CurrThread = Process.GetThread(ThreadState.Tpidr); - + KThread CurrThread = Process.GetThread(ThreadState.Tpidr); + CurrThread.Thread.StopExecution(); + + CurrThread.Handle.Set(); } private void SvcSleepThread(AThreadState ThreadState) { ulong NanoSecs = ThreadState.X0; - HThread CurrThread = Process.GetThread(ThreadState.Tpidr); + KThread CurrThread = Process.GetThread(ThreadState.Tpidr); if (NanoSecs == 0) { @@ -78,7 +80,7 @@ namespace Ryujinx.Core.OsHle.Svc { int Handle = (int)ThreadState.X1; - HThread Thread = Process.HandleTable.GetData(Handle); + KThread Thread = Process.HandleTable.GetData(Handle); if (Thread != null) { @@ -91,10 +93,10 @@ namespace Ryujinx.Core.OsHle.Svc private void SvcSetThreadPriority(AThreadState ThreadState) { + int Prio = (int)ThreadState.X0; int Handle = (int)ThreadState.X1; - int Prio = (int)ThreadState.X0; - HThread Thread = Process.HandleTable.GetData(Handle); + KThread Thread = Process.HandleTable.GetData(Handle); if (Thread != null) { @@ -117,7 +119,7 @@ namespace Ryujinx.Core.OsHle.Svc { int Handle = (int)ThreadState.X0; - HThread Thread = Process.HandleTable.GetData(Handle); + KThread Thread = Process.HandleTable.GetData(Handle); if (Thread != null) { diff --git a/Ryujinx.Core/OsHle/Svc/SvcThreadSync.cs b/Ryujinx.Core/OsHle/Svc/SvcThreadSync.cs index 38356073e6..318688b853 100644 --- a/Ryujinx.Core/OsHle/Svc/SvcThreadSync.cs +++ b/Ryujinx.Core/OsHle/Svc/SvcThreadSync.cs @@ -13,7 +13,7 @@ namespace Ryujinx.Core.OsHle.Svc long MutexAddress = (long)ThreadState.X1; int RequestingThreadHandle = (int)ThreadState.X2; - HThread RequestingThread = Process.HandleTable.GetData(RequestingThreadHandle); + KThread RequestingThread = Process.HandleTable.GetData(RequestingThreadHandle); Mutex M = new Mutex(Process, MutexAddress, OwnerThreadHandle); @@ -43,7 +43,7 @@ namespace Ryujinx.Core.OsHle.Svc int ThreadHandle = (int)ThreadState.X2; long Timeout = (long)ThreadState.X3; - HThread Thread = Process.HandleTable.GetData(ThreadHandle); + KThread Thread = Process.HandleTable.GetData(ThreadHandle); Mutex M = new Mutex(Process, MutexAddress, ThreadHandle); @@ -72,7 +72,7 @@ namespace Ryujinx.Core.OsHle.Svc long CondVarAddress = (long)ThreadState.X0; int Count = (int)ThreadState.X1; - HThread CurrThread = Process.GetThread(ThreadState.Tpidr); + KThread CurrThread = Process.GetThread(ThreadState.Tpidr); if (Ns.Os.CondVars.TryGetValue(CondVarAddress, out CondVar Cv)) { diff --git a/Ryujinx.Graphics/Gpu/NsGpuPGraph.cs b/Ryujinx.Graphics/Gpu/NsGpuPGraph.cs index 9b5fc66044..652f3e7517 100644 --- a/Ryujinx.Graphics/Gpu/NsGpuPGraph.cs +++ b/Ryujinx.Graphics/Gpu/NsGpuPGraph.cs @@ -1,7 +1,6 @@ using ChocolArm64.Memory; using Ryujinx.Graphics.Gal; using System.Collections.Generic; -using System.IO; namespace Ryujinx.Graphics.Gpu { @@ -46,24 +45,6 @@ namespace Ryujinx.Graphics.Gpu } break; - case (NsGpuRegister)0x114: - uint BindId = GetRegister((NsGpuRegister)0x11c); - - if (BindId == 0xd) - { - using (FileStream FS = new FileStream("D:\\macro.bin", FileMode.Create)) - { - BinaryWriter Writer = new BinaryWriter(FS); - - foreach (int arg in Entry.Arguments) - { - Writer.Write(arg); - } - } - } - //System.Console.WriteLine("macro bind " + Entry.Arguments[0].ToString("x8")); - break; - case NsGpuRegister._3dVertexArray0Fetch: SendVertexBuffers(Memory); break;