diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index fb3b0a5451..01845f5138 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -174,7 +174,7 @@ bool MemoryManager::is_allowed_to_mmap_to_userspace(PhysicalAddress start_addres UNMAP_AFTER_INIT void MemoryManager::parse_memory_map() { - RefPtr physical_region; + PhysicalRegion* physical_region { nullptr }; // Register used memory regions that we know of. m_used_memory_ranges.ensure_capacity(4); @@ -256,9 +256,9 @@ UNMAP_AFTER_INIT void MemoryManager::parse_memory_map() continue; // Assign page to user physical physical_region. - if (physical_region.is_null() || physical_region->upper().offset(PAGE_SIZE) != addr) { + if (!physical_region || physical_region->upper().offset(PAGE_SIZE) != addr) { m_user_physical_regions.append(PhysicalRegion::create(addr, addr)); - physical_region = m_user_physical_regions.last(); + physical_region = &m_user_physical_regions.last(); } else { physical_region->expand(physical_region->lower(), addr); } @@ -336,10 +336,10 @@ UNMAP_AFTER_INIT void MemoryManager::initialize_physical_pages() auto physical_page_array_pages_and_page_tables_count = physical_page_array_pages + needed_page_table_count; // Now that we know how much memory we need for a contiguous array of PhysicalPage instances, find a memory region that can fit it - RefPtr found_region; + PhysicalRegion* found_region { nullptr }; for (auto& region : m_user_physical_regions) { if (region.size() >= physical_page_array_pages_and_page_tables_count) { - found_region = region; + found_region = ®ion; break; } } @@ -354,10 +354,10 @@ UNMAP_AFTER_INIT void MemoryManager::initialize_physical_pages() if (found_region->size() == physical_page_array_pages_and_page_tables_count) { // We're stealing the entire region + m_physical_pages_region = move(*found_region); m_user_physical_regions.remove_first_matching([&](auto& region) { - return region == found_region.ptr(); + return ®ion == found_region; }); - m_physical_pages_region = found_region.release_nonnull(); } else { m_physical_pages_region = found_region->take_pages_from_beginning(physical_page_array_pages_and_page_tables_count); } diff --git a/Kernel/VM/MemoryManager.h b/Kernel/VM/MemoryManager.h index d944a196b9..474d55644e 100644 --- a/Kernel/VM/MemoryManager.h +++ b/Kernel/VM/MemoryManager.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -245,9 +246,9 @@ private: SystemMemoryInfo m_system_memory_info; - NonnullRefPtrVector m_user_physical_regions; - NonnullRefPtrVector m_super_physical_regions; - RefPtr m_physical_pages_region; + Vector m_user_physical_regions; + Vector m_super_physical_regions; + Optional m_physical_pages_region; PhysicalPageEntry* m_physical_page_entries { nullptr }; size_t m_physical_page_entries_free { 0 }; size_t m_physical_page_entries_count { 0 }; diff --git a/Kernel/VM/PhysicalRegion.cpp b/Kernel/VM/PhysicalRegion.cpp index 9dd32dcbcd..4e2e532ac5 100644 --- a/Kernel/VM/PhysicalRegion.cpp +++ b/Kernel/VM/PhysicalRegion.cpp @@ -4,22 +4,14 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include -#include #include #include -#include #include namespace Kernel { -NonnullRefPtr PhysicalRegion::create(PhysicalAddress lower, PhysicalAddress upper) -{ - return adopt_ref(*new PhysicalRegion(lower, upper)); -} - PhysicalRegion::PhysicalRegion(PhysicalAddress lower, PhysicalAddress upper) : m_lower(lower) , m_upper(upper) @@ -44,7 +36,7 @@ unsigned PhysicalRegion::finalize_capacity() return size(); } -NonnullRefPtr PhysicalRegion::take_pages_from_beginning(unsigned page_count) +PhysicalRegion PhysicalRegion::take_pages_from_beginning(unsigned page_count) { VERIFY(m_used == 0); VERIFY(page_count > 0); @@ -59,7 +51,7 @@ NonnullRefPtr PhysicalRegion::take_pages_from_beginning(unsigned finalize_capacity(); auto taken_region = create(taken_lower, taken_upper); - taken_region->finalize_capacity(); + taken_region.finalize_capacity(); return taken_region; } diff --git a/Kernel/VM/PhysicalRegion.h b/Kernel/VM/PhysicalRegion.h index 4d7191c22d..7f3249736c 100644 --- a/Kernel/VM/PhysicalRegion.h +++ b/Kernel/VM/PhysicalRegion.h @@ -7,19 +7,17 @@ #pragma once #include -#include #include -#include #include namespace Kernel { -class PhysicalRegion : public RefCounted { - AK_MAKE_ETERNAL - +class PhysicalRegion { public: - static NonnullRefPtr create(PhysicalAddress lower, PhysicalAddress upper); - ~PhysicalRegion() = default; + static PhysicalRegion create(PhysicalAddress lower, PhysicalAddress upper) + { + return { lower, upper }; + } void expand(PhysicalAddress lower, PhysicalAddress upper); unsigned finalize_capacity(); @@ -31,7 +29,7 @@ public: unsigned free() const { return m_pages - m_used + m_recently_returned.size(); } bool contains(PhysicalAddress paddr) const { return paddr >= m_lower && paddr <= m_upper; } - NonnullRefPtr take_pages_from_beginning(unsigned); + PhysicalRegion take_pages_from_beginning(unsigned); RefPtr take_free_page(bool supervisor); NonnullRefPtrVector take_contiguous_free_pages(size_t count, bool supervisor, size_t physical_alignment = PAGE_SIZE); @@ -41,7 +39,7 @@ private: unsigned find_contiguous_free_pages(size_t count, size_t physical_alignment = PAGE_SIZE); Optional find_and_allocate_contiguous_range(size_t count, unsigned alignment = 1); Optional find_one_free_page(); - void free_page_at(PhysicalAddress addr); + void free_page_at(PhysicalAddress); PhysicalRegion(PhysicalAddress lower, PhysicalAddress upper);