mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
fix(libSceAgcDriver): keep the global data share out of the flexible memory budget
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -403,6 +403,7 @@ target_include_directories(agc_driver_pm4_tests PRIVATE
|
||||
target_link_libraries(agc_driver_pm4_tests PRIVATE
|
||||
libSceAgcDriver
|
||||
libc
|
||||
libkernel
|
||||
)
|
||||
|
||||
set_target_properties(agc_driver_pm4_tests PROPERTIES CXX_EXTENSIONS OFF)
|
||||
|
||||
@@ -10,15 +10,16 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
extern "C" int APS5_VABI sceKernelMapFlexibleMemory(void** addr_in_out, size_t len, int prot, int flags);
|
||||
extern "C" void* APS5_VABI mmap_nid_postfix(void* address, std::size_t length, int protection, int flags, int descriptor, std::int64_t offset) noexcept;
|
||||
|
||||
namespace AgcDriver::Pm4 {
|
||||
|
||||
std::uint64_t GdsAddress() {
|
||||
static const std::uint64_t address = [] {
|
||||
constexpr int CpuGpuReadWrite = 0x33;
|
||||
void* mapped = nullptr;
|
||||
if (sceKernelMapFlexibleMemory(&mapped, GdsBytes, CpuGpuReadWrite, 0) != 0 || mapped == nullptr) throw std::runtime_error("cannot allocate the global data share");
|
||||
constexpr int ReadWrite = 0x3;
|
||||
constexpr int PrivateAnonymous = 0x1002;
|
||||
void* mapped = mmap_nid_postfix(nullptr, GdsBytes, ReadWrite, PrivateAnonymous, -1, 0);
|
||||
if (mapped == nullptr || mapped == reinterpret_cast<void*>(static_cast<std::uintptr_t>(-1))) throw std::runtime_error("cannot allocate the global data share");
|
||||
return reinterpret_cast<std::uint64_t>(mapped);
|
||||
}();
|
||||
return address;
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
extern "C" int APS5_VABI sceKernelAvailableFlexibleMemorySize(size_t* size);
|
||||
|
||||
namespace {
|
||||
|
||||
void check(bool condition, const char* reason) {
|
||||
@@ -320,9 +322,13 @@ void testCopies() {
|
||||
execute(state, makePacket(0x50, {0x40000000, 0x44332211, 0, low(destination.data()), high(destination.data()), 6}));
|
||||
check(destination[0] == 0x44332211 && destination[1] == 0x00002211, "DMA_DATA byte fill failed");
|
||||
constexpr std::uint32_t cachePolicies = (1u << 13u) | (2u << 25u);
|
||||
std::size_t flexibleBefore = 0;
|
||||
check(sceKernelAvailableFlexibleMemorySize(&flexibleBefore) == 0, "cannot query flexible memory");
|
||||
const auto toGds = makePacket(0x50, {0x60100000 | cachePolicies, low(source.data()), high(source.data()), 0x100, 0, 16});
|
||||
check(!AgcDriver::Pm4::ResolveStore(toGds, state, 64).has_value(), "DMA_DATA to GDS resolved as a memory store");
|
||||
execute(state, toGds);
|
||||
std::size_t flexibleAfter = 0;
|
||||
check(sceKernelAvailableFlexibleMemorySize(&flexibleAfter) == 0 && flexibleAfter == flexibleBefore, "the GDS was charged to the flexible memory budget");
|
||||
execute(state, makePacket(0x50, {0x20100000, 0x104, 0, 0xfff8, 0, 8}));
|
||||
destination = {};
|
||||
execute(state, makePacket(0x50, {0x20000000 | cachePolicies, 0xfff8, 0, low(destination.data()), high(destination.data()), 8}));
|
||||
|
||||
Reference in New Issue
Block a user