Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sceKernelExitThread #13298

Merged
merged 3 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Core/HLE/sceKernel.cpp
Original file line number Diff line number Diff line change
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
8 changes: 7 additions & 1 deletion Core/HLE/sceKernelThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2148,11 +2148,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;
hrydgard marked this conversation as resolved.
Show resolved Hide resolved
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 +2166,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
Original file line number Diff line number Diff line change
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;
hrydgard marked this conversation as resolved.
Show resolved Hide resolved
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