소스 검색

Kernel: Use NonnullRefPtrVector<T> instead of Vector<RefPtr<T>> some

Andreas Kling 5 년 전
부모
커밋
d74650e80d
4개의 변경된 파일9개의 추가작업 그리고 11개의 파일을 삭제
  1. 3 4
      Kernel/VM/MemoryManager.cpp
  2. 1 1
      Kernel/VM/MemoryManager.h
  3. 3 4
      Kernel/VM/PhysicalRegion.cpp
  4. 2 2
      Kernel/VM/PhysicalRegion.h

+ 3 - 4
Kernel/VM/MemoryManager.cpp

@@ -492,13 +492,12 @@ void MemoryManager::deallocate_supervisor_physical_page(PhysicalPage&& page)
     ASSERT_NOT_REACHED();
 }
 
-Vector<RefPtr<PhysicalPage>> MemoryManager::allocate_contiguous_supervisor_physical_pages(size_t size)
+NonnullRefPtrVector<PhysicalPage> MemoryManager::allocate_contiguous_supervisor_physical_pages(size_t size)
 {
     ASSERT(!(size % PAGE_SIZE));
     InterruptDisabler disabler;
     size_t count = ceil_div(size, PAGE_SIZE);
-    Vector<RefPtr<PhysicalPage>> physical_pages;
-    physical_pages.ensure_capacity(count);
+    NonnullRefPtrVector<PhysicalPage> physical_pages;
 
     for (auto& region : m_super_physical_regions) {
         physical_pages = region.take_contiguous_free_pages((count), true);
@@ -516,7 +515,7 @@ Vector<RefPtr<PhysicalPage>> MemoryManager::allocate_contiguous_supervisor_physi
         return {};
     }
 
-    auto cleanup_region = MM.allocate_kernel_region(physical_pages[0]->paddr(), PAGE_SIZE * count, "MemoryManager Allocation Sanitization", Region::Access::Read | Region::Access::Write);
+    auto cleanup_region = MM.allocate_kernel_region(physical_pages[0].paddr(), PAGE_SIZE * count, "MemoryManager Allocation Sanitization", Region::Access::Read | Region::Access::Write);
     fast_u32_fill((u32*)cleanup_region->vaddr().as_ptr(), 0, (PAGE_SIZE * count) / sizeof(u32));
     m_super_physical_pages_used += count;
     return physical_pages;

+ 1 - 1
Kernel/VM/MemoryManager.h

@@ -100,7 +100,7 @@ public:
 
     RefPtr<PhysicalPage> allocate_user_physical_page(ShouldZeroFill = ShouldZeroFill::Yes);
     RefPtr<PhysicalPage> allocate_supervisor_physical_page();
-    Vector<RefPtr<PhysicalPage>> allocate_contiguous_supervisor_physical_pages(size_t size);
+    NonnullRefPtrVector<PhysicalPage> allocate_contiguous_supervisor_physical_pages(size_t size);
     void deallocate_user_physical_page(PhysicalPage&&);
     void deallocate_supervisor_physical_page(PhysicalPage&&);
 

+ 3 - 4
Kernel/VM/PhysicalRegion.cpp

@@ -64,19 +64,18 @@ unsigned PhysicalRegion::finalize_capacity()
     return size();
 }
 
-Vector<RefPtr<PhysicalPage>> PhysicalRegion::take_contiguous_free_pages(size_t count, bool supervisor)
+NonnullRefPtrVector<PhysicalPage> PhysicalRegion::take_contiguous_free_pages(size_t count, bool supervisor)
 {
     ASSERT(m_pages);
     ASSERT(m_used != m_pages);
 
-    Vector<RefPtr<PhysicalPage>> physical_pages;
+    NonnullRefPtrVector<PhysicalPage> physical_pages;
     physical_pages.ensure_capacity(count);
 
     auto first_contiguous_page = find_contiguous_free_pages(count);
 
-    for (size_t index = 0; index < count; index++) {
+    for (size_t index = 0; index < count; index++)
         physical_pages.append(PhysicalPage::create(m_lower.offset(PAGE_SIZE * (index + first_contiguous_page)), supervisor));
-    }
     return physical_pages;
 }
 

+ 2 - 2
Kernel/VM/PhysicalRegion.h

@@ -27,7 +27,7 @@
 #pragma once
 
 #include <AK/Bitmap.h>
-#include <AK/NonnullRefPtr.h>
+#include <AK/NonnullRefPtrVector.h>
 #include <AK/Optional.h>
 #include <AK/RefCounted.h>
 #include <Kernel/VM/PhysicalPage.h>
@@ -52,7 +52,7 @@ public:
     bool contains(PhysicalPage& page) const { return page.paddr() >= m_lower && page.paddr() <= m_upper; }
 
     RefPtr<PhysicalPage> take_free_page(bool supervisor);
-    Vector<RefPtr<PhysicalPage>> take_contiguous_free_pages(size_t count, bool supervisor);
+    NonnullRefPtrVector<PhysicalPage> take_contiguous_free_pages(size_t count, bool supervisor);
     void return_page_at(PhysicalAddress addr);
     void return_page(PhysicalPage&& page) { return_page_at(page.paddr()); }