mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Kernel: Use NonnullRefPtrVector<T> instead of Vector<RefPtr<T>> some
This commit is contained in:
parent
bd12f132f3
commit
d74650e80d
Notes:
sideshowbarker
2024-07-19 06:52:43 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d74650e80df
4 changed files with 9 additions and 11 deletions
|
@ -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;
|
||||
|
|
|
@ -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&&);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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()); }
|
||||
|
||||
|
|
Loading…
Reference in a new issue