diff --git a/src/core/libraries/kernel/memory.cpp b/src/core/libraries/kernel/memory.cpp index 82c5115f1..dc317237c 100644 --- a/src/core/libraries/kernel/memory.cpp +++ b/src/core/libraries/kernel/memory.cpp @@ -15,6 +15,7 @@ #include "core/libraries/libs.h" #include "core/linker.h" #include "core/memory.h" +#include "src/common/memory_patcher.h" namespace Libraries::Kernel { @@ -26,6 +27,17 @@ u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() { int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len, u64 alignment, int memoryType, s64* physAddrOut) { + auto* memory = Core::Memory::Instance(); + + if (memory->NeedsExtraMemory()) { + LOG_INFO(Kernel_Vmm, "Game '{}' requires extra memory, applying expanded allocation.", + MemoryPatcher::g_game_serial); + + } else { + LOG_INFO(Kernel_Vmm, "Game '{}' using standard memory allocation.", + MemoryPatcher::g_game_serial); + } + if (searchStart < 0 || searchEnd < 0) { LOG_ERROR(Kernel_Vmm, "Invalid parameters!"); return ORBIS_KERNEL_ERROR_EINVAL; @@ -56,7 +68,6 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u return ORBIS_KERNEL_ERROR_EAGAIN; } - auto* memory = Core::Memory::Instance(); PAddr phys_addr = memory->Allocate(searchStart, searchEnd, len, alignment, memoryType); if (phys_addr == -1) { return ORBIS_KERNEL_ERROR_EAGAIN; diff --git a/src/core/libraries/kernel/memory.h b/src/core/libraries/kernel/memory.h index 400b6c3fc..1b47f93a8 100644 --- a/src/core/libraries/kernel/memory.h +++ b/src/core/libraries/kernel/memory.h @@ -6,8 +6,8 @@ #include "common/bit_field.h" #include "common/types.h" -constexpr u64 SCE_KERNEL_TOTAL_MEM = 5248_MB; -constexpr u64 SCE_KERNEL_TOTAL_MEM_PRO = 5888_MB; +constexpr u64 SCE_KERNEL_TOTAL_MEM = 5248_MB * 4; +constexpr u64 SCE_KERNEL_TOTAL_MEM_PRO = 5888_MB * 4; constexpr u64 SCE_FLEXIBLE_MEMORY_BASE = 64_MB; constexpr u64 SCE_FLEXIBLE_MEMORY_SIZE = 512_MB; diff --git a/src/core/memory.h b/src/core/memory.h index a6a55e288..812ca5518 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -5,12 +5,15 @@ #include #include +#include + #include #include "common/enum.h" #include "common/singleton.h" #include "common/types.h" #include "core/address_space.h" #include "core/libraries/kernel/memory.h" +#include "src/common/memory_patcher.h" namespace Vulkan { class Rasterizer; @@ -163,6 +166,13 @@ public: const VAddr end_addr = end_it->first + end_it->second.size; return virtual_addr >= vma_map.begin()->first && virtual_addr < end_addr; } + bool NeedsExtraMemory() { + static const std::unordered_set extra_memory_games = { + // here should be games with needs of extra memory as EXAMPLE + "CUSA03173"}; + + return extra_memory_games.find(MemoryPatcher::g_game_serial) != extra_memory_games.end(); + } u64 ClampRangeSize(VAddr virtual_addr, u64 size);