From 5b0e627dc0ea31b96dee700917d288421f02ec8a Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Wed, 26 Jul 2023 23:52:26 +0300 Subject: [PATCH] some dummy HLE functions and implementations in libc --- src/Core/PS4/HLE/LibC.cpp | 61 +++++++++++++++++++++++++---- src/Core/PS4/HLE/LibC.h | 1 + src/Core/PS4/HLE/LibKernel.cpp | 8 ++-- src/Core/PS4/HLE/LibSceVideoOut.cpp | 12 +++--- src/Core/PS4/HLE/LibSceVideoOut.h | 2 +- 5 files changed, 66 insertions(+), 18 deletions(-) diff --git a/src/Core/PS4/HLE/LibC.cpp b/src/Core/PS4/HLE/LibC.cpp index a3651e4d..6590941e 100644 --- a/src/Core/PS4/HLE/LibC.cpp +++ b/src/Core/PS4/HLE/LibC.cpp @@ -2,6 +2,7 @@ #include "Libs.h" #include "../Loader/Elf.h" #include "../../../Debug.h" +#include namespace HLE::Libs::LibC { @@ -12,16 +13,60 @@ namespace HLE::Libs::LibC { //dummy no need atm } - int PS4_SYSV_ABI __cxa_guard_acquire(u64* guard_object) - { - BREAKPOINT(); - return 0; - } + static pthread_mutex_t __guard_mutex; + static pthread_once_t __once_control = PTHREAD_ONCE_INIT; - int PS4_SYSV_ABI __cxa_guard_release(u64* guard_object) + static void recursiveMutex() + { + pthread_mutexattr_t recursiveMutexAttr; + pthread_mutexattr_init(&recursiveMutexAttr); + pthread_mutexattr_settype(&recursiveMutexAttr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&__guard_mutex, &recursiveMutexAttr); + } + + static pthread_mutex_t* mutex_quard() { + pthread_once(&__once_control, &recursiveMutex); + return &__guard_mutex; + } + + int PS4_SYSV_ABI __cxa_guard_acquire(u64* guard_object) { + if ((*((uint8_t*)guard_object) != 0)) // low 8 bits checks if its already init + { + return 0; + } + int result = ::pthread_mutex_lock(mutex_quard()); + if (result != 0) { + BREAKPOINT(); + } + + // Check if another thread has completed initializer run + if ((*((uint8_t*)guard_object) != 0)) { // check again if other thread init it + int result = ::pthread_mutex_unlock(mutex_quard()); + if (result != 0) { + BREAKPOINT(); + } + return 0; + } + + if (((uint8_t*)guard_object)[1] != 0) { // the second lowest byte marks if it's being used by a thread + BREAKPOINT(); + } + + // mark this guard object as being in use + ((uint8_t*)guard_object)[1] = 1; + + return 1; + } + + void PS4_SYSV_ABI __cxa_guard_release(u64* guard_object) { - BREAKPOINT(); - return 0; + *((uint8_t*)guard_object) = 1;//mark it as done + + // release global mutex + int result = ::pthread_mutex_unlock(mutex_quard()); + if (result != 0) { + BREAKPOINT(); + } } int PS4_SYSV_ABI memcmp(const void* s1, const void* s2, size_t n) { diff --git a/src/Core/PS4/HLE/LibC.h b/src/Core/PS4/HLE/LibC.h index d554a073..ee82b993 100644 --- a/src/Core/PS4/HLE/LibC.h +++ b/src/Core/PS4/HLE/LibC.h @@ -11,6 +11,7 @@ namespace HLE::Libs::LibC { static PS4_SYSV_ABI void _Assert(); static PS4_SYSV_ABI void catchReturnFromMain(int status); int PS4_SYSV_ABI __cxa_guard_acquire(u64* guard_object); + void PS4_SYSV_ABI __cxa_guard_release(u64* guard_object); int PS4_SYSV_ABI memcmp(const void* s1, const void* s2, size_t n); void* PS4_SYSV_ABI memcpy(void* dest, const void* src, size_t n); diff --git a/src/Core/PS4/HLE/LibKernel.cpp b/src/Core/PS4/HLE/LibKernel.cpp index 081be066..4ec53f5f 100644 --- a/src/Core/PS4/HLE/LibKernel.cpp +++ b/src/Core/PS4/HLE/LibKernel.cpp @@ -2,6 +2,7 @@ #include "LibKernel.h" #include "Libs.h" #include "../../../Debug.h" +#include "../../../Util/Log.h" namespace HLE::Libs::LibKernel { @@ -27,7 +28,8 @@ namespace HLE::Libs::LibKernel { int PS4_SYSV_ABI sceKernelCreateEqueue(/* SceKernelEqueue* eq*/ int eq, const char* name) { - BREAKPOINT(); + //BREAKPOINT(); + LOG_INFO_IF(true, "dummy sceKernelCreateEqueue\n"); return 0; } int PS4_SYSV_ABI sceKernelWaitEqueue(/*SceKernelEqueue eq, SceKernelEvent* ev,*/ int num, int* out /*, SceKernelUseconds* timo*/) @@ -37,8 +39,8 @@ namespace HLE::Libs::LibKernel { } int PS4_SYSV_ABI sceKernelIsNeoMode() { - BREAKPOINT(); - return 0; + //BREAKPOINT(); + return 0; //it isn't PS4VR TODO } static PS4_SYSV_ABI void stack_chk_fail() { BREAKPOINT(); diff --git a/src/Core/PS4/HLE/LibSceVideoOut.cpp b/src/Core/PS4/HLE/LibSceVideoOut.cpp index 6f57b730..a056e38f 100644 --- a/src/Core/PS4/HLE/LibSceVideoOut.cpp +++ b/src/Core/PS4/HLE/LibSceVideoOut.cpp @@ -4,6 +4,7 @@ #include "../../../Debug.h" #include "VideoOut/VideoOutCodes.h" #include "UserManagement/UsrMngCodes.h" +#include "../../../Util/Log.h" namespace HLE::Libs::LibSceVideoOut { @@ -22,7 +23,8 @@ namespace HLE::Libs::LibSceVideoOut { return 0; } int32_t PS4_SYSV_ABI sceVideoOutAddFlipEvent(/*SceKernelEqueue eq,*/ int32_t handle, void* udata) { - BREAKPOINT(); + //BREAKPOINT(); + LOG_INFO_IF(true, "dummy sceVideoOutAddFlipEvent\n"); return 0; } int32_t PS4_SYSV_ABI sceVideoOutSetFlipRate(int32_t handle, int32_t rate) { @@ -41,7 +43,7 @@ namespace HLE::Libs::LibSceVideoOut { } - int32_t PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, int32_t busType, int32_t index, const void* param) + s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param) { if (userId != SCE_USER_SERVICE_USER_ID_SYSTEM) { @@ -59,10 +61,8 @@ namespace HLE::Libs::LibSceVideoOut { { BREAKPOINT(); } - for (;;) { - printf("videoopen\n"); - } - return 0; + LOG_INFO_IF(true, "dummy sceVideoOutOpen\n"); + return 1;//dummy return TODO } int32_t PS4_SYSV_ABI sceVideoOutIsFlipPending(int32_t handle) { BREAKPOINT(); diff --git a/src/Core/PS4/HLE/LibSceVideoOut.h b/src/Core/PS4/HLE/LibSceVideoOut.h index 7d8d644d..c9563b0e 100644 --- a/src/Core/PS4/HLE/LibSceVideoOut.h +++ b/src/Core/PS4/HLE/LibSceVideoOut.h @@ -17,6 +17,6 @@ void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(/* SceVideoOutBufferAttribute* a uint32_t aspectRatio, uint32_t width, uint32_t height, uint32_t pitchInPixel); int32_t PS4_SYSV_ABI sceVideoOutGetResolutionStatus(int32_t handle /*, SceVideoOutResolutionStatus* status*/); -int32_t PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, int32_t busType, int32_t index, const void* param); +s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param); int32_t PS4_SYSV_ABI sceVideoOutIsFlipPending(int32_t handle); }; // namespace HLE::Libs::LibSceVideoOut \ No newline at end of file