From aa1e209845b496e60b31ad74fed30623b3e9ad39 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 28 Feb 2020 20:29:14 +0100 Subject: [PATCH] Kernel: Remove some unnecessary indirection in InodeFile::mmap() InodeFile now directly calls Process::allocate_region_with_vmobject() instead of taking an awkward detour via a special Region constructor. --- Kernel/FileSystem/InodeFile.cpp | 3 ++- Kernel/Process.cpp | 13 +------------ Kernel/Process.h | 1 - Kernel/VM/Region.cpp | 17 ----------------- Kernel/VM/Region.h | 2 -- 5 files changed, 3 insertions(+), 33 deletions(-) diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp index 37a33f7e52..1f4d70c127 100644 --- a/Kernel/FileSystem/InodeFile.cpp +++ b/Kernel/FileSystem/InodeFile.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace Kernel { @@ -63,7 +64,7 @@ KResultOr InodeFile::mmap(Process& process, FileDescription& descriptio { ASSERT(offset == 0); // FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec. - auto* region = process.allocate_file_backed_region(preferred_vaddr, size, inode(), description.absolute_path(), prot); + auto* region = process.allocate_region_with_vmobject(preferred_vaddr, size, SharedInodeVMObject::create_with_inode(inode()), offset, description.absolute_path(), prot); if (!region) return KResult(-ENOMEM); return region; diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 51350d9d38..4d31f72f8d 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -66,9 +66,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -205,16 +205,6 @@ Region* Process::allocate_region(VirtualAddress vaddr, size_t size, const String return allocate_region(range, name, prot, commit); } -Region* Process::allocate_file_backed_region(VirtualAddress vaddr, size_t size, NonnullRefPtr inode, const String& name, int prot) -{ - auto range = allocate_range(vaddr, size); - if (!range.is_valid()) - return nullptr; - auto& region = add_region(Region::create_user_accessible(range, inode, name, prot_to_region_access_flags(prot))); - region.map(page_directory()); - return ®ion; -} - Region* Process::allocate_region_with_vmobject(const Range& range, NonnullRefPtr vmobject, size_t offset_in_vmobject, const String& name, int prot, bool user_accessible) { ASSERT(range.is_valid()); @@ -241,7 +231,6 @@ Region* Process::allocate_region_with_vmobject(const Range& range, NonnullRefPtr return region; } - Region* Process::allocate_region_with_vmobject(VirtualAddress vaddr, size_t size, NonnullRefPtr vmobject, size_t offset_in_vmobject, const String& name, int prot, bool user_accessible) { auto range = allocate_range(vaddr, size); diff --git a/Kernel/Process.h b/Kernel/Process.h index 371bdfe089..96360398f5 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -367,7 +367,6 @@ 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, bool user_accessible = true); - Region* allocate_file_backed_region(VirtualAddress, size_t, NonnullRefPtr, 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_with_vmobject(const Range&, NonnullRefPtr, size_t offset_in_vmobject, const String& name, int prot, bool user_accessible = true); Region* allocate_region(const Range&, const String& name, int prot = PROT_READ | PROT_WRITE, bool commit = true); diff --git a/Kernel/VM/Region.cpp b/Kernel/VM/Region.cpp index 070f58afaf..752fb4e18a 100644 --- a/Kernel/VM/Region.cpp +++ b/Kernel/VM/Region.cpp @@ -48,16 +48,6 @@ Region::Region(const Range& range, const String& name, u8 access, bool cacheable MM.register_region(*this); } -Region::Region(const Range& range, NonnullRefPtr inode, const String& name, u8 access, bool cacheable) - : m_range(range) - , m_vmobject(SharedInodeVMObject::create_with_inode(*inode)) - , m_name(name) - , m_access(access) - , m_cacheable(cacheable) -{ - MM.register_region(*this); -} - Region::Region(const Range& range, NonnullRefPtr vmobject, size_t offset_in_vmobject, const String& name, u8 access, bool cacheable) : m_range(range) , m_offset_in_vmobject(offset_in_vmobject) @@ -206,13 +196,6 @@ NonnullOwnPtr Region::create_user_accessible(const Range& range, Nonnull return region; } -NonnullOwnPtr Region::create_user_accessible(const Range& range, NonnullRefPtr inode, const StringView& name, u8 access, bool cacheable) -{ - auto region = make(range, move(inode), name, access, cacheable); - region->m_user_accessible = true; - return region; -} - NonnullOwnPtr Region::create_kernel_only(const Range& range, NonnullRefPtr vmobject, size_t offset_in_vmobject, const StringView& name, u8 access, bool cacheable) { auto region = make(range, move(vmobject), offset_in_vmobject, name, access, cacheable); diff --git a/Kernel/VM/Region.h b/Kernel/VM/Region.h index 3a96f3616e..60f2cd4d8b 100644 --- a/Kernel/VM/Region.h +++ b/Kernel/VM/Region.h @@ -57,7 +57,6 @@ public: static NonnullOwnPtr create_user_accessible(const Range&, const StringView& name, u8 access, bool cacheable = true); static NonnullOwnPtr create_user_accessible(const Range&, NonnullRefPtr, size_t offset_in_vmobject, const StringView& name, u8 access, bool cacheable = true); - static NonnullOwnPtr create_user_accessible(const Range&, NonnullRefPtr, const StringView& name, u8 access, bool cacheable = true); static NonnullOwnPtr create_kernel_only(const Range&, const StringView& name, u8 access, bool cacheable = true); static NonnullOwnPtr create_kernel_only(const Range&, NonnullRefPtr, size_t offset_in_vmobject, const StringView& name, u8 access, bool cacheable = true); @@ -163,7 +162,6 @@ public: // NOTE: These are public so we can make<> them. Region(const Range&, const String&, u8 access, bool cacheable); Region(const Range&, NonnullRefPtr, size_t offset_in_vmobject, const String&, u8 access, bool cacheable); - Region(const Range&, NonnullRefPtr, const String&, u8 access, bool cacheable); private: Bitmap& ensure_cow_map() const;