mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-23 02:24:38 +00:00
Clear stack before executing guest code (#2877)
* Clear stack before executing guest code
* clang, don't optimize me 🚨
avoid ClearStack function being optimized in release builds
This commit is contained in:
parent
1aa7eb8a42
commit
3b7c36e1ba
@ -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>
|
||||||
|
__attribute__((optnone)) void ClearStack() {
|
||||||
|
volatile void* buf = alloca(size);
|
||||||
|
memset(const_cast<void*>(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