mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "SceTypes.hpp"
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
|
||||
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<int>(0x8002000E);
|
||||
static constexpr int SCE_KERNEL_ERROR_EINVAL = static_cast<int>(0x80020016);
|
||||
static constexpr int SCE_KERNEL_ERROR_ETIMEDOUT = static_cast<int>(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);
|
||||
|
||||
Reference in New Issue
Block a user