mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-30 14:04:55 +00:00
Clear stack before executing guest code
This commit is contained in:
parent
d542d952f4
commit
3f9f7adae4
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include "common/types.h"
|
#include "common/types.h"
|
||||||
|
|
||||||
|
void* memset(void* ptr, int value, size_t num);
|
||||||
|
|
||||||
namespace Xbyak {
|
namespace Xbyak {
|
||||||
class CodeGenerator;
|
class CodeGenerator;
|
||||||
}
|
}
|
||||||
@ -41,9 +43,18 @@ Tcb* GetTcbBase();
|
|||||||
/// Makes sure TLS is initialized for the thread before entering guest.
|
/// Makes sure TLS is initialized for the thread before entering guest.
|
||||||
void EnsureThreadInitialized();
|
void EnsureThreadInitialized();
|
||||||
|
|
||||||
|
template <size_t size>
|
||||||
|
void ClearStack() {
|
||||||
|
void* buf = alloca(size);
|
||||||
|
memset(buf, 0, size);
|
||||||
|
buf = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
template <class ReturnType, class... FuncArgs, class... CallArgs>
|
template <class ReturnType, class... FuncArgs, class... CallArgs>
|
||||||
ReturnType ExecuteGuest(PS4_SYSV_ABI ReturnType (*func)(FuncArgs...), CallArgs&&... args) {
|
ReturnType ExecuteGuest(PS4_SYSV_ABI ReturnType (*func)(FuncArgs...), CallArgs&&... args) {
|
||||||
EnsureThreadInitialized();
|
EnsureThreadInitialized();
|
||||||
|
// clear stack to avoid trash from EnsureThreadInitialized
|
||||||
|
ClearStack<13_KB>();
|
||||||
return func(std::forward<CallArgs>(args)...);
|
return func(std::forward<CallArgs>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user