summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2022-01-28 16:23:24 +0200
committerIdan Horowitz <idan.horowitz@gmail.com>2022-01-28 19:05:52 +0200
commit4d2f1a05ecc8d6e1c1573d2013eebb87d91dc83b (patch)
treea590739cfdba847d93eaa462febc8c6fdb260aee /Kernel
parent956824afe2f35a7bc05fc27cb285914c6cebb30b (diff)
downloadserenity-4d2f1a05ecc8d6e1c1573d2013eebb87d91dc83b.zip
Kernel: Make allocate_contiguous_supervisor_physical_pages OOM-fallible
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Memory/AnonymousVMObject.cpp4
-rw-r--r--Kernel/Memory/MemoryManager.cpp17
-rw-r--r--Kernel/Memory/MemoryManager.h2
3 files changed, 7 insertions, 16 deletions
diff --git a/Kernel/Memory/AnonymousVMObject.cpp b/Kernel/Memory/AnonymousVMObject.cpp
index ad3465e732..fe7471bcfc 100644
--- a/Kernel/Memory/AnonymousVMObject.cpp
+++ b/Kernel/Memory/AnonymousVMObject.cpp
@@ -81,9 +81,7 @@ ErrorOr<NonnullRefPtr<AnonymousVMObject>> AnonymousVMObject::try_create_with_siz
ErrorOr<NonnullRefPtr<AnonymousVMObject>> AnonymousVMObject::try_create_physically_contiguous_with_size(size_t size)
{
- auto contiguous_physical_pages = MM.allocate_contiguous_supervisor_physical_pages(size);
- if (contiguous_physical_pages.is_empty())
- return ENOMEM;
+ auto contiguous_physical_pages = TRY(MM.allocate_contiguous_supervisor_physical_pages(size));
auto new_physical_pages = TRY(FixedArray<RefPtr<PhysicalPage>>::try_create(contiguous_physical_pages.span()));
diff --git a/Kernel/Memory/MemoryManager.cpp b/Kernel/Memory/MemoryManager.cpp
index 1b72cc4d24..670b5123d7 100644
--- a/Kernel/Memory/MemoryManager.cpp
+++ b/Kernel/Memory/MemoryManager.cpp
@@ -759,12 +759,9 @@ ErrorOr<NonnullOwnPtr<Memory::Region>> MemoryManager::allocate_dma_buffer_page(S
ErrorOr<NonnullOwnPtr<Memory::Region>> MemoryManager::allocate_dma_buffer_pages(size_t size, StringView name, Memory::Region::Access access, NonnullRefPtrVector<Memory::PhysicalPage>& dma_buffer_pages)
{
VERIFY(!(size % PAGE_SIZE));
- dma_buffer_pages = allocate_contiguous_supervisor_physical_pages(size);
- if (dma_buffer_pages.is_empty())
- return ENOMEM;
+ dma_buffer_pages = TRY(allocate_contiguous_supervisor_physical_pages(size));
// 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_pages.first().paddr(), size, name, access, Region::Cacheable::No);
- return region_or_error;
+ return allocate_kernel_region(dma_buffer_pages.first().paddr(), size, name, access, Region::Cacheable::No);
}
ErrorOr<NonnullOwnPtr<Memory::Region>> MemoryManager::allocate_dma_buffer_pages(size_t size, StringView name, Memory::Region::Access access)
@@ -939,7 +936,7 @@ RefPtr<PhysicalPage> MemoryManager::allocate_user_physical_page(ShouldZeroFill s
return page;
}
-NonnullRefPtrVector<PhysicalPage> MemoryManager::allocate_contiguous_supervisor_physical_pages(size_t size)
+ErrorOr<NonnullRefPtrVector<PhysicalPage>> MemoryManager::allocate_contiguous_supervisor_physical_pages(size_t size)
{
VERIFY(!(size % PAGE_SIZE));
SpinlockLocker lock(s_mm_lock);
@@ -948,15 +945,11 @@ NonnullRefPtrVector<PhysicalPage> MemoryManager::allocate_contiguous_supervisor_
if (physical_pages.is_empty()) {
dmesgln("MM: no super physical pages available");
- VERIFY_NOT_REACHED();
- return {};
+ return ENOMEM;
}
{
- auto region_or_error = MM.allocate_kernel_region(physical_pages[0].paddr(), PAGE_SIZE * count, "MemoryManager Allocation Sanitization", Region::Access::Read | Region::Access::Write);
- if (region_or_error.is_error())
- TODO();
- auto cleanup_region = region_or_error.release_value();
+ auto cleanup_region = TRY(MM.allocate_kernel_region(physical_pages[0].paddr(), PAGE_SIZE * count, "MemoryManager Allocation Sanitization", Region::Access::Read | Region::Access::Write));
memset(cleanup_region->vaddr().as_ptr(), 0, PAGE_SIZE * count);
}
m_system_memory_info.super_physical_pages_used += count;
diff --git a/Kernel/Memory/MemoryManager.h b/Kernel/Memory/MemoryManager.h
index 9ccf422115..0020a77d6e 100644
--- a/Kernel/Memory/MemoryManager.h
+++ b/Kernel/Memory/MemoryManager.h
@@ -173,7 +173,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();
- NonnullRefPtrVector<PhysicalPage> allocate_contiguous_supervisor_physical_pages(size_t size);
+ ErrorOr<NonnullRefPtrVector<PhysicalPage>> allocate_contiguous_supervisor_physical_pages(size_t size);
void deallocate_physical_page(PhysicalAddress);
ErrorOr<NonnullOwnPtr<Region>> allocate_contiguous_kernel_region(size_t, StringView name, Region::Access access, Region::Cacheable = Region::Cacheable::Yes);