libkernel: Fix sceKernelAllocateDirectMemory and sceKernelAvailableDirectMemorySize (#2803)

* AllocateDirectMemory fixes

search_start and search_end were ignored in certain cases, this fixes that issue.
I've also basically rewritten the function in the process, since the lack of documentation made it difficult to make the proper adjustments.

* DirectQueryAvailable fixes

remaining_size was calculated incorrectly in cases where a free dmem_area had a base earlier than search_start, or an end after search_end.

* Reduce sceKernelGetDirectMemorySize log severity

By this point, we've confirmed that sceKernelGetDirectMemorySize is hardware-accurate. There's no reason to clog logs with this function, which games usually call before every sceKernelAllocateDirectMemory call.

* Clang

* Fix phys_addr_out

phys_addr_out should be equal to search_start in cases where search_start is greater than the dmem_area base.

* Dividing by zero is fun

Need to check for alignment when aligning things.

* Update memory.cpp

* Clang
This commit is contained in:
Stephen Miller 2025-04-18 03:00:14 -05:00 committed by GitHub
parent df89241eb8
commit 20b11f2d63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 25 deletions

View file

@ -19,7 +19,7 @@
namespace Libraries::Kernel {
u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() {
LOG_WARNING(Kernel_Vmm, "called");
LOG_TRACE(Kernel_Vmm, "called");
const auto* memory = Core::Memory::Instance();
return memory->GetTotalDirectSize();
}