mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2024-12-29 11:06:07 +00:00
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
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:
parent
5d7407dc7d
commit
fae0c0ae85
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue