2024-02-23 22:32:32 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2023-11-10 18:52:41 +01:00
|
|
|
|
2024-04-04 18:47:59 +02:00
|
|
|
#include <mutex>
|
2024-04-13 23:35:48 +02:00
|
|
|
#include <thread>
|
2024-06-15 13:36:07 +02:00
|
|
|
#include <semaphore.h>
|
2024-07-04 23:15:44 +02:00
|
|
|
#include "common/alignment.h"
|
2024-02-27 23:10:34 +01:00
|
|
|
#include "common/assert.h"
|
2024-06-15 13:36:07 +02:00
|
|
|
#include "common/error.h"
|
2024-02-27 23:10:34 +01:00
|
|
|
#include "common/logging/log.h"
|
2024-06-05 21:08:18 +02:00
|
|
|
#include "common/singleton.h"
|
2024-06-01 22:50:03 +02:00
|
|
|
#include "common/thread.h"
|
2024-04-13 23:35:48 +02:00
|
|
|
#include "core/libraries/error_codes.h"
|
|
|
|
#include "core/libraries/kernel/thread_management.h"
|
2024-06-15 13:36:07 +02:00
|
|
|
#include "core/libraries/kernel/threads/threads.h"
|
2024-04-13 23:35:48 +02:00
|
|
|
#include "core/libraries/libs.h"
|
2024-06-05 21:08:18 +02:00
|
|
|
#include "core/linker.h"
|
2024-05-09 22:45:09 +02:00
|
|
|
#ifdef _WIN64
|
|
|
|
#include <windows.h>
|
2024-07-04 23:15:44 +02:00
|
|
|
#else
|
|
|
|
#include <sys/mman.h>
|
2024-05-09 22:45:09 +02:00
|
|
|
#endif
|
2023-08-03 12:05:13 +02:00
|
|
|
|
2024-04-13 23:35:48 +02:00
|
|
|
namespace Libraries::Kernel {
|
2023-07-17 22:46:25 +02:00
|
|
|
|
2023-11-16 07:49:26 +01:00
|
|
|
thread_local ScePthread g_pthread_self{};
|
2023-07-18 17:54:46 +02:00
|
|
|
PThreadCxt* g_pthread_cxt = nullptr;
|
|
|
|
|
2023-11-10 18:52:41 +01:00
|
|
|
void init_pthreads() {
|
|
|
|
g_pthread_cxt = new PThreadCxt{};
|
2023-11-16 12:31:12 +01:00
|
|
|
// default mutex init
|
2023-11-10 18:52:41 +01:00
|
|
|
ScePthreadMutexattr default_mutexattr = nullptr;
|
|
|
|
scePthreadMutexattrInit(&default_mutexattr);
|
|
|
|
g_pthread_cxt->setDefaultMutexattr(default_mutexattr);
|
2023-11-16 12:31:12 +01:00
|
|
|
// default cond init
|
|
|
|
ScePthreadCondattr default_condattr = nullptr;
|
|
|
|
scePthreadCondattrInit(&default_condattr);
|
|
|
|
g_pthread_cxt->setDefaultCondattr(default_condattr);
|
2024-04-04 18:16:10 +02:00
|
|
|
// default attr init
|
|
|
|
ScePthreadAttr default_attr = nullptr;
|
|
|
|
scePthreadAttrInit(&default_attr);
|
|
|
|
g_pthread_cxt->SetDefaultAttr(default_attr);
|
2024-06-10 21:59:12 +02:00
|
|
|
// default rw init
|
|
|
|
OrbisPthreadRwlockattr default_rwattr = nullptr;
|
|
|
|
scePthreadRwlockattrInit(&default_rwattr);
|
|
|
|
g_pthread_cxt->setDefaultRwattr(default_rwattr);
|
2024-04-04 18:16:10 +02:00
|
|
|
|
|
|
|
g_pthread_cxt->SetPthreadPool(new PThreadPool);
|
2023-11-10 18:52:41 +01:00
|
|
|
}
|
|
|
|
|
2023-11-12 09:57:50 +01:00
|
|
|
void pthreadInitSelfMainThread() {
|
2024-07-04 23:15:44 +02:00
|
|
|
auto* pthread_pool = g_pthread_cxt->GetPthreadPool();
|
|
|
|
g_pthread_self = pthread_pool->Create();
|
2023-11-16 07:49:26 +01:00
|
|
|
scePthreadAttrInit(&g_pthread_self->attr);
|
|
|
|
g_pthread_self->pth = pthread_self();
|
|
|
|
g_pthread_self->name = "Main_Thread";
|
2023-07-20 10:20:11 +02:00
|
|
|
}
|
2023-07-18 17:54:46 +02:00
|
|
|
|
2023-11-10 18:52:41 +01:00
|
|
|
int PS4_SYSV_ABI scePthreadAttrInit(ScePthreadAttr* attr) {
|
2023-07-18 17:54:46 +02:00
|
|
|
*attr = new PthreadAttrInternal{};
|
|
|
|
|
2023-07-20 10:20:11 +02:00
|
|
|
int result = pthread_attr_init(&(*attr)->pth_attr);
|
2023-07-18 17:54:46 +02:00
|
|
|
|
|
|
|
(*attr)->affinity = 0x7f;
|
|
|
|
(*attr)->guard_size = 0x1000;
|
|
|
|
|
|
|
|
SceKernelSchedParam param{};
|
|
|
|
param.sched_priority = 700;
|
|
|
|
|
2023-07-20 11:18:43 +02:00
|
|
|
result = (result == 0 ? scePthreadAttrSetinheritsched(attr, 4) : result);
|
2023-07-18 17:54:46 +02:00
|
|
|
result = (result == 0 ? scePthreadAttrSetschedparam(attr, ¶m) : result);
|
|
|
|
result = (result == 0 ? scePthreadAttrSetschedpolicy(attr, SCHED_OTHER) : result);
|
|
|
|
result = (result == 0 ? scePthreadAttrSetdetachstate(attr, PTHREAD_CREATE_JOINABLE) : result);
|
|
|
|
|
|
|
|
switch (result) {
|
2024-02-23 21:57:57 +01:00
|
|
|
case 0:
|
|
|
|
return SCE_OK;
|
|
|
|
case ENOMEM:
|
|
|
|
return SCE_KERNEL_ERROR_ENOMEM;
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
2023-07-18 17:54:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-30 21:19:42 +01:00
|
|
|
int PS4_SYSV_ABI scePthreadAttrDestroy(ScePthreadAttr* attr) {
|
|
|
|
|
|
|
|
int result = pthread_attr_destroy(&(*attr)->pth_attr);
|
|
|
|
|
|
|
|
delete *attr;
|
|
|
|
*attr = nullptr;
|
|
|
|
|
|
|
|
if (result == 0) {
|
|
|
|
return SCE_OK;
|
|
|
|
}
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
2024-04-02 17:07:24 +02:00
|
|
|
int PS4_SYSV_ABI scePthreadAttrSetguardsize(ScePthreadAttr* attr, size_t guard_size) {
|
|
|
|
if (attr == nullptr || *attr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*attr)->guard_size = guard_size;
|
|
|
|
|
|
|
|
return SCE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadAttrGetguardsize(const ScePthreadAttr* attr, size_t* guard_size) {
|
|
|
|
if (guard_size == nullptr || attr == nullptr || *attr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*guard_size = (*attr)->guard_size;
|
|
|
|
|
|
|
|
return SCE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadAttrGetinheritsched(const ScePthreadAttr* attr, int* inherit_sched) {
|
|
|
|
|
|
|
|
if (inherit_sched == nullptr || attr == nullptr || *attr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = pthread_attr_getinheritsched(&(*attr)->pth_attr, inherit_sched);
|
|
|
|
|
|
|
|
switch (*inherit_sched) {
|
|
|
|
case PTHREAD_EXPLICIT_SCHED:
|
|
|
|
*inherit_sched = 0;
|
|
|
|
break;
|
|
|
|
case PTHREAD_INHERIT_SCHED:
|
|
|
|
*inherit_sched = 4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadAttrGetdetachstate(const ScePthreadAttr* attr, int* state) {
|
|
|
|
if (state == nullptr || attr == nullptr || *attr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
2024-06-15 13:36:07 +02:00
|
|
|
// int result = pthread_attr_getdetachstate(&(*attr)->pth_attr, state);
|
2024-04-02 17:07:24 +02:00
|
|
|
int result = 0;
|
|
|
|
*state = ((*attr)->detached ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE);
|
|
|
|
|
|
|
|
switch (*state) {
|
|
|
|
case PTHREAD_CREATE_JOINABLE:
|
|
|
|
*state = 0;
|
|
|
|
break;
|
|
|
|
case PTHREAD_CREATE_DETACHED:
|
|
|
|
*state = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL);
|
|
|
|
}
|
|
|
|
|
2023-11-10 18:52:41 +01:00
|
|
|
int PS4_SYSV_ABI scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate) {
|
2023-07-18 17:54:46 +02:00
|
|
|
if (attr == nullptr || *attr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pstate = PTHREAD_CREATE_JOINABLE;
|
|
|
|
switch (detachstate) {
|
2024-02-23 21:57:57 +01:00
|
|
|
case 0:
|
|
|
|
pstate = PTHREAD_CREATE_JOINABLE;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pstate = PTHREAD_CREATE_DETACHED;
|
|
|
|
break;
|
|
|
|
default:
|
2024-02-27 23:10:34 +01:00
|
|
|
UNREACHABLE_MSG("Invalid detachstate: {}", detachstate);
|
2024-02-23 21:57:57 +01:00
|
|
|
}
|
|
|
|
|
2024-06-15 13:36:07 +02:00
|
|
|
// int result = pthread_attr_setdetachstate(&(*attr)->pth_attr, pstate);
|
2023-11-16 07:49:26 +01:00
|
|
|
int result = 0;
|
2023-07-18 17:54:46 +02:00
|
|
|
(*attr)->detached = (pstate == PTHREAD_CREATE_DETACHED);
|
2023-11-10 19:51:02 +01:00
|
|
|
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
2023-07-18 17:54:46 +02:00
|
|
|
}
|
|
|
|
|
2023-11-10 18:52:41 +01:00
|
|
|
int PS4_SYSV_ABI scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched) {
|
2023-07-18 17:54:46 +02:00
|
|
|
if (attr == nullptr || *attr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pinherit_sched = PTHREAD_INHERIT_SCHED;
|
|
|
|
switch (inheritSched) {
|
2024-02-23 21:57:57 +01:00
|
|
|
case 0:
|
|
|
|
pinherit_sched = PTHREAD_EXPLICIT_SCHED;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
pinherit_sched = PTHREAD_INHERIT_SCHED;
|
|
|
|
break;
|
|
|
|
default:
|
2024-02-27 23:10:34 +01:00
|
|
|
UNREACHABLE_MSG("Invalid inheritSched: {}", inheritSched);
|
2023-07-18 17:54:46 +02:00
|
|
|
}
|
|
|
|
|
2023-07-20 10:20:11 +02:00
|
|
|
int result = pthread_attr_setinheritsched(&(*attr)->pth_attr, pinherit_sched);
|
2023-07-18 17:54:46 +02:00
|
|
|
|
2023-11-10 19:51:02 +01:00
|
|
|
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
2023-07-18 17:54:46 +02:00
|
|
|
}
|
|
|
|
|
2024-04-02 17:07:24 +02:00
|
|
|
int PS4_SYSV_ABI scePthreadAttrGetschedparam(const ScePthreadAttr* attr,
|
|
|
|
SceKernelSchedParam* param) {
|
|
|
|
|
|
|
|
if (param == nullptr || attr == nullptr || *attr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = pthread_attr_getschedparam(&(*attr)->pth_attr, param);
|
|
|
|
|
|
|
|
if (param->sched_priority <= -2) {
|
|
|
|
param->sched_priority = 767;
|
|
|
|
} else if (param->sched_priority >= +2) {
|
|
|
|
param->sched_priority = 256;
|
|
|
|
} else {
|
|
|
|
param->sched_priority = 700;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
2024-02-23 21:57:57 +01:00
|
|
|
int PS4_SYSV_ABI scePthreadAttrSetschedparam(ScePthreadAttr* attr,
|
|
|
|
const SceKernelSchedParam* param) {
|
2023-07-18 17:54:46 +02:00
|
|
|
if (param == nullptr || attr == nullptr || *attr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
SceKernelSchedParam pparam{};
|
|
|
|
if (param->sched_priority <= 478) {
|
|
|
|
pparam.sched_priority = +2;
|
|
|
|
} else if (param->sched_priority >= 733) {
|
|
|
|
pparam.sched_priority = -2;
|
|
|
|
} else {
|
|
|
|
pparam.sched_priority = 0;
|
|
|
|
}
|
|
|
|
|
2024-06-16 00:50:07 +02:00
|
|
|
// We always use SCHED_OTHER for now, so don't call this for now.
|
|
|
|
// int result = pthread_attr_setschedparam(&(*attr)->pth_attr, &pparam);
|
|
|
|
int result = 0;
|
2023-11-10 19:51:02 +01:00
|
|
|
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
2023-07-18 17:54:46 +02:00
|
|
|
}
|
|
|
|
|
2024-04-02 17:07:24 +02:00
|
|
|
int PS4_SYSV_ABI scePthreadAttrGetschedpolicy(const ScePthreadAttr* attr, int* policy) {
|
|
|
|
if (policy == nullptr || attr == nullptr || *attr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = pthread_attr_getschedpolicy(&(*attr)->pth_attr, policy);
|
|
|
|
|
|
|
|
switch (*policy) {
|
|
|
|
case SCHED_OTHER:
|
|
|
|
*policy = (*attr)->policy;
|
|
|
|
break;
|
|
|
|
case SCHED_FIFO:
|
|
|
|
*policy = 1;
|
|
|
|
break;
|
|
|
|
case SCHED_RR:
|
|
|
|
*policy = 3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
2023-11-10 18:52:41 +01:00
|
|
|
int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) {
|
2023-07-18 17:54:46 +02:00
|
|
|
if (attr == nullptr || *attr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
2024-06-16 00:50:07 +02:00
|
|
|
int ppolicy = SCHED_OTHER; // winpthreads only supports SCHED_OTHER
|
|
|
|
if (policy != SCHED_OTHER) {
|
|
|
|
LOG_ERROR(Kernel_Pthread, "policy={} not supported by winpthreads", policy);
|
2023-11-12 14:09:18 +01:00
|
|
|
}
|
2023-07-18 17:54:46 +02:00
|
|
|
|
2024-06-15 13:36:07 +02:00
|
|
|
(*attr)->policy = policy;
|
2023-11-12 14:09:18 +01:00
|
|
|
int result = pthread_attr_setschedpolicy(&(*attr)->pth_attr, ppolicy);
|
2023-11-10 19:51:02 +01:00
|
|
|
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
2023-07-18 17:54:46 +02:00
|
|
|
}
|
2024-06-15 13:36:07 +02:00
|
|
|
|
2024-02-23 21:57:57 +01:00
|
|
|
ScePthread PS4_SYSV_ABI scePthreadSelf() {
|
|
|
|
return g_pthread_self;
|
|
|
|
}
|
2023-07-18 17:54:46 +02:00
|
|
|
|
2024-02-23 21:57:57 +01:00
|
|
|
int PS4_SYSV_ABI scePthreadAttrSetaffinity(ScePthreadAttr* pattr,
|
|
|
|
const /*SceKernelCpumask*/ u64 mask) {
|
2024-02-27 23:10:34 +01:00
|
|
|
LOG_INFO(Kernel_Pthread, "called");
|
2023-11-16 07:49:26 +01:00
|
|
|
|
|
|
|
if (pattr == nullptr || *pattr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*pattr)->affinity = mask;
|
|
|
|
return SCE_OK;
|
|
|
|
}
|
|
|
|
|
2024-03-30 21:19:42 +01:00
|
|
|
int PS4_SYSV_ABI scePthreadAttrGetaffinity(const ScePthreadAttr* pattr,
|
|
|
|
/* SceKernelCpumask*/ u64* mask) {
|
|
|
|
if (pattr == nullptr || *pattr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*mask = (*pattr)->affinity;
|
|
|
|
|
|
|
|
return SCE_OK;
|
|
|
|
}
|
2024-04-02 17:07:24 +02:00
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadAttrGetstackaddr(const ScePthreadAttr* attr, void** stack_addr) {
|
|
|
|
|
|
|
|
if (stack_addr == nullptr || attr == nullptr || *attr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
2024-07-15 02:55:58 +02:00
|
|
|
size_t stack_size = 0;
|
|
|
|
int result = pthread_attr_getstack(&(*attr)->pth_attr, stack_addr, &stack_size);
|
2024-04-02 17:07:24 +02:00
|
|
|
|
|
|
|
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadAttrGetstacksize(const ScePthreadAttr* attr, size_t* stack_size) {
|
|
|
|
|
|
|
|
if (stack_size == nullptr || attr == nullptr || *attr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = pthread_attr_getstacksize(&(*attr)->pth_attr, stack_size);
|
|
|
|
|
|
|
|
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadAttrSetstackaddr(ScePthreadAttr* attr, void* addr) {
|
|
|
|
|
|
|
|
if (addr == nullptr || attr == nullptr || *attr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
2024-07-15 02:55:58 +02:00
|
|
|
size_t stack_size = 0;
|
|
|
|
pthread_attr_getstacksize(&(*attr)->pth_attr, &stack_size);
|
|
|
|
|
|
|
|
int result = pthread_attr_setstack(&(*attr)->pth_attr, addr, stack_size);
|
2024-04-02 17:07:24 +02:00
|
|
|
|
|
|
|
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadAttrSetstacksize(ScePthreadAttr* attr, size_t stack_size) {
|
|
|
|
|
|
|
|
if (stack_size == 0 || attr == nullptr || *attr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = pthread_attr_setstacksize(&(*attr)->pth_attr, stack_size);
|
|
|
|
|
|
|
|
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
2024-06-08 08:23:55 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_attr_init(ScePthreadAttr* attr) {
|
|
|
|
int result = scePthreadAttrInit(attr);
|
|
|
|
if (result < 0) {
|
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_attr_setstacksize(ScePthreadAttr* attr, size_t stacksize) {
|
|
|
|
int result = scePthreadAttrSetstacksize(attr, stacksize);
|
|
|
|
if (result < 0) {
|
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-11-16 07:49:26 +01:00
|
|
|
int PS4_SYSV_ABI scePthreadSetaffinity(ScePthread thread, const /*SceKernelCpumask*/ u64 mask) {
|
2024-02-27 23:10:34 +01:00
|
|
|
LOG_INFO(Kernel_Pthread, "called");
|
2023-11-16 07:49:26 +01:00
|
|
|
|
|
|
|
if (thread == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_ESRCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto result = scePthreadAttrSetaffinity(&thread->attr, mask);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2024-04-02 17:07:24 +02:00
|
|
|
|
2024-07-28 17:43:44 +02:00
|
|
|
int PS4_SYSV_ABI scePthreadGetaffinity(ScePthread thread, /*SceKernelCpumask*/ u64* mask) {
|
|
|
|
LOG_INFO(Kernel_Pthread, "called");
|
|
|
|
|
|
|
|
if (thread == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_ESRCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto result = scePthreadAttrGetaffinity(&thread->attr, mask);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-06-15 13:36:07 +02:00
|
|
|
ScePthreadMutex* createMutex(ScePthreadMutex* addr) {
|
|
|
|
if (addr == nullptr || *addr != nullptr) {
|
2023-11-12 19:23:42 +01:00
|
|
|
return addr;
|
|
|
|
}
|
2024-06-13 23:58:57 +02:00
|
|
|
static std::mutex mutex;
|
|
|
|
std::scoped_lock lk{mutex};
|
2024-06-15 13:36:07 +02:00
|
|
|
if (*addr != nullptr) {
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
const VAddr vaddr = reinterpret_cast<VAddr>(addr);
|
2023-11-12 19:23:42 +01:00
|
|
|
std::string name = fmt::format("mutex{:#x}", vaddr);
|
2024-06-15 13:36:07 +02:00
|
|
|
scePthreadMutexInit(addr, nullptr, name.c_str());
|
2023-11-12 19:23:42 +01:00
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2024-02-23 21:57:57 +01:00
|
|
|
int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr,
|
|
|
|
const char* name) {
|
2023-11-10 18:52:41 +01:00
|
|
|
if (mutex == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
if (attr == nullptr) {
|
|
|
|
attr = g_pthread_cxt->getDefaultMutexattr();
|
|
|
|
}
|
|
|
|
|
|
|
|
*mutex = new PthreadMutexInternal{};
|
|
|
|
if (name != nullptr) {
|
|
|
|
(*mutex)->name = name;
|
2023-11-10 22:30:28 +01:00
|
|
|
} else {
|
2023-11-16 12:31:12 +01:00
|
|
|
(*mutex)->name = "nonameMutex";
|
2023-11-10 18:52:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int result = pthread_mutex_init(&(*mutex)->pth_mutex, &(*attr)->pth_mutex_attr);
|
|
|
|
|
|
|
|
if (name != nullptr) {
|
2024-02-27 23:10:34 +01:00
|
|
|
LOG_INFO(Kernel_Pthread, "name={}, result={}", name, result);
|
2023-11-10 18:52:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (result) {
|
2024-02-23 21:57:57 +01:00
|
|
|
case 0:
|
|
|
|
return SCE_OK;
|
|
|
|
case EAGAIN:
|
|
|
|
return SCE_KERNEL_ERROR_EAGAIN;
|
|
|
|
case EINVAL:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
case ENOMEM:
|
|
|
|
return SCE_KERNEL_ERROR_ENOMEM;
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
2023-11-10 18:52:41 +01:00
|
|
|
}
|
|
|
|
}
|
2023-11-11 11:13:43 +01:00
|
|
|
|
2024-04-01 13:21:40 +02:00
|
|
|
int PS4_SYSV_ABI scePthreadMutexDestroy(ScePthreadMutex* mutex) {
|
|
|
|
|
|
|
|
if (mutex == nullptr || *mutex == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = pthread_mutex_destroy(&(*mutex)->pth_mutex);
|
|
|
|
|
2024-08-08 14:02:10 +02:00
|
|
|
LOG_DEBUG(Kernel_Pthread, "name={}, result={}", (*mutex)->name, result);
|
2024-04-01 13:21:40 +02:00
|
|
|
|
|
|
|
delete *mutex;
|
|
|
|
*mutex = nullptr;
|
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case 0:
|
|
|
|
return SCE_OK;
|
|
|
|
case EBUSY:
|
|
|
|
return SCE_KERNEL_ERROR_EBUSY;
|
|
|
|
case EINVAL:
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2023-11-10 18:52:41 +01:00
|
|
|
int PS4_SYSV_ABI scePthreadMutexattrInit(ScePthreadMutexattr* attr) {
|
|
|
|
*attr = new PthreadMutexattrInternal{};
|
|
|
|
|
|
|
|
int result = pthread_mutexattr_init(&(*attr)->pth_mutex_attr);
|
|
|
|
|
2024-06-15 13:36:07 +02:00
|
|
|
result = (result == 0 ? scePthreadMutexattrSettype(attr, 1) : result);
|
2023-11-10 18:52:41 +01:00
|
|
|
result = (result == 0 ? scePthreadMutexattrSetprotocol(attr, 0) : result);
|
|
|
|
|
|
|
|
switch (result) {
|
2024-02-23 21:57:57 +01:00
|
|
|
case 0:
|
|
|
|
return SCE_OK;
|
|
|
|
case ENOMEM:
|
|
|
|
return SCE_KERNEL_ERROR_ENOMEM;
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
2023-11-10 18:52:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadMutexattrSettype(ScePthreadMutexattr* attr, int type) {
|
|
|
|
int ptype = PTHREAD_MUTEX_DEFAULT;
|
|
|
|
switch (type) {
|
2024-02-23 21:57:57 +01:00
|
|
|
case 1:
|
|
|
|
ptype = PTHREAD_MUTEX_ERRORCHECK;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ptype = PTHREAD_MUTEX_RECURSIVE;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
ptype = PTHREAD_MUTEX_NORMAL;
|
|
|
|
break;
|
|
|
|
default:
|
2024-02-27 23:10:34 +01:00
|
|
|
UNREACHABLE_MSG("Invalid type: {}", type);
|
2023-11-10 18:52:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int result = pthread_mutexattr_settype(&(*attr)->pth_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) {
|
2024-02-23 21:57:57 +01:00
|
|
|
case 0:
|
|
|
|
pprotocol = PTHREAD_PRIO_NONE;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pprotocol = PTHREAD_PRIO_INHERIT;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
pprotocol = PTHREAD_PRIO_PROTECT;
|
|
|
|
break;
|
|
|
|
default:
|
2024-02-27 23:10:34 +01:00
|
|
|
UNREACHABLE_MSG("Invalid protocol: {}", protocol);
|
2024-02-23 21:57:57 +01:00
|
|
|
}
|
|
|
|
|
2024-06-15 20:04:36 +02:00
|
|
|
#if _WIN64
|
|
|
|
int result = 0;
|
|
|
|
#else
|
2024-06-15 13:36:07 +02:00
|
|
|
int result = pthread_mutexattr_setprotocol(&(*attr)->pth_mutex_attr, pprotocol);
|
2024-06-15 20:04:36 +02:00
|
|
|
#endif
|
2023-11-10 18:52:41 +01:00
|
|
|
(*attr)->pprotocol = pprotocol;
|
|
|
|
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
2023-11-11 09:49:44 +01:00
|
|
|
|
2024-06-15 13:36:07 +02:00
|
|
|
int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex) {
|
|
|
|
mutex = createMutex(mutex);
|
2023-11-10 22:30:28 +01:00
|
|
|
if (mutex == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = pthread_mutex_lock(&(*mutex)->pth_mutex);
|
2024-04-02 17:07:24 +02:00
|
|
|
if (result != 0) {
|
2024-06-15 13:36:07 +02:00
|
|
|
LOG_TRACE(Kernel_Pthread, "Locked name={}, result={}", (*mutex)->name, result);
|
2024-04-02 17:07:24 +02:00
|
|
|
}
|
2024-06-15 10:28:51 +02:00
|
|
|
|
2023-11-10 22:30:28 +01:00
|
|
|
switch (result) {
|
2024-02-23 21:57:57 +01:00
|
|
|
case 0:
|
|
|
|
return SCE_OK;
|
|
|
|
case EAGAIN:
|
|
|
|
return SCE_KERNEL_ERROR_EAGAIN;
|
|
|
|
case EINVAL:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
case EDEADLK:
|
|
|
|
return SCE_KERNEL_ERROR_EDEADLK;
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
2023-11-10 22:30:28 +01:00
|
|
|
}
|
|
|
|
}
|
2024-06-15 13:36:07 +02:00
|
|
|
|
2023-11-10 22:30:28 +01:00
|
|
|
int PS4_SYSV_ABI scePthreadMutexUnlock(ScePthreadMutex* mutex) {
|
2024-06-15 13:36:07 +02:00
|
|
|
mutex = createMutex(mutex);
|
2023-11-10 22:30:28 +01:00
|
|
|
if (mutex == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = pthread_mutex_unlock(&(*mutex)->pth_mutex);
|
2024-04-02 17:07:24 +02:00
|
|
|
if (result != 0) {
|
2024-06-15 13:36:07 +02:00
|
|
|
LOG_TRACE(Kernel_Pthread, "Unlocking name={}, result={}", (*mutex)->name, result);
|
2024-04-02 17:07:24 +02:00
|
|
|
}
|
2024-06-15 10:28:51 +02:00
|
|
|
|
2023-11-10 22:30:28 +01:00
|
|
|
switch (result) {
|
2024-02-23 21:57:57 +01:00
|
|
|
case 0:
|
|
|
|
return SCE_OK;
|
|
|
|
case EINVAL:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
case EPERM:
|
|
|
|
return SCE_KERNEL_ERROR_EPERM;
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
2023-11-10 22:30:28 +01:00
|
|
|
}
|
|
|
|
}
|
2023-11-10 18:52:41 +01:00
|
|
|
|
2024-03-26 18:20:55 +01:00
|
|
|
int PS4_SYSV_ABI scePthreadMutexattrDestroy(ScePthreadMutexattr* attr) {
|
|
|
|
int result = pthread_mutexattr_destroy(&(*attr)->pth_mutex_attr);
|
|
|
|
|
|
|
|
delete *attr;
|
|
|
|
*attr = nullptr;
|
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case 0:
|
|
|
|
return SCE_OK;
|
|
|
|
case ENOMEM:
|
|
|
|
return SCE_KERNEL_ERROR_ENOMEM;
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-15 13:36:07 +02:00
|
|
|
ScePthreadCond* createCond(ScePthreadCond* addr) {
|
|
|
|
if (addr == nullptr || *addr != nullptr) {
|
2023-11-16 12:31:12 +01:00
|
|
|
return addr;
|
|
|
|
}
|
2024-06-15 13:36:07 +02:00
|
|
|
static std::mutex mutex;
|
|
|
|
std::scoped_lock lk{mutex};
|
|
|
|
if (*addr != nullptr) {
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
const VAddr vaddr = reinterpret_cast<VAddr>(addr);
|
2023-11-16 12:31:12 +01:00
|
|
|
std::string name = fmt::format("cond{:#x}", vaddr);
|
|
|
|
scePthreadCondInit(static_cast<ScePthreadCond*>(addr), nullptr, name.c_str());
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2024-02-23 21:57:57 +01:00
|
|
|
int PS4_SYSV_ABI scePthreadCondInit(ScePthreadCond* cond, const ScePthreadCondattr* attr,
|
|
|
|
const char* name) {
|
2023-11-16 12:31:12 +01:00
|
|
|
if (cond == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr == nullptr) {
|
|
|
|
attr = g_pthread_cxt->getDefaultCondattr();
|
|
|
|
}
|
|
|
|
|
|
|
|
*cond = new PthreadCondInternal{};
|
|
|
|
|
|
|
|
if (name != nullptr) {
|
|
|
|
(*cond)->name = name;
|
|
|
|
} else {
|
|
|
|
(*cond)->name = "nonameCond";
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = pthread_cond_init(&(*cond)->cond, &(*attr)->cond_attr);
|
|
|
|
|
|
|
|
if (name != nullptr) {
|
2024-02-27 23:10:34 +01:00
|
|
|
LOG_INFO(Kernel_Pthread, "name={}, result={}", (*cond)->name, result);
|
2023-11-16 12:31:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (result) {
|
2024-02-23 21:57:57 +01:00
|
|
|
case 0:
|
|
|
|
return SCE_OK;
|
|
|
|
case EAGAIN:
|
|
|
|
return SCE_KERNEL_ERROR_EAGAIN;
|
|
|
|
case EINVAL:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
case ENOMEM:
|
|
|
|
return SCE_KERNEL_ERROR_ENOMEM;
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
2023-11-16 12:31:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadCondattrInit(ScePthreadCondattr* attr) {
|
|
|
|
*attr = new PthreadCondAttrInternal{};
|
|
|
|
|
|
|
|
int result = pthread_condattr_init(&(*attr)->cond_attr);
|
|
|
|
|
|
|
|
switch (result) {
|
2024-02-23 21:57:57 +01:00
|
|
|
case 0:
|
|
|
|
return SCE_OK;
|
|
|
|
case ENOMEM:
|
|
|
|
return SCE_KERNEL_ERROR_ENOMEM;
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
2023-11-16 12:31:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadCondBroadcast(ScePthreadCond* cond) {
|
2024-06-15 13:36:07 +02:00
|
|
|
cond = createCond(cond);
|
2023-11-16 12:31:12 +01:00
|
|
|
if (cond == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = pthread_cond_broadcast(&(*cond)->cond);
|
|
|
|
|
2024-06-15 13:36:07 +02:00
|
|
|
LOG_TRACE(Kernel_Pthread, "called name={}, result={}", (*cond)->name, result);
|
2023-11-16 12:31:12 +01:00
|
|
|
|
|
|
|
return (result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL);
|
|
|
|
}
|
2024-02-27 23:10:34 +01:00
|
|
|
|
2024-05-30 11:51:04 +02:00
|
|
|
int PS4_SYSV_ABI scePthreadCondTimedwait(ScePthreadCond* cond, ScePthreadMutex* mutex, u64 usec) {
|
2024-06-15 13:36:07 +02:00
|
|
|
cond = createCond(cond);
|
2024-05-30 11:51:04 +02:00
|
|
|
if (cond == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
if (mutex == nullptr || *mutex == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
timespec time{};
|
|
|
|
time.tv_sec = usec / 1000000;
|
|
|
|
time.tv_nsec = ((usec % 1000000) * 1000);
|
|
|
|
int result = pthread_cond_timedwait(&(*cond)->cond, &(*mutex)->pth_mutex, &time);
|
|
|
|
|
2024-06-14 09:37:26 +02:00
|
|
|
// LOG_INFO(Kernel_Pthread, "scePthreadCondTimedwait, result={}", result);
|
2024-05-30 11:51:04 +02:00
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case 0:
|
|
|
|
return SCE_OK;
|
|
|
|
case ETIMEDOUT:
|
|
|
|
return SCE_KERNEL_ERROR_ETIMEDOUT;
|
|
|
|
case EINTR:
|
|
|
|
return SCE_KERNEL_ERROR_EINTR;
|
|
|
|
case EAGAIN:
|
|
|
|
return SCE_KERNEL_ERROR_EAGAIN;
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-08 08:23:55 +02:00
|
|
|
int PS4_SYSV_ABI scePthreadCondDestroy(ScePthreadCond* cond) {
|
|
|
|
if (cond == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
int result = pthread_cond_destroy(&(*cond)->cond);
|
|
|
|
|
2024-08-08 14:02:10 +02:00
|
|
|
LOG_DEBUG(Kernel_Pthread, "scePthreadCondDestroy, result={}", result);
|
2024-06-08 08:23:55 +02:00
|
|
|
|
2024-08-05 12:45:28 +02:00
|
|
|
delete *cond;
|
|
|
|
*cond = nullptr;
|
|
|
|
|
2024-06-08 08:23:55 +02:00
|
|
|
switch (result) {
|
|
|
|
case 0:
|
|
|
|
return SCE_OK;
|
|
|
|
case EBUSY:
|
|
|
|
return SCE_KERNEL_ERROR_EBUSY;
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-10 18:52:41 +01:00
|
|
|
int PS4_SYSV_ABI posix_pthread_mutex_init(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr) {
|
2024-04-02 17:07:24 +02:00
|
|
|
// LOG_INFO(Kernel_Pthread, "posix pthread_mutex_init redirect to scePthreadMutexInit");
|
2023-11-10 18:52:41 +01:00
|
|
|
int result = scePthreadMutexInit(mutex, attr, nullptr);
|
|
|
|
if (result < 0) {
|
2024-02-23 21:57:57 +01:00
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
2023-11-11 08:45:47 +01:00
|
|
|
return rt;
|
2023-11-10 18:52:41 +01:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-11-10 20:08:32 +01:00
|
|
|
int PS4_SYSV_ABI posix_pthread_mutex_lock(ScePthreadMutex* mutex) {
|
2024-04-02 17:07:24 +02:00
|
|
|
// LOG_INFO(Kernel_Pthread, "posix pthread_mutex_lock redirect to scePthreadMutexLock");
|
2023-11-10 20:08:32 +01:00
|
|
|
int result = scePthreadMutexLock(mutex);
|
|
|
|
if (result < 0) {
|
2024-02-23 21:57:57 +01:00
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
2023-11-11 08:45:47 +01:00
|
|
|
return rt;
|
2023-11-10 20:08:32 +01:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_mutex_unlock(ScePthreadMutex* mutex) {
|
2024-04-02 17:07:24 +02:00
|
|
|
// LOG_INFO(Kernel_Pthread, "posix pthread_mutex_unlock redirect to scePthreadMutexUnlock");
|
2023-11-10 20:08:32 +01:00
|
|
|
int result = scePthreadMutexUnlock(mutex);
|
|
|
|
if (result < 0) {
|
2024-02-23 21:57:57 +01:00
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
2023-11-11 08:45:47 +01:00
|
|
|
return rt;
|
2023-11-10 20:08:32 +01:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-06-08 08:23:55 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_mutex_destroy(ScePthreadMutex* mutex) {
|
|
|
|
int result = scePthreadMutexDestroy(mutex);
|
|
|
|
if (result < 0) {
|
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_cond_wait(ScePthreadCond* cond, ScePthreadMutex* mutex) {
|
|
|
|
int result = scePthreadCondWait(cond, mutex);
|
|
|
|
if (result < 0) {
|
2024-07-25 22:01:12 +02:00
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_cond_timedwait(ScePthreadCond* cond, ScePthreadMutex* mutex,
|
|
|
|
u64 usec) {
|
|
|
|
int result = scePthreadCondTimedwait(cond, mutex, usec);
|
|
|
|
if (result < 0) {
|
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
|
|
|
return rt;
|
2024-06-08 08:23:55 +02:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-11-16 12:31:12 +01:00
|
|
|
int PS4_SYSV_ABI posix_pthread_cond_broadcast(ScePthreadCond* cond) {
|
|
|
|
int result = scePthreadCondBroadcast(cond);
|
|
|
|
if (result != 0) {
|
2024-02-23 21:57:57 +01:00
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
2023-11-16 12:31:12 +01:00
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-06-08 08:23:55 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_mutexattr_init(ScePthreadMutexattr* attr) {
|
|
|
|
int result = scePthreadMutexattrInit(attr);
|
|
|
|
if (result < 0) {
|
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_mutexattr_settype(ScePthreadMutexattr* attr, int type) {
|
|
|
|
int result = scePthreadMutexattrSettype(attr, type);
|
|
|
|
if (result < 0) {
|
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_mutexattr_destroy(ScePthreadMutexattr* attr) {
|
|
|
|
int result = scePthreadMutexattrDestroy(attr);
|
|
|
|
if (result < 0) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-07-17 22:34:22 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_once(pthread_once_t* once_control, void (*init_routine)(void)) {
|
|
|
|
return pthread_once(once_control, init_routine);
|
|
|
|
}
|
|
|
|
|
2024-06-08 08:23:55 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_mutexattr_setprotocol(ScePthreadMutexattr* attr, int protocol) {
|
|
|
|
int result = scePthreadMutexattrSetprotocol(attr, protocol);
|
|
|
|
if (result < 0) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-07-09 11:18:34 +02:00
|
|
|
#ifndef HAVE_PTHREAD_MUTEX_TIMEDLOCK
|
|
|
|
static int pthread_mutex_timedlock(pthread_mutex_t* mutex, const struct timespec* abstime) {
|
|
|
|
int rc;
|
|
|
|
while ((rc = pthread_mutex_trylock(mutex)) == EBUSY) {
|
|
|
|
struct timespec curr_time;
|
|
|
|
clock_gettime(CLOCK_REALTIME, &curr_time);
|
|
|
|
|
|
|
|
s64 remaining_ns = 0;
|
|
|
|
remaining_ns +=
|
|
|
|
(static_cast<s64>(abstime->tv_sec) - static_cast<s64>(curr_time.tv_sec)) * 1000000000L;
|
|
|
|
remaining_ns += static_cast<s64>(abstime->tv_nsec) - static_cast<s64>(curr_time.tv_nsec);
|
|
|
|
|
|
|
|
if (remaining_ns <= 0) {
|
|
|
|
return ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct timespec sleep_time;
|
|
|
|
sleep_time.tv_sec = 0;
|
|
|
|
if (remaining_ns < 5000000L) {
|
|
|
|
sleep_time.tv_nsec = remaining_ns;
|
|
|
|
} else {
|
|
|
|
sleep_time.tv_nsec = 5000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
nanosleep(&sleep_time, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-07-05 14:23:35 +02:00
|
|
|
int PS4_SYSV_ABI scePthreadMutexTimedlock(ScePthreadMutex* mutex, u64 usec) {
|
|
|
|
mutex = createMutex(mutex);
|
|
|
|
if (mutex == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
timespec time{};
|
|
|
|
time.tv_sec = usec / 1000000;
|
|
|
|
time.tv_nsec = ((usec % 1000000) * 1000);
|
|
|
|
int result = pthread_mutex_timedlock(&(*mutex)->pth_mutex, &time);
|
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case 0:
|
|
|
|
return SCE_OK;
|
|
|
|
case ETIMEDOUT:
|
|
|
|
return SCE_KERNEL_ERROR_ETIMEDOUT;
|
|
|
|
case EINTR:
|
|
|
|
return SCE_KERNEL_ERROR_EINTR;
|
|
|
|
case EAGAIN:
|
|
|
|
return SCE_KERNEL_ERROR_EAGAIN;
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-02 17:07:24 +02:00
|
|
|
static int pthread_copy_attributes(ScePthreadAttr* dst, const ScePthreadAttr* src) {
|
|
|
|
if (dst == nullptr || *dst == nullptr || src == nullptr || *src == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 mask = 0;
|
|
|
|
int state = 0;
|
|
|
|
size_t guard_size = 0;
|
|
|
|
int inherit_sched = 0;
|
|
|
|
SceKernelSchedParam param = {};
|
|
|
|
int policy = 0;
|
|
|
|
void* stack_addr = nullptr;
|
|
|
|
size_t stack_size = 0;
|
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
result = (result == 0 ? scePthreadAttrGetaffinity(src, &mask) : result);
|
|
|
|
result = (result == 0 ? scePthreadAttrGetdetachstate(src, &state) : result);
|
|
|
|
result = (result == 0 ? scePthreadAttrGetguardsize(src, &guard_size) : result);
|
|
|
|
result = (result == 0 ? scePthreadAttrGetinheritsched(src, &inherit_sched) : result);
|
|
|
|
result = (result == 0 ? scePthreadAttrGetschedparam(src, ¶m) : result);
|
|
|
|
result = (result == 0 ? scePthreadAttrGetschedpolicy(src, &policy) : result);
|
|
|
|
result = (result == 0 ? scePthreadAttrGetstackaddr(src, &stack_addr) : result);
|
|
|
|
result = (result == 0 ? scePthreadAttrGetstacksize(src, &stack_size) : result);
|
|
|
|
|
|
|
|
result = (result == 0 ? scePthreadAttrSetaffinity(dst, mask) : result);
|
|
|
|
result = (result == 0 ? scePthreadAttrSetdetachstate(dst, state) : result);
|
|
|
|
result = (result == 0 ? scePthreadAttrSetguardsize(dst, guard_size) : result);
|
|
|
|
result = (result == 0 ? scePthreadAttrSetinheritsched(dst, inherit_sched) : result);
|
|
|
|
result = (result == 0 ? scePthreadAttrSetschedparam(dst, ¶m) : result);
|
|
|
|
result = (result == 0 ? scePthreadAttrSetschedpolicy(dst, policy) : result);
|
|
|
|
if (stack_addr != nullptr) {
|
|
|
|
result = (result == 0 ? scePthreadAttrSetstackaddr(dst, stack_addr) : result);
|
|
|
|
}
|
|
|
|
if (stack_size != 0) {
|
|
|
|
result = (result == 0 ? scePthreadAttrSetstacksize(dst, stack_size) : result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadAttrGet(ScePthread thread, ScePthreadAttr* attr) {
|
|
|
|
if (thread == nullptr || attr == nullptr || *attr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pthread_copy_attributes(attr, &thread->attr);
|
|
|
|
}
|
|
|
|
|
2024-04-04 18:16:10 +02:00
|
|
|
static void cleanup_thread(void* arg) {
|
|
|
|
auto* thread = static_cast<ScePthread>(arg);
|
2024-06-15 13:36:07 +02:00
|
|
|
for (const auto& [key, destructor] : thread->key_destructors) {
|
|
|
|
if (void* value = pthread_getspecific(key); value != nullptr) {
|
|
|
|
destructor(value);
|
|
|
|
}
|
|
|
|
}
|
2024-04-04 18:16:10 +02:00
|
|
|
thread->is_almost_done = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void* run_thread(void* arg) {
|
|
|
|
auto* thread = static_cast<ScePthread>(arg);
|
2024-06-01 22:50:03 +02:00
|
|
|
Common::SetCurrentThreadName(thread->name.c_str());
|
2024-06-05 21:08:18 +02:00
|
|
|
auto* linker = Common::Singleton<Core::Linker>::Instance();
|
|
|
|
linker->InitTlsForThread(false);
|
2024-04-04 18:16:10 +02:00
|
|
|
void* ret = nullptr;
|
|
|
|
g_pthread_self = thread;
|
|
|
|
pthread_cleanup_push(cleanup_thread, thread);
|
|
|
|
thread->is_started = true;
|
|
|
|
ret = thread->entry(thread->arg);
|
|
|
|
pthread_cleanup_pop(1);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadCreate(ScePthread* thread, const ScePthreadAttr* attr,
|
2024-06-15 13:36:07 +02:00
|
|
|
PthreadEntryFunc start_routine, void* arg, const char* name) {
|
2024-04-04 18:16:10 +02:00
|
|
|
if (thread == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* pthread_pool = g_pthread_cxt->GetPthreadPool();
|
|
|
|
|
|
|
|
if (attr == nullptr) {
|
|
|
|
attr = g_pthread_cxt->GetDefaultAttr();
|
|
|
|
}
|
|
|
|
|
|
|
|
*thread = pthread_pool->Create();
|
|
|
|
|
|
|
|
if ((*thread)->attr != nullptr) {
|
|
|
|
scePthreadAttrDestroy(&(*thread)->attr);
|
|
|
|
}
|
|
|
|
scePthreadAttrInit(&(*thread)->attr);
|
|
|
|
|
|
|
|
int result = pthread_copy_attributes(&(*thread)->attr, attr);
|
2024-07-04 23:15:44 +02:00
|
|
|
ASSERT(result == 0);
|
2024-04-04 18:16:10 +02:00
|
|
|
|
2024-07-04 23:15:44 +02:00
|
|
|
if (name != NULL) {
|
|
|
|
(*thread)->name = name;
|
|
|
|
} else {
|
|
|
|
(*thread)->name = "no-name";
|
2024-04-04 18:16:10 +02:00
|
|
|
}
|
2024-07-04 23:15:44 +02:00
|
|
|
(*thread)->entry = start_routine;
|
|
|
|
(*thread)->arg = arg;
|
|
|
|
(*thread)->is_almost_done = false;
|
|
|
|
(*thread)->is_detached = (*attr)->detached;
|
|
|
|
(*thread)->is_started = false;
|
|
|
|
|
|
|
|
pthread_attr_setstacksize(&(*attr)->pth_attr, 2_MB);
|
|
|
|
result = pthread_create(&(*thread)->pth, &(*attr)->pth_attr, run_thread, *thread);
|
2024-04-04 18:16:10 +02:00
|
|
|
|
2024-04-04 18:47:59 +02:00
|
|
|
LOG_INFO(Kernel_Pthread, "thread create name = {}", (*thread)->name);
|
2024-04-04 18:16:10 +02:00
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case 0:
|
|
|
|
return SCE_OK;
|
|
|
|
case ENOMEM:
|
|
|
|
return SCE_KERNEL_ERROR_ENOMEM;
|
|
|
|
case EAGAIN:
|
|
|
|
return SCE_KERNEL_ERROR_EAGAIN;
|
|
|
|
case EDEADLK:
|
|
|
|
return SCE_KERNEL_ERROR_EDEADLK;
|
|
|
|
case EPERM:
|
|
|
|
return SCE_KERNEL_ERROR_EPERM;
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ScePthread PThreadPool::Create() {
|
|
|
|
std::scoped_lock lock{m_mutex};
|
|
|
|
|
|
|
|
for (auto* p : m_threads) {
|
|
|
|
if (p->is_free) {
|
|
|
|
p->is_free = false;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* ret = new PthreadInternal{};
|
|
|
|
ret->is_free = false;
|
|
|
|
ret->is_detached = false;
|
|
|
|
ret->is_almost_done = false;
|
|
|
|
ret->attr = nullptr;
|
|
|
|
|
|
|
|
m_threads.push_back(ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-04-05 08:27:13 +02:00
|
|
|
void PS4_SYSV_ABI scePthreadYield() {
|
|
|
|
sched_yield();
|
|
|
|
}
|
|
|
|
|
2024-06-20 16:10:14 +02:00
|
|
|
void PS4_SYSV_ABI posix_pthread_yield() {
|
|
|
|
sched_yield();
|
|
|
|
}
|
|
|
|
|
2024-06-08 08:23:55 +02:00
|
|
|
int PS4_SYSV_ABI scePthreadAttrGetstack(ScePthreadAttr* attr, void** addr, size_t* size) {
|
|
|
|
|
|
|
|
int result = pthread_attr_getstack(&(*attr)->pth_attr, addr, size);
|
|
|
|
LOG_INFO(Kernel_Pthread, "scePthreadAttrGetstack: result = {}", result);
|
|
|
|
|
|
|
|
if (result == 0) {
|
|
|
|
return SCE_OK;
|
|
|
|
}
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadJoin(ScePthread thread, void** res) {
|
|
|
|
int result = pthread_join(thread->pth, res);
|
|
|
|
LOG_INFO(Kernel_Pthread, "scePthreadJoin result = {}", result);
|
|
|
|
thread->is_detached = false;
|
|
|
|
return ORBIS_OK;
|
|
|
|
}
|
|
|
|
|
2024-06-08 19:13:02 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_join(ScePthread thread, void** res) {
|
|
|
|
int result = pthread_join(thread->pth, res);
|
|
|
|
LOG_INFO(Kernel_Pthread, "posix_pthread_join result = {}", result);
|
|
|
|
thread->is_detached = false;
|
|
|
|
return ORBIS_OK;
|
|
|
|
}
|
|
|
|
|
2024-05-13 13:04:25 +02:00
|
|
|
int PS4_SYSV_ABI scePthreadDetach(ScePthread thread) {
|
|
|
|
LOG_INFO(Kernel_Pthread, "thread create name = {}", thread->name);
|
|
|
|
thread->is_detached = true;
|
|
|
|
return ORBIS_OK;
|
|
|
|
}
|
|
|
|
|
2024-06-08 08:23:55 +02:00
|
|
|
ScePthread PS4_SYSV_ABI posix_pthread_self() {
|
2024-05-13 14:08:15 +02:00
|
|
|
return g_pthread_self;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadCondSignal(ScePthreadCond* cond) {
|
2024-07-10 18:20:19 +02:00
|
|
|
cond = createCond(cond);
|
2024-05-13 14:08:15 +02:00
|
|
|
if (cond == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = pthread_cond_signal(&(*cond)->cond);
|
|
|
|
|
2024-06-14 09:37:26 +02:00
|
|
|
// LOG_INFO(Kernel_Pthread, "scePthreadCondSignal, result={}", result);
|
2024-05-13 14:08:15 +02:00
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case 0:
|
|
|
|
return SCE_OK;
|
|
|
|
case EBUSY:
|
|
|
|
return SCE_KERNEL_ERROR_EBUSY;
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadCondWait(ScePthreadCond* cond, ScePthreadMutex* mutex) {
|
2024-06-15 13:36:07 +02:00
|
|
|
cond = createCond(cond);
|
|
|
|
if (cond == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
2024-05-13 14:08:15 +02:00
|
|
|
}
|
|
|
|
if (mutex == nullptr || *mutex == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
int result = pthread_cond_wait(&(*cond)->cond, &(*mutex)->pth_mutex);
|
|
|
|
|
2024-08-05 12:45:28 +02:00
|
|
|
LOG_DEBUG(Kernel_Pthread, "scePthreadCondWait, result={}", result);
|
2024-05-13 14:08:15 +02:00
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case 0:
|
|
|
|
return SCE_OK;
|
|
|
|
case EINTR:
|
|
|
|
return SCE_KERNEL_ERROR_EINTR;
|
|
|
|
case EAGAIN:
|
|
|
|
return SCE_KERNEL_ERROR_EAGAIN;
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadCondattrDestroy(ScePthreadCondattr* attr) {
|
|
|
|
if (attr == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
int result = pthread_condattr_destroy(&(*attr)->cond_attr);
|
|
|
|
|
2024-08-05 12:45:28 +02:00
|
|
|
LOG_DEBUG(Kernel_Pthread, "scePthreadCondattrDestroy: result = {} ", result);
|
2024-05-13 14:08:15 +02:00
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case 0:
|
|
|
|
return SCE_OK;
|
|
|
|
case ENOMEM:
|
|
|
|
return SCE_KERNEL_ERROR_ENOMEM;
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-13 19:09:32 +02:00
|
|
|
int PS4_SYSV_ABI scePthreadMutexTrylock(ScePthreadMutex* mutex) {
|
2024-06-15 13:36:07 +02:00
|
|
|
mutex = createMutex(mutex);
|
2024-05-13 19:09:32 +02:00
|
|
|
if (mutex == nullptr) {
|
|
|
|
return ORBIS_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = pthread_mutex_trylock(&(*mutex)->pth_mutex);
|
|
|
|
if (result != 0) {
|
2024-06-10 21:59:12 +02:00
|
|
|
LOG_TRACE(Kernel_Pthread, "name={}, result={}", (*mutex)->name, result);
|
2024-05-13 19:09:32 +02:00
|
|
|
}
|
2024-06-15 10:28:51 +02:00
|
|
|
|
2024-05-13 19:09:32 +02:00
|
|
|
switch (result) {
|
|
|
|
case 0:
|
|
|
|
return ORBIS_OK;
|
|
|
|
case EAGAIN:
|
|
|
|
return ORBIS_KERNEL_ERROR_EAGAIN;
|
|
|
|
case EBUSY:
|
|
|
|
return ORBIS_KERNEL_ERROR_EBUSY;
|
|
|
|
case EINVAL:
|
|
|
|
default:
|
|
|
|
return ORBIS_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-16 19:09:08 +02:00
|
|
|
int PS4_SYSV_ABI scePthreadEqual(ScePthread thread1, ScePthread thread2) {
|
|
|
|
return (thread1 == thread2 ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2024-06-08 19:01:28 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_equal(ScePthread thread1, ScePthread thread2) {
|
|
|
|
return (thread1 == thread2 ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2024-06-05 21:08:18 +02:00
|
|
|
struct TlsIndex {
|
|
|
|
u64 ti_module;
|
|
|
|
u64 ti_offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
void* PS4_SYSV_ABI __tls_get_addr(TlsIndex* index) {
|
|
|
|
auto* linker = Common::Singleton<Core::Linker>::Instance();
|
|
|
|
return linker->TlsGetAddr(index->ti_module, index->ti_offset);
|
|
|
|
}
|
|
|
|
|
2024-06-08 08:23:55 +02:00
|
|
|
int PS4_SYSV_ABI posix_sched_get_priority_max() {
|
|
|
|
return ORBIS_KERNEL_PRIO_FIFO_HIGHEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_sched_get_priority_min() {
|
|
|
|
return ORBIS_KERNEL_PRIO_FIFO_LOWEST;
|
|
|
|
}
|
|
|
|
|
2024-06-08 19:13:02 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_mutex_trylock(ScePthreadMutex* mutex) {
|
|
|
|
int result = scePthreadMutexTrylock(mutex);
|
|
|
|
if (result < 0) {
|
2024-06-15 13:36:07 +02:00
|
|
|
// UNREACHABLE();
|
2024-06-08 19:13:02 +02:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_attr_destroy(ScePthreadAttr* attr) {
|
|
|
|
int result = scePthreadAttrDestroy(attr);
|
|
|
|
if (result < 0) {
|
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-07-28 17:43:44 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_attr_setschedparam(ScePthreadAttr* attr,
|
|
|
|
const SceKernelSchedParam* param) {
|
|
|
|
int result = scePthreadAttrSetschedparam(attr, param);
|
|
|
|
if (result < 0) {
|
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_attr_setinheritsched(ScePthreadAttr* attr, int inheritSched) {
|
|
|
|
int result = scePthreadAttrSetinheritsched(attr, inheritSched);
|
|
|
|
if (result < 0) {
|
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_setprio(ScePthread thread, int prio) {
|
|
|
|
int result = scePthreadSetprio(thread, prio);
|
|
|
|
if (result < 0) {
|
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-06-08 19:13:02 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_attr_setdetachstate(ScePthreadAttr* attr, int detachstate) {
|
|
|
|
// LOG_INFO(Kernel_Pthread, "posix pthread_mutexattr_init redirect to scePthreadMutexattrInit");
|
|
|
|
int result = scePthreadAttrSetdetachstate(attr, detachstate);
|
|
|
|
if (result < 0) {
|
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_create_name_np(ScePthread* thread, const ScePthreadAttr* attr,
|
2024-06-15 13:36:07 +02:00
|
|
|
PthreadEntryFunc start_routine, void* arg,
|
2024-06-08 19:13:02 +02:00
|
|
|
const char* name) {
|
|
|
|
int result = scePthreadCreate(thread, attr, start_routine, arg, name);
|
|
|
|
if (result != 0) {
|
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-06-14 09:37:26 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_create(ScePthread* thread, const ScePthreadAttr* attr,
|
2024-06-15 13:36:07 +02:00
|
|
|
PthreadEntryFunc start_routine, void* arg) {
|
|
|
|
return posix_pthread_create_name_np(thread, attr, start_routine, arg, "NoName");
|
|
|
|
}
|
2024-06-13 23:58:57 +02:00
|
|
|
|
2024-06-15 13:36:07 +02:00
|
|
|
using Destructor = void (*)(void*);
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_key_create(u32* key, Destructor func) {
|
2024-07-09 11:18:34 +02:00
|
|
|
pthread_key_t thread_key;
|
|
|
|
int rc = pthread_key_create(&thread_key, func);
|
|
|
|
*key = static_cast<u32>(thread_key);
|
|
|
|
return rc;
|
2024-06-15 13:36:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_setspecific(int key, const void* value) {
|
|
|
|
return pthread_setspecific(key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* PS4_SYSV_ABI posix_pthread_getspecific(int key) {
|
|
|
|
return pthread_getspecific(key);
|
|
|
|
}
|
|
|
|
|
2024-06-16 01:01:20 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_cond_init(ScePthreadCond* cond, const ScePthreadCondattr* attr) {
|
2024-06-15 13:36:07 +02:00
|
|
|
// LOG_INFO(Kernel_Pthread, "posix pthread_mutex_init redirect to scePthreadMutexInit");
|
2024-06-16 01:01:20 +02:00
|
|
|
int result = scePthreadCondInit(cond, attr, "NoName");
|
2024-06-15 13:36:07 +02:00
|
|
|
if (result < 0) {
|
2024-06-14 09:37:26 +02:00
|
|
|
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP
|
|
|
|
? result + -SCE_KERNEL_ERROR_UNKNOWN
|
|
|
|
: POSIX_EOTHER;
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2024-06-15 13:36:07 +02:00
|
|
|
|
2024-06-15 16:51:51 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_cond_signal(ScePthreadCond* cond) {
|
|
|
|
int result = scePthreadCondSignal(cond);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_cond_destroy(ScePthreadCond* cond) {
|
|
|
|
int result = scePthreadCondDestroy(cond);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-06-15 13:36:07 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_setcancelstate(int state, int* oldstate) {
|
|
|
|
return pthread_setcancelstate(state, oldstate);
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_detach(ScePthread thread) {
|
|
|
|
return pthread_detach(thread->pth);
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_sem_init(sem_t* sem, int pshared, unsigned int value) {
|
|
|
|
return sem_init(sem, pshared, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_sem_wait(sem_t* sem) {
|
|
|
|
return sem_wait(sem);
|
|
|
|
}
|
|
|
|
|
2024-08-08 22:42:51 +02:00
|
|
|
int PS4_SYSV_ABI posix_sem_trywait(sem_t* sem) {
|
|
|
|
return sem_trywait(sem);
|
|
|
|
}
|
|
|
|
|
2024-07-29 01:31:15 +02:00
|
|
|
#ifndef HAVE_SEM_TIMEDWAIT
|
|
|
|
int sem_timedwait(sem_t* sem, const struct timespec* abstime) {
|
|
|
|
int rc;
|
|
|
|
while ((rc = sem_trywait(sem)) == EAGAIN) {
|
|
|
|
struct timespec curr_time;
|
|
|
|
clock_gettime(CLOCK_REALTIME, &curr_time);
|
|
|
|
|
|
|
|
s64 remaining_ns = 0;
|
|
|
|
remaining_ns +=
|
|
|
|
(static_cast<s64>(abstime->tv_sec) - static_cast<s64>(curr_time.tv_sec)) * 1000000000L;
|
|
|
|
remaining_ns += static_cast<s64>(abstime->tv_nsec) - static_cast<s64>(curr_time.tv_nsec);
|
|
|
|
|
|
|
|
if (remaining_ns <= 0) {
|
|
|
|
return ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct timespec sleep_time;
|
|
|
|
sleep_time.tv_sec = 0;
|
|
|
|
if (remaining_ns < 5000000L) {
|
|
|
|
sleep_time.tv_nsec = remaining_ns;
|
|
|
|
} else {
|
|
|
|
sleep_time.tv_nsec = 5000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
nanosleep(&sleep_time, nullptr);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-07-25 09:13:14 +02:00
|
|
|
int PS4_SYSV_ABI posix_sem_timedwait(sem_t* sem, const timespec* t) {
|
|
|
|
return sem_timedwait(sem, t);
|
|
|
|
}
|
|
|
|
|
2024-06-15 13:36:07 +02:00
|
|
|
int PS4_SYSV_ABI posix_sem_post(sem_t* sem) {
|
|
|
|
return sem_post(sem);
|
|
|
|
}
|
|
|
|
|
2024-07-24 08:03:26 +02:00
|
|
|
int PS4_SYSV_ABI posix_sem_destroy(sem_t* sem) {
|
|
|
|
return sem_destroy(sem);
|
|
|
|
}
|
|
|
|
|
2024-06-29 15:44:39 +02:00
|
|
|
int PS4_SYSV_ABI posix_sem_getvalue(sem_t* sem, int* sval) {
|
|
|
|
return sem_getvalue(sem, sval);
|
|
|
|
}
|
|
|
|
|
2024-07-30 21:37:05 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_attr_getstacksize(const pthread_attr_t* attr, size_t* size) {
|
|
|
|
return pthread_attr_getstacksize(attr, size);
|
|
|
|
}
|
|
|
|
|
2024-06-15 13:36:07 +02:00
|
|
|
int PS4_SYSV_ABI scePthreadGetschedparam(ScePthread thread, int* policy,
|
|
|
|
SceKernelSchedParam* param) {
|
|
|
|
return pthread_getschedparam(thread->pth, policy, param);
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadSetschedparam(ScePthread thread, int policy,
|
|
|
|
const SceKernelSchedParam* param) {
|
2024-06-16 00:50:07 +02:00
|
|
|
LOG_ERROR(Kernel_Pthread, "(STUBBED) called policy={}, sched_priority={}", policy,
|
|
|
|
param->sched_priority);
|
|
|
|
return ORBIS_OK;
|
2024-06-15 13:36:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadOnce(int* once_control, void (*init_routine)(void)) {
|
|
|
|
return pthread_once(reinterpret_cast<pthread_once_t*>(once_control), init_routine);
|
|
|
|
}
|
|
|
|
|
2024-06-22 17:12:04 +02:00
|
|
|
[[noreturn]] void PS4_SYSV_ABI scePthreadExit(void* value_ptr) {
|
2024-06-21 18:09:55 +02:00
|
|
|
pthread_exit(value_ptr);
|
2024-06-25 09:56:19 +02:00
|
|
|
UNREACHABLE();
|
2024-06-21 18:09:55 +02:00
|
|
|
}
|
|
|
|
|
2024-07-25 22:01:12 +02:00
|
|
|
[[noreturn]] void PS4_SYSV_ABI posix_pthread_exit(void* value_ptr) {
|
|
|
|
pthread_exit(value_ptr);
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2024-07-03 19:05:21 +02:00
|
|
|
int PS4_SYSV_ABI scePthreadGetthreadid() {
|
2024-07-04 08:38:25 +02:00
|
|
|
return (int)(size_t)g_pthread_self;
|
2024-07-03 19:05:21 +02:00
|
|
|
}
|
|
|
|
|
2024-07-04 10:22:43 +02:00
|
|
|
int PS4_SYSV_ABI scePthreadGetprio(ScePthread thread, int* prio) {
|
|
|
|
*prio = thread->prio;
|
|
|
|
return ORBIS_OK;
|
|
|
|
}
|
|
|
|
int PS4_SYSV_ABI scePthreadSetprio(ScePthread thread, int prio) {
|
|
|
|
thread->prio = prio;
|
|
|
|
return ORBIS_OK;
|
|
|
|
}
|
|
|
|
|
2024-07-14 08:34:48 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_condattr_init(ScePthreadCondattr* attr) {
|
|
|
|
int result = scePthreadCondattrInit(attr);
|
|
|
|
LOG_INFO(Kernel_Pthread,
|
|
|
|
"posix_pthread_condattr_init redirect to scePthreadCondattrInit, result = {}", result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_condattr_destroy(ScePthreadCondattr* attr) {
|
|
|
|
int result = scePthreadCondattrDestroy(attr);
|
|
|
|
LOG_INFO(Kernel_Pthread,
|
|
|
|
"posix_pthread_condattr_destroy redirect to scePthreadCondattrDestroy, result = {}",
|
|
|
|
result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_condattr_setclock(ScePthreadCondattr* attr, clockid_t clock) {
|
|
|
|
(*attr)->clock = clock;
|
|
|
|
return SCE_OK;
|
|
|
|
}
|
|
|
|
|
2024-07-24 08:03:26 +02:00
|
|
|
int PS4_SYSV_ABI posix_pthread_getschedparam(ScePthread thread, int* policy,
|
|
|
|
SceKernelSchedParam* param) {
|
|
|
|
return scePthreadGetschedparam(thread, policy, param);
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_setschedparam(ScePthread thread, int policy,
|
|
|
|
const SceKernelSchedParam* param) {
|
|
|
|
return scePthreadSetschedparam(thread, policy, param);
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI posix_pthread_attr_getschedpolicy(const ScePthreadAttr* attr, int* policy) {
|
|
|
|
return scePthreadAttrGetschedpolicy(attr, policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI scePthreadRename(ScePthread thread, const char* name) {
|
|
|
|
thread->name = name;
|
|
|
|
LOG_INFO(Kernel_Pthread, "scePthreadRename: name = {}", thread->name);
|
|
|
|
return SCE_OK;
|
|
|
|
}
|
|
|
|
|
2024-04-13 23:35:48 +02:00
|
|
|
void pthreadSymbolsRegister(Core::Loader::SymbolsResolver* sym) {
|
2024-06-15 13:36:07 +02:00
|
|
|
LIB_FUNCTION("lZzFeSxPl08", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_setcancelstate);
|
|
|
|
LIB_FUNCTION("0TyVk4MSLt0", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_cond_init);
|
2024-06-15 16:51:51 +02:00
|
|
|
LIB_FUNCTION("2MOy+rUfuhQ", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_cond_signal);
|
|
|
|
LIB_FUNCTION("RXXqi4CtF8w", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_cond_destroy);
|
2024-06-15 13:36:07 +02:00
|
|
|
LIB_FUNCTION("mqULNdimTn0", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_key_create);
|
|
|
|
LIB_FUNCTION("0-KXaS70xy4", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_getspecific);
|
|
|
|
LIB_FUNCTION("WrOLvHU0yQM", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_setspecific);
|
2023-11-10 19:51:02 +01:00
|
|
|
LIB_FUNCTION("4+h9EzwKF4I", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetschedpolicy);
|
|
|
|
LIB_FUNCTION("-Wreprtu0Qs", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetdetachstate);
|
2024-08-08 22:42:51 +02:00
|
|
|
LIB_FUNCTION("JaRMy+QcpeU", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrGetdetachstate);
|
2023-11-10 19:51:02 +01:00
|
|
|
LIB_FUNCTION("eXbUSpEaTsA", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetinheritsched);
|
|
|
|
LIB_FUNCTION("DzES9hQF4f4", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetschedparam);
|
|
|
|
LIB_FUNCTION("nsYoNRywwNg", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrInit);
|
2024-03-30 21:19:42 +01:00
|
|
|
LIB_FUNCTION("62KCwEMmzcM", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrDestroy);
|
2024-06-08 08:23:55 +02:00
|
|
|
LIB_FUNCTION("onNY9Byn-W8", "libkernel", 1, "libkernel", 1, 1, scePthreadJoin);
|
2024-05-13 13:04:25 +02:00
|
|
|
LIB_FUNCTION("4qGrR6eoP9Y", "libkernel", 1, "libkernel", 1, 1, scePthreadDetach);
|
2024-05-16 19:09:08 +02:00
|
|
|
LIB_FUNCTION("3PtV6p3QNX4", "libkernel", 1, "libkernel", 1, 1, scePthreadEqual);
|
2024-06-21 18:09:55 +02:00
|
|
|
LIB_FUNCTION("3kg7rT0NQIs", "libkernel", 1, "libkernel", 1, 1, scePthreadExit);
|
2024-07-25 22:01:12 +02:00
|
|
|
LIB_FUNCTION("FJrT5LuUBAU", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_exit);
|
2024-06-08 19:01:28 +02:00
|
|
|
LIB_FUNCTION("7Xl257M4VNI", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_equal);
|
2024-06-15 13:36:07 +02:00
|
|
|
LIB_FUNCTION("h9CcP3J0oVM", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_join);
|
2024-07-03 19:05:21 +02:00
|
|
|
LIB_FUNCTION("EI-5-jlq2dE", "libkernel", 1, "libkernel", 1, 1, scePthreadGetthreadid);
|
2024-07-04 10:22:43 +02:00
|
|
|
LIB_FUNCTION("1tKyG7RlMJo", "libkernel", 1, "libkernel", 1, 1, scePthreadGetprio);
|
|
|
|
LIB_FUNCTION("W0Hpm2X0uPE", "libkernel", 1, "libkernel", 1, 1, scePthreadSetprio);
|
2024-07-24 08:03:26 +02:00
|
|
|
LIB_FUNCTION("GBUY7ywdULE", "libkernel", 1, "libkernel", 1, 1, scePthreadRename);
|
2024-03-31 10:30:43 +02:00
|
|
|
|
2023-11-16 07:49:26 +01:00
|
|
|
LIB_FUNCTION("aI+OeCz8xrQ", "libkernel", 1, "libkernel", 1, 1, scePthreadSelf);
|
2024-06-08 08:23:55 +02:00
|
|
|
LIB_FUNCTION("EotR8a3ASf4", "libkernel", 1, "libkernel", 1, 1, posix_pthread_self);
|
|
|
|
LIB_FUNCTION("EotR8a3ASf4", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_self);
|
2023-11-16 07:49:26 +01:00
|
|
|
LIB_FUNCTION("3qxgM4ezETA", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetaffinity);
|
2024-03-30 21:19:42 +01:00
|
|
|
LIB_FUNCTION("8+s5BzZjxSg", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrGetaffinity);
|
2024-04-02 17:07:24 +02:00
|
|
|
LIB_FUNCTION("x1X76arYMxU", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrGet);
|
2024-06-15 13:36:07 +02:00
|
|
|
LIB_FUNCTION("FXPWHNk8Of0", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrGetschedparam);
|
|
|
|
LIB_FUNCTION("P41kTWUS3EI", "libkernel", 1, "libkernel", 1, 1, scePthreadGetschedparam);
|
|
|
|
LIB_FUNCTION("oIRFTjoILbg", "libkernel", 1, "libkernel", 1, 1, scePthreadSetschedparam);
|
2024-05-13 13:04:25 +02:00
|
|
|
LIB_FUNCTION("UTXzJbWhhTE", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetstacksize);
|
2024-06-05 21:08:18 +02:00
|
|
|
LIB_FUNCTION("vNe1w4diLCs", "libkernel", 1, "libkernel", 1, 1, __tls_get_addr);
|
2024-06-14 09:37:26 +02:00
|
|
|
LIB_FUNCTION("OxhIB8LB-PQ", "libkernel", 1, "libkernel", 1, 1, posix_pthread_create);
|
|
|
|
LIB_FUNCTION("OxhIB8LB-PQ", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_create);
|
2023-11-16 07:49:26 +01:00
|
|
|
LIB_FUNCTION("bt3CTBKmGyI", "libkernel", 1, "libkernel", 1, 1, scePthreadSetaffinity);
|
2024-07-28 17:43:44 +02:00
|
|
|
LIB_FUNCTION("rcrVFJsQWRY", "libkernel", 1, "libkernel", 1, 1, scePthreadGetaffinity);
|
2023-11-16 07:49:26 +01:00
|
|
|
LIB_FUNCTION("6UgtwV+0zb4", "libkernel", 1, "libkernel", 1, 1, scePthreadCreate);
|
2024-04-05 08:27:13 +02:00
|
|
|
LIB_FUNCTION("T72hz6ffq08", "libkernel", 1, "libkernel", 1, 1, scePthreadYield);
|
2024-06-20 16:10:14 +02:00
|
|
|
LIB_FUNCTION("B5GmVDKwpn0", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_yield);
|
|
|
|
|
2024-06-08 08:23:55 +02:00
|
|
|
LIB_FUNCTION("-quPa4SEJUw", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrGetstack);
|
2024-06-15 13:36:07 +02:00
|
|
|
LIB_FUNCTION("Ru36fiTtJzA", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrGetstackaddr);
|
|
|
|
LIB_FUNCTION("-fA+7ZlGDQs", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrGetstacksize);
|
2024-06-13 23:58:57 +02:00
|
|
|
LIB_FUNCTION("14bOACANTBo", "libkernel", 1, "libkernel", 1, 1, scePthreadOnce);
|
2024-04-05 08:27:13 +02:00
|
|
|
|
2023-11-16 12:31:12 +01:00
|
|
|
// mutex calls
|
2023-11-16 07:49:26 +01:00
|
|
|
LIB_FUNCTION("cmo1RIYva9o", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexInit);
|
2024-04-01 13:21:40 +02:00
|
|
|
LIB_FUNCTION("2Of0f+3mhhE", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexDestroy);
|
2023-11-16 07:49:26 +01:00
|
|
|
LIB_FUNCTION("F8bUHwAG284", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrInit);
|
2024-03-26 18:20:55 +01:00
|
|
|
LIB_FUNCTION("smWEktiyyG0", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrDestroy);
|
2023-11-16 07:49:26 +01:00
|
|
|
LIB_FUNCTION("iMp8QpE+XO4", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrSettype);
|
|
|
|
LIB_FUNCTION("1FGvU0i9saQ", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrSetprotocol);
|
2023-11-10 20:08:32 +01:00
|
|
|
LIB_FUNCTION("9UK1vLZQft4", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexLock);
|
|
|
|
LIB_FUNCTION("tn3VlD0hG60", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexUnlock);
|
2024-05-13 19:09:32 +02:00
|
|
|
LIB_FUNCTION("upoVrzMHFeE", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexTrylock);
|
2024-07-05 14:23:35 +02:00
|
|
|
LIB_FUNCTION("IafI2PxcPnQ", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexTimedlock);
|
|
|
|
|
2024-02-23 21:57:57 +01:00
|
|
|
// cond calls
|
2023-11-16 12:31:12 +01:00
|
|
|
LIB_FUNCTION("2Tb92quprl0", "libkernel", 1, "libkernel", 1, 1, scePthreadCondInit);
|
|
|
|
LIB_FUNCTION("m5-2bsNfv7s", "libkernel", 1, "libkernel", 1, 1, scePthreadCondattrInit);
|
|
|
|
LIB_FUNCTION("JGgj7Uvrl+A", "libkernel", 1, "libkernel", 1, 1, scePthreadCondBroadcast);
|
2024-05-13 14:08:15 +02:00
|
|
|
LIB_FUNCTION("WKAXJ4XBPQ4", "libkernel", 1, "libkernel", 1, 1, scePthreadCondWait);
|
|
|
|
LIB_FUNCTION("waPcxYiR3WA", "libkernel", 1, "libkernel", 1, 1, scePthreadCondattrDestroy);
|
2024-05-15 12:10:51 +02:00
|
|
|
LIB_FUNCTION("kDh-NfxgMtE", "libkernel", 1, "libkernel", 1, 1, scePthreadCondSignal);
|
2024-05-30 11:51:04 +02:00
|
|
|
LIB_FUNCTION("BmMjYxmew1w", "libkernel", 1, "libkernel", 1, 1, scePthreadCondTimedwait);
|
2024-06-08 08:23:55 +02:00
|
|
|
LIB_FUNCTION("g+PZd2hiacg", "libkernel", 1, "libkernel", 1, 1, scePthreadCondDestroy);
|
|
|
|
|
2023-11-10 18:52:41 +01:00
|
|
|
// posix calls
|
2024-06-08 08:23:55 +02:00
|
|
|
LIB_FUNCTION("wtkt-teR1so", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_attr_init);
|
|
|
|
LIB_FUNCTION("2Q0z6rnBrTE", "libScePosix", 1, "libkernel", 1, 1,
|
|
|
|
posix_pthread_attr_setstacksize);
|
2023-11-10 22:30:28 +01:00
|
|
|
LIB_FUNCTION("ttHNfU+qDBU", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_mutex_init);
|
2023-11-10 20:08:32 +01:00
|
|
|
LIB_FUNCTION("7H0iTOciTLo", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_mutex_lock);
|
|
|
|
LIB_FUNCTION("2Z+PpY6CaJg", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_mutex_unlock);
|
2024-06-08 08:23:55 +02:00
|
|
|
LIB_FUNCTION("ltCfaGr2JGE", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_mutex_destroy);
|
2024-07-01 21:42:45 +02:00
|
|
|
LIB_FUNCTION("Op8TBGY5KHg", "libkernel", 1, "libkernel", 1, 1, posix_pthread_cond_wait);
|
2024-06-08 08:23:55 +02:00
|
|
|
LIB_FUNCTION("Op8TBGY5KHg", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_cond_wait);
|
2024-07-25 22:01:12 +02:00
|
|
|
LIB_FUNCTION("27bAgiJmOh0", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_cond_timedwait);
|
2023-11-16 12:31:12 +01:00
|
|
|
LIB_FUNCTION("mkx2fVhNMsg", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_cond_broadcast);
|
2024-06-08 08:23:55 +02:00
|
|
|
LIB_FUNCTION("dQHWEsJtoE4", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_mutexattr_init);
|
|
|
|
LIB_FUNCTION("mDmgMOGVUqg", "libScePosix", 1, "libkernel", 1, 1,
|
|
|
|
posix_pthread_mutexattr_settype);
|
|
|
|
LIB_FUNCTION("5txKfcMUAok", "libScePosix", 1, "libkernel", 1, 1,
|
|
|
|
posix_pthread_mutexattr_setprotocol);
|
|
|
|
LIB_FUNCTION("HF7lK46xzjY", "libScePosix", 1, "libkernel", 1, 1,
|
|
|
|
posix_pthread_mutexattr_destroy);
|
2024-07-14 08:34:48 +02:00
|
|
|
LIB_FUNCTION("mKoTx03HRWA", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_condattr_init);
|
|
|
|
LIB_FUNCTION("dJcuQVn6-Iw", "libScePosix", 1, "libkernel", 1, 1,
|
|
|
|
posix_pthread_condattr_destroy);
|
|
|
|
LIB_FUNCTION("EjllaAqAPZo", "libScePosix", 1, "libkernel", 1, 1,
|
|
|
|
posix_pthread_condattr_setclock);
|
2024-07-17 22:34:22 +02:00
|
|
|
LIB_FUNCTION("Z4QosVuAsA0", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_once);
|
2024-07-24 08:03:26 +02:00
|
|
|
LIB_FUNCTION("RtLRV-pBTTY", "libScePosix", 1, "libkernel", 1, 1,
|
|
|
|
posix_pthread_attr_getschedpolicy);
|
2024-04-02 07:51:17 +02:00
|
|
|
|
2023-11-11 09:49:44 +01:00
|
|
|
// openorbis weird functions
|
|
|
|
LIB_FUNCTION("7H0iTOciTLo", "libkernel", 1, "libkernel", 1, 1, posix_pthread_mutex_lock);
|
2023-11-11 11:13:43 +01:00
|
|
|
LIB_FUNCTION("2Z+PpY6CaJg", "libkernel", 1, "libkernel", 1, 1, posix_pthread_mutex_unlock);
|
2023-11-16 12:31:12 +01:00
|
|
|
LIB_FUNCTION("mkx2fVhNMsg", "libkernel", 1, "libkernel", 1, 1, posix_pthread_cond_broadcast);
|
2024-06-08 19:13:02 +02:00
|
|
|
LIB_FUNCTION("K-jXhbt2gn4", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_mutex_trylock);
|
|
|
|
LIB_FUNCTION("E+tyo3lp5Lw", "libScePosix", 1, "libkernel", 1, 1,
|
|
|
|
posix_pthread_attr_setdetachstate);
|
|
|
|
LIB_FUNCTION("zHchY8ft5pk", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_attr_destroy);
|
2024-07-28 17:43:44 +02:00
|
|
|
LIB_FUNCTION("euKRgm0Vn2M", "libScePosix", 1, "libkernel", 1, 1,
|
|
|
|
posix_pthread_attr_setschedparam);
|
|
|
|
LIB_FUNCTION("7ZlAakEf0Qg", "libScePosix", 1, "libkernel", 1, 1,
|
|
|
|
posix_pthread_attr_setinheritsched);
|
|
|
|
LIB_FUNCTION("a2P9wYGeZvc", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_setprio);
|
2024-06-08 19:13:02 +02:00
|
|
|
LIB_FUNCTION("Jmi+9w9u0E4", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_create_name_np);
|
2024-06-15 13:36:07 +02:00
|
|
|
LIB_FUNCTION("OxhIB8LB-PQ", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_create);
|
|
|
|
LIB_FUNCTION("+U1R4WtXvoc", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_detach);
|
2024-06-08 08:23:55 +02:00
|
|
|
LIB_FUNCTION("CBNtXOoef-E", "libScePosix", 1, "libkernel", 1, 1, posix_sched_get_priority_max);
|
|
|
|
LIB_FUNCTION("m0iS6jNsXds", "libScePosix", 1, "libkernel", 1, 1, posix_sched_get_priority_min);
|
2024-07-24 08:03:26 +02:00
|
|
|
LIB_FUNCTION("FIs3-UQT9sg", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_getschedparam);
|
|
|
|
LIB_FUNCTION("Xs9hdiD7sAA", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_setschedparam);
|
2024-06-15 13:36:07 +02:00
|
|
|
LIB_FUNCTION("pDuPEf3m4fI", "libScePosix", 1, "libkernel", 1, 1, posix_sem_init);
|
|
|
|
LIB_FUNCTION("YCV5dGGBcCo", "libScePosix", 1, "libkernel", 1, 1, posix_sem_wait);
|
2024-08-08 22:42:51 +02:00
|
|
|
LIB_FUNCTION("WBWzsRifCEA", "libScePosix", 1, "libkernel", 1, 1, posix_sem_trywait);
|
2024-07-25 09:13:14 +02:00
|
|
|
LIB_FUNCTION("w5IHyvahg-o", "libScePosix", 1, "libkernel", 1, 1, posix_sem_timedwait);
|
2024-06-15 13:36:07 +02:00
|
|
|
LIB_FUNCTION("IKP8typ0QUk", "libScePosix", 1, "libkernel", 1, 1, posix_sem_post);
|
2024-07-24 08:03:26 +02:00
|
|
|
LIB_FUNCTION("cDW233RAwWo", "libScePosix", 1, "libkernel", 1, 1, posix_sem_destroy);
|
2024-06-29 15:44:39 +02:00
|
|
|
LIB_FUNCTION("Bq+LRV-N6Hk", "libScePosix", 1, "libkernel", 1, 1, posix_sem_getvalue);
|
2024-07-30 21:37:05 +02:00
|
|
|
LIB_FUNCTION("0qOtCR-ZHck", "libScePosix", 1, "libkernel", 1, 1,
|
|
|
|
posix_pthread_attr_getstacksize);
|
2024-06-07 20:30:26 +02:00
|
|
|
// libs
|
2024-06-15 13:36:07 +02:00
|
|
|
RwlockSymbolsRegister(sym);
|
|
|
|
SemaphoreSymbolsRegister(sym);
|
|
|
|
KeySymbolsRegister(sym);
|
2023-11-10 18:52:41 +01:00
|
|
|
}
|
|
|
|
|
2024-04-13 23:35:48 +02:00
|
|
|
} // namespace Libraries::Kernel
|