mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
fix(agc): grow a command buffer whose free space is below its reserved words
A command buffer with fewer free dwords than reserved_dw (an empty one whose title allocates its storage in the callback, as Marvel's Wolverine does) threw "reserved space exceeds command buffer capacity" before its callback ran. Its available space is now 0, so the allocation goes to the callback with the reserved words added, as for any other full buffer. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -45,7 +45,7 @@ std::uint32_t available(const CommandBuffer& buffer, const char* function) {
|
||||
Require(bottom <= up && up <= down && down <= top, function, "invalid command buffer cursors");
|
||||
Require(bottom != 0 || top == 0, function, "null command buffer storage");
|
||||
const auto count = (down - up) / sizeof(std::uint32_t);
|
||||
Require(count >= buffer.reserved_dw, function, "reserved space exceeds command buffer capacity");
|
||||
if (count <= buffer.reserved_dw) return 0;
|
||||
Require(count - buffer.reserved_dw <= std::numeric_limits<std::uint32_t>::max(), function, "command buffer capacity overflow");
|
||||
return static_cast<std::uint32_t>(count - buffer.reserved_dw);
|
||||
}
|
||||
|
||||
@@ -63,6 +63,16 @@ bool APS5_VABI grow(CommandBuffer* buffer, std::uint32_t count, void* userData)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool APS5_VABI growReserved(CommandBuffer* buffer, std::uint32_t count, void* userData) {
|
||||
auto& storage = *static_cast<Storage*>(userData);
|
||||
check(count == 5 + 4, "incorrect callback allocation including reserved words");
|
||||
buffer->bottom = storage.words.data();
|
||||
buffer->top = storage.words.data() + storage.words.size();
|
||||
buffer->cursor_up = buffer->bottom;
|
||||
buffer->cursor_down = buffer->top;
|
||||
return true;
|
||||
}
|
||||
|
||||
void testPackets() {
|
||||
Storage storage;
|
||||
sceAgcDcbResetQueue(&storage.buffer, 0, 3);
|
||||
@@ -77,6 +87,10 @@ void testPackets() {
|
||||
CommandBuffer empty{nullptr, nullptr, nullptr, nullptr, grow, &destination, 0};
|
||||
Agc::Command::Emit(&empty, 0x15u, {1, 1, 1, 0x41u}, __func__);
|
||||
check(empty.cursor_up == destination.words.data() + 5, "guest ABI allocation callback failed");
|
||||
Storage reservedDestination;
|
||||
CommandBuffer reserved{nullptr, nullptr, nullptr, nullptr, growReserved, &reservedDestination, 4};
|
||||
Agc::Command::Emit(&reserved, 0x15u, {1, 1, 1, 0x41u}, __func__);
|
||||
check(reserved.cursor_up == reservedDestination.words.data() + 5, "buffer with less room than its reserved words did not grow");
|
||||
Storage exhausted;
|
||||
exhausted.buffer.cursor_down = exhausted.words.data() + 2;
|
||||
expectFailure([&] { Agc::Command::WriteNop(&exhausted.buffer, 3, __func__); });
|
||||
|
||||
Reference in New Issue
Block a user