diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-05-17 04:32:08 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-17 04:32:08 +0200 |
commit | 87b54a82c77bf811e9e9497cfb6037ac1a8ecde3 (patch) | |
tree | aaf85c74c3ef8b11b89a7c8426688bfadf5a8472 /Kernel | |
parent | 4a6fcfbacf45a52af8b5073d628155de6ff16584 (diff) | |
download | serenity-87b54a82c77bf811e9e9497cfb6037ac1a8ecde3.zip |
Kernel: Let Region keep a Range internally.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Process.cpp | 6 | ||||
-rw-r--r-- | Kernel/VM/MemoryManager.cpp | 2 | ||||
-rw-r--r-- | Kernel/VM/RangeAllocator.h | 2 | ||||
-rw-r--r-- | Kernel/VM/Region.cpp | 21 | ||||
-rw-r--r-- | Kernel/VM/Region.h | 21 |
5 files changed, 26 insertions, 26 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index bb1f0caee0..0275cc83c5 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -79,7 +79,7 @@ Region* Process::allocate_region(LinearAddress laddr, size_t size, String&& name else range = m_range_allocator.allocate_specific(laddr, size); - m_regions.append(adopt(*new Region(range.base(), range.size(), move(name), is_readable, is_writable))); + m_regions.append(adopt(*new Region(range, move(name), is_readable, is_writable))); MM.map_region(*this, *m_regions.last()); if (commit) m_regions.last()->commit(); @@ -97,7 +97,7 @@ Region* Process::allocate_file_backed_region(LinearAddress laddr, size_t size, R else range = m_range_allocator.allocate_specific(laddr, size); - m_regions.append(adopt(*new Region(range.base(), range.size(), move(inode), move(name), is_readable, is_writable))); + m_regions.append(adopt(*new Region(range, move(inode), move(name), is_readable, is_writable))); MM.map_region(*this, *m_regions.last()); return m_regions.last().ptr(); } @@ -115,7 +115,7 @@ Region* Process::allocate_region_with_vmo(LinearAddress laddr, size_t size, Reta offset_in_vmo &= PAGE_MASK; size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE; - m_regions.append(adopt(*new Region(range.base(), range.size(), move(vmo), offset_in_vmo, move(name), is_readable, is_writable))); + m_regions.append(adopt(*new Region(range, move(vmo), offset_in_vmo, move(name), is_readable, is_writable))); MM.map_region(*this, *m_regions.last()); return m_regions.last().ptr(); } diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index 5ef89cfa0b..b26cca4c09 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -404,7 +404,7 @@ RetainPtr<Region> MemoryManager::allocate_kernel_region(size_t size, String&& na ASSERT(!(size % PAGE_SIZE)); auto range = m_range_allocator.allocate_anywhere(size); ASSERT(range.is_valid()); - auto region = adopt(*new Region(range.base(), range.size(), move(name), true, true, false)); + auto region = adopt(*new Region(range, move(name), true, true, false)); MM.map_region_at_address(*m_kernel_page_directory, *region, range.base(), false); // FIXME: It would be cool if these could zero-fill on demand instead. region->commit(); diff --git a/Kernel/VM/RangeAllocator.h b/Kernel/VM/RangeAllocator.h index bd1575ef4e..a2f1575bdc 100644 --- a/Kernel/VM/RangeAllocator.h +++ b/Kernel/VM/RangeAllocator.h @@ -17,6 +17,8 @@ public: size_t size() const { return m_size; } bool is_valid() const { return !m_base.is_null(); } + bool contains(LinearAddress laddr) const { return laddr >= base() && laddr < end(); } + LinearAddress end() const { return m_base.offset(m_size); } bool operator==(const Range& other) const diff --git a/Kernel/VM/Region.cpp b/Kernel/VM/Region.cpp index 27b0d5ebff..e1cd53dbdc 100644 --- a/Kernel/VM/Region.cpp +++ b/Kernel/VM/Region.cpp @@ -4,10 +4,9 @@ #include <Kernel/Process.h> #include <Kernel/Thread.h> -Region::Region(LinearAddress a, size_t s, String&& n, bool r, bool w, bool cow) - : m_laddr(a) - , m_size(s) - , m_vmo(VMObject::create_anonymous(s)) +Region::Region(const Range& range, String&& n, bool r, bool w, bool cow) + : m_range(range) + , m_vmo(VMObject::create_anonymous(size())) , m_name(move(n)) , m_readable(r) , m_writable(w) @@ -17,9 +16,8 @@ Region::Region(LinearAddress a, size_t s, String&& n, bool r, bool w, bool cow) MM.register_region(*this); } -Region::Region(LinearAddress a, size_t s, RetainPtr<Inode>&& inode, String&& n, bool r, bool w) - : m_laddr(a) - , m_size(s) +Region::Region(const Range& range, RetainPtr<Inode>&& inode, String&& n, bool r, bool w) + : m_range(range) , m_vmo(VMObject::create_file_backed(move(inode))) , m_name(move(n)) , m_readable(r) @@ -29,9 +27,8 @@ Region::Region(LinearAddress a, size_t s, RetainPtr<Inode>&& inode, String&& n, MM.register_region(*this); } -Region::Region(LinearAddress a, size_t s, Retained<VMObject>&& vmo, size_t offset_in_vmo, String&& n, bool r, bool w, bool cow) - : m_laddr(a) - , m_size(s) +Region::Region(const Range& range, Retained<VMObject>&& vmo, size_t offset_in_vmo, String&& n, bool r, bool w, bool cow) + : m_range(range) , m_offset_in_vmo(offset_in_vmo) , m_vmo(move(vmo)) , m_name(move(n)) @@ -83,7 +80,7 @@ Retained<Region> Region::clone() laddr().get()); #endif // Create a new region backed by the same VMObject. - return adopt(*new Region(laddr(), size(), m_vmo.copy_ref(), m_offset_in_vmo, String(m_name), m_readable, m_writable)); + return adopt(*new Region(m_range, m_vmo.copy_ref(), m_offset_in_vmo, String(m_name), m_readable, m_writable)); } #ifdef MM_DEBUG @@ -96,7 +93,7 @@ Retained<Region> Region::clone() // Set up a COW region. The parent (this) region becomes COW as well! m_cow_map.fill(true); MM.remap_region(current->process().page_directory(), *this); - return adopt(*new Region(laddr(), size(), m_vmo->clone(), m_offset_in_vmo, String(m_name), m_readable, m_writable, true)); + return adopt(*new Region(m_range, m_vmo->clone(), m_offset_in_vmo, String(m_name), m_readable, m_writable, true)); } int Region::commit() diff --git a/Kernel/VM/Region.h b/Kernel/VM/Region.h index 305a35a6fb..806fa6460c 100644 --- a/Kernel/VM/Region.h +++ b/Kernel/VM/Region.h @@ -3,6 +3,7 @@ #include <AK/AKString.h> #include <AK/Bitmap.h> #include <Kernel/VM/PageDirectory.h> +#include <Kernel/VM/RangeAllocator.h> class Inode; class VMObject; @@ -10,13 +11,13 @@ class VMObject; class Region : public Retainable<Region> { friend class MemoryManager; public: - Region(LinearAddress, size_t, String&&, bool r, bool w, bool cow = false); - Region(LinearAddress, size_t, Retained<VMObject>&&, size_t offset_in_vmo, String&&, bool r, bool w, bool cow = false); - Region(LinearAddress, size_t, RetainPtr<Inode>&&, String&&, bool r, bool w); + Region(const Range&, String&&, bool r, bool w, bool cow = false); + Region(const Range&, Retained<VMObject>&&, size_t offset_in_vmo, String&&, bool r, bool w, bool cow = false); + Region(const Range&, RetainPtr<Inode>&&, String&&, bool r, bool w); ~Region(); - LinearAddress laddr() const { return m_laddr; } - size_t size() const { return m_size; } + LinearAddress laddr() const { return m_range.base(); } + size_t size() const { return m_range.size(); } bool is_readable() const { return m_readable; } bool is_writable() const { return m_writable; } String name() const { return m_name; } @@ -30,14 +31,15 @@ public: void set_shared(bool shared) { m_shared = shared; } Retained<Region> clone(); + bool contains(LinearAddress laddr) const { - return laddr >= m_laddr && laddr < m_laddr.offset(size()); + return m_range.contains(laddr); } unsigned page_index_from_address(LinearAddress laddr) const { - return (laddr - m_laddr).get() / PAGE_SIZE; + return (laddr - m_range.base()).get() / PAGE_SIZE; } size_t first_page_index() const @@ -52,7 +54,7 @@ public: size_t page_count() const { - return m_size / PAGE_SIZE; + return size() / PAGE_SIZE; } bool page_in(); @@ -82,8 +84,7 @@ public: private: RetainPtr<PageDirectory> m_page_directory; - LinearAddress m_laddr; - size_t m_size { 0 }; + Range m_range; size_t m_offset_in_vmo { 0 }; Retained<VMObject> m_vmo; String m_name; |