Serenity Operating System
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.

+3 -33
+2 -1
Kernel/FileSystem/InodeFile.cpp
··· 29 29 #include <Kernel/FileSystem/InodeFile.h> 30 30 #include <Kernel/FileSystem/VirtualFileSystem.h> 31 31 #include <Kernel/Process.h> 32 + #include <Kernel/VM/SharedInodeVMObject.h> 32 33 33 34 namespace Kernel { 34 35 ··· 63 64 { 64 65 ASSERT(offset == 0); 65 66 // FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec. 66 - auto* region = process.allocate_file_backed_region(preferred_vaddr, size, inode(), description.absolute_path(), prot); 67 + auto* region = process.allocate_region_with_vmobject(preferred_vaddr, size, SharedInodeVMObject::create_with_inode(inode()), offset, description.absolute_path(), prot); 67 68 if (!region) 68 69 return KResult(-ENOMEM); 69 70 return region;
+1 -12
Kernel/Process.cpp
··· 66 66 #include <Kernel/TTY/MasterPTY.h> 67 67 #include <Kernel/TTY/TTY.h> 68 68 #include <Kernel/Thread.h> 69 - #include <Kernel/VM/SharedInodeVMObject.h> 70 69 #include <Kernel/VM/PageDirectory.h> 71 70 #include <Kernel/VM/PurgeableVMObject.h> 71 + #include <Kernel/VM/SharedInodeVMObject.h> 72 72 #include <LibBareMetal/IO.h> 73 73 #include <LibBareMetal/Output/Console.h> 74 74 #include <LibBareMetal/StdLib.h> ··· 205 205 return allocate_region(range, name, prot, commit); 206 206 } 207 207 208 - Region* Process::allocate_file_backed_region(VirtualAddress vaddr, size_t size, NonnullRefPtr<Inode> inode, const String& name, int prot) 209 - { 210 - auto range = allocate_range(vaddr, size); 211 - if (!range.is_valid()) 212 - return nullptr; 213 - auto& region = add_region(Region::create_user_accessible(range, inode, name, prot_to_region_access_flags(prot))); 214 - region.map(page_directory()); 215 - return &region; 216 - } 217 - 218 208 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) 219 209 { 220 210 ASSERT(range.is_valid()); ··· 240 230 region->map(page_directory()); 241 231 return region; 242 232 } 243 - 244 233 245 234 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) 246 235 {
-1
Kernel/Process.h
··· 367 367 bool is_superuser() const { return m_euid == 0; } 368 368 369 369 Region* allocate_region_with_vmobject(VirtualAddress, size_t, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const String& name, int prot, bool user_accessible = true); 370 - Region* allocate_file_backed_region(VirtualAddress, size_t, NonnullRefPtr<Inode>, const String& name, int prot); 371 370 Region* allocate_region(VirtualAddress, size_t, const String& name, int prot = PROT_READ | PROT_WRITE, bool commit = true); 372 371 Region* allocate_region_with_vmobject(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const String& name, int prot, bool user_accessible = true); 373 372 Region* allocate_region(const Range&, const String& name, int prot = PROT_READ | PROT_WRITE, bool commit = true);
-17
Kernel/VM/Region.cpp
··· 48 48 MM.register_region(*this); 49 49 } 50 50 51 - Region::Region(const Range& range, NonnullRefPtr<Inode> inode, const String& name, u8 access, bool cacheable) 52 - : m_range(range) 53 - , m_vmobject(SharedInodeVMObject::create_with_inode(*inode)) 54 - , m_name(name) 55 - , m_access(access) 56 - , m_cacheable(cacheable) 57 - { 58 - MM.register_region(*this); 59 - } 60 - 61 51 Region::Region(const Range& range, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, const String& name, u8 access, bool cacheable) 62 52 : m_range(range) 63 53 , m_offset_in_vmobject(offset_in_vmobject) ··· 202 192 NonnullOwnPtr<Region> Region::create_user_accessible(const Range& range, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, const StringView& name, u8 access, bool cacheable) 203 193 { 204 194 auto region = make<Region>(range, move(vmobject), offset_in_vmobject, name, access, cacheable); 205 - region->m_user_accessible = true; 206 - return region; 207 - } 208 - 209 - NonnullOwnPtr<Region> Region::create_user_accessible(const Range& range, NonnullRefPtr<Inode> inode, const StringView& name, u8 access, bool cacheable) 210 - { 211 - auto region = make<Region>(range, move(inode), name, access, cacheable); 212 195 region->m_user_accessible = true; 213 196 return region; 214 197 }
-2
Kernel/VM/Region.h
··· 57 57 58 58 static NonnullOwnPtr<Region> create_user_accessible(const Range&, const StringView& name, u8 access, bool cacheable = true); 59 59 static NonnullOwnPtr<Region> create_user_accessible(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const StringView& name, u8 access, bool cacheable = true); 60 - static NonnullOwnPtr<Region> create_user_accessible(const Range&, NonnullRefPtr<Inode>, const StringView& name, u8 access, bool cacheable = true); 61 60 static NonnullOwnPtr<Region> create_kernel_only(const Range&, const StringView& name, u8 access, bool cacheable = true); 62 61 static NonnullOwnPtr<Region> create_kernel_only(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const StringView& name, u8 access, bool cacheable = true); 63 62 ··· 163 162 // NOTE: These are public so we can make<> them. 164 163 Region(const Range&, const String&, u8 access, bool cacheable); 165 164 Region(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const String&, u8 access, bool cacheable); 166 - Region(const Range&, NonnullRefPtr<Inode>, const String&, u8 access, bool cacheable); 167 165 168 166 private: 169 167 Bitmap& ensure_cow_map() const;