From 042b1f68145ad3754fd98429b405c5c1a173d3fc Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 8 May 2020 21:47:08 +0200 Subject: [PATCH] Kernel: Propagate failure to commit VM regions in more places Ultimately we should not panic just because we can't fully commit a VM region (by populating it with physical pages.) This patch handles some of the situations where commit() can fail. --- Kernel/Process.cpp | 16 ++++++++-------- Kernel/Process.h | 4 ++-- Kernel/VM/MemoryManager.cpp | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 2f258675180..cd46574a958 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -193,23 +193,23 @@ Region& Process::allocate_split_region(const Region& source_region, const Range& return region; } -Region* Process::allocate_region(const Range& range, const String& name, int prot, bool commit) +Region* Process::allocate_region(const Range& range, const String& name, int prot, bool should_commit) { ASSERT(range.is_valid()); auto vmobject = AnonymousVMObject::create_with_size(range.size()); - auto& region = add_region(Region::create_user_accessible(range, vmobject, 0, name, prot_to_region_access_flags(prot))); - region.map(page_directory()); - if (commit) - region.commit(); - return ®ion; + auto region = Region::create_user_accessible(range, vmobject, 0, name, prot_to_region_access_flags(prot)); + region->map(page_directory()); + if (should_commit && !region->commit()) + return nullptr; + return &add_region(move(region)); } -Region* Process::allocate_region(VirtualAddress vaddr, size_t size, const String& name, int prot, bool commit) +Region* Process::allocate_region(VirtualAddress vaddr, size_t size, const String& name, int prot, bool should_commit) { auto range = allocate_range(vaddr, size); if (!range.is_valid()) return nullptr; - return allocate_region(range, name, prot, commit); + return allocate_region(range, name, prot, should_commit); } Region* Process::allocate_region_with_vmobject(const Range& range, NonnullRefPtr vmobject, size_t offset_in_vmobject, const String& name, int prot) diff --git a/Kernel/Process.h b/Kernel/Process.h index f8d5fd265c5..ecf3ef10293 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -374,9 +374,9 @@ public: bool is_superuser() const { return m_euid == 0; } Region* allocate_region_with_vmobject(VirtualAddress, size_t, NonnullRefPtr, size_t offset_in_vmobject, const String& name, int prot); - Region* allocate_region(VirtualAddress, size_t, const String& name, int prot = PROT_READ | PROT_WRITE, bool commit = true); + Region* allocate_region(VirtualAddress, size_t, const String& name, int prot = PROT_READ | PROT_WRITE, bool should_commit = true); Region* allocate_region_with_vmobject(const Range&, NonnullRefPtr, size_t offset_in_vmobject, const String& name, int prot); - Region* allocate_region(const Range&, const String& name, int prot = PROT_READ | PROT_WRITE, bool commit = true); + Region* allocate_region(const Range&, const String& name, int prot = PROT_READ | PROT_WRITE, bool should_commit = true); bool deallocate_region(Region& region); Region& allocate_split_region(const Region& source_region, const Range&, size_t offset_in_vmobject); diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index 4257d9f31f6..7268a652df9 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -358,8 +358,8 @@ OwnPtr MemoryManager::allocate_kernel_region(size_t size, const StringVi auto region = allocate_kernel_region_with_vmobject(range, vmobject, name, access, user_accessible, cacheable); if (!region) return nullptr; - if (should_commit) - region->commit(); + if (should_commit && !region->commit()) + return nullptr; return region; }