HLE: Correct helper thread arg handling.

This commit is contained in:
Unknown W. Brackets
2021-02-27 12:51:25 -08:00
parent aa13f5afb7
commit fa320599dc
3 changed files with 12 additions and 10 deletions
+10 -8
View File
@@ -2025,22 +2025,24 @@ int __KernelStartThread(SceUID threadToStartID, int argSize, u32 argBlockPtr, bo
u32 &sp = startThread->context.r[MIPS_REG_SP];
// Force args means just use those as a0/a1 without any special treatment.
// This is a hack to avoid allocating memory for helper threads which take args.
if ((argBlockPtr && argSize > 0) || forceArgs) {
if (forceArgs) {
startThread->context.r[MIPS_REG_A0] = argSize;
startThread->context.r[MIPS_REG_A1] = argBlockPtr;
} else if (argBlockPtr && argSize > 0) {
// Make room for the arguments, always 0x10 aligned.
if (!forceArgs)
sp -= (argSize + 0xf) & ~0xf;
sp -= (argSize + 0xf) & ~0xf;
startThread->context.r[MIPS_REG_A0] = argSize;
startThread->context.r[MIPS_REG_A1] = sp;
// Now copy argument to stack.
if (Memory::IsValidAddress(argBlockPtr)) {
Memory::Memcpy(sp, argBlockPtr, argSize, "ThreadStartArgs");
}
} else {
startThread->context.r[MIPS_REG_A0] = 0;
startThread->context.r[MIPS_REG_A1] = 0;
}
// Now copy argument to stack.
if (!forceArgs && Memory::IsValidAddress(argBlockPtr)) {
Memory::Memcpy(sp, argBlockPtr, argSize, "ThreadStartArgs");
}
// On the PSP, there's an extra 64 bytes of stack eaten after the args.
// This could be stack overflow safety, or just stack eaten by the kernel entry func.
sp -= 64;