diff --git a/core/libs/prx/libSceAgcDriver/tests/GuestAllocations.cpp b/core/libs/prx/libSceAgcDriver/tests/GuestAllocations.cpp index 881e71011..87e915baa 100644 --- a/core/libs/prx/libSceAgcDriver/tests/GuestAllocations.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/GuestAllocations.cpp @@ -3,6 +3,7 @@ #include "prx/libc/include/GuestHeap.hpp" #include "prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp" #include +#include namespace { @@ -44,4 +45,34 @@ void RunGuestAllocationTests() { Require(static_cast(pointer)[31] == 0x66, "aligned guest realloc lost data"); GuestHeap::GuestHeapFree_nid_postfix(pointer); Require(GuestAllocations::GuestAllocationsAcquire_nid_postfix().empty(), "freed guest allocations remain registered"); + std::array mapping{}; + { + GuestAllocations::Mutation mutation; + mutation.Add(mapping.data(), mapping.size(), true, true); + reject([&] { mutation.RequireAvailable(mapping.data() + 32, 16); }); + mutation.Protect(mapping.data() + 32, 32, true, false, [] {}); + } + { + const auto lease = GuestAllocations::GuestAllocationsAcquire_nid_postfix(); + Require(lease.size() == 3 && lease[0]->bytes == 32 && !lease[1]->writable && lease[2]->bytes == 64, "partial protection did not split the mapping"); + GuestAllocations::Mutation mutation; + reject([&] { mutation.Unmap(mapping.data() + 32, 32, [](const void*, bool) {}); }); + } + { + GuestAllocations::Mutation mutation; + bool applied = false; + mutation.Unmap(mapping.data() + 32, 32, [&](const void* allocation, bool last) { + Require(allocation == mapping.data() && !last, "partial unmap released the allocation"); + applied = true; + }); + Require(applied, "partial unmap callback was not called"); + reject([&] { mutation.Protect(mapping.data(), mapping.size(), true, true, [] {}); }); + mutation.Unmap(mapping.data(), 32, [&](const void* allocation, bool last) { + Require(allocation == mapping.data() && !last, "first fragment released remaining mapping"); + }); + mutation.Unmap(mapping.data() + 64, 64, [&](const void* allocation, bool last) { + Require(allocation == mapping.data() && last, "last fragment did not release the original allocation"); + }); + } + Require(GuestAllocations::GuestAllocationsAcquire_nid_postfix().empty(), "unmapped fragments remain registered"); }