core/kernel: Miscellaneous memory fixes (#557)
Some checks are pending
Reuse / reuse (push) Waiting to run
Clang Format / clang-format (push) Waiting to run
Linux-Qt / build (push) Waiting to run
Linux / build (push) Waiting to run
macOS-Qt / build (push) Waiting to run
macOS / build (push) Waiting to run
Windows-Qt / build (push) Waiting to run
Windows / build (push) Waiting to run

* core/libraries/kernel: Fix inaccurate direct memory size

* core/memory: Fix available dmem query on non-free dmem areas

* core/kernel: return ENOMEM if memory area size is zero

* core/kernel: Fix returns on `sceKernelAvailableDirectMemorySize`

* core/memory: Remove unneeded size alignment
This commit is contained in:
Daniel R. 2024-08-26 03:14:21 +02:00 committed by GitHub
parent 5d7407dc7d
commit fae0c0ae85
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 5 deletions

View file

@ -75,19 +75,28 @@ s32 PS4_SYSV_ABI sceKernelAvailableDirectMemorySize(u64 searchStart, u64 searchE
LOG_WARNING(Kernel_Vmm, "called searchStart = {:#x}, searchEnd = {:#x}, alignment = {:#x}", LOG_WARNING(Kernel_Vmm, "called searchStart = {:#x}, searchEnd = {:#x}, alignment = {:#x}",
searchStart, searchEnd, alignment); searchStart, searchEnd, alignment);
if (searchEnd <= searchStart) { if (physAddrOut == nullptr || sizeOut == nullptr) {
return ORBIS_KERNEL_ERROR_EINVAL; return ORBIS_KERNEL_ERROR_EINVAL;
} }
if (searchEnd > SCE_KERNEL_MAIN_DMEM_SIZE) { if (searchEnd > SCE_KERNEL_MAIN_DMEM_SIZE) {
return ORBIS_KERNEL_ERROR_EINVAL; return ORBIS_KERNEL_ERROR_EINVAL;
} }
if (searchEnd <= searchStart) {
return ORBIS_KERNEL_ERROR_ENOMEM;
}
auto* memory = Core::Memory::Instance(); auto* memory = Core::Memory::Instance();
PAddr physAddr; PAddr physAddr{};
s32 result = size_t size{};
memory->DirectQueryAvailable(searchStart, searchEnd, alignment, &physAddr, sizeOut); s32 result = memory->DirectQueryAvailable(searchStart, searchEnd, alignment, &physAddr, &size);
if (size == 0) {
return ORBIS_KERNEL_ERROR_ENOMEM;
}
*physAddrOut = static_cast<u64>(physAddr); *physAddrOut = static_cast<u64>(physAddr);
*sizeOut = size;
return result; return result;
} }

View file

@ -6,7 +6,7 @@
#include "common/bit_field.h" #include "common/bit_field.h"
#include "common/types.h" #include "common/types.h"
constexpr u64 SCE_KERNEL_MAIN_DMEM_SIZE = 6_GB; // ~ 6GB constexpr u64 SCE_KERNEL_MAIN_DMEM_SIZE = 4608_MB; // ~ 4.5GB
namespace Libraries::Kernel { namespace Libraries::Kernel {

View file

@ -328,6 +328,11 @@ int MemoryManager::DirectQueryAvailable(PAddr search_start, PAddr search_end, si
PAddr paddr{}; PAddr paddr{};
size_t max_size{}; size_t max_size{};
while (dmem_area != dmem_map.end() && dmem_area->second.GetEnd() <= search_end) { while (dmem_area != dmem_map.end() && dmem_area->second.GetEnd() <= search_end) {
if (!dmem_area->second.is_free) {
dmem_area++;
continue;
}
if (dmem_area->second.size > max_size) { if (dmem_area->second.size > max_size) {
paddr = dmem_area->second.base; paddr = dmem_area->second.base;
max_size = dmem_area->second.size; max_size = dmem_area->second.size;