From 813385caa34efb76b7e5f7d51c40f83e4531bd8d Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 3 Aug 2023 13:27:07 +0300 Subject: [PATCH] improved logging in sceKernelAllocateDirectMemory --- src/Core/PS4/HLE/Kernel/memory_management.cpp | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Core/PS4/HLE/Kernel/memory_management.cpp b/src/Core/PS4/HLE/Kernel/memory_management.cpp index a3885953..f22c94f4 100644 --- a/src/Core/PS4/HLE/Kernel/memory_management.cpp +++ b/src/Core/PS4/HLE/Kernel/memory_management.cpp @@ -1,4 +1,7 @@ +#include "memory_management.h" + #include + #include #include @@ -7,10 +10,11 @@ #include "../ErrorCodes.h" #include "../Libs.h" #include "Objects/physical_memory.h" -#include "memory_management.h" namespace HLE::Libs::LibKernel::MemoryManagement { +constexpr bool log_file_memory = true; // disable it to disable logging + bool isPowerOfTwo(u64 n) { return std::popcount(n) == 1; } bool is16KBAligned(u64 n) { return ((n % (16ull * 1024) == 0)); } @@ -24,43 +28,42 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u PRINT_FUNCTION_NAME(); if (searchStart < 0 || searchEnd <= searchStart) { - // TODO debug logging + LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EINVAL searchStart,searchEnd invalid\n"); return SCE_KERNEL_ERROR_EINVAL; } bool isInRange = (searchStart < len && searchEnd > len); if (len <= 0 || !is16KBAligned(len) || !isInRange) { - // TODO debug logging + LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EINVAL memory range invalid\n"); return SCE_KERNEL_ERROR_EINVAL; } if ((alignment != 0 || is16KBAligned(alignment)) && !isPowerOfTwo(alignment)) { - // TODO debug logging + LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EINVAL alignment invalid\n"); return SCE_KERNEL_ERROR_EINVAL; } if (physAddrOut == nullptr) { - // TODO debug logging + LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EINVAL physAddrOut is null\n"); return SCE_KERNEL_ERROR_EINVAL; } auto memtype = magic_enum::enum_cast(memoryType); - LOG_INFO_IF(true, "search_start = {}\n", log_hex_full(searchStart)); - LOG_INFO_IF(true, "search_end = {}\n", log_hex_full(searchEnd)); - LOG_INFO_IF(true, "len = {}\n", log_hex_full(len)); - LOG_INFO_IF(true, "alignment = {}\n", log_hex_full(alignment)); - LOG_INFO_IF(true, "memory_type = {}\n", magic_enum::enum_name(memtype.value())); + LOG_INFO_IF(log_file_memory, "search_start = {}\n", log_hex_full(searchStart)); + LOG_INFO_IF(log_file_memory, "search_end = {}\n", log_hex_full(searchEnd)); + LOG_INFO_IF(log_file_memory, "len = {}\n", log_hex_full(len)); + LOG_INFO_IF(log_file_memory, "alignment = {}\n", log_hex_full(alignment)); + LOG_INFO_IF(log_file_memory, "memory_type = {}\n", magic_enum::enum_name(memtype.value())); u64 physical_addr = 0; auto* physical_memory = Singleton::Instance(); if (!physical_memory->Alloc(searchStart, searchEnd, len, alignment, &physical_addr, memoryType)) { - // TODO debug logging + LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EAGAIN can't allocate physical memory\n"); return SCE_KERNEL_ERROR_EAGAIN; } *physAddrOut = static_cast(physical_addr); - LOG_INFO_IF(true, "physAddrOut = {}\n", log_hex_full(physical_addr)); + LOG_INFO_IF(true, "physAddrOut = {}\n", log_hex_full(physical_addr)); return SCE_OK; } -int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int flags, s64 directMemoryStart, u64 alignment) -{ +int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int flags, s64 directMemoryStart, u64 alignment) { auto* physical_memory = Singleton::Instance(); BREAKPOINT(); return SCE_OK;