Merge pull request #456 from StevenMiller123/sem_fix

Improve posix_sem functions
This commit is contained in:
georgemoralis 2024-08-17 10:57:19 +03:00 committed by GitHub
commit 43e92bb987
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 68 additions and 7 deletions

View File

@ -125,6 +125,37 @@ int ErrnoToSceKernelError(int e) {
return res > SCE_KERNEL_ERROR_ESTOP ? SCE_KERNEL_ERROR_UNKNOWN : res;
}
void SetPosixErrno(int e) {
// Some error numbers are different between supported OSes or the PS4
switch (e) {
case EPERM:
g_posix_errno = POSIX_EPERM;
break;
case EAGAIN:
g_posix_errno = POSIX_EAGAIN;
break;
case ENOMEM:
g_posix_errno = POSIX_ENOMEM;
break;
case EINVAL:
g_posix_errno = POSIX_EINVAL;
break;
case ENOSPC:
g_posix_errno = POSIX_ENOSPC;
break;
case ERANGE:
g_posix_errno = POSIX_ERANGE;
break;
case EDEADLK:
g_posix_errno = POSIX_EDEADLK;
break;
case ETIMEDOUT:
g_posix_errno = POSIX_ETIMEDOUT;
break;
default:
g_posix_errno = e;
}
}
int PS4_SYSV_ABI sceKernelMmap(void* addr, u64 len, int prot, int flags, int fd, size_t offset,
void** res) {
LOG_INFO(Kernel_Vmm, "called addr = {}, len = {}, prot = {}, flags = {}, fd = {}, offset = {}",

View File

@ -14,6 +14,7 @@ namespace Libraries::Kernel {
void ErrSceToPosix(int result);
int ErrnoToSceKernelError(int e);
void SetPosixErrno(int e);
struct OrbisTimesec {
time_t t;

View File

@ -11,6 +11,7 @@
#include "common/singleton.h"
#include "common/thread.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/kernel/libkernel.h"
#include "core/libraries/kernel/thread_management.h"
#include "core/libraries/kernel/threads/threads.h"
#include "core/libraries/libs.h"
@ -1374,15 +1375,27 @@ int PS4_SYSV_ABI posix_pthread_detach(ScePthread thread) {
}
int PS4_SYSV_ABI posix_sem_init(sem_t* sem, int pshared, unsigned int value) {
return sem_init(sem, pshared, value);
int result = sem_init(sem, pshared, value);
if (result == -1) {
SetPosixErrno(errno);
}
return result;
}
int PS4_SYSV_ABI posix_sem_wait(sem_t* sem) {
return sem_wait(sem);
int result = sem_wait(sem);
if (result == -1) {
SetPosixErrno(errno);
}
return result;
}
int PS4_SYSV_ABI posix_sem_trywait(sem_t* sem) {
return sem_trywait(sem);
int result = sem_trywait(sem);
if (result == -1) {
SetPosixErrno(errno);
}
return result;
}
#ifndef HAVE_SEM_TIMEDWAIT
@ -1416,19 +1429,35 @@ int sem_timedwait(sem_t* sem, const struct timespec* abstime) {
#endif
int PS4_SYSV_ABI posix_sem_timedwait(sem_t* sem, const timespec* t) {
return sem_timedwait(sem, t);
int result = sem_timedwait(sem, t);
if (result == -1) {
SetPosixErrno(errno);
}
return result;
}
int PS4_SYSV_ABI posix_sem_post(sem_t* sem) {
return sem_post(sem);
int result = sem_post(sem);
if (result == -1) {
SetPosixErrno(errno);
}
return result;
}
int PS4_SYSV_ABI posix_sem_destroy(sem_t* sem) {
return sem_destroy(sem);
int result = sem_destroy(sem);
if (result == -1) {
SetPosixErrno(errno);
}
return result;
}
int PS4_SYSV_ABI posix_sem_getvalue(sem_t* sem, int* sval) {
return sem_getvalue(sem, sval);
int result = sem_getvalue(sem, sval);
if (result == -1) {
SetPosixErrno(errno);
}
return result;
}
int PS4_SYSV_ABI posix_pthread_attr_getstacksize(const pthread_attr_t* attr, size_t* size) {