mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-22 18:15:14 +00:00
added scePthreadMutexattrInit,scePthreadMutexattrSettype,scePthreadMutexattrSetprotocol
This commit is contained in:
parent
1eddb3e831
commit
4fe9d76a7a
@ -1,9 +1,8 @@
|
||||
#include "ThreadManagement.h"
|
||||
|
||||
#include <Core/PS4/HLE/ErrorCodes.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include "../ErrorCodes.h"
|
||||
|
||||
namespace HLE::Libs::LibKernel::ThreadManagement {
|
||||
|
||||
thread_local PthreadInternal* g_pthread_self = nullptr;
|
||||
@ -16,7 +15,7 @@ void Pthread_Init_Self_MainThread() {
|
||||
g_pthread_self->name = "Main_Thread";
|
||||
}
|
||||
|
||||
int scePthreadAttrInit(ScePthreadAttr* attr) {
|
||||
int PS4_SYSV_ABI scePthreadAttrInit(ScePthreadAttr* attr) {
|
||||
*attr = new PthreadAttrInternal{};
|
||||
|
||||
int result = pthread_attr_init(&(*attr)->pth_attr);
|
||||
@ -39,7 +38,7 @@ int scePthreadAttrInit(ScePthreadAttr* attr) {
|
||||
}
|
||||
}
|
||||
|
||||
int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate) {
|
||||
int PS4_SYSV_ABI scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate) {
|
||||
if (attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
@ -61,7 +60,7 @@ int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched) {
|
||||
int PS4_SYSV_ABI scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched) {
|
||||
if (attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
@ -81,7 +80,7 @@ int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param) {
|
||||
int PS4_SYSV_ABI scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param) {
|
||||
if (param == nullptr || attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
@ -103,7 +102,7 @@ int scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam*
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) {
|
||||
int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) {
|
||||
if (attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
@ -122,4 +121,49 @@ int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadMutexattrInit(ScePthreadMutexattr* attr) {
|
||||
*attr = new PthreadMutexAttrInternal{};
|
||||
|
||||
int result = pthread_mutexattr_init(&(*attr)->mutex_attr);
|
||||
|
||||
result = (result == 0 ? scePthreadMutexattrSettype(attr, 1) : result);
|
||||
result = (result == 0 ? scePthreadMutexattrSetprotocol(attr, 0) : result);
|
||||
|
||||
switch (result) {
|
||||
case 0: return SCE_OK;
|
||||
case ENOMEM: return SCE_KERNEL_ERROR_ENOMEM;
|
||||
default: return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadMutexattrSettype(ScePthreadMutexattr* attr, int type) {
|
||||
int ptype = PTHREAD_MUTEX_DEFAULT;
|
||||
switch (type) {
|
||||
case 1: ptype = PTHREAD_MUTEX_ERRORCHECK; break;
|
||||
case 2: ptype = PTHREAD_MUTEX_RECURSIVE; break;
|
||||
case 3:
|
||||
case 4: ptype = PTHREAD_MUTEX_NORMAL; break;
|
||||
default: BREAKPOINT(); // invalid
|
||||
}
|
||||
|
||||
int result = pthread_mutexattr_settype(&(*attr)->mutex_attr, ptype);
|
||||
return (result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL);
|
||||
}
|
||||
int PS4_SYSV_ABI scePthreadMutexattrSetprotocol(ScePthreadMutexattr* attr, int protocol) {
|
||||
int pprotocol = PTHREAD_PRIO_NONE;
|
||||
switch (protocol) {
|
||||
case 0: pprotocol = PTHREAD_PRIO_NONE; break;
|
||||
case 1: pprotocol = PTHREAD_PRIO_INHERIT; break;
|
||||
case 2: pprotocol = PTHREAD_PRIO_PROTECT; break;
|
||||
default: BREAKPOINT(); // invalid
|
||||
}
|
||||
|
||||
int result = 0; // pthread_mutexattr_setprotocol(&(*attr)->p, pprotocol); //TODO setprotocol seems to have issue with winpthreads (to check it)
|
||||
(*attr)->attr_protocol = pprotocol;
|
||||
return (result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL);
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex) {
|
||||
|
||||
}
|
||||
}; // namespace HLE::Libs::LibKernel::ThreadManagement
|
@ -1,17 +1,21 @@
|
||||
#pragma once
|
||||
#define _TIMESPEC_DEFINED
|
||||
|
||||
#include <types.h>
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include "../../../../types.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace HLE::Libs::LibKernel::ThreadManagement {
|
||||
|
||||
struct PthreadAttrInternal;
|
||||
struct PthreadMutexInternal;
|
||||
struct PthreadMutexAttrInternal;
|
||||
|
||||
using SceKernelSchedParam = ::sched_param;
|
||||
using SceKernelSchedParam = ::sched_param;
|
||||
using ScePthreadAttr = PthreadAttrInternal*;
|
||||
using ScePthreadMutex = PthreadMutexInternal*;
|
||||
using ScePthreadMutexattr = PthreadMutexAttrInternal*;
|
||||
|
||||
struct PthreadInternal {
|
||||
u08 reserved[4096];
|
||||
@ -28,15 +32,32 @@ struct PthreadAttrInternal {
|
||||
pthread_attr_t pth_attr;
|
||||
};
|
||||
|
||||
|
||||
struct PthreadMutexAttrInternal {
|
||||
u08 reserved[64];
|
||||
pthread_mutexattr_t mutex_attr;
|
||||
int attr_protocol;
|
||||
};
|
||||
|
||||
struct PthreadMutexInternal {
|
||||
u08 reserved[256];
|
||||
std::string name;
|
||||
pthread_mutex_t mutex;
|
||||
};
|
||||
|
||||
class PThreadCxt {};
|
||||
|
||||
void Pthread_Init_Self_MainThread();
|
||||
|
||||
//HLE FUNCTIONS
|
||||
int scePthreadAttrInit(ScePthreadAttr* attr);
|
||||
int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate);
|
||||
int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched);
|
||||
int scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param);
|
||||
int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy);
|
||||
// HLE FUNCTIONS
|
||||
int PS4_SYSV_ABI scePthreadAttrInit(ScePthreadAttr* attr);
|
||||
int PS4_SYSV_ABI scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate);
|
||||
int PS4_SYSV_ABI scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched);
|
||||
int PS4_SYSV_ABI scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param);
|
||||
int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy);
|
||||
int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex);
|
||||
int PS4_SYSV_ABI scePthreadMutexattrInit(ScePthreadMutexattr* attr);
|
||||
int PS4_SYSV_ABI scePthreadMutexattrSettype(ScePthreadMutexattr* attr, int type);
|
||||
int PS4_SYSV_ABI scePthreadMutexattrSetprotocol(ScePthreadMutexattr* attr, int protocol);
|
||||
|
||||
} // namespace HLE::Libs::LibKernel::ThreadManagement
|
@ -8,6 +8,7 @@
|
||||
#include "Kernel/Objects/physical_memory.h"
|
||||
#include "Kernel/cpu_management.h"
|
||||
#include "Kernel/event_queues.h"
|
||||
#include "Kernel/ThreadManagement.h"
|
||||
|
||||
namespace HLE::Libs::LibKernel {
|
||||
|
||||
@ -52,7 +53,10 @@ namespace HLE::Libs::LibKernel {
|
||||
PS4_SYSV_ABI void pthread_rwlock_unlock() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void pthread_detach() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void pthread_mutexattr_init() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void pthread_mutex_lock() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void pthread_mutex_lock() {
|
||||
//posix call
|
||||
|
||||
}
|
||||
PS4_SYSV_ABI void munmap() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void pthread_mutex_destroy() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void sceKernelUsleep() { BREAKPOINT(); }
|
||||
@ -91,7 +95,12 @@ namespace HLE::Libs::LibKernel {
|
||||
LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail);
|
||||
//time
|
||||
LIB_FUNCTION("-2IRUCO--PM", "libkernel", 1, "libkernel", 1, 1, sceKernelReadTsc);
|
||||
//Pthreads
|
||||
LIB_FUNCTION("F8bUHwAG284", "libkernel", 1, "libkernel", 1, 1, ThreadManagement::scePthreadMutexattrInit);
|
||||
LIB_FUNCTION("iMp8QpE+XO4", "libkernel", 1, "libkernel", 1, 1, ThreadManagement::scePthreadMutexattrSettype);
|
||||
LIB_FUNCTION("1FGvU0i9saQ", "libkernel", 1, "libkernel", 1, 1, ThreadManagement::scePthreadMutexattrSetprotocol);
|
||||
|
||||
//TODO
|
||||
LIB_FUNCTION("6XG4B33N09g", "libkernel", 1, "libkernel", 1, 1, sched_yield);
|
||||
LIB_FUNCTION("mkawd0NA9ts", "libkernel", 1, "libkernel", 1, 1, sysconf);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user