diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-05-30 16:14:37 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-30 16:14:37 +0200 |
commit | baaede1bf9e8c4180f0c2aed251645e69dfea6bf (patch) | |
tree | b6697c7234f328e0437869e8ecb83d675afb2d48 /Kernel/VM | |
parent | 8fe72d7b3cfadb66bda77d295fbe178667190444 (diff) | |
download | serenity-baaede1bf9e8c4180f0c2aed251645e69dfea6bf.zip |
Kernel: Make the Process allocate_region* API's understand "int prot".
Instead of having to inspect 'prot' at every call site, make the Process
API's take care of that so we can just pass it through.
Diffstat (limited to 'Kernel/VM')
-rw-r--r-- | Kernel/VM/MemoryManager.cpp | 2 | ||||
-rw-r--r-- | Kernel/VM/Region.cpp | 21 | ||||
-rw-r--r-- | Kernel/VM/Region.h | 30 |
3 files changed, 31 insertions, 22 deletions
diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index 1f3c328dd7..06e66f670b 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -403,7 +403,7 @@ RetainPtr<Region> MemoryManager::allocate_kernel_region(size_t size, String&& na ASSERT(!(size % PAGE_SIZE)); auto range = kernel_page_directory().range_allocator().allocate_anywhere(size); ASSERT(range.is_valid()); - auto region = adopt(*new Region(range, move(name), true, true, false)); + auto region = adopt(*new Region(range, move(name), PROT_READ | PROT_WRITE | PROT_EXEC, 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/Region.cpp b/Kernel/VM/Region.cpp index e1cd53dbdc..3c93cfff7c 100644 --- a/Kernel/VM/Region.cpp +++ b/Kernel/VM/Region.cpp @@ -4,36 +4,33 @@ #include <Kernel/Process.h> #include <Kernel/Thread.h> -Region::Region(const Range& range, String&& n, bool r, bool w, bool cow) +Region::Region(const Range& range, String&& n, byte access, bool cow) : m_range(range) , m_vmo(VMObject::create_anonymous(size())) , m_name(move(n)) - , m_readable(r) - , m_writable(w) + , m_access(access) , m_cow_map(Bitmap::create(m_vmo->page_count(), cow)) { m_vmo->set_name(m_name); MM.register_region(*this); } -Region::Region(const Range& range, RetainPtr<Inode>&& inode, String&& n, bool r, bool w) +Region::Region(const Range& range, RetainPtr<Inode>&& inode, String&& n, byte access) : m_range(range) , m_vmo(VMObject::create_file_backed(move(inode))) , m_name(move(n)) - , m_readable(r) - , m_writable(w) + , m_access(access) , m_cow_map(Bitmap::create(m_vmo->page_count())) { MM.register_region(*this); } -Region::Region(const Range& range, Retained<VMObject>&& vmo, size_t offset_in_vmo, String&& n, bool r, bool w, bool cow) +Region::Region(const Range& range, Retained<VMObject>&& vmo, size_t offset_in_vmo, String&& n, byte access, bool cow) : m_range(range) , m_offset_in_vmo(offset_in_vmo) , m_vmo(move(vmo)) , m_name(move(n)) - , m_readable(r) - , m_writable(w) + , m_access(access) , m_cow_map(Bitmap::create(m_vmo->page_count(), cow)) { MM.register_region(*this); @@ -71,7 +68,7 @@ bool Region::page_in() Retained<Region> Region::clone() { ASSERT(current); - if (m_shared || (m_readable && !m_writable)) { + if (m_shared || (is_readable() && !is_writable())) { #ifdef MM_DEBUG dbgprintf("%s<%u> Region::clone(): sharing %s (L%x)\n", current->process().name().characters(), @@ -80,7 +77,7 @@ Retained<Region> Region::clone() laddr().get()); #endif // Create a new region backed by the same VMObject. - return adopt(*new Region(m_range, 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_access)); } #ifdef MM_DEBUG @@ -93,7 +90,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(m_range, 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_access, true)); } int Region::commit() diff --git a/Kernel/VM/Region.h b/Kernel/VM/Region.h index 254469cf1d..76c6645f3e 100644 --- a/Kernel/VM/Region.h +++ b/Kernel/VM/Region.h @@ -10,17 +10,24 @@ class VMObject; class Region : public Retainable<Region> { friend class MemoryManager; - public: - 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); + enum Access + { + Read = 1, + Write = 2, + Execute = 4, + }; + + Region(const Range&, String&&, byte access, bool cow = false); + Region(const Range&, Retained<VMObject>&&, size_t offset_in_vmo, String&&, byte access, bool cow = false); + Region(const Range&, RetainPtr<Inode>&&, String&&, byte access); ~Region(); 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; } + bool is_readable() const { return m_access & Access::Read; } + bool is_writable() const { return m_access & Access::Write; } + bool is_executable() const { return m_access & Access::Execute; } String name() const { return m_name; } void set_name(String&& name) { m_name = move(name); } @@ -81,7 +88,13 @@ public: bool should_cow(size_t page_index) const { return m_cow_map.get(page_index); } void set_should_cow(size_t page_index, bool cow) { m_cow_map.set(page_index, cow); } - void set_writable(bool b) { m_writable = b; } + void set_writable(bool b) + { + if (b) + m_access |= Access::Read; + else + m_access &= ~Access::Write; + } private: RetainPtr<PageDirectory> m_page_directory; @@ -89,8 +102,7 @@ private: size_t m_offset_in_vmo { 0 }; Retained<VMObject> m_vmo; String m_name; - bool m_readable { true }; - bool m_writable { true }; + byte m_access { 0 }; bool m_shared { false }; Bitmap m_cow_map; }; |