From e0c3d9c8dfe317c3c65267efa5c4e2014d9727a6 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 4 Apr 2018 16:07:44 -0300 Subject: [PATCH] Fix SvcGetThreadId --- Ryujinx.Core/OsHle/Svc/SvcThread.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Ryujinx.Core/OsHle/Svc/SvcThread.cs b/Ryujinx.Core/OsHle/Svc/SvcThread.cs index 77cef44c..f58c2dc0 100644 --- a/Ryujinx.Core/OsHle/Svc/SvcThread.cs +++ b/Ryujinx.Core/OsHle/Svc/SvcThread.cs @@ -1,6 +1,8 @@ using ChocolArm64.State; using Ryujinx.Core.OsHle.Handles; +using static Ryujinx.Core.OsHle.ErrorCode; + namespace Ryujinx.Core.OsHle.Svc { partial class SvcHandler @@ -61,11 +63,11 @@ namespace Ryujinx.Core.OsHle.Svc } private void SvcSleepThread(AThreadState ThreadState) - { + { ulong NanoSecs = ThreadState.X0; KThread CurrThread = Process.GetThread(ThreadState.Tpidr); - + if (NanoSecs == 0) { Process.Scheduler.Yield(CurrThread); @@ -117,7 +119,7 @@ namespace Ryujinx.Core.OsHle.Svc private void SvcGetThreadId(AThreadState ThreadState) { - int Handle = (int)ThreadState.X0; + int Handle = (int)ThreadState.X1; KThread Thread = Process.HandleTable.GetData(Handle); @@ -126,8 +128,12 @@ namespace Ryujinx.Core.OsHle.Svc ThreadState.X0 = 0; ThreadState.X1 = (ulong)Thread.ThreadId; } + else + { + Logging.Warn($"Tried to GetThreadId on invalid thread handle 0x{Handle:x8}!"); - //TODO: Error codes. + ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidHandle); + } } } } \ No newline at end of file