From e30dedd46fef0176a01b4bcabcfec40c82f7fd2f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 27 Apr 2013 13:58:59 -0700 Subject: [PATCH] Allocate thread stack on create, not on start. Also, don't free and reallocate on thread reset. --- Core/HLE/sceKernelThread.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index bcfd46682c..4d0d42e5d8 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -336,12 +336,16 @@ public: return false; } - // Fill the stack. - Memory::Memset(stackBlock, 0xFF, stackSize); - context.r[MIPS_REG_SP] = stackBlock + stackSize; - stackEnd = context.r[MIPS_REG_SP]; nt.initialStack = stackBlock; nt.stackSize = stackSize; + return true; + } + + bool FillStack() { + // Fill the stack. + Memory::Memset(stackBlock, 0xFF, nt.stackSize); + context.r[MIPS_REG_SP] = stackBlock + nt.stackSize; + stackEnd = context.r[MIPS_REG_SP]; // What's this 512? context.r[MIPS_REG_K0] = context.r[MIPS_REG_SP] - 256; context.r[MIPS_REG_SP] -= 512; @@ -1682,7 +1686,7 @@ void __KernelResetThread(Thread *t) t->pendingMipsCalls.clear(); t->context.r[MIPS_REG_RA] = threadReturnHackAddr; //hack! TODO fix - t->AllocateStack(t->nt.stackSize); // can change the stacksize! + t->FillStack(); } Thread *__KernelCreateThread(SceUID &id, SceUID moduleId, const char *name, u32 entryPoint, u32 priority, int stacksize, u32 attr) @@ -1721,6 +1725,8 @@ Thread *__KernelCreateThread(SceUID &id, SceUID moduleId, const char *name, u32 strncpy(t->nt.name, name, KERNELOBJECT_MAX_NAME_LENGTH); t->nt.name[KERNELOBJECT_MAX_NAME_LENGTH] = '\0'; + + t->AllocateStack(t->nt.stackSize); // can change the stacksize! return t; }