diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index f438f3cb1e..d17c804bb7 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -184,7 +184,7 @@ public: if (ptr == nullptr) { LOG_CRITICAL(HW_Memory, "Failed to allocate fallback buffer with size {:#x}, error {}", size, GetLastError()); } - return VirtualAlloc(nullptr, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); + return ptr; } void Map(size_t virtual_offset, size_t host_offset, size_t length, MemoryPermission perms) { @@ -707,7 +707,7 @@ HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_) { #if defined(__OPENORBIS__) || defined(__managarm__) LOG_WARNING(HW_Memory, "Platform doesn't support fastmem"); - backing_base = malloc(backing_size); + backing_base = static_cast(malloc(backing_size)); virtual_base = nullptr; #else // Try to allocate a fastmem arena. diff --git a/src/common/host_memory.h b/src/common/host_memory.h index c85ea1ffab..a7fd0532b7 100644 --- a/src/common/host_memory.h +++ b/src/common/host_memory.h @@ -85,7 +85,7 @@ private: u8* virtual_base{}; size_t virtual_base_offset{}; // Windows requires it for kernels whom lack proper support for some functions! - bool fallback_buffer; + bool fallback_buffer{false}; }; } // namespace Common diff --git a/src/common/page_table.cpp b/src/common/page_table.cpp index f3aa6b58c0..e8b291507b 100644 --- a/src/common/page_table.cpp +++ b/src/common/page_table.cpp @@ -26,18 +26,19 @@ bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* c // Setup invalid defaults. out_entry->phys_addr = 0; out_entry->block_size = page_size; - // Setup return context - context->next_page += 1; - context->next_offset += page_size; // Validate that we can read the actual entry. if (auto const page = context->next_page; page < entries.size()) { // Validate that the entry is mapped. if (auto const paddr = entries[page].addr; paddr != 0) { // Populate the results and return true - out_entry->phys_addr = (entries[page].GetPhysOffset(current_page_bits)) + context->next_offset; + out_entry->phys_addr = entries[page].GetPhysOffset(current_page_bits) + context->next_offset; + context->next_page += 1; + context->next_offset += page_size; return true; } } + context->next_page += 1; + context->next_offset += page_size; // Otherwise return false return false; } diff --git a/src/common/page_table.h b/src/common/page_table.h index 2b6dca152c..e5deab93db 100644 --- a/src/common/page_table.h +++ b/src/common/page_table.h @@ -100,9 +100,8 @@ struct PageTable { PageTable(const PageTable&) = delete; PageTable& operator=(const PageTable&) = delete; - - PageTable(PageTable&&) noexcept = default; - PageTable& operator=(PageTable&&) noexcept = default; + PageTable(PageTable&&) noexcept = delete; + PageTable& operator=(PageTable&&) noexcept = delete; bool BeginTraversal(TraversalEntry* out_entry, TraversalContext* out_context, Common::ProcessAddress address) const; diff --git a/src/common/sparse_large_vector.h b/src/common/sparse_large_vector.h index b1e9636840..917607118f 100644 --- a/src/common/sparse_large_vector.h +++ b/src/common/sparse_large_vector.h @@ -58,19 +58,8 @@ public: SparseLargeVector(const SparseLargeVector&) = delete; SparseLargeVector& operator=(const SparseLargeVector&) = delete; - - SparseLargeVector(SparseLargeVector&& other) noexcept - : alloc_size{std::exchange(other.alloc_size, 0)} - , base_ptr{std::exchange(other.base_ptr, nullptr)} - , committed_pages{std::exchange(other.base_ptr, nullptr)} - {} - - SparseLargeVector& operator=(SparseLargeVector&& other) noexcept { - alloc_size = std::exchange(other.alloc_size, 0); - base_ptr = std::exchange(other.base_ptr, nullptr); - committed_pages = std::exchange(other.base_ptr, nullptr); - return *this; - } + SparseLargeVector(SparseLargeVector&& other) = delete; + SparseLargeVector& operator=(SparseLargeVector&& other) = delete; void ResizeAndClear(std::size_t count) noexcept { if (auto const new_size = count * sizeof(T); new_size != alloc_size) { diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 5c634cb611..9f9c0f6585 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -125,14 +125,14 @@ struct Memory::Impl { [[nodiscard]] u8* GetPointerFromRasterizerCachedMemory(u64 vaddr) const { Common::PhysicalAddress const paddr = current_page_table->entries[vaddr >> YUZU_PAGEBITS].GetPhysOffset(YUZU_PAGEBITS); if (paddr) - return system.DeviceMemory().GetPointer((paddr << YUZU_PAGEBITS) + vaddr); + return system.DeviceMemory().GetPointer(paddr + vaddr); return {}; } [[nodiscard]] u8* GetPointerFromDebugMemory(u64 vaddr) const { const Common::PhysicalAddress paddr = current_page_table->entries[vaddr >> YUZU_PAGEBITS].GetPhysOffset(YUZU_PAGEBITS); if (paddr != 0) - return system.DeviceMemory().GetPointer((paddr << YUZU_PAGEBITS) + vaddr); + return system.DeviceMemory().GetPointer(paddr + vaddr); return {}; } @@ -555,6 +555,8 @@ struct Memory::Impl { entry.addr = static_cast(GetInteger(target) >> YUZU_PAGEBITS) - static_cast(base); entry.block = static_cast(orig_base); + ASSERT_MSG(entry.GetPhysOffset(YUZU_PAGEBITS) == GetInteger(target) - (base << YUZU_PAGEBITS), "assert failed; {:#x} == {:#x}", entry.GetPhysOffset(YUZU_PAGEBITS), GetInteger(target) - (base << YUZU_PAGEBITS)); + ASSERT_MSG(page_table.entries[base].ptr.Pointer(), "memory mapping base yield a nullptr within the table");