From 7fcea3277d072e372c9c1dfb41c83791f7fa37b8 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Fri, 10 Nov 2023 23:30:28 +0200 Subject: [PATCH] some mutexlock , mutexunlock implementations --- src/core/hle/error_codes.h | 2 + .../libraries/libkernel/thread_management.cpp | 38 ++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/core/hle/error_codes.h b/src/core/hle/error_codes.h index cdb26407..3794432a 100644 --- a/src/core/hle/error_codes.h +++ b/src/core/hle/error_codes.h @@ -2,7 +2,9 @@ constexpr int SCE_OK = 0; +constexpr int SCE_KERNEL_ERROR_EPERM = 0x80020001; constexpr int SCE_KERNEL_ERROR_EBADF = 0x80020009; +constexpr int SCE_KERNEL_ERROR_EDEADLK = 0x8002000B; constexpr int SCE_KERNEL_ERROR_ENOMEM = 0x8002000c; // Insufficient memory constexpr int SCE_KERNEL_ERROR_EFAULT = 0x8002000e; // Invalid address pointer constexpr int SCE_KERNEL_ERROR_EINVAL = 0x80020016; // null or invalid states diff --git a/src/core/hle/libraries/libkernel/thread_management.cpp b/src/core/hle/libraries/libkernel/thread_management.cpp index 35b6b990..e8a7003e 100644 --- a/src/core/hle/libraries/libkernel/thread_management.cpp +++ b/src/core/hle/libraries/libkernel/thread_management.cpp @@ -133,6 +133,8 @@ int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMut *mutex = new PthreadMutexInternal{}; if (name != nullptr) { (*mutex)->name = name; + } else { + (*mutex)->name = "dummy"; } int result = pthread_mutex_init(&(*mutex)->pth_mutex, &(*attr)->pth_mutex_attr); @@ -193,8 +195,39 @@ int PS4_SYSV_ABI scePthreadMutexattrSetprotocol(ScePthreadMutexattr* attr, int p return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL; } -int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex) {} -int PS4_SYSV_ABI scePthreadMutexUnlock(ScePthreadMutex* mutex) {} +int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex) { + PRINT_FUNCTION_NAME(); + if (mutex == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + int result = pthread_mutex_lock(&(*mutex)->pth_mutex); + printf("mutex lock: %s, %d\n", (*mutex)->name.c_str(), result); + switch (result) { + 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; + } +} +int PS4_SYSV_ABI scePthreadMutexUnlock(ScePthreadMutex* mutex) { + PRINT_FUNCTION_NAME(); + + if (mutex == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + int result = pthread_mutex_unlock(&(*mutex)->pth_mutex); + printf("mutex unlock: %s, %d\n", (*mutex)->name.c_str(), result); + switch (result) { + 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; + } +} int PS4_SYSV_ABI posix_pthread_mutex_init(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr) { LOG_INFO_IF(log_pthread_file, "posix pthread_mutex_init redirect to scePthreadMutexInit\n"); @@ -236,6 +269,7 @@ void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("9UK1vLZQft4", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexLock); LIB_FUNCTION("tn3VlD0hG60", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexUnlock); // posix calls + LIB_FUNCTION("ttHNfU+qDBU", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_mutex_init); 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); }