Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix sceKernelExitThread
  • Loading branch information
sum2012 committed Aug 17, 2020
1 parent ea376ef commit df1f126
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Core/HLE/sceKernel.cpp
Expand Up @@ -744,7 +744,7 @@ const HLEFunction ThreadManForUser[] =
{0X1181E963, &WrapI_U<sceKernelDelaySysClockThreadCB>, "sceKernelDelaySysClockThreadCB", 'i', "P", HLE_NOT_IN_INTERRUPT | HLE_NOT_DISPATCH_SUSPENDED },
{0XCEADEB47, &WrapI_U<sceKernelDelayThread>, "sceKernelDelayThread", 'i', "x", HLE_NOT_IN_INTERRUPT | HLE_NOT_DISPATCH_SUSPENDED },
{0X68DA9E36, &WrapI_U<sceKernelDelayThreadCB>, "sceKernelDelayThreadCB", 'i', "x", HLE_NOT_IN_INTERRUPT | HLE_NOT_DISPATCH_SUSPENDED },
{0XAA73C935, &WrapV_I<sceKernelExitThread>, "sceKernelExitThread", 'v', "i" },
{0XAA73C935, &WrapI_I<sceKernelExitThread>, "sceKernelExitThread", 'i', "i" },
{0X809CE29B, &WrapV_I<sceKernelExitDeleteThread>, "sceKernelExitDeleteThread", 'v', "i" },
{0x94aa61ee, &WrapI_V<sceKernelGetThreadCurrentPriority>, "sceKernelGetThreadCurrentPriority", 'i', "" },
{0X293B45B8, &WrapI_V<sceKernelGetThreadId>, "sceKernelGetThreadId", 'i', "", HLE_NOT_IN_INTERRUPT },
Expand Down Expand Up @@ -887,7 +887,7 @@ const HLEFunction ThreadManForKernel[] =
{0x446D8DE6, &WrapI_CUUIUU<sceKernelCreateThread>, "sceKernelCreateThread", 'i', "sxxixx", HLE_NOT_IN_INTERRUPT | HLE_KERNEL_SYSCALL },
{0xF475845D, &WrapI_IIU<sceKernelStartThread>, "sceKernelStartThread", 'i', "iix", HLE_NOT_IN_INTERRUPT | HLE_KERNEL_SYSCALL },
{0X9FA03CD3, &WrapI_I<sceKernelDeleteThread>, "sceKernelDeleteThread", 'i', "i", HLE_KERNEL_SYSCALL },
{0XAA73C935, &WrapV_I<sceKernelExitThread>, "sceKernelExitThread", 'v', "i", HLE_KERNEL_SYSCALL },
{0XAA73C935, &WrapI_I<sceKernelExitThread>, "sceKernelExitThread", 'i', "i", HLE_KERNEL_SYSCALL },
{0X809CE29B, &WrapV_I<sceKernelExitDeleteThread>, "sceKernelExitDeleteThread", 'v', "i", HLE_KERNEL_SYSCALL },
{0X9944F31F, &WrapI_I<sceKernelSuspendThread>, "sceKernelSuspendThread", 'i', "i", HLE_KERNEL_SYSCALL },
{0X75156E8F, &WrapI_I<sceKernelResumeThread>, "sceKernelResumeThread", 'i', "i", HLE_KERNEL_SYSCALL },
Expand Down
10 changes: 9 additions & 1 deletion Core/HLE/sceKernelThread.cpp
Expand Up @@ -49,6 +49,8 @@
#include "Core/HLE/KernelWaitHelpers.h"
#include "Core/HLE/ThreadQueueList.h"



typedef struct
{
WaitType type;
Expand Down Expand Up @@ -2148,11 +2150,16 @@ void __KernelReturnFromThread()
// The stack will be deallocated when the thread is deleted.
}

void sceKernelExitThread(int exitStatus) {
int sceKernelExitThread(int exitStatus) {
if (!__KernelIsDispatchEnabled() && sceKernelGetCompiledSdkVersion() > 0x0307FFFF)
return ERROR_KERNEL_WAIT_CAN_NOT_WAIT;
PSPThread *thread = __GetCurrentThread();
_dbg_assert_msg_(thread != NULL, "Exited from a NULL thread.");

INFO_LOG(SCEKERNEL, "sceKernelExitThread(%d)", exitStatus);
if (exitStatus < 0) {
exitStatus = ERROR_KERNEL_ILLEGAL_ARGUMENT;
}
__KernelStopThread(currentThread, exitStatus, "thread exited");

hleReSchedule("thread exited");
Expand All @@ -2161,6 +2168,7 @@ void sceKernelExitThread(int exitStatus) {
__KernelThreadTriggerEvent((thread->nt.attr & PSP_THREAD_ATTR_KERNEL) != 0, thread->GetUID(), THREADEVENT_EXIT);

// The stack will be deallocated when the thread is deleted.
return 0;
}

void _sceKernelExitThread(int exitStatus) {
Expand Down
4 changes: 3 additions & 1 deletion Core/HLE/sceKernelThread.h
Expand Up @@ -41,7 +41,7 @@ void __KernelStopThread(SceUID threadID, int exitStatus, const char *reason);
u32 __KernelDeleteThread(SceUID threadID, int exitStatus, const char *reason);
int sceKernelDeleteThread(int threadHandle);
void sceKernelExitDeleteThread(int exitStatus);
void sceKernelExitThread(int exitStatus);
int sceKernelExitThread(int exitStatus);
void _sceKernelExitThread(int exitStatus);
SceUID sceKernelGetThreadId();
int sceKernelGetThreadCurrentPriority();
Expand Down Expand Up @@ -77,6 +77,8 @@ struct SceKernelSysClock {
u32_le hi;
};

static const int ERROR_KERNEL_WAIT_CAN_NOT_WAIT = 0x800201a7;
static const int ERROR_KERNEL_ILLEGAL_ARGUMENT = 0x800200d2;

// TODO: Map these to PSP wait types. Most of these are wrong.
// remember to update the waitTypeNames array in sceKernelThread.cpp when changing these
Expand Down

0 comments on commit df1f126

Please sign in to comment.