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
40 changes: 18 additions & 22 deletions core/libs/prx/libSceVoiceQoS/Export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ constexpr int SCE_VOICE_ERROR_LIBVOICEQOS_INITIALIZED = static_cast<int>(0x804E0
std::mutex g_mutex;
bool g_initialized = false;

int checkInit(const char* func) {
std::lock_guard lock(g_mutex);
if (!g_initialized) return SCE_VOICE_ERROR_LIBVOICEQOS_NOT_INIT;
NotImplemented_nid_no_patch(func);
return 0;
}

}

extern "C" {
Expand All @@ -36,58 +43,47 @@ int APS5_VABI sceVoiceQoSEnd() {
}

int APS5_VABI sceVoiceQoSCreateLocalEndpoint() {
NotImplemented_nid_no_patch(__func__);
return 0;
return checkInit(__func__);
}

int APS5_VABI sceVoiceQoSDeleteLocalEndpoint() {
NotImplemented_nid_no_patch(__func__);
return 0;
return checkInit(__func__);
}

int APS5_VABI sceVoiceQoSCreateRemoteEndpoint() {
NotImplemented_nid_no_patch(__func__);
return 0;
return checkInit(__func__);
}

int APS5_VABI sceVoiceQoSDeleteRemoteEndpoint() {
NotImplemented_nid_no_patch(__func__);
return 0;
return checkInit(__func__);
}

int APS5_VABI sceVoiceQoSConnect() {
NotImplemented_nid_no_patch(__func__);
return 0;
return checkInit(__func__);
}

int APS5_VABI sceVoiceQoSDisconnect() {
NotImplemented_nid_no_patch(__func__);
return 0;
return checkInit(__func__);
}

int APS5_VABI sceVoiceQoSSetLocalEndpointAttribute() {
NotImplemented_nid_no_patch(__func__);
return 0;
return checkInit(__func__);
}

int APS5_VABI sceVoiceQoSSetRemoteEndpointAttribute() {
NotImplemented_nid_no_patch(__func__);
return 0;
return checkInit(__func__);
}

int APS5_VABI sceVoiceQoSReadPacket() {
NotImplemented_nid_no_patch(__func__);
return 0;
return checkInit(__func__);
}

int APS5_VABI sceVoiceQoSWritePacket() {
NotImplemented_nid_no_patch(__func__);
return 0;
return checkInit(__func__);
}

int APS5_VABI sceVoiceQoSGetLocalEndpointAttribute() {
NotImplemented_nid_no_patch(__func__);
return 0;
return checkInit(__func__);
}

}
32 changes: 29 additions & 3 deletions core/libs/tests/GuestVoiceQoS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,44 @@
extern "C" {
int APS5_VABI sceVoiceQoSInit(void*, std::uint32_t, std::int32_t);
int APS5_VABI sceVoiceQoSEnd();
int APS5_VABI sceVoiceQoSCreateLocalEndpoint();
int APS5_VABI sceVoiceQoSDeleteLocalEndpoint();
int APS5_VABI sceVoiceQoSCreateRemoteEndpoint();
int APS5_VABI sceVoiceQoSDeleteRemoteEndpoint();
int APS5_VABI sceVoiceQoSConnect();
int APS5_VABI sceVoiceQoSDisconnect();
int APS5_VABI sceVoiceQoSSetLocalEndpointAttribute();
int APS5_VABI sceVoiceQoSSetRemoteEndpointAttribute();
int APS5_VABI sceVoiceQoSReadPacket();
int APS5_VABI sceVoiceQoSWritePacket();
int APS5_VABI sceVoiceQoSGetLocalEndpointAttribute();
}

static void Require(bool value) { if (!value) std::abort(); }

static void RequireUninitialized(int notInitialized) {
Require(sceVoiceQoSEnd() == notInitialized);
Require(sceVoiceQoSCreateLocalEndpoint() == notInitialized);
Require(sceVoiceQoSDeleteLocalEndpoint() == notInitialized);
Require(sceVoiceQoSCreateRemoteEndpoint() == notInitialized);
Require(sceVoiceQoSDeleteRemoteEndpoint() == notInitialized);
Require(sceVoiceQoSConnect() == notInitialized);
Require(sceVoiceQoSDisconnect() == notInitialized);
Require(sceVoiceQoSSetLocalEndpointAttribute() == notInitialized);
Require(sceVoiceQoSSetRemoteEndpointAttribute() == notInitialized);
Require(sceVoiceQoSReadPacket() == notInitialized);
Require(sceVoiceQoSWritePacket() == notInitialized);
Require(sceVoiceQoSGetLocalEndpointAttribute() == notInitialized);
}

int main(int argc, char** argv) {
Require(argc == 2);
constexpr int argumentInvalid = static_cast<int>(0x804E0902);
constexpr int initialized = static_cast<int>(0x804E0905);
constexpr int notInitialized = static_cast<int>(0x804E0901);
const auto appType = static_cast<std::int32_t>(std::strtoul(argv[1], nullptr, 16));
std::vector<std::uint8_t> memory(0x40000, 0xAA);
Require(sceVoiceQoSEnd() == notInitialized);
RequireUninitialized(notInitialized);
Require(sceVoiceQoSInit(nullptr, 0x40000, appType) == argumentInvalid);
Require(sceVoiceQoSInit(nullptr, 0, appType) == argumentInvalid);
for (std::uint32_t size : {0u, 1u, 0x100u, 0x3FFFFu, 0x40001u, 0x80000u, 0xFFFFFFFFu}) Require(sceVoiceQoSInit(memory.data(), size, appType) == argumentInvalid);
Expand All @@ -29,10 +55,10 @@ int main(int argc, char** argv) {
Require(sceVoiceQoSInit(memory.data(), 0x40000, appType) == initialized);
Require(sceVoiceQoSInit(nullptr, 0, 0) == initialized);
Require(sceVoiceQoSEnd() == 0);
Require(sceVoiceQoSEnd() == notInitialized);
RequireUninitialized(notInitialized);
Require(sceVoiceQoSInit(nullptr, 0x40000, appType) == argumentInvalid);
Require(sceVoiceQoSInit(memory.data(), 0x40000, appType) == 0);
Require(sceVoiceQoSInit(memory.data(), 0x40000, appType) == initialized);
Require(sceVoiceQoSEnd() == 0);
Require(sceVoiceQoSEnd() == notInitialized);
RequireUninitialized(notInitialized);
}
2 changes: 1 addition & 1 deletion docs/dev/TechnicalDebt.md
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ Throughout the project, every function at every stage either **does exactly what
- [sce::Json::InitParameter2 base-object constructor](../../core/libs/prx/libSceJson2/Export.cpp) (libSceJson2) - forwards to the complete-object constructor and uses its inferred layout and default field values; constructor equivalence and initialization bytes remain unverified on the console
- [_fstatfs](../../core/libs/prx/libkernel/File/src/Stdio.cpp) (libkernel) fills the FreeBSD 11 `struct statfs` of the PS5 payload SDK with the host volume that holds the file: block size, transfer size, total, free and available blocks, maximum name length and the read-only, `nosuid` and `noexec` flags (on Windows only read-only, and `f_files` and `f_ffree` are 0, as NTFS has no fixed number of files). The filesystem type number and name, mount paths, owner, filesystem id and I/O counters are left 0 or empty, since they would describe a host mount, not a console one. Sockets and pipes return `EINVAL`, as FreeBSD's `getvnode` does; a Windows descriptor that is neither a file nor a pipe throws. Stremio Plus (PPSA74126) reads the free space before a download and only logs the other fields
- [fstatvfs](../../core/libs/prx/libSceLibcInternal/FilesystemStatistics.cpp) (libSceLibcInternal) converts `_fstatfs` to the 88-byte `struct statvfs` as FreeBSD 9.2's `sfs2svfs` does (`f_bsize` from the transfer size, `f_frsize` from the block size, `f_favail` equal to `f_ffree`, `f_fsid` 0, `ST_RDONLY` and `ST_NOSUID` only). Differences: `f_namemax` is the `statfs` value, not `fpathconf(_PC_NAME_MAX)`; negative `f_bavail` and `f_ffree` wrap to unsigned without `EOVERFLOW`, as the same-width copy in FreeBSD does; inode counts are 0 on Windows, inherited from `_fstatfs`; a null output returns `EFAULT` after the descriptor is validated, where FreeBSD would fault. Layout and conversion are unverified against the PS5 library (PS5MC imports `fstatvfs` but was not run)
- [sceVoiceQoSEnd](../../core/libs/prx/libSceVoiceQoS/Export.cpp) (libSceVoiceQoS) - `0x804E0901` (not initialized) before any initialization was measured on a PS5 (firmware 13.60, #1407); ending an initialized library was not, because a valid `sceVoiceQoSInit` never returns inside a homebrew payload. PPSA14632 calls it at shutdown and PPSA26344 after a nonzero `sceVoiceQoSInit`. After an initialization it returns 0 and clears the init flag, so the library can be initialized again. Whether the console also ends the libSceVoice instance that its `sceVoiceQoSInit` starts ([prosper](https://github.com/mattias800/prosper)'s reading of the module), and what it answers while endpoints exist, is unknown; no endpoint is implemented
- [sceVoiceQoSEnd and endpoint stubs](../../core/libs/prx/libSceVoiceQoS/Export.cpp) (libSceVoiceQoS) - `0x804E0901` (not initialized) before any initialization was measured on a PS5 (firmware 13.60, #1407); ending an initialized library was not, because a valid `sceVoiceQoSInit` never returns inside a homebrew payload. PPSA14632 calls it at shutdown and PPSA26344 after a nonzero `sceVoiceQoSInit`. After an initialization it returns 0 and clears the init flag, so the library can be initialized again. All other functions check initialization and return `0x804E0901` before initialization. Whether the console also ends the libSceVoice instance that its `sceVoiceQoSInit` starts ([prosper](https://github.com/mattias800/prosper)'s reading of the module), and what it answers while endpoints exist, is unknown; no endpoint is implemented
- [_WStoul](../../core/libs/prx/libc/src/Strings.cpp), [_Iswctype](../../core/libs/prx/libc/src/RuneLocale.cpp) and [swscanf_s](../../core/libs/prx/libc/src/ScanningWide.cpp) (libc) - `_WStoul` is `wcstoul` and throws for a base other than 0 or 2 to 36. `_Iswctype` takes the class numbers of Dinkumware's [xwcc.h](https://github.com/superna9999/ti-cgt6x/blob/cgt6x_7_3_4/include/xwcc.h) (1 `alnum` to 11 `xdigit`, 12 `blank`) and throws for any other value, including the FreeBSD masks `wctype` returns; the numbering is not confirmed on the console's `libc.prx`. `swscanf_s` follows C11 7.29.2.2 and K.3.9.1.5, but reads the size argument as `unsigned int` like `sscanf_s` where K.3.9.1.5 specifies `rsize_t`; the console's width is unverified. A runtime-constraint violation (null buffer, format or receiving pointer) only returns `EOF`, and a too small array gets a null first element as in `sscanf_s`. A literal mismatch is a matching failure and a field that is only a prefix, such as `0x` or `1e`, does not convert, as C11 requires; FreeBSD's `vfwscanf` reports an input failure for the first and converts the second. Integers out of range are truncated from `strtoll`/`strtoull`. It throws for `%p`, `%S`, `%C`, unknown length modifiers, scanset ranges, `%n` with suppression or width, and narrow `%s`, `%c` or `%[` input that the C-locale `wcrtomb` cannot convert
- [sceSharePlayGetCurrentConnectionInfoA](../../core/libs/prx/libSceSharePlay/Export.cpp) (libSceSharePlay) - reports no Share Play session, as the library keeps none: status 0 (DORMANT), mode 0, empty online IDs, account IDs 0 and both user IDs -1 (`SCE_USER_SERVICE_USER_ID_INVALID`). A null pointer returns `SCE_SHARE_PLAY_ERROR_INVALID_ARGS` (0x810E0001). The 72-byte `SceSharePlayConnectionInfoA` layout and the error code follow [KytyPS5](https://github.com/KytyPS5/KytyPS5/blob/main/src/libs/libNet.cpp) and [fpPS4](https://github.com/red-prig/fpPS4/blob/trunk/src/ps4_libsceshareplay.pas), which agree on both; KytyPS5 sets the user IDs to -1 and fpPS4 leaves them 0, and which one the console returns is not verified. KytyPS5 also returns `SCE_SHARE_PLAY_ERROR_NOT_INITIALIZED` before `sceSharePlayInitialize`; this library keeps no initialization state and does not.
- [sceAgcCreatePrimState](../../core/libs/prx/libSceAgc/Shader/src/PrimState.cpp) (libSceAgc) - the `ge_user_vgpr_en` special is passed to the user configuration registers at whatever offset the shader header stores, as the SPRX does according to [OpenAGC](https://github.com/OpenAGC/OpenAGC/blob/3c7e8072f0d7684e930454794fd5c02056946d73/src/game_compat.c#L1181-L1252), which copies all four specials verbatim (KytyPS5 stops on any other offset). PPSA99039, PPSA99505, PPSA99515 and PPSA99997 build their headers by hand with it at 0x25c (`GE_USER_VGPR1`) instead of 0x262 (`GE_USER_VGPR_EN`), value 0, and run on the console; it is not moved to 0x262, and the driver reads neither register. `ge_cntl`, `vgt_shader_stages_en` and a used `vgt_gs_out_prim_type` must still be at their own offsets, since the driver reads those registers there, so a header that stores one elsewhere throws naming the offset, although by OpenAGC the SPRX would copy it as well
Expand Down
Loading