From 70bbd700e2642b58ecfb3d145c5e7492eac94346 Mon Sep 17 00:00:00 2001 From: Dean Galvin Date: Tue, 29 Sep 2026 13:22:21 +1300 Subject: [PATCH] feat(libkernel): accept priority-inheritance mutexes scePthreadMutexattrSetprotocol threw for SCE_PTHREAD_PRIO_INHERIT, so a title creating its mutexes with priority inheritance stopped at the first one. Guest thread priorities are recorded (scePthreadSetprio/Getprio) but never applied to host scheduling, so there is no priority for a waiter to lend to the owner: an inheriting mutex locks, unlocks and reports errors exactly like a PRIO_NONE one here, and the protocol is accepted. The POSIX pthread_mutexattr_setprotocol wrapper already accepts it. Priority protection (PRIO_PROTECT, with its ceilings) and unknown protocols still throw. --- core/libs/prx/libkernel/Pthread/src/Mutex.cpp | 6 ++++-- core/libs/tests/GuestKernelErrors.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core/libs/prx/libkernel/Pthread/src/Mutex.cpp b/core/libs/prx/libkernel/Pthread/src/Mutex.cpp index 270c47655..598b914d1 100644 --- a/core/libs/prx/libkernel/Pthread/src/Mutex.cpp +++ b/core/libs/prx/libkernel/Pthread/src/Mutex.cpp @@ -118,8 +118,10 @@ int APS5_VABI scePthreadMutexattrSettype(PthreadMutexattr* attr, int type) { int APS5_VABI scePthreadMutexattrSetprotocol(PthreadMutexattr* attr, int protocol) { if (!attr || !*attr) throw std::invalid_argument("Mutex attributes are not initialized"); - if (protocol != 0) - throw std::invalid_argument("Mutex priority inheritance and protection are unsupported"); + constexpr int PrioNone = 0; + constexpr int PrioInherit = 1; + if (protocol != PrioNone && protocol != PrioInherit) + throw std::invalid_argument("Mutex priority protection is unsupported"); return 0; } diff --git a/core/libs/tests/GuestKernelErrors.cpp b/core/libs/tests/GuestKernelErrors.cpp index 96997af26..972d74aa0 100644 --- a/core/libs/tests/GuestKernelErrors.cpp +++ b/core/libs/tests/GuestKernelErrors.cpp @@ -1,6 +1,7 @@ #include "SceTypes.hpp" #include #include +#include extern "C" { int APS5_VABI sceKernelCreateEqueue(KernelEqueue* eq, const char* name); @@ -10,6 +11,7 @@ int APS5_VABI sceKernelDeleteUserEvent(KernelEqueue eq, int id); int APS5_VABI scePthreadMutexattrInit(PthreadMutexattr* attr); int APS5_VABI scePthreadMutexattrDestroy(PthreadMutexattr* attr); int APS5_VABI scePthreadMutexattrSettype(PthreadMutexattr* attr, int type); +int APS5_VABI scePthreadMutexattrSetprotocol(PthreadMutexattr* attr, int protocol); int APS5_VABI scePthreadMutexInit(PthreadMutex* mutex, const PthreadMutexattr* attr, const char* name); int APS5_VABI scePthreadMutexDestroy(PthreadMutex* mutex); int APS5_VABI scePthreadMutexLock(PthreadMutex* mutex); @@ -24,6 +26,9 @@ static constexpr int SCE_KERNEL_ERROR_EFAULT = static_cast(0x8002000E); static constexpr int SCE_KERNEL_ERROR_EINVAL = static_cast(0x80020016); static constexpr int SCE_KERNEL_ERROR_ETIMEDOUT = static_cast(0x8002003C); static constexpr int MUTEX_TYPE_ERRORCHECK = 1; +static constexpr int PRIO_NONE = 0; +static constexpr int PRIO_INHERIT = 1; +static constexpr int PRIO_PROTECT = 2; static void Require(bool value) { if (!value) std::abort(); } @@ -46,6 +51,15 @@ int main() { PthreadMutexattr attr = nullptr; Require(scePthreadMutexattrInit(&attr) == SCE_OK); Require(scePthreadMutexattrSettype(&attr, MUTEX_TYPE_ERRORCHECK) == SCE_OK); + Require(scePthreadMutexattrSetprotocol(&attr, PRIO_NONE) == SCE_OK); + Require(scePthreadMutexattrSetprotocol(&attr, PRIO_INHERIT) == SCE_OK); + bool protectionRejected = false; + try { + scePthreadMutexattrSetprotocol(&attr, PRIO_PROTECT); + } catch (const std::invalid_argument&) { + protectionRejected = true; + } + Require(protectionRejected); PthreadMutex mutex = nullptr; Require(scePthreadMutexInit(&mutex, &attr, nullptr) == SCE_OK); Require(scePthreadMutexattrDestroy(&attr) == SCE_OK);