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
11 changes: 9 additions & 2 deletions core/libs/prx/libkernel/Aio/src/Aio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,15 @@ int APS5_VABI sceKernelAioWaitRequest(int32_t id, int32_t* state, uint32_t* usec
}
}

int APS5_VABI sceKernelAioPollRequests() {
NotImplemented_nid_no_patch(__func__);
int APS5_VABI sceKernelAioPollRequests(const int32_t* id, int32_t num, int32_t* state) {
const int error = ValidateIds(id, num, state, "sceKernelAioPollRequests");
if (error != 0) return error;
std::array<int32_t, AioIdNumMax> snapshot{};
{
std::lock_guard<std::mutex> lock(g_mutex);
for (int32_t i = 0; i < num; ++i) snapshot[i] = g_states[id[i]];
}
for (int32_t i = 0; i < num; ++i) state[i] = snapshot[i];
return 0;
}

Expand Down
34 changes: 34 additions & 0 deletions core/libs/tests/GuestAio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void APS5_VABI sceKernelAioInitializeParam(void* param);
int APS5_VABI sceKernelAioSubmitReadCommands(KernelAioRwRequest* req, std::int32_t size, std::int32_t prio, std::int32_t* id);
int APS5_VABI sceKernelAioSubmitWriteCommands(KernelAioRwRequest* req, std::int32_t size, std::int32_t prio, std::int32_t* id);
int APS5_VABI sceKernelAioPollRequest(std::int32_t id, std::int32_t* state);
int APS5_VABI sceKernelAioPollRequests(const std::int32_t* id, std::int32_t num, std::int32_t* state);
int APS5_VABI sceKernelAioWaitRequest(std::int32_t id, std::int32_t* state, std::uint32_t* usec);
int APS5_VABI sceKernelAioSubmitReadCommandsMultiple(KernelAioRwRequest* req, std::int32_t size, std::int32_t prio, std::int32_t* id);
int APS5_VABI sceKernelAioSubmitWriteCommandsMultiple(KernelAioRwRequest* req, std::int32_t size, std::int32_t prio, std::int32_t* id);
Expand Down Expand Up @@ -113,6 +114,25 @@ int main() {
std::int32_t writeStates[2] = {0, 0};
Check(sceKernelAioWaitRequests(writeIds, 2, writeStates, 1, nullptr) == 0);
Check(writeStates[0] == 3 && writeStates[1] == 4);
std::int32_t pollStates[3] = {-1, -1, 91};
Check(sceKernelAioPollRequests(writeIds, 2, pollStates) == 0);
Check(pollStates[0] == 3 && pollStates[1] == 4 && pollStates[2] == 91);
const std::int32_t repeatedIds[3] = {writeIds[1], writeIds[0], writeIds[1]};
Check(sceKernelAioPollRequests(repeatedIds, 3, pollStates) == 0);
Check(pollStates[0] == 4 && pollStates[1] == 3 && pollStates[2] == 4);
std::int32_t overlapping[3] = {writeIds[0], writeIds[1], 77};
Check(sceKernelAioPollRequests(overlapping, 2, overlapping + 1) == 0);
Check(overlapping[0] == writeIds[0] && overlapping[1] == 3 && overlapping[2] == 4);
std::array<std::int32_t, 128> maximumIds{};
std::array<std::int32_t, 129> maximumStates{};
maximumIds.fill(writeIds[0]);
maximumStates.fill(91);
Check(sceKernelAioPollRequests(maximumIds.data(), 128, maximumStates.data()) == 0);
for (std::size_t i = 0; i < maximumIds.size(); ++i) Check(maximumStates[i] == 3);
Check(maximumStates.back() == 91);
pollStates[0] = 77;
Check(sceKernelAioPollRequests(writeIds, 0, pollStates) == 0);
Check(pollStates[0] == 77);
std::array<char, 4> readBack{};
std::array<char, 4> tail{};
KernelAioResult readBackResult{-1, 0};
Expand All @@ -137,6 +157,8 @@ int main() {
Check(cancelled == 4);
Check(sceKernelAioPollRequest(readIds[0], &polled) == 0);
Check(polled == 4);
Check(sceKernelAioPollRequests(readIds, 2, pollStates) == 0);
Check(pollStates[0] == 4 && pollStates[1] == 3);
Check(sceKernelAioCancelRequest(0, &cancelled) == 0);
Check(cancelled == 2);
std::int32_t cancelIds[2] = {0, readIds[1]};
Expand All @@ -154,6 +176,13 @@ int main() {
Check(sceKernelClose(batchFd) == 0);
std::int32_t badIds[2] = {readIds[0], 9999};
std::int32_t untouched[2] = {7, 7};
Check(sceKernelAioPollRequests(nullptr, 2, untouched) == SCE_KERNEL_ERROR_EFAULT);
Check(sceKernelAioPollRequests(readIds, 2, nullptr) == SCE_KERNEL_ERROR_EFAULT);
Check(sceKernelAioPollRequests(readIds, -1, untouched) == SCE_KERNEL_ERROR_EINVAL);
Check(sceKernelAioPollRequests(badIds, 2, untouched) == SCE_KERNEL_ERROR_EINVAL);
const std::int32_t zeroId[2] = {readIds[0], 0};
Check(sceKernelAioPollRequests(zeroId, 2, untouched) == SCE_KERNEL_ERROR_EINVAL);
Check(untouched[0] == 7 && untouched[1] == 7);
Check(sceKernelAioSubmitReadCommandsMultiple(nullptr, 1, 0, readIds) == SCE_KERNEL_ERROR_EFAULT);
Check(sceKernelAioSubmitReadCommandsMultiple(readBatch, 1, 0, nullptr) == SCE_KERNEL_ERROR_EFAULT);
Check(sceKernelAioSubmitWriteCommandsMultiple(writeBatch, 0, 0, writeIds) == SCE_KERNEL_ERROR_EINVAL);
Expand All @@ -171,6 +200,11 @@ int main() {
std::array<std::int32_t, 129> manyIds{};
std::array<std::int32_t, 129> manyStates{};
manyIds.fill(readIds[0]);
manyStates.fill(77);
try { sceKernelAioPollRequests(manyIds.data(), 129, manyStates.data()); } catch (const std::runtime_error&) { threw = true; }
Check(threw);
for (const auto value : manyStates) Check(value == 77);
threw = false;
try { sceKernelAioDeleteRequests(manyIds.data(), 129, manyStates.data()); } catch (const std::runtime_error&) { threw = true; }
Check(threw);
Check(sceKernelAioCancelRequest(9999, &cancelled) == SCE_KERNEL_ERROR_EINVAL);
Expand Down
2 changes: 1 addition & 1 deletion docs/dev/TechnicalDebt.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Throughout the project, every function at every stage either **does exactly what
- [Memory protection bits 0x100 and 0x200](../../core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp) (libkernel) - taken as audio coprocessor (ACP) read and write, as in the [KytyPS5](https://github.com/KytyPS5/KytyPS5) and [etaHEN](https://github.com/etaHEN/etaHEN) headers; the coprocessor work runs on the host CPU, so they grant host read and read/write access like the GPU bits
- [sceKernelSyncOnAddressWait](../../core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cpp) (libkernel) - the only known caller passes a null timeout and a name string as the fourth argument; the timeout is assumed to point to microseconds like the other kernel waits, and the name is ignored
- [sceKernelSyncOnAddressWait8 / sceKernelSyncOnAddressWait16 / sceKernelSyncOnAddressWait32 / sceKernelSyncOnAddressWait64](../../core/libs/prx/libkernel/SyncOnAddress/src/SyncOnAddress.cpp) (libkernel) - libc's `__std_atomic_wait_direct_8/16/32/64` pass a microsecond timeout or null and ignore the result; the by-value comparand, return values and the 2- and 8-byte alignment of Wait16 and Wait64 are assumed
- [sceKernelAioSubmitReadCommandsMultiple / sceKernelAioSubmitWriteCommandsMultiple / sceKernelAioWaitRequests / sceKernelAioCancelRequest / sceKernelAioCancelRequests / sceKernelAioDeleteRequests](../../core/libs/prx/libkernel/Aio/src/Aio.cpp) (libkernel) - behaviour from shadPS4 (one id per request for the Multiple submits, cancel turns any request aborted and id 0 reports processing, wait mode 2 returns once one request completed); the 128 requests or ids per batch limit is from SharpProspero, with an unknown error, so larger batches throw; wait modes other than 1 (and) and 2 (or) throw; null pointers, negative counts and invalid ids return the codes the single-request siblings use, checked before any state is written
- [sceKernelAioSubmitReadCommandsMultiple / sceKernelAioSubmitWriteCommandsMultiple / sceKernelAioWaitRequests / sceKernelAioPollRequests / sceKernelAioCancelRequest / sceKernelAioCancelRequests / sceKernelAioDeleteRequests](../../core/libs/prx/libkernel/Aio/src/Aio.cpp) (libkernel) - behaviour from shadPS4 (one id per request for the Multiple submits, cancel turns any request aborted and id 0 reports processing, wait mode 2 returns once one request completed); the 128 requests or ids per batch limit is from SharpProspero, with an unknown error, so larger batches throw; wait modes other than 1 (and) and 2 (or) throw; null pointers, negative counts and invalid ids return the codes the single-request siblings use, checked before any state is written. Polling follows [shadPS4](https://github.com/shadps4-emu/shadPS4/blob/548789cfa5eb6c4b8d08ca4e9fd8fe118f2a06bc/src/core/libraries/kernel/aio.cpp), snapshots all requested states without waiting and uses the same batch validation; not measured on PS5 hardware
- [sceKernelGetAvailableCpumask](../../core/libs/prx/libkernel/Pthread/src/Thread.cpp) (libkernel) - returns the default thread affinity, 0x1FFF (CPUs 0 to 12), as KytyPS5 does. Titles pin threads within it (PPSA02664 passes 0x1FFB, Hades II PPSA36082 0x3 and 0x3F); whether CPU 13 is available to a title is not confirmed
- [sceKernelMapNamedFlexibleMemoryInternal](../../core/libs/prx/libkernel/DirectMemory/Export.cpp) (libkernel) - flag 0x8000 is accepted and ignored; its meaning is not established. KytyPS5 (`GUEST_MAP_UNKNOWN_8000`) and sharpemu accept it without reading it. Every known caller is the SDK 9 `libc.prx` heap (Astro Bot PPSA21564, PPSA22520), which passes it with read/write protection and uses the mapping as an older `libc.prx` uses `sceKernelMapNamedFlexibleMemory` with flags 0
- [sceKernelMtypeprotect](../../core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp) (libkernel) - sets the memory type of the direct mappings in the page-rounded range and of the direct memory behind them, as shadPS4 and prosper do (KytyPS5 ignores the type); the type is not validated, flexible pages in the range only get the protection, and a later map of the retyped direct memory reports the type it was allocated with. `sceKernelBatchMap2` operation 4 takes the same path with the entry type
Expand Down