mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-06-07 18:25:00 -06:00
Merge branch 'fontlib' of https://github.com/w1naenator/shadPS4 into fontlib
This commit is contained in:
commit
c3948bff95
@ -36,6 +36,18 @@ public:
|
|||||||
return ORBIS_KERNEL_ERROR_EBADF;
|
return ORBIS_KERNEL_ERROR_EBADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual s64 write(const void* buf, u64 nbytes) {
|
||||||
|
return ORBIS_KERNEL_ERROR_EBADF;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual s64 writev(const Libraries::Kernel::OrbisKernelIovec* iov, s32 iovcnt) {
|
||||||
|
return ORBIS_KERNEL_ERROR_EBADF;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual s64 pwritev(const Libraries::Kernel::OrbisKernelIovec* iov, s32 iovcnt, s64 offset) {
|
||||||
|
return ORBIS_KERNEL_ERROR_EBADF;
|
||||||
|
}
|
||||||
|
|
||||||
virtual s64 lseek(s64 offset, s32 whence) {
|
virtual s64 lseek(s64 offset, s32 whence) {
|
||||||
return ORBIS_KERNEL_ERROR_EBADF;
|
return ORBIS_KERNEL_ERROR_EBADF;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "fiber.h"
|
#include "fiber.h"
|
||||||
@ -6,8 +6,8 @@
|
|||||||
#include "common/elf_info.h"
|
#include "common/elf_info.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "core/libraries/fiber/fiber_error.h"
|
#include "core/libraries/fiber/fiber_error.h"
|
||||||
|
#include "core/libraries/kernel/threads/pthread.h"
|
||||||
#include "core/libraries/libs.h"
|
#include "core/libraries/libs.h"
|
||||||
#include "core/tls.h"
|
|
||||||
|
|
||||||
namespace Libraries::Fiber {
|
namespace Libraries::Fiber {
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ static constexpr u64 kFiberStackSizeCheck = 0xdeadbeefdeadbeef;
|
|||||||
static std::atomic<u32> context_size_check = false;
|
static std::atomic<u32> context_size_check = false;
|
||||||
|
|
||||||
OrbisFiberContext* GetFiberContext() {
|
OrbisFiberContext* GetFiberContext() {
|
||||||
return Core::GetTcbBase()->tcb_fiber;
|
return Libraries::Kernel::g_curthread->tcb->tcb_fiber;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" s32 PS4_SYSV_ABI _sceFiberSetJmp(OrbisFiberContext* ctx) asm("_sceFiberSetJmp");
|
extern "C" s32 PS4_SYSV_ABI _sceFiberSetJmp(OrbisFiberContext* ctx) asm("_sceFiberSetJmp");
|
||||||
@ -269,7 +269,7 @@ s32 PS4_SYSV_ABI sceFiberRunImpl(OrbisFiber* fiber, void* addr_context, u64 size
|
|||||||
return ORBIS_FIBER_ERROR_INVALID;
|
return ORBIS_FIBER_ERROR_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::Tcb* tcb = Core::GetTcbBase();
|
Core::Tcb* tcb = Libraries::Kernel::g_curthread->tcb;
|
||||||
if (tcb->tcb_fiber) {
|
if (tcb->tcb_fiber) {
|
||||||
return ORBIS_FIBER_ERROR_PERMISSION;
|
return ORBIS_FIBER_ERROR_PERMISSION;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -311,6 +311,9 @@ s64 PS4_SYSV_ABI write(s32 fd, const void* buf, u64 nbytes) {
|
|||||||
} else if (file->type == Core::FileSys::FileType::Socket) {
|
} else if (file->type == Core::FileSys::FileType::Socket) {
|
||||||
// Socket functions handle errnos internally.
|
// Socket functions handle errnos internally.
|
||||||
return file->socket->SendPacket(buf, nbytes, 0, nullptr, 0);
|
return file->socket->SendPacket(buf, nbytes, 0, nullptr, 0);
|
||||||
|
} else if (file->type == Core::FileSys::FileType::Directory) {
|
||||||
|
*__Error() = POSIX_EBADF;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return file->f.WriteRaw<u8>(buf, nbytes);
|
return file->f.WriteRaw<u8>(buf, nbytes);
|
||||||
@ -405,7 +408,11 @@ s64 PS4_SYSV_ABI writev(s32 fd, const OrbisKernelIovec* iov, s32 iovcnt) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
} else if (file->type == Core::FileSys::FileType::Directory) {
|
||||||
|
*__Error() = POSIX_EBADF;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
s64 total_written = 0;
|
s64 total_written = 0;
|
||||||
for (s32 i = 0; i < iovcnt; i++) {
|
for (s32 i = 0; i < iovcnt; i++) {
|
||||||
total_written += file->f.WriteRaw<u8>(iov[i].iov_base, iov[i].iov_len);
|
total_written += file->f.WriteRaw<u8>(iov[i].iov_base, iov[i].iov_len);
|
||||||
@ -1047,7 +1054,11 @@ s64 PS4_SYSV_ABI posix_pwritev(s32 fd, const OrbisKernelIovec* iov, s32 iovcnt,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
} else if (file->type == Core::FileSys::FileType::Directory) {
|
||||||
|
*__Error() = POSIX_EBADF;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const s64 pos = file->f.Tell();
|
const s64 pos = file->f.Tell();
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
file->f.Seek(pos);
|
file->f.Seek(pos);
|
||||||
|
|||||||
@ -368,7 +368,7 @@ bool Linker::Resolve(const std::string& name, Loader::SymbolType sym_type, Modul
|
|||||||
void* Linker::TlsGetAddr(u64 module_index, u64 offset) {
|
void* Linker::TlsGetAddr(u64 module_index, u64 offset) {
|
||||||
std::scoped_lock lk{mutex};
|
std::scoped_lock lk{mutex};
|
||||||
|
|
||||||
DtvEntry* dtv_table = GetTcbBase()->tcb_dtv;
|
DtvEntry* dtv_table = Libraries::Kernel::g_curthread->tcb->tcb_dtv;
|
||||||
if (dtv_table[0].counter != dtv_generation_counter) {
|
if (dtv_table[0].counter != dtv_generation_counter) {
|
||||||
// Generation counter changed, a dynamic module was either loaded or unloaded.
|
// Generation counter changed, a dynamic module was either loaded or unloaded.
|
||||||
const u32 old_num_dtvs = dtv_table[1].counter;
|
const u32 old_num_dtvs = dtv_table[1].counter;
|
||||||
@ -381,7 +381,7 @@ void* Linker::TlsGetAddr(u64 module_index, u64 offset) {
|
|||||||
delete[] dtv_table;
|
delete[] dtv_table;
|
||||||
|
|
||||||
// Update TCB pointer.
|
// Update TCB pointer.
|
||||||
GetTcbBase()->tcb_dtv = new_dtv_table;
|
Libraries::Kernel::g_curthread->tcb->tcb_dtv = new_dtv_table;
|
||||||
dtv_table = new_dtv_table;
|
dtv_table = new_dtv_table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@ -46,10 +46,6 @@ void SetTcbBase(void* image_address) {
|
|||||||
ASSERT(result != 0);
|
ASSERT(result != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tcb* GetTcbBase() {
|
|
||||||
return reinterpret_cast<Tcb*>(TlsGetValue(GetTcbKey()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(__APPLE__) && defined(ARCH_X86_64)
|
#elif defined(__APPLE__) && defined(ARCH_X86_64)
|
||||||
|
|
||||||
// Apple x86_64
|
// Apple x86_64
|
||||||
@ -149,12 +145,6 @@ void SetTcbBase(void* image_address) {
|
|||||||
"Failed to store thread LDT page pointer: {}", errno);
|
"Failed to store thread LDT page pointer: {}", errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tcb* GetTcbBase() {
|
|
||||||
Tcb* tcb;
|
|
||||||
asm volatile("mov %%fs:0x0, %0" : "=r"(tcb));
|
|
||||||
return tcb;
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(ARCH_X86_64)
|
#elif defined(ARCH_X86_64)
|
||||||
|
|
||||||
// Other POSIX x86_64
|
// Other POSIX x86_64
|
||||||
@ -164,13 +154,6 @@ void SetTcbBase(void* image_address) {
|
|||||||
ASSERT_MSG(ret == 0, "Failed to set GS base: errno {}", errno);
|
ASSERT_MSG(ret == 0, "Failed to set GS base: errno {}", errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tcb* GetTcbBase() {
|
|
||||||
void* tcb = nullptr;
|
|
||||||
const int ret = syscall(SYS_arch_prctl, ARCH_GET_GS, &tcb);
|
|
||||||
ASSERT_MSG(ret == 0, "Failed to get GS base: errno {}", errno);
|
|
||||||
return static_cast<Tcb*>(tcb);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// POSIX non-x86_64
|
// POSIX non-x86_64
|
||||||
@ -193,10 +176,6 @@ void SetTcbBase(void* image_address) {
|
|||||||
ASSERT(pthread_setspecific(GetTcbKey(), image_address) == 0);
|
ASSERT(pthread_setspecific(GetTcbKey(), image_address) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tcb* GetTcbBase() {
|
|
||||||
return static_cast<Tcb*>(pthread_getspecific(GetTcbKey()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
thread_local std::once_flag init_tls_flag;
|
thread_local std::once_flag init_tls_flag;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@ -36,9 +36,6 @@ u32 GetTcbKey();
|
|||||||
/// Sets the data pointer to the TCB block.
|
/// Sets the data pointer to the TCB block.
|
||||||
void SetTcbBase(void* image_address);
|
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.
|
/// Makes sure TLS is initialized for the thread before entering guest.
|
||||||
void EnsureThreadInitialized();
|
void EnsureThreadInitialized();
|
||||||
|
|
||||||
|
|||||||
@ -58,10 +58,11 @@ Frontend::WindowSDL* g_window = nullptr;
|
|||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
Emulator::Emulator() {
|
Emulator::Emulator() {
|
||||||
// Initialize NT API functions and set high priority
|
// Initialize NT API functions, set high priority and disable WER
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
Common::NtApi::Initialize();
|
Common::NtApi::Initialize();
|
||||||
SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
|
SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
|
||||||
|
SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX);
|
||||||
// need to init this in order for winsock2 to work
|
// need to init this in order for winsock2 to work
|
||||||
WORD versionWanted = MAKEWORD(2, 2);
|
WORD versionWanted = MAKEWORD(2, 2);
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user