summaryrefslogtreecommitdiff
path: root/Kernel/Memory
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2022-01-28 16:30:01 +0200
committerIdan Horowitz <idan.horowitz@gmail.com>2022-01-28 19:05:52 +0200
commitbd5b56cab0abbf4272fe2e006413f324505f552e (patch)
tree51ca8a48308cd82c8bd3e0b061e0cf421b8e0c71 /Kernel/Memory
parent4d2f1a05ecc8d6e1c1573d2013eebb87d91dc83b (diff)
downloadserenity-bd5b56cab0abbf4272fe2e006413f324505f552e.zip
Kernel: Make allocate_supervisor_physical_page OOM-fallible
Diffstat (limited to 'Kernel/Memory')
-rw-r--r--Kernel/Memory/MemoryManager.cpp14
-rw-r--r--Kernel/Memory/MemoryManager.h2
2 files changed, 6 insertions, 10 deletions
diff --git a/Kernel/Memory/MemoryManager.cpp b/Kernel/Memory/MemoryManager.cpp
index 670b5123d7..e1575c7f00 100644
--- a/Kernel/Memory/MemoryManager.cpp
+++ b/Kernel/Memory/MemoryManager.cpp
@@ -741,12 +741,9 @@ ErrorOr<NonnullOwnPtr<Region>> MemoryManager::allocate_contiguous_kernel_region(
ErrorOr<NonnullOwnPtr<Memory::Region>> MemoryManager::allocate_dma_buffer_page(StringView name, Memory::Region::Access access, RefPtr<Memory::PhysicalPage>& dma_buffer_page)
{
- dma_buffer_page = allocate_supervisor_physical_page();
- if (dma_buffer_page.is_null())
- return ENOMEM;
+ dma_buffer_page = TRY(allocate_supervisor_physical_page());
// Do not enable Cache for this region as physical memory transfers are performed (Most architectures have this behaviour by default)
- auto region_or_error = allocate_kernel_region(dma_buffer_page->paddr(), PAGE_SIZE, name, access, Region::Cacheable::No);
- return region_or_error;
+ return allocate_kernel_region(dma_buffer_page->paddr(), PAGE_SIZE, name, access, Region::Cacheable::No);
}
ErrorOr<NonnullOwnPtr<Memory::Region>> MemoryManager::allocate_dma_buffer_page(StringView name, Memory::Region::Access access)
@@ -956,22 +953,21 @@ ErrorOr<NonnullRefPtrVector<PhysicalPage>> MemoryManager::allocate_contiguous_su
return physical_pages;
}
-RefPtr<PhysicalPage> MemoryManager::allocate_supervisor_physical_page()
+ErrorOr<NonnullRefPtr<PhysicalPage>> MemoryManager::allocate_supervisor_physical_page()
{
SpinlockLocker lock(s_mm_lock);
auto page = m_super_physical_region->take_free_page();
if (!page) {
dmesgln("MM: no super physical pages available");
- VERIFY_NOT_REACHED();
- return {};
+ return ENOMEM;
}
auto* ptr = quickmap_page(*page);
memset(ptr, 0, PAGE_SIZE);
unquickmap_page();
++m_system_memory_info.super_physical_pages_used;
- return page;
+ return page.release_nonnull();
}
void MemoryManager::enter_process_address_space(Process& process)
diff --git a/Kernel/Memory/MemoryManager.h b/Kernel/Memory/MemoryManager.h
index 0020a77d6e..0c1e454fd5 100644
--- a/Kernel/Memory/MemoryManager.h
+++ b/Kernel/Memory/MemoryManager.h
@@ -172,7 +172,7 @@ public:
NonnullRefPtr<PhysicalPage> allocate_committed_user_physical_page(Badge<CommittedPhysicalPageSet>, ShouldZeroFill = ShouldZeroFill::Yes);
RefPtr<PhysicalPage> allocate_user_physical_page(ShouldZeroFill = ShouldZeroFill::Yes, bool* did_purge = nullptr);
- RefPtr<PhysicalPage> allocate_supervisor_physical_page();
+ ErrorOr<NonnullRefPtr<PhysicalPage>> allocate_supervisor_physical_page();
ErrorOr<NonnullRefPtrVector<PhysicalPage>> allocate_contiguous_supervisor_physical_pages(size_t size);
void deallocate_physical_page(PhysicalAddress);