1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:38:11 +00:00

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.
This commit is contained in:
Andreas Kling 2020-02-28 20:29:14 +01:00
parent 651417a085
commit aa1e209845
5 changed files with 3 additions and 33 deletions

View file

@ -29,6 +29,7 @@
#include <Kernel/FileSystem/InodeFile.h> #include <Kernel/FileSystem/InodeFile.h>
#include <Kernel/FileSystem/VirtualFileSystem.h> #include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/VM/SharedInodeVMObject.h>
namespace Kernel { namespace Kernel {
@ -63,7 +64,7 @@ KResultOr<Region*> InodeFile::mmap(Process& process, FileDescription& descriptio
{ {
ASSERT(offset == 0); ASSERT(offset == 0);
// FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec. // 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) if (!region)
return KResult(-ENOMEM); return KResult(-ENOMEM);
return region; return region;

View file

@ -66,9 +66,9 @@
#include <Kernel/TTY/MasterPTY.h> #include <Kernel/TTY/MasterPTY.h>
#include <Kernel/TTY/TTY.h> #include <Kernel/TTY/TTY.h>
#include <Kernel/Thread.h> #include <Kernel/Thread.h>
#include <Kernel/VM/SharedInodeVMObject.h>
#include <Kernel/VM/PageDirectory.h> #include <Kernel/VM/PageDirectory.h>
#include <Kernel/VM/PurgeableVMObject.h> #include <Kernel/VM/PurgeableVMObject.h>
#include <Kernel/VM/SharedInodeVMObject.h>
#include <LibBareMetal/IO.h> #include <LibBareMetal/IO.h>
#include <LibBareMetal/Output/Console.h> #include <LibBareMetal/Output/Console.h>
#include <LibBareMetal/StdLib.h> #include <LibBareMetal/StdLib.h>
@ -205,16 +205,6 @@ Region* Process::allocate_region(VirtualAddress vaddr, size_t size, const String
return allocate_region(range, name, prot, commit); return allocate_region(range, name, prot, commit);
} }
Region* Process::allocate_file_backed_region(VirtualAddress vaddr, size_t size, NonnullRefPtr<Inode> 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 &region;
}
Region* Process::allocate_region_with_vmobject(const Range& range, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, const String& name, int prot, bool user_accessible) Region* Process::allocate_region_with_vmobject(const Range& range, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, const String& name, int prot, bool user_accessible)
{ {
ASSERT(range.is_valid()); ASSERT(range.is_valid());
@ -241,7 +231,6 @@ Region* Process::allocate_region_with_vmobject(const Range& range, NonnullRefPtr
return region; return region;
} }
Region* Process::allocate_region_with_vmobject(VirtualAddress vaddr, size_t size, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, const String& name, int prot, bool user_accessible) Region* Process::allocate_region_with_vmobject(VirtualAddress vaddr, size_t size, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, const String& name, int prot, bool user_accessible)
{ {
auto range = allocate_range(vaddr, size); auto range = allocate_range(vaddr, size);

View file

@ -367,7 +367,6 @@ public:
bool is_superuser() const { return m_euid == 0; } bool is_superuser() const { return m_euid == 0; }
Region* allocate_region_with_vmobject(VirtualAddress, size_t, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const String& name, int prot, bool user_accessible = true); Region* allocate_region_with_vmobject(VirtualAddress, size_t, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const String& name, int prot, bool user_accessible = true);
Region* allocate_file_backed_region(VirtualAddress, size_t, NonnullRefPtr<Inode>, 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 commit = true);
Region* allocate_region_with_vmobject(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const String& name, int prot, bool user_accessible = true); Region* allocate_region_with_vmobject(const Range&, NonnullRefPtr<VMObject>, 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); Region* allocate_region(const Range&, const String& name, int prot = PROT_READ | PROT_WRITE, bool commit = true);

View file

@ -48,16 +48,6 @@ Region::Region(const Range& range, const String& name, u8 access, bool cacheable
MM.register_region(*this); MM.register_region(*this);
} }
Region::Region(const Range& range, NonnullRefPtr<Inode> 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> vmobject, size_t offset_in_vmobject, const String& name, u8 access, bool cacheable) Region::Region(const Range& range, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, const String& name, u8 access, bool cacheable)
: m_range(range) : m_range(range)
, m_offset_in_vmobject(offset_in_vmobject) , m_offset_in_vmobject(offset_in_vmobject)
@ -206,13 +196,6 @@ NonnullOwnPtr<Region> Region::create_user_accessible(const Range& range, Nonnull
return region; return region;
} }
NonnullOwnPtr<Region> Region::create_user_accessible(const Range& range, NonnullRefPtr<Inode> inode, const StringView& name, u8 access, bool cacheable)
{
auto region = make<Region>(range, move(inode), name, access, cacheable);
region->m_user_accessible = true;
return region;
}
NonnullOwnPtr<Region> Region::create_kernel_only(const Range& range, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, const StringView& name, u8 access, bool cacheable) NonnullOwnPtr<Region> Region::create_kernel_only(const Range& range, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, const StringView& name, u8 access, bool cacheable)
{ {
auto region = make<Region>(range, move(vmobject), offset_in_vmobject, name, access, cacheable); auto region = make<Region>(range, move(vmobject), offset_in_vmobject, name, access, cacheable);

View file

@ -57,7 +57,6 @@ public:
static NonnullOwnPtr<Region> create_user_accessible(const Range&, const StringView& name, u8 access, bool cacheable = true); static NonnullOwnPtr<Region> create_user_accessible(const Range&, const StringView& name, u8 access, bool cacheable = true);
static NonnullOwnPtr<Region> create_user_accessible(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const StringView& name, u8 access, bool cacheable = true); static NonnullOwnPtr<Region> create_user_accessible(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const StringView& name, u8 access, bool cacheable = true);
static NonnullOwnPtr<Region> create_user_accessible(const Range&, NonnullRefPtr<Inode>, const StringView& name, u8 access, bool cacheable = true);
static NonnullOwnPtr<Region> create_kernel_only(const Range&, const StringView& name, u8 access, bool cacheable = true); static NonnullOwnPtr<Region> create_kernel_only(const Range&, const StringView& name, u8 access, bool cacheable = true);
static NonnullOwnPtr<Region> create_kernel_only(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const StringView& name, u8 access, bool cacheable = true); static NonnullOwnPtr<Region> create_kernel_only(const Range&, NonnullRefPtr<VMObject>, 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. // NOTE: These are public so we can make<> them.
Region(const Range&, const String&, u8 access, bool cacheable); Region(const Range&, const String&, u8 access, bool cacheable);
Region(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const String&, u8 access, bool cacheable); Region(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const String&, u8 access, bool cacheable);
Region(const Range&, NonnullRefPtr<Inode>, const String&, u8 access, bool cacheable);
private: private:
Bitmap& ensure_cow_map() const; Bitmap& ensure_cow_map() const;