From 808c7e9807814407e14e31f91f22f6f76ebbca3d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Nov 2012 20:07:02 -0800 Subject: [PATCH] Fix crash in sceKernelExitDeleteThread(). 0 means current thread, seen in Wild Arms XF. Doesn't make the game run but at least it doesn't segfault. --- Core/HLE/sceKernelThread.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index 9049fb4551..8b2e6c3c6f 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -889,10 +889,24 @@ u32 sceKernelStartThread() void sceKernelGetThreadStackFreeSize() { - SceUID threadID = PARAM(0); - INFO_LOG(HLE,"sceKernelGetThreadStackFreeSize(%i)", threadID); - u32 error; - Thread *thread = kernelObjects.Get(threadID, error); + SceUID threadID = PARAM(0); + Thread *thread; + + INFO_LOG(HLE,"sceKernelGetThreadStackFreeSize(%i)", threadID); + + if (threadID == 0) + thread = currentThread; + else + { + u32 error; + thread = kernelObjects.Get(threadID, error); + if (thread == 0) + { + ERROR_LOG(HLE,"sceKernelGetThreadStackFreeSize: invalid thread id %i", threadID); + RETURN(error); + return; + } + } // Scan the stack for 0xFF int sz = 0;