diff --git a/core/libs/prx/libkernel_sys/Export.cpp b/core/libs/prx/libkernel_sys/Export.cpp index ebbff629e08a..2680307623f9 100644 --- a/core/libs/prx/libkernel_sys/Export.cpp +++ b/core/libs/prx/libkernel_sys/Export.cpp @@ -1358,7 +1358,7 @@ void APS5_VABI scePthreadSetName(Pthread thread, const char* name) { static int QueryTitleWorkaround(const KernelTitleWorkaround* workaround, std::int32_t bit, std::int32_t* enabled) { if (!workaround || !enabled) return static_cast(0x8002000E); - if (static_cast(bit) > 0x78) return static_cast(0x80020016); + if (static_cast(bit) > 0x7F) return static_cast(0x80020016); KernelTitleWorkaround localWorkaround{}; const int saved = errno; if (!GuestCopyIn_nid_no_patch(&localWorkaround, workaround, sizeof(localWorkaround))) { diff --git a/core/libs/tests/GuestKernelSys.cpp b/core/libs/tests/GuestKernelSys.cpp index 4ae64d654450..3e64fcc98818 100644 --- a/core/libs/tests/GuestKernelSys.cpp +++ b/core/libs/tests/GuestKernelSys.cpp @@ -1259,10 +1259,9 @@ static void CheckProcessQueries() { Require(query(&workaround, 65, &enabled) == 0 && enabled == 0); Require(query(&workaround, 0x77, &enabled) == 0 && enabled == 0); Require(query(&workaround, 0x78, &enabled) == 0 && enabled == 1); - for (const std::int32_t refused : {0x79, 0x7E, 0x7F}) { - enabled = -1; - Require(query(&workaround, refused, &enabled) == static_cast(0x80020016) && enabled == -1); - } + Require(query(&workaround, 0x79, &enabled) == 0 && enabled == 0); + Require(query(&workaround, 0x7E, &enabled) == 0 && enabled == 0); + Require(query(&workaround, 0x7F, &enabled) == 0 && enabled == 1); } for (const std::uint64_t selector : {std::uint64_t{0}, std::uint64_t{0x28}}) { std::int32_t enabled = -1; @@ -1275,10 +1274,9 @@ static void CheckProcessQueries() { Require(sceKernelTitleWorkaroundIsEnabled2(&workaround, selector, 64, &enabled) == 0 && enabled == 1); Require(sceKernelTitleWorkaroundIsEnabled2(&workaround, selector, 0x77, &enabled) == 0 && enabled == 0); Require(sceKernelTitleWorkaroundIsEnabled2(&workaround, selector, 0x78, &enabled) == 0 && enabled == 1); - for (const std::uint32_t refused : {0x79u, 0x7Eu, 0x7Fu}) { - enabled = -1; - Require(sceKernelTitleWorkaroundIsEnabled2(&workaround, selector, refused, &enabled) == static_cast(0x80020016) && enabled == -1); - } + Require(sceKernelTitleWorkaroundIsEnabled2(&workaround, selector, 0x79u, &enabled) == 0 && enabled == 0); + Require(sceKernelTitleWorkaroundIsEnabled2(&workaround, selector, 0x7Eu, &enabled) == 0 && enabled == 0); + Require(sceKernelTitleWorkaroundIsEnabled2(&workaround, selector, 0x7Fu, &enabled) == 0 && enabled == 1); } for (const std::uint64_t selector : {std::uint64_t{0x29}, std::uint64_t{0x2A}, ~std::uint64_t{0}}) { std::int32_t enabled = -1; diff --git a/docs/dev/debt/libkernel_sys.md b/docs/dev/debt/libkernel_sys.md index 9a27a0cda951..12b61e5af191 100644 --- a/docs/dev/debt/libkernel_sys.md +++ b/docs/dev/debt/libkernel_sys.md @@ -422,8 +422,8 @@ The following eight candidate spellings are absent from that aerolib revision. T - [linkat](../../../core/libs/prx/libkernel_sys/Export.cpp) (libkernel_sys) resolves `AT_FDCWD` (-100) and absolute paths as `link` does, and flags other than `AT_SYMLINK_FOLLOW` (0x400) return `EINVAL`, as in FreeBSD 11. Any other relative path is joined to the descriptor's host directory, found the same way as for `fchdir`, so guest path aliases and case-insensitive name matching do not apply to it, and a `..` component is not kept inside the guest root. It returns `EBADF` for a descriptor that is not open and `ENOTDIR` for one that is not a directory. Without `AT_SYMLINK_FOLLOW` a symbolic link as the source is linked itself, as in FreeBSD: on Linux and macOS through the host's `linkat` with flag 0, and on Windows through `CreateHardLinkW`, which links the link's reparse point rather than its target, dangling or not. Windows cannot hard-link a directory, so there a symbolic link or junction to a directory as the source throws. Console behaviour is unverified - [pthread_set_defaultstacksize_np and scePthreadSetDefaultstacksize](../../../core/libs/prx/libkernel_sys/Export.cpp) (libkernel_sys) set the stack size that `scePthreadAttrInit` and a thread created without attributes use, as [fpPS4's `pthread_set_defaultstacksize_np`](https://github.com/red-prig/fpPS4/blob/04cefd4/kernel/ps4_pthread_attr.pas#L89-L102) does: a size of 16384 bytes or less fails with `EINVAL` (`0x80020016` from the sce form) and there is no upper limit, so a default the host cannot allocate fails only when a thread is created. Attributes initialised earlier keep their size. Not checked on a PS5 - [pthread_mutexattr_getgen_np, pthread_mutexattr_setgen_np, scePthreadMutexattrGetgen and scePthreadMutexattrSetgen](../../../core/libs/prx/libkernel_sys/Export.Discovery.cpp) (libkernel_sys) were reconstructed from the firmware 13.60 exports: generation is a one-bit attribute, set accepts only 0 or 1 and otherwise returns `EOPNOTSUPP`, and the `sce` forms convert the POSIX error to `0x80020000 | errno`. The flag is retained in AnyPS5's attribute state; whether it changes mutex initialization is unmeasured. An unwritable generation pointer returns `EFAULT` (14). Runtime behaviour on a PS5 is not independently validated -- [sceKernelTitleWorkaroundIsEnabled](../../../core/libs/prx/libkernel_sys/Export.cpp) (libkernel_sys) - the `{version, align, ids[2]}` layout, the bit test and the limit follow PS5 firmware 13.42 libkernel_sys and libkernel, read from disassembly and not measured on a console, where bits 0 to 0x7F are accepted, the bit is compared unsigned, and the misspelled export `sceKernelTitleWorkdaroundIsEnabled` runs the same code. Titles usually pass the `title_workaround` block of `sceKernelGetAppInfo`, which is written as zeros here; where `title_workaround` sits in the 0x58-byte structure is unmeasured, and with the shadPS4 offsets (0x30 to 0x48) it falls in the zeroed bytes, so its bits read 0; an unreadable workaround pointer or an unwritable output pointer returns `SCE_KERNEL_ERROR_EFAULT` (`0x8002000e`) as a host-safety fallback; console behaviour for unwritable memory has not been measured -- [sceKernelTitleWorkaroundIsEnabled2](../../../core/libs/prx/libkernel_sys/Export.cpp) (libkernel_sys) - what the 64-bit second argument means is unknown: PS5 firmware 13.42 `system/common/lib/libkernel_sys.sprx` (read from disassembly to the return, not measured on a console) only refuses a value of 0x29 or more, unsigned, with `SCE_KERNEL_ERROR_EINVAL` (`0x80020016`) and does not otherwise read it. Its other checks and the bit test are those of `sceKernelTitleWorkaroundIsEnabled`, with a null workaround or output pointer checked first (`0x8002000e`), and it uses the same host-safety fallback for unreadable or unwritable pointers +- [sceKernelTitleWorkaroundIsEnabled](../../../core/libs/prx/libkernel_sys/Export.cpp) (libkernel_sys) - the `{version, align, ids[2]}` layout and bit test follow firmware 13.42 disassembly and were measured in a PS5 Pro payload process (firmware 13.60): bits 0 to 0x7F inclusive are accepted, 0x80, 0x81 and -1 are refused unsigned with `SCE_KERNEL_ERROR_EINVAL` (`0x80020016`) without writing the output, null pointers return `SCE_KERNEL_ERROR_EFAULT` (`0x8002000e`), and the misspelled export runs the same code. Only the words at offsets 8 and 16 light bits 0-63 and 64-0x7F; the version field is not read. Titles usually pass the `title_workaround` block of `sceKernelGetAppInfo`, which is written as zeros here; unreadable or unwritable non-null pointers keep the host-safety `EFAULT` and are unmeasured +- [sceKernelTitleWorkaroundIsEnabled2](../../../core/libs/prx/libkernel_sys/Export.cpp) (libkernel_sys) - what the 64-bit second argument means is unknown: PS5 firmware 13.42 `system/common/lib/libkernel_sys.sprx` (read from disassembly to the return) only refuses a value of 0x29 or more, unsigned, with `SCE_KERNEL_ERROR_EINVAL` (`0x80020016`) and does not otherwise read it; a payload process on a PS5 Pro (firmware 13.60) accepted selectors 0 and 0x28, refused 0x29, 0x2A and `~0ull` with that error, and answered bit 0x7F from the same buffer words as `sceKernelTitleWorkaroundIsEnabled`, so the argument is indeed unread. Its other checks and the bit test are those of `sceKernelTitleWorkaroundIsEnabled`, measured there, with a null workaround or output pointer checked first (`0x8002000e`), and it uses the same host-safety fallback for unreadable or unwritable pointers - [sceKernelGetProcessType](../../../core/libs/prx/libkernel_sys/Export.cpp) (libkernel_sys) - measured in a PS5 payload process (firmware 11.60, 2026-11-06 22:10 UTC): pids 0 and 1 return `0x80020002`, other unknown pids `0x80020003`, and we match both; the own pid and -1 return type 0 here (as in shadPS4) but 2 in the payload process, and a title process was not measured - [__sys_nanosleep](../../../core/libs/prx/libkernel_sys/AdditionalExports.cpp) (libkernel_sys) follows FreeBSD 11.4 libc's [`nanosleep.c`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/libc/sys/nanosleep.c) as the raw system call underneath `nanosleep`, executing without cancellation checks through `sceKernelNanosleep` and mapping errors to errno and -1. It inherits libkernel's sleep limits: `rmtp` is never written, `EINTR` is not produced, seconds are capped at `INT32_MAX / 2`, [short sleeps can wake early](libkernel.md#functional), and console behaviour is unverified. - [__sys_namedobj_delete](../../../core/libs/prx/libkernel_sys/NamedObject.cpp) (libkernel_sys) - not measured on a console. Deleting a live id with another type than it was created with throws: [fpPS4](https://github.com/red-prig/fpPS4/blob/8157760fd67a5ad02a53925701325fff2ded2c05/sys/kern/kern_namedobj.pas#L103-L157) answers `ESRCH`, [RPCSX](https://github.com/RPCSX/rpcsx/blob/e8ae1481ab7ba04d5c6bef89dd852aabba2c88ff/kernel/orbis/src/sys/sys_sce.cpp#L665-L715) deletes it. Both compare the low 16 bits of the type and answer `ESRCH` for an id that is not live. Errors return -1 with errno, as FreeBSD 11.4's [`__sys_` stubs](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/amd64/SYS.h#L39-L50) do.