some dummy HLE functions and implementations in libc

This commit is contained in:
georgemoralis 2023-07-26 23:52:26 +03:00
parent 7dc1f0a47b
commit 5b0e627dc0
5 changed files with 66 additions and 18 deletions

View File

@ -2,6 +2,7 @@
#include "Libs.h"
#include "../Loader/Elf.h"
#include "../../../Debug.h"
#include <pthread.h>
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) {

View File

@ -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);

View File

@ -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();

View File

@ -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();

View File

@ -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