mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-06-06 00:04:59 -06:00
This reverts commit f6d71646c0.
This commit is contained in:
parent
248b3e2d30
commit
9241ebd4dd
@ -12,28 +12,28 @@ void* PS4_SYSV_ABI AvPlayer::Allocate(void* handle, u32 alignment, u32 size) {
|
|||||||
const auto* const self = reinterpret_cast<AvPlayer*>(handle);
|
const auto* const self = reinterpret_cast<AvPlayer*>(handle);
|
||||||
const auto allocate = self->m_init_data_original.memory_replacement.allocate;
|
const auto allocate = self->m_init_data_original.memory_replacement.allocate;
|
||||||
const auto ptr = self->m_init_data_original.memory_replacement.object_ptr;
|
const auto ptr = self->m_init_data_original.memory_replacement.object_ptr;
|
||||||
return allocate(ptr, alignment, size);
|
return Core::ExecuteGuest(allocate, ptr, alignment, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PS4_SYSV_ABI AvPlayer::Deallocate(void* handle, void* memory) {
|
void PS4_SYSV_ABI AvPlayer::Deallocate(void* handle, void* memory) {
|
||||||
const auto* const self = reinterpret_cast<AvPlayer*>(handle);
|
const auto* const self = reinterpret_cast<AvPlayer*>(handle);
|
||||||
const auto deallocate = self->m_init_data_original.memory_replacement.deallocate;
|
const auto deallocate = self->m_init_data_original.memory_replacement.deallocate;
|
||||||
const auto ptr = self->m_init_data_original.memory_replacement.object_ptr;
|
const auto ptr = self->m_init_data_original.memory_replacement.object_ptr;
|
||||||
return deallocate(ptr, memory);
|
return Core::ExecuteGuest(deallocate, ptr, memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* PS4_SYSV_ABI AvPlayer::AllocateTexture(void* handle, u32 alignment, u32 size) {
|
void* PS4_SYSV_ABI AvPlayer::AllocateTexture(void* handle, u32 alignment, u32 size) {
|
||||||
const auto* const self = reinterpret_cast<AvPlayer*>(handle);
|
const auto* const self = reinterpret_cast<AvPlayer*>(handle);
|
||||||
const auto allocate = self->m_init_data_original.memory_replacement.allocate_texture;
|
const auto allocate = self->m_init_data_original.memory_replacement.allocate_texture;
|
||||||
const auto ptr = self->m_init_data_original.memory_replacement.object_ptr;
|
const auto ptr = self->m_init_data_original.memory_replacement.object_ptr;
|
||||||
return allocate(ptr, alignment, size);
|
return Core::ExecuteGuest(allocate, ptr, alignment, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PS4_SYSV_ABI AvPlayer::DeallocateTexture(void* handle, void* memory) {
|
void PS4_SYSV_ABI AvPlayer::DeallocateTexture(void* handle, void* memory) {
|
||||||
const auto* const self = reinterpret_cast<AvPlayer*>(handle);
|
const auto* const self = reinterpret_cast<AvPlayer*>(handle);
|
||||||
const auto deallocate = self->m_init_data_original.memory_replacement.deallocate_texture;
|
const auto deallocate = self->m_init_data_original.memory_replacement.deallocate_texture;
|
||||||
const auto ptr = self->m_init_data_original.memory_replacement.object_ptr;
|
const auto ptr = self->m_init_data_original.memory_replacement.object_ptr;
|
||||||
return deallocate(ptr, memory);
|
return Core::ExecuteGuest(deallocate, ptr, memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI AvPlayer::OpenFile(void* handle, const char* filename) {
|
int PS4_SYSV_ABI AvPlayer::OpenFile(void* handle, const char* filename) {
|
||||||
@ -42,7 +42,7 @@ int PS4_SYSV_ABI AvPlayer::OpenFile(void* handle, const char* filename) {
|
|||||||
|
|
||||||
const auto open = self->m_init_data_original.file_replacement.open;
|
const auto open = self->m_init_data_original.file_replacement.open;
|
||||||
const auto ptr = self->m_init_data_original.file_replacement.object_ptr;
|
const auto ptr = self->m_init_data_original.file_replacement.object_ptr;
|
||||||
return open(ptr, filename);
|
return Core::ExecuteGuest(open, ptr, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI AvPlayer::CloseFile(void* handle) {
|
int PS4_SYSV_ABI AvPlayer::CloseFile(void* handle) {
|
||||||
@ -51,7 +51,7 @@ int PS4_SYSV_ABI AvPlayer::CloseFile(void* handle) {
|
|||||||
|
|
||||||
const auto close = self->m_init_data_original.file_replacement.close;
|
const auto close = self->m_init_data_original.file_replacement.close;
|
||||||
const auto ptr = self->m_init_data_original.file_replacement.object_ptr;
|
const auto ptr = self->m_init_data_original.file_replacement.object_ptr;
|
||||||
return close(ptr);
|
return Core::ExecuteGuest(close, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI AvPlayer::ReadOffsetFile(void* handle, u8* buffer, u64 position, u32 length) {
|
int PS4_SYSV_ABI AvPlayer::ReadOffsetFile(void* handle, u8* buffer, u64 position, u32 length) {
|
||||||
@ -60,7 +60,7 @@ int PS4_SYSV_ABI AvPlayer::ReadOffsetFile(void* handle, u8* buffer, u64 position
|
|||||||
|
|
||||||
const auto read_offset = self->m_init_data_original.file_replacement.read_offset;
|
const auto read_offset = self->m_init_data_original.file_replacement.read_offset;
|
||||||
const auto ptr = self->m_init_data_original.file_replacement.object_ptr;
|
const auto ptr = self->m_init_data_original.file_replacement.object_ptr;
|
||||||
return read_offset(ptr, buffer, position, length);
|
return Core::ExecuteGuest(read_offset, ptr, buffer, position, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 PS4_SYSV_ABI AvPlayer::SizeFile(void* handle) {
|
u64 PS4_SYSV_ABI AvPlayer::SizeFile(void* handle) {
|
||||||
@ -69,7 +69,7 @@ u64 PS4_SYSV_ABI AvPlayer::SizeFile(void* handle) {
|
|||||||
|
|
||||||
const auto size = self->m_init_data_original.file_replacement.size;
|
const auto size = self->m_init_data_original.file_replacement.size;
|
||||||
const auto ptr = self->m_init_data_original.file_replacement.object_ptr;
|
const auto ptr = self->m_init_data_original.file_replacement.object_ptr;
|
||||||
return size(ptr);
|
return Core::ExecuteGuest(size, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
AvPlayerInitData AvPlayer::StubInitData(const AvPlayerInitData& data) {
|
AvPlayerInitData AvPlayer::StubInitData(const AvPlayerInitData& data) {
|
||||||
|
|||||||
@ -92,7 +92,7 @@ void AvPlayerState::DefaultEventCallback(void* opaque, AvPlayerEvents event_id,
|
|||||||
const auto callback = self->m_event_replacement.event_callback;
|
const auto callback = self->m_event_replacement.event_callback;
|
||||||
const auto ptr = self->m_event_replacement.object_ptr;
|
const auto ptr = self->m_event_replacement.object_ptr;
|
||||||
if (callback != nullptr) {
|
if (callback != nullptr) {
|
||||||
callback(ptr, event_id, 0, event_data);
|
Core::ExecuteGuest(callback, ptr, event_id, 0, event_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -99,16 +99,16 @@ public:
|
|||||||
if (m_ime_mode) {
|
if (m_ime_mode) {
|
||||||
OrbisImeParam param = m_param.ime;
|
OrbisImeParam param = m_param.ime;
|
||||||
if (use_param_handler) {
|
if (use_param_handler) {
|
||||||
param.handler(param.arg, event);
|
Core::ExecuteGuest(param.handler, param.arg, event);
|
||||||
} else {
|
} else {
|
||||||
handler(param.arg, event);
|
Core::ExecuteGuest(handler, param.arg, event);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
OrbisImeKeyboardParam param = m_param.key;
|
OrbisImeKeyboardParam param = m_param.key;
|
||||||
if (use_param_handler) {
|
if (use_param_handler) {
|
||||||
param.handler(param.arg, event);
|
Core::ExecuteGuest(param.handler, param.arg, event);
|
||||||
} else {
|
} else {
|
||||||
handler(param.arg, event);
|
Core::ExecuteGuest(handler, param.arg, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -131,7 +131,8 @@ bool ImeDialogState::CallTextFilter() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = text_filter(out_text, &out_text_length, src_text, src_text_length);
|
int ret =
|
||||||
|
Core::ExecuteGuest(text_filter, out_text, &out_text_length, src_text, src_text_length);
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return false;
|
return false;
|
||||||
@ -152,7 +153,7 @@ bool ImeDialogState::CallKeyboardFilter(const OrbisImeKeycode* src_keycode, u16*
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = keyboard_filter(src_keycode, out_keycode, out_status, nullptr);
|
int ret = Core::ExecuteGuest(keyboard_filter, src_keycode, out_keycode, out_status, nullptr);
|
||||||
return ret == 0;
|
return ret == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -194,21 +194,6 @@ int PS4_SYSV_ABI posix_pthread_detach(PthreadT pthread) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __clang__
|
|
||||||
__attribute__((optnone))
|
|
||||||
#else
|
|
||||||
__attribute__((optimize("O0")))
|
|
||||||
#endif
|
|
||||||
void ClearStack(const PthreadAttr& attr) {
|
|
||||||
void* sp;
|
|
||||||
asm("mov %%rsp, %0" : "=rm"(sp));
|
|
||||||
// leave a safety net of 128 bytes for memset
|
|
||||||
const u64 size = (u64)sp - (u64)attr.stackaddr_attr - 128;
|
|
||||||
volatile void* buf = alloca(size);
|
|
||||||
memset(const_cast<void*>(buf), 0, size);
|
|
||||||
buf = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void RunThread(void* arg) {
|
static void RunThread(void* arg) {
|
||||||
auto* curthread = static_cast<Pthread*>(arg);
|
auto* curthread = static_cast<Pthread*>(arg);
|
||||||
g_curthread = curthread;
|
g_curthread = curthread;
|
||||||
@ -217,12 +202,7 @@ static void RunThread(void* arg) {
|
|||||||
|
|
||||||
/* Run the current thread's start routine with argument: */
|
/* Run the current thread's start routine with argument: */
|
||||||
curthread->native_thr.Initialize();
|
curthread->native_thr.Initialize();
|
||||||
Core::EnsureThreadInitialized();
|
void* ret = Core::ExecuteGuest(curthread->start_routine, curthread->arg);
|
||||||
|
|
||||||
// Clear the stack before running the guest thread
|
|
||||||
ClearStack(curthread->attr);
|
|
||||||
|
|
||||||
void* ret = curthread->start_routine(curthread->arg);
|
|
||||||
|
|
||||||
/* Remove thread from tracking */
|
/* Remove thread from tracking */
|
||||||
DebugState.RemoveCurrentThreadFromGuestList();
|
DebugState.RemoveCurrentThreadFromGuestList();
|
||||||
|
|||||||
@ -84,7 +84,7 @@ void _thread_cleanupspecific() {
|
|||||||
* destructor:
|
* destructor:
|
||||||
*/
|
*/
|
||||||
lk.unlock();
|
lk.unlock();
|
||||||
destructor(data);
|
Core::ExecuteGuest(destructor, data);
|
||||||
lk.lock();
|
lk.lock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,7 +50,7 @@ void NetCtlInternal::CheckCallback() {
|
|||||||
: ORBIS_NET_CTL_EVENT_TYPE_DISCONNECTED;
|
: ORBIS_NET_CTL_EVENT_TYPE_DISCONNECTED;
|
||||||
for (const auto [func, arg] : callbacks) {
|
for (const auto [func, arg] : callbacks) {
|
||||||
if (func != nullptr) {
|
if (func != nullptr) {
|
||||||
func(event, arg);
|
Core::ExecuteGuest(func, event, arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ void NetCtlInternal::CheckNpToolkitCallback() {
|
|||||||
: ORBIS_NET_CTL_EVENT_TYPE_DISCONNECTED;
|
: ORBIS_NET_CTL_EVENT_TYPE_DISCONNECTED;
|
||||||
for (const auto [func, arg] : nptool_callbacks) {
|
for (const auto [func, arg] : nptool_callbacks) {
|
||||||
if (func != nullptr) {
|
if (func != nullptr) {
|
||||||
func(event, arg);
|
Core::ExecuteGuest(func, event, arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -160,13 +160,13 @@ s32 PS4_SYSV_ABI sceNgs2SystemCreateWithAllocator(const OrbisNgs2SystemOption* o
|
|||||||
result = SystemSetup(option, &bufferInfo, 0, 0);
|
result = SystemSetup(option, &bufferInfo, 0, 0);
|
||||||
if (result >= 0) {
|
if (result >= 0) {
|
||||||
uintptr_t sysUserData = allocator->userData;
|
uintptr_t sysUserData = allocator->userData;
|
||||||
result = hostAlloc(&bufferInfo);
|
result = Core::ExecuteGuest(hostAlloc, &bufferInfo);
|
||||||
if (result >= 0) {
|
if (result >= 0) {
|
||||||
OrbisNgs2Handle* handleCopy = outHandle;
|
OrbisNgs2Handle* handleCopy = outHandle;
|
||||||
result = SystemSetup(option, &bufferInfo, hostFree, handleCopy);
|
result = SystemSetup(option, &bufferInfo, hostFree, handleCopy);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
if (hostFree) {
|
if (hostFree) {
|
||||||
hostFree(&bufferInfo);
|
Core::ExecuteGuest(hostFree, &bufferInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
#include "dimensions.h"
|
#include "dimensions.h"
|
||||||
|
|
||||||
#include "core/tls.h"
|
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
@ -624,8 +622,6 @@ libusb_transfer_status DimensionsBackend::HandleAsyncTransfer(libusb_transfer* t
|
|||||||
s32 DimensionsBackend::SubmitTransfer(libusb_transfer* transfer) {
|
s32 DimensionsBackend::SubmitTransfer(libusb_transfer* transfer) {
|
||||||
if (transfer->endpoint == 0x01) {
|
if (transfer->endpoint == 0x01) {
|
||||||
std::thread write_thread([this, transfer] {
|
std::thread write_thread([this, transfer] {
|
||||||
Core::EnsureThreadInitialized();
|
|
||||||
|
|
||||||
HandleAsyncTransfer(transfer);
|
HandleAsyncTransfer(transfer);
|
||||||
|
|
||||||
const u8 flags = transfer->flags;
|
const u8 flags = transfer->flags;
|
||||||
|
|||||||
@ -135,8 +135,7 @@ void Linker::Execute(const std::vector<std::string>& args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
params.entry_addr = module->GetEntryAddress();
|
params.entry_addr = module->GetEntryAddress();
|
||||||
Core::EnsureThreadInitialized();
|
ExecuteGuest(RunMainEntry, ¶ms);
|
||||||
RunMainEntry(¶ms);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,7 +379,8 @@ void* Linker::TlsGetAddr(u64 module_index, u64 offset) {
|
|||||||
if (!addr) {
|
if (!addr) {
|
||||||
// Module was just loaded by above code. Allocate TLS block for it.
|
// Module was just loaded by above code. Allocate TLS block for it.
|
||||||
const u32 init_image_size = module->tls.init_image_size;
|
const u32 init_image_size = module->tls.init_image_size;
|
||||||
u8* dest = reinterpret_cast<u8*>(heap_api->heap_malloc(module->tls.image_size));
|
u8* dest = reinterpret_cast<u8*>(
|
||||||
|
Core::ExecuteGuest(heap_api->heap_malloc, module->tls.image_size));
|
||||||
const u8* src = reinterpret_cast<const u8*>(module->tls.image_virtual_addr);
|
const u8* src = reinterpret_cast<const u8*>(module->tls.image_virtual_addr);
|
||||||
std::memcpy(dest, src, init_image_size);
|
std::memcpy(dest, src, init_image_size);
|
||||||
std::memset(dest + init_image_size, 0, module->tls.image_size - init_image_size);
|
std::memset(dest + init_image_size, 0, module->tls.image_size - init_image_size);
|
||||||
@ -412,7 +412,7 @@ void* Linker::AllocateTlsForThread(bool is_primary) {
|
|||||||
ASSERT_MSG(ret == 0, "Unable to allocate TLS+TCB for the primary thread");
|
ASSERT_MSG(ret == 0, "Unable to allocate TLS+TCB for the primary thread");
|
||||||
} else {
|
} else {
|
||||||
if (heap_api) {
|
if (heap_api) {
|
||||||
addr_out = heap_api->heap_malloc(total_tls_size);
|
addr_out = Core::ExecuteGuest(heap_api->heap_malloc, total_tls_size);
|
||||||
} else {
|
} else {
|
||||||
addr_out = std::malloc(total_tls_size);
|
addr_out = std::malloc(total_tls_size);
|
||||||
}
|
}
|
||||||
@ -422,7 +422,7 @@ void* Linker::AllocateTlsForThread(bool is_primary) {
|
|||||||
|
|
||||||
void Linker::FreeTlsForNonPrimaryThread(void* pointer) {
|
void Linker::FreeTlsForNonPrimaryThread(void* pointer) {
|
||||||
if (heap_api) {
|
if (heap_api) {
|
||||||
heap_api->heap_free(pointer);
|
Core::ExecuteGuest(heap_api->heap_free, pointer);
|
||||||
} else {
|
} else {
|
||||||
std::free(pointer);
|
std::free(pointer);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,8 +97,7 @@ Module::~Module() = default;
|
|||||||
s32 Module::Start(u64 args, const void* argp, void* param) {
|
s32 Module::Start(u64 args, const void* argp, void* param) {
|
||||||
LOG_INFO(Core_Linker, "Module started : {}", name);
|
LOG_INFO(Core_Linker, "Module started : {}", name);
|
||||||
const VAddr addr = dynamic_info.init_virtual_addr + GetBaseAddress();
|
const VAddr addr = dynamic_info.init_virtual_addr + GetBaseAddress();
|
||||||
Core::EnsureThreadInitialized();
|
return ExecuteGuest(reinterpret_cast<EntryFunc>(addr), args, argp, param);
|
||||||
return reinterpret_cast<EntryFunc>(addr)(args, argp, param);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::LoadModuleToMemory(u32& max_tls_index) {
|
void Module::LoadModuleToMemory(u32& max_tls_index) {
|
||||||
|
|||||||
@ -45,6 +45,29 @@ 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>
|
||||||
|
#ifdef __clang__
|
||||||
|
__attribute__((optnone))
|
||||||
|
#else
|
||||||
|
__attribute__((optimize("O0")))
|
||||||
|
#endif
|
||||||
|
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
|
||||||
|
auto* tcb = GetTcbBase();
|
||||||
|
if (tcb != nullptr && tcb->tcb_fiber == nullptr) {
|
||||||
|
ClearStack<12_KB>();
|
||||||
|
}
|
||||||
|
return func(std::forward<CallArgs>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
template <class F, F f>
|
template <class F, F f>
|
||||||
struct HostCallWrapperImpl;
|
struct HostCallWrapperImpl;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user