diff --git a/core/libs/prx/libkernel/Pthread/Posix/Mutex.cpp b/core/libs/prx/libkernel/Pthread/Posix/Mutex.cpp index a51401a86..ee0695d43 100644 --- a/core/libs/prx/libkernel/Pthread/Posix/Mutex.cpp +++ b/core/libs/prx/libkernel/Pthread/Posix/Mutex.cpp @@ -118,4 +118,11 @@ int APS5_VABI pthread_mutexattr_settype_nid_postfix(PthreadMutexattr* attr, int return PosixThread::ToErrno(scePthreadMutexattrSettype(attr, type)); } +int APS5_VABI pthread_mutexattr_gettype_nid_postfix(const PthreadMutexattr* attr, int* type) { + if (!attr || !*attr) return POSIX_EINVAL; + if (!type) throw std::runtime_error("pthread_mutexattr_gettype: null type"); + *type = static_cast((*attr)->type); + return 0; +} + } diff --git a/core/libs/tests/GuestPthreadMutexattr.cpp b/core/libs/tests/GuestPthreadMutexattr.cpp index 1725c4a38..410fb354e 100644 --- a/core/libs/tests/GuestPthreadMutexattr.cpp +++ b/core/libs/tests/GuestPthreadMutexattr.cpp @@ -8,6 +8,8 @@ int APS5_VABI pthread_mutexattr_destroy_nid_postfix(PthreadMutexattr* attr); int APS5_VABI pthread_mutexattr_setprotocol_nid_postfix(PthreadMutexattr* attr, int protocol); int APS5_VABI pthread_mutexattr_setprioceiling_nid_postfix(PthreadMutexattr* attr, int prioceiling); int APS5_VABI pthread_mutexattr_getprioceiling_nid_postfix(const PthreadMutexattr* attr, int* prioceiling); +int APS5_VABI pthread_mutexattr_settype_nid_postfix(PthreadMutexattr* attr, int type); +int APS5_VABI pthread_mutexattr_gettype_nid_postfix(const PthreadMutexattr* attr, int* type); int APS5_VABI pthread_mutex_init_nid_postfix(PthreadMutex* mutex, const PthreadMutexattr* attr); int APS5_VABI pthread_mutex_lock_nid_postfix(PthreadMutex* mutex); int APS5_VABI pthread_mutex_unlock_nid_postfix(PthreadMutex* mutex); @@ -33,7 +35,26 @@ static bool Throws(Call call) { return false; } +static void CheckType() { + PthreadMutexattr attr = nullptr; + Require(pthread_mutexattr_init_nid_postfix(&attr) == 0); + int type = -1; + Require(pthread_mutexattr_gettype_nid_postfix(&attr, &type) == 0 && type == 1); + for (const int set : {2, 3, 4, 1}) { + Require(pthread_mutexattr_settype_nid_postfix(&attr, set) == 0); + Require(pthread_mutexattr_gettype_nid_postfix(&attr, &type) == 0 && type == set); + } + Require(pthread_mutexattr_settype_nid_postfix(&attr, 5) == GUEST_EINVAL); + Require(pthread_mutexattr_gettype_nid_postfix(&attr, &type) == 0 && type == 1); + Require(Throws([&] { pthread_mutexattr_gettype_nid_postfix(&attr, nullptr); })); + Require(pthread_mutexattr_destroy_nid_postfix(&attr) == 0); + type = -1; + Require(pthread_mutexattr_gettype_nid_postfix(&attr, &type) == GUEST_EINVAL && type == -1); + Require(pthread_mutexattr_gettype_nid_postfix(nullptr, &type) == GUEST_EINVAL && type == -1); +} + int main() { + CheckType(); PthreadMutexattr attr = nullptr; Require(pthread_mutexattr_init_nid_postfix(&attr) == 0); int ceiling = -1;