From f96a21551ad7bc459660d9ce3e1fa37f066cffb3 Mon Sep 17 00:00:00 2001 From: IndecisiveTurtle <47210458+raphaelthegreat@users.noreply.github.com> Date: Sun, 10 Nov 2024 20:15:28 +0200 Subject: [PATCH] libs: Reduce logging --- src/core/address_space.cpp | 37 ++++++++++++----------- src/core/file_sys/file.cpp | 5 ++-- src/core/libraries/kernel/memory.cpp | 8 +++-- src/core/libraries/libs.h | 45 ++-------------------------- src/video_core/amdgpu/liverpool.cpp | 2 +- 5 files changed, 32 insertions(+), 65 deletions(-) diff --git a/src/core/address_space.cpp b/src/core/address_space.cpp index 224c762a..6ba44225 100644 --- a/src/core/address_space.cpp +++ b/src/core/address_space.cpp @@ -103,7 +103,7 @@ struct AddressSpace::Impl { const uintptr_t system_reserved_addr = reinterpret_cast(system_reserved_base); const uintptr_t user_addr = reinterpret_cast(user_base); regions.emplace(system_managed_addr, - MemoryRegion{system_managed_addr, virtual_size - reduction, false}); + MemoryRegion{system_managed_addr, virtual_size - reduction, false}); // Allocate backing file that represents the total physical memory. backing_handle = @@ -157,8 +157,7 @@ struct AddressSpace::Impl { ASSERT_MSG(ret, "VirtualProtect failed. {}", Common::GetLastErrorMsg()); } else { ptr = MapViewOfFile3(backing, process, reinterpret_cast(virtual_addr), - phys_addr, size, MEM_REPLACE_PLACEHOLDER, prot, - nullptr, 0); + phys_addr, size, MEM_REPLACE_PLACEHOLDER, prot, nullptr, 0); } } else { ptr = @@ -211,7 +210,8 @@ struct AddressSpace::Impl { region_size, size); // Split the placeholder. - if (!VirtualFreeEx(process, LPVOID(address), size, MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)) { + if (!VirtualFreeEx(process, LPVOID(address), size, + MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)) { UNREACHABLE_MSG("Region splitting failed: {}", Common::GetLastErrorMsg()); return nullptr; } @@ -220,7 +220,7 @@ struct AddressSpace::Impl { region.size = size; const VAddr new_mapping_start = address + size; regions.emplace_hint(std::next(it), new_mapping_start, - MemoryRegion(new_mapping_start, region_size - size, false)); + MemoryRegion(new_mapping_start, region_size - size, false)); return ®ion; } @@ -232,7 +232,8 @@ struct AddressSpace::Impl { ASSERT(region_size >= minimum_size); // Split the placeholder. - if (!VirtualFreeEx(process, LPVOID(address), size, MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)) { + if (!VirtualFreeEx(process, LPVOID(address), size, + MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)) { UNREACHABLE_MSG("Region splitting failed: {}", Common::GetLastErrorMsg()); return nullptr; } @@ -241,8 +242,7 @@ struct AddressSpace::Impl { if (region_size == minimum_size) { // Split into two; update tracked mappings and return the second one region.size = offset_in_region; - it = regions.emplace_hint(std::next(it), address, - MemoryRegion(address, size, false)); + it = regions.emplace_hint(std::next(it), address, MemoryRegion(address, size, false)); return &it->second; } else { // Split into three; update tracked mappings and return the middle one @@ -251,10 +251,11 @@ struct AddressSpace::Impl { const size_t middle_mapping_size = size; const VAddr after_mapping_start = address + size; const size_t after_mapping_size = region_size - minimum_size; - it = regions.emplace_hint(std::next(it), - after_mapping_start, MemoryRegion(after_mapping_start, after_mapping_size, false)); - it = regions.emplace_hint(it, middle_mapping_start, - MemoryRegion(middle_mapping_start, middle_mapping_size, false)); + it = regions.emplace_hint(std::next(it), after_mapping_start, + MemoryRegion(after_mapping_start, after_mapping_size, false)); + it = regions.emplace_hint( + it, middle_mapping_start, + MemoryRegion(middle_mapping_start, middle_mapping_size, false)); return &it->second; } } @@ -266,13 +267,13 @@ struct AddressSpace::Impl { "Invalid address/size given to unmap."); auto& [base, region] = *it; region.is_mapped = false; - + // Check if a placeholder exists right before us. auto it_prev = it != regions.begin() ? std::prev(it) : regions.end(); if (it_prev != regions.end() && !it_prev->second.is_mapped) { const size_t total_size = it_prev->second.size + size; if (!VirtualFreeEx(process, LPVOID(it_prev->first), total_size, - MEM_RELEASE | MEM_COALESCE_PLACEHOLDERS)) { + MEM_RELEASE | MEM_COALESCE_PLACEHOLDERS)) { UNREACHABLE_MSG("Region coalescing failed: {}", Common::GetLastErrorMsg()); } @@ -285,7 +286,8 @@ struct AddressSpace::Impl { auto it_next = std::next(it); if (it_next != regions.end() && !it_next->second.is_mapped) { const size_t total_size = it->second.size + it_next->second.size; - if (!VirtualFreeEx(process, LPVOID(it->first), total_size, MEM_RELEASE | MEM_COALESCE_PLACEHOLDERS)) { + if (!VirtualFreeEx(process, LPVOID(it->first), total_size, + MEM_RELEASE | MEM_COALESCE_PLACEHOLDERS)) { UNREACHABLE_MSG("Region coalescing failed: {}", Common::GetLastErrorMsg()); } @@ -325,8 +327,9 @@ struct AddressSpace::Impl { const size_t range_size = std::min(region.base + region.size, virtual_end) - range_addr; DWORD old_flags{}; if (!VirtualProtectEx(process, LPVOID(range_addr), range_size, new_flags, &old_flags)) { - UNREACHABLE_MSG("Failed to change virtual memory protection for address {:#x}, size {}", - range_addr, range_size); + UNREACHABLE_MSG( + "Failed to change virtual memory protection for address {:#x}, size {}", + range_addr, range_size); } } } diff --git a/src/core/file_sys/file.cpp b/src/core/file_sys/file.cpp index e0660607..be6bc76b 100644 --- a/src/core/file_sys/file.cpp +++ b/src/core/file_sys/file.cpp @@ -6,10 +6,10 @@ #include "core/file_sys/file.h" #ifdef _WIN64 -#include "common/ntapi.h" #include #include #include +#include "common/ntapi.h" #endif namespace Core::FileSys { @@ -27,7 +27,8 @@ int File::Open(const std::filesystem::path& path, Common::FS::FileAccessMode f_a } else { UNREACHABLE(); } - handle = CreateFileW(path.native().c_str(), access, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + handle = CreateFileW(path.native().c_str(), access, FILE_SHARE_READ, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, NULL); if (handle == INVALID_HANDLE_VALUE) { return ENOENT; } diff --git a/src/core/libraries/kernel/memory.cpp b/src/core/libraries/kernel/memory.cpp index 9fb6b680..13b3a9f4 100644 --- a/src/core/libraries/kernel/memory.cpp +++ b/src/core/libraries/kernel/memory.cpp @@ -5,8 +5,8 @@ #include "common/alignment.h" #include "common/assert.h" -#include "common/scope_exit.h" #include "common/logging/log.h" +#include "common/scope_exit.h" #include "common/singleton.h" #include "core/file_sys/fs.h" #include "core/libraries/error_codes.h" @@ -166,7 +166,8 @@ int PS4_SYSV_ABI sceKernelMapNamedDirectMemory(void** addr, u64 len, int prot, i const auto map_flags = static_cast(flags); SCOPE_EXIT { LOG_INFO(Kernel_Vmm, - "in_addr = {:#x}, out_addr = {}, len = {:#x}, prot = {:#x}, flags = {:#x}, directMemoryStart = {:#x}, " + "in_addr = {:#x}, out_addr = {}, len = {:#x}, prot = {:#x}, flags = {:#x}, " + "directMemoryStart = {:#x}, " "alignment = {:#x}", in_addr, fmt::ptr(*addr), len, prot, flags, directMemoryStart, alignment); }; @@ -205,7 +206,8 @@ s32 PS4_SYSV_ABI sceKernelMapNamedFlexibleMemory(void** addr_in_out, std::size_t const auto mem_prot = static_cast(prot); const auto map_flags = static_cast(flags); SCOPE_EXIT { - LOG_INFO(Kernel_Vmm, "in_addr = {:#x}, out_addr = {}, len = {:#x}, prot = {:#x}, flags = {:#x}", + LOG_INFO(Kernel_Vmm, + "in_addr = {:#x}, out_addr = {}, len = {:#x}, prot = {:#x}, flags = {:#x}", in_addr, fmt::ptr(*addr_in_out), len, prot, flags); }; auto* memory = Core::Memory::Instance(); diff --git a/src/core/libraries/libs.h b/src/core/libraries/libs.h index 375f1abd..aa5ba4a9 100644 --- a/src/core/libraries/libs.h +++ b/src/core/libraries/libs.h @@ -9,46 +9,9 @@ #include "core/loader/elf.h" #include "core/loader/symbols_resolver.h" -template -struct StringLiteral { - constexpr StringLiteral(const char (&str)[N]) { - std::copy_n(str, N, value); - } - - char value[N]; -}; - -template -struct wrapper_impl; - -template -struct wrapper_impl { - static R PS4_SYSV_ABI wrap(Args... args) { - if (std::string_view(name.value) != "scePthreadEqual" && - std::string_view(name.value) != "sceUserServiceGetEvent" && - !std::string_view(name.value).contains("scePthreadMutex") && - !std::string_view(name.value).contains("pthread_mutex")) { - // LOG_WARNING(Core_Linker, "Function {} called", name.value); - } - if constexpr (std::is_same_v || std::is_same_v) { - const u32 ret = f(args...); - if (ret != 0 && !std::string_view(name.value).contains("pthread_equal")) { - LOG_WARNING(Core_Linker, "Function {} returned {:#x}", name.value, ret); - } - return ret; - } - // stuff - return f(args...); - } -}; - -template -constexpr auto wrapper = wrapper_impl::wrap; - -// #define W(foo) wrapper<#foo, decltype(&foo), foo> #define W(foo) foo -#define LIB_FUNCTION(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, f) \ +#define LIB_FUNCTION(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \ { \ Core::Loader::SymbolResolver sr{}; \ sr.name = nid; \ @@ -58,10 +21,8 @@ constexpr auto wrapper = wrapper_impl::wrap; sr.module_version_major = moduleVersionMajor; \ sr.module_version_minor = moduleVersionMinor; \ sr.type = Core::Loader::SymbolType::Function; \ - { \ - auto func = reinterpret_cast(wrapper<#f, decltype(&f), f>); \ - sym->AddSymbol(sr, func); \ - } \ + auto func = reinterpret_cast(function); \ + sym->AddSymbol(sr, func); \ } #define LIB_OBJ(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \ diff --git a/src/video_core/amdgpu/liverpool.cpp b/src/video_core/amdgpu/liverpool.cpp index 7fbb33ea..12b5de43 100644 --- a/src/video_core/amdgpu/liverpool.cpp +++ b/src/video_core/amdgpu/liverpool.cpp @@ -570,7 +570,7 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span dcb, std::spansrc_sel == DmaDataSrc::Gds && dma_data->dst_sel == DmaDataDst::Memory) { - //LOG_WARNING(Render_Vulkan, "GDS memory read"); + // LOG_WARNING(Render_Vulkan, "GDS memory read"); } else if (dma_data->src_sel == DmaDataSrc::Memory && dma_data->dst_sel == DmaDataDst::Memory) { rasterizer->InlineData(dma_data->DstAddress(),