mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-22 16:43:05 -05:00
On a PS5 (firmware 12.70), of the values 0, 1, 2 and -1, pthread_condattr_setpshared accepts only 0 and leaves the attribute unchanged otherwise. pthread_condattr_getpshared reports 0 and returns EINVAL for a null, uninitialized or destroyed attribute, also with a null output. With an initialized attribute a null output crashes the console; here it throws. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
63 lines
2.9 KiB
C++
63 lines
2.9 KiB
C++
#include "SceTypes.hpp"
|
|
#include <cstdlib>
|
|
#include <initializer_list>
|
|
#include <stdexcept>
|
|
|
|
extern "C" {
|
|
int APS5_VABI scePthreadCondattrInit(PthreadCondattr* attr);
|
|
int APS5_VABI scePthreadCondattrDestroy(PthreadCondattr* attr);
|
|
int APS5_VABI scePthreadCondattrSetclock(PthreadCondattr* attr, KernelClockid clockId);
|
|
int APS5_VABI pthread_condattr_setclock_nid_postfix(PthreadCondattr* attr, KernelClockid clockId);
|
|
int APS5_VABI pthread_condattr_setpshared_nid_postfix(PthreadCondattr* attr, int pshared);
|
|
int APS5_VABI pthread_condattr_getpshared_nid_postfix(const PthreadCondattr* attr, int* pshared);
|
|
}
|
|
|
|
static constexpr int SCE_OK = 0;
|
|
static constexpr int SceEinval = static_cast<int>(0x80020016u);
|
|
static constexpr int GuestEinval = 22;
|
|
static constexpr KernelClockid Monotonic = 4;
|
|
|
|
static void Require(bool value) { if (!value) std::abort(); }
|
|
|
|
int main() {
|
|
PthreadCondattr unset = nullptr;
|
|
int sharing = -1;
|
|
Require(scePthreadCondattrSetclock(nullptr, Monotonic) == SceEinval);
|
|
Require(scePthreadCondattrSetclock(&unset, Monotonic) == SceEinval);
|
|
Require(scePthreadCondattrDestroy(nullptr) == SceEinval);
|
|
Require(scePthreadCondattrDestroy(&unset) == SceEinval);
|
|
Require(pthread_condattr_setclock_nid_postfix(&unset, Monotonic) == GuestEinval);
|
|
Require(pthread_condattr_setpshared_nid_postfix(nullptr, 0) == GuestEinval);
|
|
Require(pthread_condattr_setpshared_nid_postfix(&unset, 0) == GuestEinval);
|
|
Require(pthread_condattr_getpshared_nid_postfix(nullptr, &sharing) == GuestEinval && sharing == -1);
|
|
Require(pthread_condattr_getpshared_nid_postfix(&unset, &sharing) == GuestEinval && sharing == -1);
|
|
|
|
PthreadCondattr attr = nullptr;
|
|
Require(scePthreadCondattrInit(&attr) == SCE_OK);
|
|
for (const KernelClockid clock : {0, 1, 2, Monotonic, 5, 12}) {
|
|
Require(scePthreadCondattrSetclock(&attr, clock) == SCE_OK);
|
|
Require(pthread_condattr_setclock_nid_postfix(&attr, clock) == 0);
|
|
}
|
|
Require(pthread_condattr_getpshared_nid_postfix(&attr, &sharing) == 0 && sharing == 0);
|
|
for (const int invalid : {1, 2, -1}) {
|
|
Require(pthread_condattr_setpshared_nid_postfix(&attr, invalid) == GuestEinval);
|
|
sharing = -1;
|
|
Require(pthread_condattr_getpshared_nid_postfix(&attr, &sharing) == 0 && sharing == 0);
|
|
}
|
|
Require(pthread_condattr_setpshared_nid_postfix(&attr, 0) == 0);
|
|
sharing = -1;
|
|
Require(pthread_condattr_getpshared_nid_postfix(&attr, &sharing) == 0 && sharing == 0);
|
|
bool threw = false;
|
|
try {
|
|
pthread_condattr_getpshared_nid_postfix(&attr, nullptr);
|
|
} catch (const std::runtime_error&) {
|
|
threw = true;
|
|
}
|
|
Require(threw);
|
|
Require(scePthreadCondattrDestroy(&attr) == SCE_OK && attr == nullptr);
|
|
Require(scePthreadCondattrDestroy(&attr) == SceEinval);
|
|
sharing = -1;
|
|
Require(pthread_condattr_getpshared_nid_postfix(&attr, &sharing) == GuestEinval && sharing == -1);
|
|
Require(pthread_condattr_setpshared_nid_postfix(&attr, 0) == GuestEinval);
|
|
}
|