mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-06-25 20:06:17 +00:00
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions
73 lines
1.7 KiB
C++
73 lines
1.7 KiB
C++
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include "common/types.h"
|
|
|
|
void* memset(void* ptr, int value, size_t num);
|
|
|
|
namespace Xbyak {
|
|
class CodeGenerator;
|
|
}
|
|
|
|
namespace Libraries::Fiber {
|
|
struct OrbisFiberContext;
|
|
}
|
|
|
|
namespace Core {
|
|
|
|
union DtvEntry {
|
|
std::size_t counter;
|
|
u8* pointer;
|
|
};
|
|
|
|
struct Tcb {
|
|
Tcb* tcb_self;
|
|
DtvEntry* tcb_dtv;
|
|
void* tcb_thread;
|
|
::Libraries::Fiber::OrbisFiberContext* tcb_fiber;
|
|
};
|
|
|
|
#ifdef _WIN32
|
|
/// Gets the thread local storage key for the TCB block.
|
|
u32 GetTcbKey();
|
|
#endif
|
|
|
|
/// Sets the data pointer to the TCB block.
|
|
void SetTcbBase(void* image_address);
|
|
|
|
/// Retrieves Tcb structure for the calling thread.
|
|
Tcb* GetTcbBase();
|
|
|
|
/// Makes sure TLS is initialized for the thread before entering guest.
|
|
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>
|
|
ReturnType ExecuteGuest(PS4_SYSV_ABI ReturnType (*func)(FuncArgs...), CallArgs&&... args) {
|
|
EnsureThreadInitialized();
|
|
// clear stack to avoid trash from EnsureThreadInitialized
|
|
ClearStack<13_KB>();
|
|
return func(std::forward<CallArgs>(args)...);
|
|
}
|
|
|
|
template <class F, F f>
|
|
struct HostCallWrapperImpl;
|
|
|
|
template <class ReturnType, class... Args, PS4_SYSV_ABI ReturnType (*func)(Args...)>
|
|
struct HostCallWrapperImpl<PS4_SYSV_ABI ReturnType (*)(Args...), func> {
|
|
static ReturnType PS4_SYSV_ABI wrap(Args... args) {
|
|
return func(args...);
|
|
}
|
|
};
|
|
|
|
#define HOST_CALL(func) (Core::HostCallWrapperImpl<decltype(&(func)), func>::wrap)
|
|
|
|
} // namespace Core
|