1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 03:35:09 +00:00

Kernel: Make MM.commit_user_physical_pages() return KResultOr

..and use TRY() at call sites. :^)
This commit is contained in:
Andreas Kling 2021-09-05 21:54:12 +02:00
parent 98dc08fe56
commit 2f790cf78f
3 changed files with 11 additions and 20 deletions

View file

@ -69,9 +69,9 @@ UNMAP_AFTER_INIT MemoryManager::MemoryManager()
protect_kernel_image();
// We're temporarily "committing" to two pages that we need to allocate below
auto committed_pages = commit_user_physical_pages(2);
auto committed_pages = commit_user_physical_pages(2).release_value();
m_shared_zero_page = committed_pages->take_one();
m_shared_zero_page = committed_pages.take_one();
// We're wasting a page here, we just need a special tag (physical
// address) so that we know when we need to lazily allocate a page
@ -79,7 +79,7 @@ UNMAP_AFTER_INIT MemoryManager::MemoryManager()
// than potentially failing if no pages are available anymore.
// By using a tag we don't have to query the VMObject for every page
// whether it was committed or not
m_lazy_committed_page = committed_pages->take_one();
m_lazy_committed_page = committed_pages.take_one();
}
UNMAP_AFTER_INIT MemoryManager::~MemoryManager()
@ -763,12 +763,12 @@ OwnPtr<Region> MemoryManager::allocate_kernel_region_with_vmobject(VMObject& vmo
return allocate_kernel_region_with_vmobject(range.value(), vmobject, name, access, cacheable);
}
Optional<CommittedPhysicalPageSet> MemoryManager::commit_user_physical_pages(size_t page_count)
KResultOr<CommittedPhysicalPageSet> MemoryManager::commit_user_physical_pages(size_t page_count)
{
VERIFY(page_count > 0);
SpinlockLocker lock(s_mm_lock);
if (m_system_memory_info.user_physical_pages_uncommitted < page_count)
return {};
return ENOMEM;
m_system_memory_info.user_physical_pages_uncommitted -= page_count;
m_system_memory_info.user_physical_pages_committed += page_count;