diff --git a/src/core/hle/libraries/libkernel/libkernel.cpp b/src/core/hle/libraries/libkernel/libkernel.cpp index 7ab71291..52e1a8e6 100644 --- a/src/core/hle/libraries/libkernel/libkernel.cpp +++ b/src/core/hle/libraries/libkernel/libkernel.cpp @@ -1,15 +1,16 @@ -#include "common/log.h" +#include "core/hle/libraries/libkernel/libkernel.h" + #include "common/debug.h" +#include "common/log.h" #include "common/singleton.h" -#include "core/loader/elf.h" #include "core/hle/kernel/Objects/physical_memory.h" #include "core/hle/kernel/cpu_management.h" #include "core/hle/kernel/event_queues.h" #include "core/hle/kernel/memory_management.h" -#include "core/hle/libraries/libkernel/libkernel.h" #include "core/hle/libraries/libkernel/file_system.h" #include "core/hle/libraries/libkernel/time_management.h" #include "core/hle/libraries/libs.h" +#include "core/loader/elf.h" #ifdef _WIN64 #include @@ -25,13 +26,12 @@ int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len) { return 0; } -static PS4_SYSV_ABI void stack_chk_fail() { - BREAKPOINT(); -} +static PS4_SYSV_ABI void stack_chk_fail() { BREAKPOINT(); } -int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) { - BREAKPOINT(); -} +int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) { BREAKPOINT(); } + +static thread_local int libc_error; +int* PS4_SYSV_ABI __Error() { return &libc_error; } void LibKernel_Register(Loader::SymbolsResolver* sym) { // obj @@ -48,10 +48,11 @@ void LibKernel_Register(Loader::SymbolsResolver* sym) { // misc LIB_FUNCTION("WslcK1FQcGI", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelIsNeoMode); LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail); - + LIB_FUNCTION("9BcDykPmo1I", "libkernel", 1, "libkernel", 1, 1, __Error); + Core::Libraries::LibKernel::fileSystemSymbolsRegister(sym); Core::Libraries::LibKernel::timeSymbolsRegister(sym); Core::Libraries::LibKernel::pthreadSymbolsRegister(sym); } -} // namespace Core::Libraries::LibKernel +} // namespace Core::Libraries::LibKernel diff --git a/src/core/hle/libraries/libkernel/libkernel.h b/src/core/hle/libraries/libkernel/libkernel.h index a10adbb3..2d65a54d 100644 --- a/src/core/hle/libraries/libkernel/libkernel.h +++ b/src/core/hle/libraries/libkernel/libkernel.h @@ -1,6 +1,7 @@ #pragma once #include + #include "common/types.h" namespace Core::Loader { @@ -10,7 +11,8 @@ class SymbolsResolver; namespace Core::Libraries::LibKernel { int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len); +int* PS4_SYSV_ABI __Error(); void LibKernel_Register(Loader::SymbolsResolver* sym); -} // namespace Core::Libraries::LibKernel +} // namespace Core::Libraries::LibKernel diff --git a/src/core/hle/libraries/libkernel/thread_management.cpp b/src/core/hle/libraries/libkernel/thread_management.cpp index 82e6d00a..36755737 100644 --- a/src/core/hle/libraries/libkernel/thread_management.cpp +++ b/src/core/hle/libraries/libkernel/thread_management.cpp @@ -151,6 +151,18 @@ int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMut default: return SCE_KERNEL_ERROR_EINVAL; } } + +void* createMutex(void* addr) { + if (addr == nullptr || *static_cast(addr) != nullptr) { + return addr; + } + auto vaddr = reinterpret_cast(addr); + + std::string name = fmt::format("mutex{:#x}",vaddr); + scePthreadMutexInit(static_cast(addr), nullptr, name.c_str()); + return addr; +} + int PS4_SYSV_ABI scePthreadMutexattrInit(ScePthreadMutexattr* attr) { *attr = new PthreadMutexattrInternal{}; @@ -197,9 +209,7 @@ int PS4_SYSV_ABI scePthreadMutexattrSetprotocol(ScePthreadMutexattr* attr, int p } int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex) { PRINT_FUNCTION_NAME(); - if (mutex != nullptr || *static_cast((void*)mutex) == nullptr) { - scePthreadMutexInit(mutex, nullptr, "nomame"); // init mutex if it doesn't exist - } + mutex = static_cast(createMutex(mutex)); if (mutex == nullptr) { return SCE_KERNEL_ERROR_EINVAL; @@ -217,9 +227,7 @@ int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex) { } int PS4_SYSV_ABI scePthreadMutexUnlock(ScePthreadMutex* mutex) { PRINT_FUNCTION_NAME(); - if (mutex != nullptr || *static_cast((void*)mutex) == nullptr) { - scePthreadMutexInit(mutex, nullptr, "nomame"); // init mutex if it doesn't exist this probably won't need - } + mutex = static_cast(createMutex(mutex)); if (mutex == nullptr) { return SCE_KERNEL_ERROR_EINVAL; } @@ -284,6 +292,7 @@ void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) { // openorbis weird functions LIB_FUNCTION("7H0iTOciTLo", "libkernel", 1, "libkernel", 1, 1, posix_pthread_mutex_lock); + LIB_FUNCTION("2Z+PpY6CaJg", "libkernel", 1, "libkernel", 1, 1, posix_pthread_mutex_unlock); } } // namespace Core::Libraries::LibKernel