GR2-win-crash-fix (#4033)

* Improve stack clearing logic in ExecuteGuest

Added a check for fiber stacks before clearing the stack in ExecuteGuest.
That fixes Gravity Rush 2 crash on Windows.

* Refactor ExecuteGuest to simplify stack clearing logic

This enough for GR2

* Recover thread initialization in ExecuteGuest function

* Enhance null check for thread control block

* Fix condition to check tcb before clearing stack
This commit is contained in:
Valdis Bogdāns
2026-02-14 23:30:09 +02:00
committed by GitHub
parent 98af227a8d
commit 0f92285e50

View File

@@ -61,7 +61,10 @@ template <class ReturnType, class... FuncArgs, class... CallArgs>
ReturnType ExecuteGuest(PS4_SYSV_ABI ReturnType (*func)(FuncArgs...), CallArgs&&... args) {
EnsureThreadInitialized();
// clear stack to avoid trash from EnsureThreadInitialized
ClearStack<12_KB>();
auto* tcb = GetTcbBase();
if (tcb != nullptr && tcb->tcb_fiber == nullptr) {
ClearStack<12_KB>();
}
return func(std::forward<CallArgs>(args)...);
}