common: Rewrite logging based on cut down citra logger (#86)

* common: Rewrite logging based on cut down Citra logger

* code: Misc fixes

* core: Bring back tls handler

* linker: Cleanup

* config: Remove log level

* logging: Enable console output by default

* core: Fix windows build
This commit is contained in:
GPUCode 2024-02-28 00:10:34 +02:00 committed by GitHub
parent b3084646a8
commit 79d6c8a377
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
70 changed files with 3212 additions and 1541 deletions

View file

@ -2,14 +2,13 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "Util/config.h"
#include "common/log.h"
#include "common/logging/log.h"
#include "core/hle/kernel/cpu_management.h"
#include "core/hle/libraries/libs.h"
namespace Core::Kernel {
int PS4_SYSV_ABI sceKernelIsNeoMode() {
PRINT_FUNCTION_NAME();
LOG_INFO(Kernel_Sce, "called");
return Config::isNeoMode();
}

View file

@ -1,51 +1,44 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/debug.h"
#include "common/log.h"
#include "common/assert.h"
#include "common/logging/log.h"
#include "core/hle/error_codes.h"
#include "core/hle/kernel/event_queues.h"
#include "core/hle/libraries/libs.h"
namespace Core::Kernel {
constexpr bool log_file_equeues = true; // disable it to disable logging
int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name) {
PRINT_FUNCTION_NAME();
if (eq == nullptr) {
LOG_TRACE_IF(log_file_equeues,
"sceKernelCreateEqueue returned SCE_KERNEL_ERROR_EINVAL eq invalid\n");
LOG_ERROR(Kernel_Event, "Event queue is null!");
return SCE_KERNEL_ERROR_EINVAL;
}
if (name == nullptr) {
LOG_TRACE_IF(log_file_equeues,
"sceKernelCreateEqueue returned SCE_KERNEL_ERROR_EFAULT name invalid\n");
LOG_ERROR(Kernel_Event, "Event queue name is invalid!");
return SCE_KERNEL_ERROR_EFAULT;
}
if (name == NULL) {
LOG_TRACE_IF(log_file_equeues,
"sceKernelCreateEqueue returned SCE_KERNEL_ERROR_EINVAL name is null\n");
LOG_ERROR(Kernel_Event, "Event queue name is null!");
return SCE_KERNEL_ERROR_EINVAL;
}
if (strlen(name) > 31) { // max is 32 including null terminator
LOG_TRACE_IF(log_file_equeues,
"sceKernelCreateEqueue returned SCE_KERNEL_ERROR_ENAMETOOLONG name size "
"exceeds 32 bytes\n");
// Maximum is 32 including null terminator
static constexpr size_t MaxEventQueueNameSize = 32;
if (std::strlen(name) > MaxEventQueueNameSize) {
LOG_ERROR(Kernel_Event, "Event queue name exceeds 32 bytes!");
return SCE_KERNEL_ERROR_ENAMETOOLONG;
}
LOG_INFO(Kernel_Event, "name = {}", name);
*eq = new EqueueInternal;
(*eq)->setName(std::string(name));
LOG_INFO_IF(log_file_equeues, "sceKernelCreateEqueue created with name \"{}\"\n", name);
return SCE_OK;
}
int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, SceKernelEvent* ev, int num, int* out,
SceKernelUseconds* timo) {
PRINT_FUNCTION_NAME();
LOG_INFO(Kernel_Event, "num = {}", num);
if (eq == nullptr) {
return SCE_KERNEL_ERROR_EBADF;
@ -66,10 +59,10 @@ int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, SceKernelEvent* ev, int
if (timo != nullptr) {
// Only events that have already arrived at the time of this function call can be received
if (*timo == 0) {
BREAKPOINT();
UNREACHABLE();
} else {
// Wait until an event arrives with timing out
BREAKPOINT();
UNREACHABLE();
}
}

View file

@ -2,106 +2,85 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <bit>
#include <magic_enum.hpp>
#include "common/debug.h"
#include "common/log.h"
#include "common/assert.h"
#include "common/logging/log.h"
#include "common/singleton.h"
#include "core/PS4/GPU/gpu_memory.h"
#include "core/hle/error_codes.h"
#include "core/hle/kernel/Objects/physical_memory.h"
#include "core/hle/kernel/memory_management.h"
#include "core/hle/libraries/libs.h"
#include "core/virtual_memory.h"
namespace Core::Kernel {
constexpr bool log_file_memory = true; // disable it to disable logging
bool is16KBAligned(u64 n) {
return ((n % (16ull * 1024) == 0));
}
u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() {
PRINT_FUNCTION_NAME();
LOG_WARNING(Kernel_Vmm, "(STUBBED) called");
return SCE_KERNEL_MAIN_DMEM_SIZE;
}
int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len,
u64 alignment, int memoryType, s64* physAddrOut) {
PRINT_FUNCTION_NAME();
LOG_INFO(Kernel_Vmm,
"searchStart = {:#x}, searchEnd = {:#x}, len = {:#x}, alignment = {:#x}, memoryType = "
"{:#x}",
searchStart, searchEnd, len, alignment, memoryType);
if (searchStart < 0 || searchEnd <= searchStart) {
LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned "
"SCE_KERNEL_ERROR_EINVAL searchStart,searchEnd invalid\n");
LOG_ERROR(Kernel_Vmm, "Provided address range is invalid!");
return SCE_KERNEL_ERROR_EINVAL;
}
bool isInRange = (searchStart < len && searchEnd > len);
if (len <= 0 || !is16KBAligned(len) || !isInRange) {
LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned "
"SCE_KERNEL_ERROR_EINVAL memory range invalid\n");
const bool is_in_range = (searchStart < len && searchEnd > len);
if (len <= 0 || !is16KBAligned(len) || !is_in_range) {
LOG_ERROR(Kernel_Vmm, "Provided address range is invalid!");
return SCE_KERNEL_ERROR_EINVAL;
}
if ((alignment != 0 || is16KBAligned(alignment)) && !std::has_single_bit(alignment)) {
LOG_TRACE_IF(
log_file_memory,
"sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EINVAL alignment invalid\n");
LOG_ERROR(Kernel_Vmm, "Alignment value is invalid!");
return SCE_KERNEL_ERROR_EINVAL;
}
if (physAddrOut == nullptr) {
LOG_TRACE_IF(
log_file_memory,
"sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EINVAL physAddrOut is null\n");
LOG_ERROR(Kernel_Vmm, "Result physical address pointer is null!");
return SCE_KERNEL_ERROR_EINVAL;
}
auto memtype = magic_enum::enum_cast<MemoryTypes>(memoryType);
LOG_INFO_IF(log_file_memory, "search_start = {:#x}\n", searchStart);
LOG_INFO_IF(log_file_memory, "search_end = {:#x}\n", searchEnd);
LOG_INFO_IF(log_file_memory, "len = {:#x}\n", len);
LOG_INFO_IF(log_file_memory, "alignment = {:#x}\n", alignment);
LOG_INFO_IF(log_file_memory, "memory_type = {}\n", magic_enum::enum_name(memtype.value()));
u64 physical_addr = 0;
auto* physical_memory = Common::Singleton<PhysicalMemory>::Instance();
if (!physical_memory->Alloc(searchStart, searchEnd, len, alignment, &physical_addr,
memoryType)) {
LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned "
"SCE_KERNEL_ERROR_EAGAIN can't allocate physical memory\n");
LOG_CRITICAL(Kernel_Vmm, "Unable to allocate physical memory");
return SCE_KERNEL_ERROR_EAGAIN;
}
*physAddrOut = static_cast<s64>(physical_addr);
LOG_INFO_IF(true, "physAddrOut = {:#x}\n", physical_addr);
LOG_INFO(Kernel_Vmm, "physAddrOut = {:#x}", physical_addr);
return SCE_OK;
}
int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int flags,
s64 directMemoryStart, u64 alignment) {
PRINT_FUNCTION_NAME();
LOG_INFO(
Kernel_Vmm,
"len = {:#x}, prot = {:#x}, flags = {:#x}, directMemoryStart = {:#x}, alignment = {:#x}",
len, prot, flags, directMemoryStart, alignment);
if (len == 0 || !is16KBAligned(len)) {
LOG_TRACE_IF(log_file_memory,
"sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL len invalid\n");
LOG_ERROR(Kernel_Vmm, "Map size is either zero or not 16KB aligned!");
return SCE_KERNEL_ERROR_EINVAL;
}
if (!is16KBAligned(directMemoryStart)) {
LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL "
"directMemoryStart invalid\n");
LOG_ERROR(Kernel_Vmm, "Start address is not 16KB aligned!");
return SCE_KERNEL_ERROR_EINVAL;
}
if (alignment != 0) {
if ((!std::has_single_bit(alignment) && !is16KBAligned(alignment))) {
LOG_TRACE_IF(
log_file_memory,
"sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL alignment invalid\n");
LOG_ERROR(Kernel_Vmm, "Alignment value is invalid!");
return SCE_KERNEL_ERROR_EINVAL;
}
}
LOG_INFO_IF(log_file_memory, "len = {:#x}\n", len);
LOG_INFO_IF(log_file_memory, "prot = {:#x}\n", prot);
LOG_INFO_IF(log_file_memory, "flags = {:#x}\n", flags);
LOG_INFO_IF(log_file_memory, "directMemoryStart = {:#x}\n", directMemoryStart);
LOG_INFO_IF(log_file_memory, "alignment = {:#x}\n", alignment);
VirtualMemory::MemoryMode cpu_mode = VirtualMemory::MemoryMode::NoAccess;
GPU::MemoryMode gpu_mode = GPU::MemoryMode::NoAccess;
@ -112,7 +91,7 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl
gpu_mode = GPU::MemoryMode::ReadWrite;
break;
default:
BREAKPOINT();
UNREACHABLE();
}
auto in_addr = reinterpret_cast<u64>(*addr);
@ -121,8 +100,7 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl
if (flags == 0) {
out_addr = VirtualMemory::memory_alloc_aligned(in_addr, len, cpu_mode, alignment);
}
LOG_INFO_IF(log_file_memory, "in_addr = {:#x}\n", in_addr);
LOG_INFO_IF(log_file_memory, "out_addr = {:#x}\n", out_addr);
LOG_INFO(Kernel_Vmm, "in_addr = {:#x}, out_addr = {:#x}", in_addr, out_addr);
*addr = reinterpret_cast<void*>(out_addr); // return out_addr to first functions parameter
@ -132,7 +110,7 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl
auto* physical_memory = Common::Singleton<PhysicalMemory>::Instance();
if (!physical_memory->Map(out_addr, directMemoryStart, len, prot, cpu_mode, gpu_mode)) {
BREAKPOINT();
UNREACHABLE();
}
if (gpu_mode != GPU::MemoryMode::NoAccess) {

View file

@ -3,7 +3,7 @@
#include <cstdlib>
#include "common/debug.h"
#include "common/log.h"
#include "common/logging/log.h"
#include "common/singleton.h"
#include "core/hle/libraries/libc/libc.h"
#include "core/hle/libraries/libc/libc_cxa.h"
@ -49,15 +49,15 @@ void PS4_SYSV_ABI ps4___cxa_pure_virtual() {
}
static PS4_SYSV_ABI void ps4_init_env() {
PRINT_DUMMY_FUNCTION_NAME();
LOG_INFO(Lib_LibC, "called");
}
static PS4_SYSV_ABI void ps4_catchReturnFromMain(int status) {
LOG_INFO_IF(log_file_libc, "catchReturnFromMain returned ={}\n", status);
LOG_INFO(Lib_LibC, "returned = {}", status);
}
static PS4_SYSV_ABI void ps4__Assert() {
PRINT_DUMMY_FUNCTION_NAME();
LOG_INFO(Lib_LibC, "called");
BREAKPOINT();
}
@ -66,18 +66,18 @@ PS4_SYSV_ABI void ps4__ZdlPv(void* ptr) {
}
PS4_SYSV_ABI void ps4__ZSt11_Xbad_allocv() {
PRINT_DUMMY_FUNCTION_NAME();
LOG_INFO(Lib_LibC, "called");
BREAKPOINT();
}
PS4_SYSV_ABI void ps4__ZSt14_Xlength_errorPKc() {
PRINT_DUMMY_FUNCTION_NAME();
LOG_INFO(Lib_LibC, "called");
BREAKPOINT();
}
PS4_SYSV_ABI void* ps4__Znwm(u64 count) {
if (count == 0) {
LOG_ERROR_IF(log_file_libc, "_Znwm count ={}\n", count);
LOG_INFO(Lib_LibC, "_Znwm count ={}", count);
BREAKPOINT();
}
void* ptr = std::malloc(count);
@ -457,6 +457,7 @@ void libcSymbolsRegister(Loader::SymbolsResolver* sym) {
LIB_FUNCTION("8zTFvBIAIN8", "libc", 1, "libc", 1, 1, ps4_memset);
// stdio functions
LIB_FUNCTION("xeYO4u7uyJ0", "libc", 1, "libc", 1, 1, ps4_fopen);
LIB_FUNCTION("hcuQgD53UxM", "libc", 1, "libc", 1, 1, ps4_printf);
LIB_FUNCTION("Q2V+iqvjgC0", "libc", 1, "libc", 1, 1, ps4_vsnprintf);
LIB_FUNCTION("YQ0navp+YIc", "libc", 1, "libc", 1, 1, ps4_puts);

View file

@ -1,8 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/debug.h"
#include "common/log.h"
#include "common/logging/log.h"
#include "core/hle/libraries/libc/libc_cxa.h"
// adapted from
@ -10,8 +9,6 @@
namespace Core::Libraries::LibC {
constexpr bool log_file_cxa = true; // disable it to disable logging
// This file implements the __cxa_guard_* functions as defined at:
// http://www.codesourcery.com/public/cxx-abi/abi.html
//
@ -103,8 +100,7 @@ int PS4_SYSV_ABI ps4___cxa_guard_acquire(u64* guard_object) {
int result = ::pthread_mutex_lock(guard_mutex());
if (result != 0) {
LOG_TRACE_IF(log_file_cxa, "__cxa_guard_acquire(): pthread_mutex_lock failed with {}\n",
result);
LOG_ERROR(Lib_LibC, "pthread_mutex_lock failed with {}", result);
}
// At this point all other threads will block in __cxa_guard_acquire()
@ -112,8 +108,7 @@ int PS4_SYSV_ABI ps4___cxa_guard_acquire(u64* guard_object) {
if (initializerHasRun(guard_object)) {
int result = ::pthread_mutex_unlock(guard_mutex());
if (result != 0) {
LOG_TRACE_IF(log_file_cxa,
"__cxa_guard_acquire(): pthread_mutex_unlock failed with {}\n", result);
LOG_ERROR(Lib_LibC, "pthread_mutex_lock failed with {}", result);
}
return 0;
}
@ -123,8 +118,8 @@ int PS4_SYSV_ABI ps4___cxa_guard_acquire(u64* guard_object) {
// But if the same thread can call __cxa_guard_acquire() on the
// *same* guard object again, we call abort();
if (inUse(guard_object)) {
LOG_TRACE_IF(log_file_cxa, "__cxa_guard_acquire(): initializer for function local static "
"variable called enclosing function\n");
LOG_ERROR(Lib_LibC,
"initializer for function local static variable called enclosing function");
}
// mark this guard object as being in use
@ -146,8 +141,7 @@ void PS4_SYSV_ABI ps4___cxa_guard_release(u64* guard_object) {
// release global mutex
int result = ::pthread_mutex_unlock(guard_mutex());
if (result != 0) {
LOG_TRACE_IF(log_file_cxa, "__cxa_guard_acquire(): pthread_mutex_unlock failed with {}\n",
result);
LOG_ERROR(Lib_LibC, "pthread_mutex_unlock failed with {}", result);
}
}
@ -157,8 +151,7 @@ void PS4_SYSV_ABI ps4___cxa_guard_release(u64* guard_object) {
void PS4_SYSV_ABI ps4___cxa_guard_abort(u64* guard_object) {
int result = ::pthread_mutex_unlock(guard_mutex());
if (result != 0) {
LOG_TRACE_IF(log_file_cxa, "__cxa_guard_abort(): pthread_mutex_unlock failed with {}\n",
result);
LOG_ERROR(Lib_LibC, "pthread_mutex_unlock failed with {}", result);
}
// now reset state, so possible to try to initialize again

View file

@ -1,13 +1,17 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/debug.h"
#include "common/log.h"
#include "common/assert.h"
#include "common/singleton.h"
#include "core/file_sys/fs.h"
#include "core/hle/libraries/libc/libc_stdio.h"
namespace Core::Libraries::LibC {
constexpr bool log_file_libc = true; // disable it to disable logging
std::FILE* PS4_SYSV_ABI ps4_fopen(const char* filename, const char* mode) {
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
return std::fopen(mnt->GetHostFile(filename).c_str(), mode);
}
int PS4_SYSV_ABI ps4_printf(VA_ARGS) {
VA_CTX(ctx);
@ -20,8 +24,8 @@ int PS4_SYSV_ABI ps4_fprintf(FILE* file, VA_ARGS) {
VA_CTX(ctx);
return printf_ctx(&ctx);
}
LOG_ERROR_IF(log_file_libc, "libc:Unimplemented fprintf case\n");
BREAKPOINT();
UNREACHABLE_MSG("Unimplemented fprintf case");
return 0;
}

View file

@ -8,6 +8,7 @@
namespace Core::Libraries::LibC {
std::FILE* PS4_SYSV_ABI ps4_fopen(const char* filename, const char* mode);
int PS4_SYSV_ABI ps4_printf(VA_ARGS);
int PS4_SYSV_ABI ps4_vsnprintf(char* s, size_t n, const char* format, VaList* arg);
int PS4_SYSV_ABI ps4_puts(const char* s);

View file

@ -2,24 +2,18 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <cstdlib>
#include "common/debug.h"
#include "common/log.h"
#include "common/assert.h"
#include "core/hle/libraries/libc/libc_stdlib.h"
namespace Core::Libraries::LibC {
constexpr bool log_file_libc = true; // disable it to disable logging
void PS4_SYSV_ABI ps4_exit(int code) {
std::exit(code);
}
int PS4_SYSV_ABI ps4_atexit(void (*func)()) {
int rt = std::atexit(func);
if (rt != 0) {
LOG_ERROR_IF(log_file_libc, "atexit returned {}\n", rt);
BREAKPOINT();
}
ASSERT_MSG(rt == 0, "atexit returned {}", rt);
return rt;
}

View file

@ -59,6 +59,7 @@
#include <cstdbool>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <string>
#include "va_ctx.h"

View file

@ -1,8 +1,8 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/debug.h"
#include "common/log.h"
#include "common/assert.h"
#include "common/logging/log.h"
#include "common/singleton.h"
#include "core/file_sys/fs.h"
#include "core/hle/error_codes.h"
@ -11,45 +11,41 @@
namespace Core::Libraries::LibKernel {
constexpr bool log_file_fs = true; // disable it to disable logging
int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) {
LOG_INFO_IF(log_file_fs, "sceKernelOpen path = {} flags = {:#x} mode = {:#x}\n", path, flags,
mode);
LOG_INFO(Kernel_Fs, "path = {} flags = {:#x} mode = {:#x}", path, flags, mode);
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
// only open files support!
u32 handle = h->createHandle();
auto* file = h->getFile(handle);
u32 handle = h->CreateHandle();
auto* file = h->GetFile(handle);
file->m_guest_name = path;
file->m_host_name = mnt->getHostFile(file->m_guest_name);
file->m_host_name = mnt->GetHostFile(file->m_guest_name);
bool result = file->f.open(file->m_host_name);
if (!result) {
h->deleteHandle(handle);
file->f.Open(file->m_host_name, Common::FS::FileAccessMode::Read);
if (!file->f.IsOpen()) {
h->DeleteHandle(handle);
return SCE_KERNEL_ERROR_EACCES;
}
file->isOpened = true;
file->is_opened = true;
return handle;
}
int PS4_SYSV_ABI posix_open(const char* path, int flags, /* SceKernelMode*/ u16 mode) {
LOG_INFO_IF(log_file_fs, "posix open redirect to sceKernelOpen\n");
LOG_INFO(Kernel_Fs, "posix open redirect to sceKernelOpen\n");
int result = sceKernelOpen(path, flags, mode);
if (result < 0) {
BREAKPOINT(); // posix calls different only for their return values
}
// Posix calls different only for their return values
ASSERT(result >= 0);
return result;
}
size_t PS4_SYSV_ABI _readv(int d, const SceKernelIovec* iov, int iovcnt) {
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* file = h->getFile(d);
auto* file = h->GetFile(d);
size_t total_read = 0;
file->m_mutex.lock();
for (int i = 0; i < iovcnt; i++) {
total_read += file->f.readBytes(iov[i].iov_base, iov[i].iov_len).second;
total_read += file->f.ReadRaw<u8>(iov[i].iov_base, iov[i].iov_len);
}
file->m_mutex.unlock();
return total_read;

View file

@ -13,7 +13,7 @@ namespace Core::Libraries::LibKernel {
struct SceKernelIovec {
void* iov_base;
size_t iov_len;
std::size_t iov_len;
};
int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, /* SceKernelMode*/ u16 mode);

View file

@ -1,10 +1,8 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/debug.h"
#include "common/log.h"
#include "common/singleton.h"
#include "core/hle/kernel/Objects/physical_memory.h"
#include "common/assert.h"
#include "common/logging/log.h"
#include "core/hle/kernel/cpu_management.h"
#include "core/hle/kernel/event_queues.h"
#include "core/hle/kernel/memory_management.h"
@ -24,21 +22,19 @@
namespace Core::Libraries::LibKernel {
constexpr bool log_libkernel_file = true; // disable it to disable logging
static u64 g_stack_chk_guard = 0xDEADBEEF54321ABC; // dummy return
int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len) {
BREAKPOINT();
UNREACHABLE();
return 0;
}
static PS4_SYSV_ABI void stack_chk_fail() {
BREAKPOINT();
UNREACHABLE();
}
int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) {
BREAKPOINT();
UNREACHABLE();
}
void PS4_SYSV_ABI sceKernelUsleep(unsigned int microseconds) {
@ -71,10 +67,9 @@ int* PS4_SYSV_ABI __Error() {
int PS4_SYSV_ABI sceKernelMmap(void* addr, u64 len, int prot, int flags, int fd, off_t offset,
void** res) {
#ifdef _WIN64
PRINT_FUNCTION_NAME();
if (prot > 3) // READ,WRITE or bitwise READ | WRITE supported
{
LOG_ERROR_IF(log_libkernel_file, "sceKernelMmap prot ={} not supported\n", prot);
LOG_INFO(Kernel_Vmm, "called");
if (prot > 3) {
LOG_ERROR(Kernel_Vmm, "prot = {} not supported", prot);
}
DWORD flProtect;
if (prot & PROT_WRITE) {
@ -114,13 +109,11 @@ int PS4_SYSV_ABI sceKernelMmap(void* addr, u64 len, int prot, int flags, int fd,
PS4_SYSV_ABI void* posix_mmap(void* addr, u64 len, int prot, int flags, int fd, u64 offset) {
void* ptr;
LOG_INFO_IF(log_libkernel_file, "posix mmap redirect to sceKernelMmap\n");
LOG_INFO(Kernel_Vmm, "posix mmap redirect to sceKernelMmap\n");
// posix call the difference is that there is a different behaviour when it doesn't return 0 or
// SCE_OK
int result = sceKernelMmap(addr, len, prot, flags, fd, offset, &ptr);
if (result != 0) {
BREAKPOINT();
}
ASSERT(result == 0);
return ptr;
}

View file

@ -1,8 +1,8 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/debug.h"
#include "common/log.h"
#include "common/assert.h"
#include "common/logging/log.h"
#include "core/hle/error_codes.h"
#include "core/hle/libraries/libkernel/thread_management.h"
#include "core/hle/libraries/libs.h"
@ -12,8 +12,6 @@ namespace Core::Libraries::LibKernel {
thread_local ScePthread g_pthread_self{};
PThreadCxt* g_pthread_cxt = nullptr;
constexpr bool log_pthread_file = true; // disable it to disable logging
void init_pthreads() {
g_pthread_cxt = new PThreadCxt{};
// default mutex init
@ -73,9 +71,7 @@ int PS4_SYSV_ABI scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachst
pstate = PTHREAD_CREATE_DETACHED;
break;
default:
LOG_TRACE_IF(log_pthread_file, "scePthreadAttrSetdetachstate invalid detachstate: {}\n",
detachstate);
std::exit(0);
UNREACHABLE_MSG("Invalid detachstate: {}", detachstate);
}
// int result = pthread_attr_setdetachstate(&(*attr)->pth_attr, pstate); doesn't seem to work
@ -101,9 +97,7 @@ int PS4_SYSV_ABI scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inherit
pinherit_sched = PTHREAD_INHERIT_SCHED;
break;
default:
LOG_TRACE_IF(log_pthread_file, "scePthreadAttrSetinheritsched invalid inheritSched: {}\n",
inheritSched);
std::exit(0);
UNREACHABLE_MSG("Invalid inheritSched: {}", inheritSched);
}
int result = pthread_attr_setinheritsched(&(*attr)->pth_attr, pinherit_sched);
@ -138,9 +132,7 @@ int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy)
int ppolicy = SCHED_OTHER; // winpthreads only supports SCHED_OTHER
if (policy != SCHED_OTHER) {
LOG_TRACE_IF(log_pthread_file,
"scePthreadAttrSetschedpolicy policy={} not supported by winpthreads\n",
policy);
LOG_ERROR(Kernel_Pthread, "policy={} not supported by winpthreads\n", policy);
}
(*attr)->policy = policy;
@ -154,7 +146,7 @@ ScePthread PS4_SYSV_ABI scePthreadSelf() {
int PS4_SYSV_ABI scePthreadAttrSetaffinity(ScePthreadAttr* pattr,
const /*SceKernelCpumask*/ u64 mask) {
PRINT_FUNCTION_NAME();
LOG_INFO(Kernel_Pthread, "called");
if (pattr == nullptr || *pattr == nullptr) {
return SCE_KERNEL_ERROR_EINVAL;
@ -166,7 +158,7 @@ int PS4_SYSV_ABI scePthreadAttrSetaffinity(ScePthreadAttr* pattr,
}
int PS4_SYSV_ABI scePthreadSetaffinity(ScePthread thread, const /*SceKernelCpumask*/ u64 mask) {
PRINT_FUNCTION_NAME();
LOG_INFO(Kernel_Pthread, "called");
if (thread == nullptr) {
return SCE_KERNEL_ERROR_ESRCH;
@ -178,12 +170,10 @@ int PS4_SYSV_ABI scePthreadSetaffinity(ScePthread thread, const /*SceKernelCpuma
}
int PS4_SYSV_ABI scePthreadCreate(ScePthread* thread, const ScePthreadAttr* attr,
pthreadEntryFunc start_routine, void* arg, const char* name) {
PRINT_DUMMY_FUNCTION_NAME();
LOG_INFO(Kernel_Pthread, "(STUBBED) called");
return 0;
}
/****
* Mutex calls
*/
void* createMutex(void* addr) {
if (addr == nullptr || *static_cast<ScePthreadMutex*>(addr) != nullptr) {
return addr;
@ -197,7 +187,7 @@ void* createMutex(void* addr) {
int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr,
const char* name) {
PRINT_FUNCTION_NAME();
LOG_INFO(Kernel_Pthread, "called");
if (mutex == nullptr) {
return SCE_KERNEL_ERROR_EINVAL;
}
@ -215,7 +205,7 @@ int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMut
int result = pthread_mutex_init(&(*mutex)->pth_mutex, &(*attr)->pth_mutex_attr);
if (name != nullptr) {
LOG_INFO_IF(log_pthread_file, "mutex_init name={},result={}\n", name, result);
LOG_INFO(Kernel_Pthread, "name={}, result={}", name, result);
}
switch (result) {
@ -264,8 +254,7 @@ int PS4_SYSV_ABI scePthreadMutexattrSettype(ScePthreadMutexattr* attr, int type)
ptype = PTHREAD_MUTEX_NORMAL;
break;
default:
LOG_TRACE_IF(log_pthread_file, "scePthreadMutexattrSettype invalid type: {}\n", type);
std::exit(0);
UNREACHABLE_MSG("Invalid type: {}", type);
}
int result = pthread_mutexattr_settype(&(*attr)->pth_mutex_attr, ptype);
@ -286,9 +275,7 @@ int PS4_SYSV_ABI scePthreadMutexattrSetprotocol(ScePthreadMutexattr* attr, int p
pprotocol = PTHREAD_PRIO_PROTECT;
break;
default:
LOG_TRACE_IF(log_pthread_file, "scePthreadMutexattrSetprotocol invalid protocol: {}\n",
protocol);
std::exit(0);
UNREACHABLE_MSG("Invalid protocol: {}", protocol);
}
int result = 0; // pthread_mutexattr_setprotocol(&(*attr)->p, pprotocol); //it appears that
@ -298,7 +285,7 @@ int PS4_SYSV_ABI scePthreadMutexattrSetprotocol(ScePthreadMutexattr* attr, int p
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
}
int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex) {
PRINT_FUNCTION_NAME();
LOG_INFO(Kernel_Pthread, "called");
mutex = static_cast<ScePthreadMutex*>(createMutex(mutex));
if (mutex == nullptr) {
@ -306,8 +293,7 @@ int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex) {
}
int result = pthread_mutex_lock(&(*mutex)->pth_mutex);
LOG_INFO_IF(log_pthread_file, "scePthreadMutexLock name={} result={}\n", (*mutex)->name,
result);
LOG_INFO(Kernel_Pthread, "name={}, result={}", (*mutex)->name, result);
switch (result) {
case 0:
return SCE_OK;
@ -322,15 +308,14 @@ int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex) {
}
}
int PS4_SYSV_ABI scePthreadMutexUnlock(ScePthreadMutex* mutex) {
PRINT_FUNCTION_NAME();
LOG_INFO(Kernel_Pthread, "called");
mutex = static_cast<ScePthreadMutex*>(createMutex(mutex));
if (mutex == nullptr) {
return SCE_KERNEL_ERROR_EINVAL;
}
int result = pthread_mutex_unlock(&(*mutex)->pth_mutex);
LOG_INFO_IF(log_pthread_file, "scePthreadMutexUnlock name={} result={}\n", (*mutex)->name,
result);
LOG_INFO(Kernel_Pthread, "name={}, result={}", (*mutex)->name, result);
switch (result) {
case 0:
return SCE_OK;
@ -344,9 +329,6 @@ int PS4_SYSV_ABI scePthreadMutexUnlock(ScePthreadMutex* mutex) {
}
}
/****
* Cond calls
*/
void* createCond(void* addr) {
if (addr == nullptr || *static_cast<ScePthreadCond*>(addr) != nullptr) {
return addr;
@ -379,7 +361,7 @@ int PS4_SYSV_ABI scePthreadCondInit(ScePthreadCond* cond, const ScePthreadCondat
int result = pthread_cond_init(&(*cond)->cond, &(*attr)->cond_attr);
if (name != nullptr) {
LOG_INFO_IF(log_pthread_file, "cond init name={},result={}\n", (*cond)->name, result);
LOG_INFO(Kernel_Pthread, "name={}, result={}", (*cond)->name, result);
}
switch (result) {
@ -412,7 +394,7 @@ int PS4_SYSV_ABI scePthreadCondattrInit(ScePthreadCondattr* attr) {
}
int PS4_SYSV_ABI scePthreadCondBroadcast(ScePthreadCond* cond) {
PRINT_FUNCTION_NAME();
LOG_INFO(Kernel_Pthread, "called");
cond = static_cast<ScePthreadCond*>(createCond(cond));
if (cond == nullptr) {
@ -421,15 +403,13 @@ int PS4_SYSV_ABI scePthreadCondBroadcast(ScePthreadCond* cond) {
int result = pthread_cond_broadcast(&(*cond)->cond);
LOG_INFO_IF(log_pthread_file, "cond broadcast name={},result={}\n", (*cond)->name, result);
LOG_INFO(Kernel_Pthread, "name={}, result={}", (*cond)->name, result);
return (result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL);
}
/****
* Posix calls
*/
int PS4_SYSV_ABI posix_pthread_mutex_init(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr) {
LOG_INFO_IF(log_pthread_file, "posix pthread_mutex_init redirect to scePthreadMutexInit\n");
LOG_INFO(Kernel_Pthread, "posix pthread_mutex_init redirect to scePthreadMutexInit");
int result = scePthreadMutexInit(mutex, attr, nullptr);
if (result < 0) {
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
@ -441,7 +421,7 @@ int PS4_SYSV_ABI posix_pthread_mutex_init(ScePthreadMutex* mutex, const ScePthre
}
int PS4_SYSV_ABI posix_pthread_mutex_lock(ScePthreadMutex* mutex) {
LOG_INFO_IF(log_pthread_file, "posix pthread_mutex_lock redirect to scePthreadMutexLock\n");
LOG_INFO(Kernel_Pthread, "posix pthread_mutex_lock redirect to scePthreadMutexLock");
int result = scePthreadMutexLock(mutex);
if (result < 0) {
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
@ -453,7 +433,7 @@ int PS4_SYSV_ABI posix_pthread_mutex_lock(ScePthreadMutex* mutex) {
}
int PS4_SYSV_ABI posix_pthread_mutex_unlock(ScePthreadMutex* mutex) {
LOG_INFO_IF(log_pthread_file, "posix pthread_mutex_unlock redirect to scePthreadMutexUnlock\n");
LOG_INFO(Kernel_Pthread, "posix pthread_mutex_unlock redirect to scePthreadMutexUnlock");
int result = scePthreadMutexUnlock(mutex);
if (result < 0) {
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
@ -465,8 +445,8 @@ int PS4_SYSV_ABI posix_pthread_mutex_unlock(ScePthreadMutex* mutex) {
}
int PS4_SYSV_ABI posix_pthread_cond_broadcast(ScePthreadCond* cond) {
LOG_INFO_IF(log_pthread_file,
"posix posix_pthread_cond_broadcast redirect to scePthreadCondBroadcast\n");
LOG_INFO(Kernel_Pthread,
"posix posix_pthread_cond_broadcast redirect to scePthreadCondBroadcast");
int result = scePthreadCondBroadcast(cond);
if (result != 0) {
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
@ -510,4 +490,4 @@ void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) {
LIB_FUNCTION("mkx2fVhNMsg", "libkernel", 1, "libkernel", 1, 1, posix_pthread_cond_broadcast);
}
} // namespace Core::Libraries::LibKernel
} // namespace Core::Libraries::LibKernel

View file

@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "Emulator/Host/controller.h"
#include "common/log.h"
#include "common/logging/log.h"
#include "common/singleton.h"
#include "core/hle/error_codes.h"
#include "core/hle/libraries/libpad/pad.h"
@ -10,15 +10,14 @@
namespace Core::Libraries::LibPad {
constexpr bool log_file_pad = true; // disable it to disable logging
int PS4_SYSV_ABI scePadInit() {
LOG_WARNING(Lib_Pad, "(STUBBED) called");
return SCE_OK;
}
int PS4_SYSV_ABI scePadOpen(Core::Libraries::LibUserService::SceUserServiceUserId userId, s32 type,
int PS4_SYSV_ABI scePadOpen(Core::Libraries::LibUserService::SceUserServiceUserId user_id, s32 type,
s32 index, const ScePadOpenParam* pParam) {
LOG_INFO_IF(log_file_pad, "scePadOpen userid = {} type = {} index = {}\n", userId, type, index);
LOG_INFO(Lib_Pad, "(STUBBED) called user_id = {} type = {} index = {}", user_id, type, index);
return 1; // dummy
}

View file

@ -34,15 +34,6 @@
sym->AddSymbol(sr, func); \
}
#define PRINT_FUNCTION_NAME() \
{ LOG_INFO_IF(true, "{}()\n", __func__); }
#define PRINT_DUMMY_FUNCTION_NAME() \
{ LOG_WARN_IF(true, "dummy {}()\n", __func__); }
#define PRINT_UNIMPLEMENTED_FUNCTION_NAME() \
{ LOG_ERROR_IF(true, "{}()\n", __func__); }
namespace Core::Libraries {
void InitHLELibs(Loader::SymbolsResolver* sym);

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/log.h"
#include "common/logging/log.h"
#include "core/PS4/GPU/gpu_memory.h"
#include "core/hle/libraries/libs.h"
#include "core/hle/libraries/libscegnmdriver/libscegnmdriver.h"
@ -10,12 +10,12 @@
namespace Core::Libraries::LibSceGnmDriver {
int32_t sceGnmSubmitDone() {
PRINT_DUMMY_FUNCTION_NAME();
LOG_WARNING(Lib_GnmDriver, "(STUBBED) called");
return 0;
}
void sceGnmFlushGarlic() {
PRINT_FUNCTION_NAME();
LOG_WARNING(Lib_GnmDriver, "(STUBBED) called");
GPU::flushGarlic(Emu::getGraphicCtx());
}

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/log.h"
#include "common/logging/log.h"
#include "core/hle/error_codes.h"
#include "core/hle/libraries/libs.h"
#include "core/hle/libraries/libsystemservice/system_service.h"
@ -9,7 +9,7 @@
namespace Core::Libraries::LibSystemService {
s32 PS4_SYSV_ABI sceSystemServiceHideSplashScreen() {
PRINT_DUMMY_FUNCTION_NAME();
LOG_WARNING(Lib_SystemService, "(STUBBED) called");
return SCE_OK;
}

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/log.h"
#include "common/logging/log.h"
#include "core/hle/error_codes.h"
#include "core/hle/libraries/libs.h"
#include "core/hle/libraries/libuserservice/libuserservice.h"
@ -9,12 +9,12 @@
namespace Core::Libraries::LibUserService {
s32 PS4_SYSV_ABI sceUserServiceInitialize(const SceUserServiceInitializeParams* initParams) {
PRINT_DUMMY_FUNCTION_NAME();
LOG_WARNING(Lib_UserService, "(STUBBED) called");
return SCE_OK;
}
s32 PS4_SYSV_ABI sceUserServiceGetLoginUserIdList(SceUserServiceLoginUserIdList* userIdList) {
PRINT_DUMMY_FUNCTION_NAME();
LOG_WARNING(Lib_UserService, "(STUBBED) called");
userIdList->user_id[0] = 1;
userIdList->user_id[1] = -1;
userIdList->user_id[2] = -1;