mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-23 10:35:03 +00:00
scePthreadMutexLock, scePthreadMutexUnLock
This commit is contained in:
parent
4fe9d76a7a
commit
332316b972
@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
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
|
||||
|
@ -162,8 +162,64 @@ int PS4_SYSV_ABI scePthreadMutexattrSetprotocol(ScePthreadMutexattr* attr, int p
|
||||
(*attr)->attr_protocol = pprotocol;
|
||||
return (result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL);
|
||||
}
|
||||
int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr, const char* name) {
|
||||
if (mutex == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
if (attr == nullptr) {
|
||||
ScePthreadMutexattr mutexattr = nullptr;
|
||||
scePthreadMutexattrInit(&mutexattr);
|
||||
attr = &mutexattr;
|
||||
}
|
||||
|
||||
*mutex = new PthreadMutexInternal{};
|
||||
|
||||
(*mutex)->name = name;
|
||||
|
||||
int result = pthread_mutex_init(&(*mutex)->mutex, &(*attr)->mutex_attr);
|
||||
|
||||
if (name != nullptr) {
|
||||
printf("\tmutex init: %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 ENOMEM: return SCE_KERNEL_ERROR_ENOMEM;
|
||||
default: return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex) {
|
||||
std::string name = "dummy";
|
||||
// we assume we need one mutex so init one (we don't even check if it exists TODO)
|
||||
scePthreadMutexInit(mutex, nullptr, name.c_str());
|
||||
|
||||
int result = pthread_mutex_lock(&(*mutex)->mutex);
|
||||
|
||||
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) {
|
||||
if (mutex == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int result = pthread_mutex_unlock(&(*mutex)->mutex);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}; // namespace HLE::Libs::LibKernel::ThreadManagement
|
@ -59,5 +59,6 @@ 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);
|
||||
|
||||
int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr, const char* name);
|
||||
int PS4_SYSV_ABI scePthreadMutexUnlock(ScePthreadMutex* mutex);
|
||||
} // namespace HLE::Libs::LibKernel::ThreadManagement
|
@ -1,14 +1,16 @@
|
||||
#include "../Loader/Elf.h"
|
||||
#include "LibKernel.h"
|
||||
#include "Libs.h"
|
||||
#include <debug.h>
|
||||
|
||||
#include <Util/log.h>
|
||||
#include "Kernel/memory_management.h"
|
||||
#include <debug.h>
|
||||
|
||||
#include "../../../Util/Singleton.h"
|
||||
#include "../Loader/Elf.h"
|
||||
#include "Kernel/Objects/physical_memory.h"
|
||||
#include "Kernel/ThreadManagement.h"
|
||||
#include "Kernel/cpu_management.h"
|
||||
#include "Kernel/event_queues.h"
|
||||
#include "Kernel/ThreadManagement.h"
|
||||
#include "Kernel/memory_management.h"
|
||||
#include "Libs.h"
|
||||
|
||||
namespace HLE::Libs::LibKernel {
|
||||
|
||||
@ -19,9 +21,7 @@ namespace HLE::Libs::LibKernel {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static PS4_SYSV_ABI void stack_chk_fail() { BREAKPOINT();
|
||||
}
|
||||
static PS4_SYSV_ABI void stack_chk_fail() { BREAKPOINT(); }
|
||||
u64 PS4_SYSV_ABI sceKernelReadTsc() {
|
||||
LARGE_INTEGER c;
|
||||
QueryPerformanceCounter(&c);
|
||||
@ -31,7 +31,6 @@ namespace HLE::Libs::LibKernel {
|
||||
PS4_SYSV_ABI void sysconf() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void open() { BREAKPOINT(); }
|
||||
|
||||
|
||||
PS4_SYSV_ABI void ioctl() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void sigprocmask() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void nanosleep() { BREAKPOINT(); }
|
||||
@ -43,19 +42,29 @@ namespace HLE::Libs::LibKernel {
|
||||
PS4_SYSV_ABI void pthread_rwlock_wrlock() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void pthread_cond_destroy() { BREAKPOINT(); }
|
||||
|
||||
|
||||
PS4_SYSV_ABI void pthread_rwlock_rdlock() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void pthread_setspecific() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void pthread_equal() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void pthread_mutex_unlock() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI int pthread_mutex_unlock(ThreadManagement::ScePthreadMutex* mutex) {
|
||||
// posix call the difference is that there is a different behaviour when it doesn't return 0 or SCE_OK
|
||||
int result = ThreadManagement::scePthreadMutexUnlock(mutex);
|
||||
if (result != 0) {
|
||||
BREAKPOINT();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
PS4_SYSV_ABI void pthread_cond_timedwait() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void poll() { BREAKPOINT(); }
|
||||
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() {
|
||||
//posix call
|
||||
|
||||
int PS4_SYSV_ABI pthread_mutex_lock(ThreadManagement::ScePthreadMutex* mutex) {
|
||||
// posix call the difference is that there is a different behaviour when it doesn't return 0 or SCE_OK
|
||||
int result = ThreadManagement::scePthreadMutexLock(mutex);
|
||||
if (result != 0) {
|
||||
BREAKPOINT();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
PS4_SYSV_ABI void munmap() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void pthread_mutex_destroy() { BREAKPOINT(); }
|
||||
@ -73,11 +82,12 @@ namespace HLE::Libs::LibKernel {
|
||||
PS4_SYSV_ABI void madvise() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void _writev() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void lseek() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void __error() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI int* __error() { return _errno(); }
|
||||
PS4_SYSV_ABI void pthread_once() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void pthread_cond_wait() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void raise() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void pthread_cond_signal() { BREAKPOINT(); }
|
||||
PS4_SYSV_ABI void _ioctl() { BREAKPOINT(); }
|
||||
|
||||
void LibKernel_Register(SymbolsResolver* sym) {
|
||||
// obj
|
||||
@ -99,6 +109,8 @@ namespace HLE::Libs::LibKernel {
|
||||
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);
|
||||
LIB_FUNCTION("9UK1vLZQft4", "libkernel", 1, "libkernel", 1, 1, ThreadManagement::scePthreadMutexLock);
|
||||
LIB_FUNCTION("tn3VlD0hG60", "libkernel", 1, "libkernel", 1, 1, ThreadManagement::scePthreadMutexUnlock);
|
||||
|
||||
// TODO
|
||||
LIB_FUNCTION("6XG4B33N09g", "libkernel", 1, "libkernel", 1, 1, sched_yield);
|
||||
@ -146,6 +158,7 @@ namespace HLE::Libs::LibKernel {
|
||||
LIB_FUNCTION("Op8TBGY5KHg", "libkernel", 1, "libkernel", 1, 1, pthread_cond_wait);
|
||||
LIB_FUNCTION("0t0-MxQNwK4", "libkernel", 1, "libkernel", 1, 1, raise);
|
||||
LIB_FUNCTION("2MOy+rUfuhQ", "libkernel", 1, "libkernel", 1, 1, pthread_cond_signal);
|
||||
LIB_FUNCTION("wW+k21cmbwQ", "libkernel", 1, "libkernel", 1, 1, _ioctl);
|
||||
}
|
||||
|
||||
};
|
||||
}; // namespace HLE::Libs::LibKernel
|
Loading…
Reference in New Issue
Block a user