Oops, still had an unaligned stack in some thunks.

This commit is contained in:
Unknown W. Brackets 2014-02-23 16:56:27 -08:00
parent b7651b61c7
commit eb386603fa
2 changed files with 8 additions and 8 deletions

View File

@ -151,7 +151,7 @@ const void *ThunkManager::ProtectFunction(const void *function, int num_params)
PanicAlert("Trying to protect functions before the emu is started. Bad bad bad.");
const u8 *call_point = GetCodePtr();
Enter(this);
Enter(this, true);
#ifdef _M_X64
ABI_CallFunction(function);
@ -169,29 +169,29 @@ const void *ThunkManager::ProtectFunction(const void *function, int num_params)
ABI_RestoreStack(num_params * 4);
#endif
Leave(this);
Leave(this, true);
RET();
thunks[function] = call_point;
return (const void *)call_point;
}
void ThunkManager::Enter(ThunkEmitter *emit)
void ThunkManager::Enter(ThunkEmitter *emit, bool withinCall)
{
#ifdef _M_X64
// Make sure to align stack.
emit->SUB(64, R(ESP), Imm32(ThunkStackOffset() + ThunkBytesNeeded()));
emit->SUB(64, R(ESP), Imm32(ThunkStackOffset() + ThunkBytesNeeded() + (withinCall ? 0 : 8)));
emit->ABI_CallFunction(save_regs);
#else
emit->CALL((const void *)save_regs);
#endif
}
void ThunkManager::Leave(ThunkEmitter *emit)
void ThunkManager::Leave(ThunkEmitter *emit, bool withinCall)
{
#ifdef _M_X64
emit->ABI_CallFunction(load_regs);
emit->ADD(64, R(ESP), Imm32(ThunkStackOffset() + ThunkBytesNeeded()));
emit->ADD(64, R(ESP), Imm32(ThunkStackOffset() + ThunkBytesNeeded() + (withinCall ? 0 : 8)));
#else
emit->CALL((void*)load_regs);
#endif

View File

@ -87,8 +87,8 @@ public:
return ProtectFunction((const void *)func, 4);
}
void Enter(ThunkEmitter *emit);
void Leave(ThunkEmitter *emit);
void Enter(ThunkEmitter *emit, bool withinCall = false);
void Leave(ThunkEmitter *emit, bool withinCall = false);
private:
void Init();