Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/libs/prx/libkernel/Pthread/Posix/Cond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ int APS5_VABI pthread_condattr_init_nid_postfix(PthreadCondattr* attr) {

int APS5_VABI pthread_condattr_setclock_nid_postfix(PthreadCondattr* attr, KernelClockid clock_id) {
if (!attr || !*attr) return PosixThread::GUEST_EINVAL;
if (clock_id != 0 && clock_id != 1 && clock_id != 2 && clock_id != 4) return PosixThread::GUEST_EINVAL;
return toPosix(scePthreadCondattrSetclock(attr, clock_id));
}

Expand Down
44 changes: 44 additions & 0 deletions core/libs/tests/GuestCondTimedwait.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "SceTypes.hpp"
#include "prx/libkernel/Pthread/include/Pthread.hpp"
#include <atomic>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <limits>

extern "C" {
int APS5_VABI scePthreadCreate(Pthread* thread, const PthreadAttr* attr, PthreadEntry entry, void* arg, const char* name);
Expand All @@ -17,6 +20,11 @@ int APS5_VABI scePthreadCondDestroy(PthreadCond* cond);
int APS5_VABI scePthreadCondTimedwait(PthreadCond* cond, PthreadMutex* mutex, unsigned int usec);
int APS5_VABI scePthreadCondSignal(PthreadCond* cond);
int APS5_VABI pthread_cond_reltimedwait_np_nid_postfix(PthreadCond* cond, PthreadMutex* mutex, unsigned int usec);
int APS5_VABI pthread_condattr_init_nid_postfix(PthreadCondattr* attr);
int APS5_VABI pthread_condattr_destroy_nid_postfix(PthreadCondattr* attr);
int APS5_VABI pthread_condattr_setclock_nid_postfix(PthreadCondattr* attr, KernelClockid clockId);
int APS5_VABI pthread_cond_timedwait_nid_postfix(PthreadCond* cond, PthreadMutex* mutex, const KernelTimespec* abstime);
int* APS5_VABI __error_nid_postfix();
int APS5_VABI __cxa_atexit_nid_postfix(void (APS5_VABI *)(void*), void*, void*);
void APS5_VABI __pthread_cxa_finalize_nid_postfix(void*);
unsigned int APS5_VABI sceKernelSleep(unsigned int seconds);
Expand All @@ -29,6 +37,7 @@ static constexpr int SCE_OK = 0;
static constexpr int SCE_KERNEL_ERROR_ETIMEDOUT = static_cast<int>(0x8002003C);
static constexpr int SCE_KERNEL_ERROR_EBUSY = static_cast<int>(0x80020010);
static constexpr int POSIX_EPERM = 1;
static constexpr int POSIX_EINVAL = 22;
static constexpr int POSIX_ETIMEDOUT = 60;

static void Require(bool value) { if (!value) std::abort(); }
Expand Down Expand Up @@ -104,7 +113,42 @@ static void RelativeWait() {
Require(scePthreadMutexDestroy(&signalled.mutex) == SCE_OK);
}

static void AttributeClockValidation() {
PthreadCondattr empty = nullptr;
Require(pthread_condattr_setclock_nid_postfix(nullptr, 0) == POSIX_EINVAL);
Require(pthread_condattr_setclock_nid_postfix(&empty, 0) == POSIX_EINVAL);
for (const KernelClockid accepted : {0, 1, 2, 4}) {
PthreadCondattr attr = nullptr;
Require(pthread_condattr_init_nid_postfix(&attr) == 0);
*__error_nid_postfix() = 12345;
Require(pthread_condattr_setclock_nid_postfix(&attr, accepted) == 0);
Require(*__error_nid_postfix() == 12345);
for (const KernelClockid rejected : {std::numeric_limits<KernelClockid>::min(), -1, 3, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, std::numeric_limits<KernelClockid>::max()}) {
const int result = pthread_condattr_setclock_nid_postfix(&attr, rejected);
if (result != POSIX_EINVAL) {
std::fprintf(stderr, "pthread_condattr_setclock accepted unsupported clock %d: result %d\n", rejected, result);
std::abort();
}
Require(*__error_nid_postfix() == 12345);
Require(attr->_clockid == accepted);
}
Signalled signalled;
Require(scePthreadCondInit(&signalled.cond, &attr, nullptr) == 0);
Require(pthread_condattr_destroy_nid_postfix(&attr) == 0 && attr == nullptr);
Require(scePthreadMutexInit(&signalled.mutex, nullptr, nullptr) == 0);
Require(scePthreadMutexLock(&signalled.mutex) == 0);
const KernelTimespec expired{-1, 0};
Require(pthread_cond_timedwait_nid_postfix(&signalled.cond, &signalled.mutex, &expired) == POSIX_ETIMEDOUT);
RequireHeldByCaller(signalled);
Require(scePthreadMutexUnlock(&signalled.mutex) == 0);
Require(scePthreadMutexDestroy(&signalled.mutex) == 0);
Require(scePthreadCondDestroy(&signalled.cond) == 0);
}
}

int main() {
AttributeClockValidation();
RelativeWait();

Context context;
Expand Down
2 changes: 2 additions & 0 deletions docs/dev/debt/libkernel.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### Unknown function info

- [pthread_condattr_setclock](../../../core/libs/prx/libkernel/Pthread/Posix/Cond.cpp) (libkernel) accepts guest clock IDs 0, 1, 2 and 4 (`CLOCK_REALTIME`, `CLOCK_VIRTUAL`, `CLOCK_PROF`, `CLOCK_MONOTONIC`) and returns `EINVAL` without changing the attribute for any other ID, following FreeBSD 11 [thr_condattr.c](https://github.com/freebsd/freebsd-src/blob/releng/11.4/lib/libthr/thread/thr_condattr.c). The console's accepted clock IDs have not been measured.

- [getlogin_r](../../../core/libs/prx/libkernel/System/src/Login.cpp) (libkernel) returns the host effective account name: `GetUserNameW` as UTF-8 on Windows and `getpwuid_r(geteuid())` on POSIX. A valid account returns a name even without a login session; host `getlogin_r`, `USER` and `LOGNAME` are not consulted. The console's login name and behaviour without a session are unknown. Account lookup or encoding failures, a missing or empty account name, and POSIX account records exceeding the 16 KiB lookup buffer throw; there is no replacement name or retry. A short guest buffer returns `ERANGE` without modifying it, and a null output returns `EFAULT`.
- [sceCoredumpGetThreadContextInfo](../../../core/libs/prx/libkernel/System/src/Coredump.cpp) (libkernel, NID `ShChva57wIM`) - declared as a throwing stub. The pointer and size arguments and integer return type follow [SharpProspero's PS5 bindings](https://github.com/SvenGDK/SharpProspero/blob/5dfdb4b0b166e83dc9ae275001afb695f12c7174/src/SharpProspero/Interop/Kernel/KernelSystem.cs). The context structure and console behavior are unverified; the stub does not read or write caller memory. PPSA01736 imports it
- [sceKernelGetSystemSwVersion](../../../core/libs/prx/libkernel/System/src/SystemConfiguration.cpp) (libkernel) reports baseline system software version `0x01000000` ("01.000.000") for ProsperoStore (PPSA99000). The 0x28-byte layout (`uint64_t size` at 0, `versionString` at 8 and `version` at 0x24) matches [ProsperoStore's caller](https://github.com/blackbearreloaded/ProsperoStore/blob/20584011/src/diag/trace.cpp#L20-L26), [shadPS4](https://github.com/shadps4-emu/shadPS4/blob/811bfcd7d1/src/core/libraries/kernel/kernel.h#L45-L49), [fpPS4](https://github.com/red-prig/fpPS4/blob/04cefd43e6/kernel/ps4_libkernel.pas#L502-L506) and [OpenOrbis](https://github.com/OpenOrbis/OpenOrbis-PS4-Toolchain/blob/0a1aaf9dd4/include/orbis/_types/kernel.h#L256-L260). These sources support the structure layout, but not the reported version value: the console firmware version remains unverified. The checks are unverified too: a null pointer returns `SCE_KERNEL_ERROR_EFAULT` and a `size` other than 0x28 returns `SCE_KERNEL_ERROR_EINVAL`, while shadPS4 returns success for null and never reads `size`.
Expand Down
Loading