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
+1 -1
View File
@@ -29,7 +29,7 @@
HLEHelperThread::HLEHelperThread() : id_(-1), entry_(0) {
}
HLEHelperThread::HLEHelperThread(const char *threadName, u32 instructions[], u32 instrCount, u32 prio, int stacksize) {
HLEHelperThread::HLEHelperThread(const char *threadName, const u32 instructions[], u32 instrCount, u32 prio, int stacksize) {
u32 instrBytes = instrCount * sizeof(u32);
u32 totalBytes = instrBytes + sizeof(u32) * 2;
AllocEntry(totalBytes);
+1 -1
View File
@@ -25,7 +25,7 @@ class HLEHelperThread {
public:
// For savestates.
HLEHelperThread();
HLEHelperThread(const char *threadName, u32 instructions[], u32 instrCount, u32 prio, int stacksize);
HLEHelperThread(const char *threadName, const u32 instructions[], u32 instrCount, u32 prio, int stacksize);
HLEHelperThread(const char *threadName, const char *module, const char *func, u32 prio, int stacksize);
~HLEHelperThread();
void DoState(PointerWrap &p);
+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;