From 7afc0fb9c83fd13cf48c52e26ce6fc5741d42e2b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 22 May 2019 13:24:28 +0200 Subject: Kernel: Forked children should inherit their RangeAllocator by copy. Otherwise we'll start handing out addresses that are very likely already in use by existing ranges. --- Kernel/Process.cpp | 2 +- Kernel/VM/PageDirectory.cpp | 4 ++-- Kernel/VM/PageDirectory.h | 4 ++-- Kernel/VM/RangeAllocator.cpp | 5 +++++ Kernel/VM/RangeAllocator.h | 1 + 5 files changed, 11 insertions(+), 5 deletions(-) (limited to 'Kernel') diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 80de78b8a5..32555f5ea5 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -557,7 +557,7 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring { dbgprintf("Process: New process PID=%u with name=%s\n", m_pid, m_name.characters()); - m_page_directory = PageDirectory::create_for_userspace(); + m_page_directory = PageDirectory::create_for_userspace(fork_parent ? &fork_parent->page_directory().range_allocator() : nullptr); #ifdef MM_DEBUG dbgprintf("Process %u ctor: PD=%x created\n", pid(), m_page_directory.ptr()); #endif diff --git a/Kernel/VM/PageDirectory.cpp b/Kernel/VM/PageDirectory.cpp index c3f5070ce3..befd020ce4 100644 --- a/Kernel/VM/PageDirectory.cpp +++ b/Kernel/VM/PageDirectory.cpp @@ -12,8 +12,8 @@ PageDirectory::PageDirectory(PhysicalAddress paddr) m_directory_page = PhysicalPage::create_eternal(paddr, true); } -PageDirectory::PageDirectory() - : m_range_allocator(LinearAddress(userspace_range_base), kernelspace_range_base - userspace_range_base) +PageDirectory::PageDirectory(const RangeAllocator* parent_range_allocator) + : m_range_allocator(parent_range_allocator ? RangeAllocator(*parent_range_allocator) : RangeAllocator(LinearAddress(userspace_range_base), kernelspace_range_base - userspace_range_base)) { MM.populate_page_directory(*this); } diff --git a/Kernel/VM/PageDirectory.h b/Kernel/VM/PageDirectory.h index 2937eab520..409a5f919c 100644 --- a/Kernel/VM/PageDirectory.h +++ b/Kernel/VM/PageDirectory.h @@ -9,7 +9,7 @@ class PageDirectory : public Retainable { friend class MemoryManager; public: - static Retained create_for_userspace() { return adopt(*new PageDirectory); } + static Retained create_for_userspace(const RangeAllocator* parent_range_allocator = nullptr) { return adopt(*new PageDirectory(parent_range_allocator)); } static Retained create_at_fixed_address(PhysicalAddress paddr) { return adopt(*new PageDirectory(paddr)); } ~PageDirectory(); @@ -21,7 +21,7 @@ public: RangeAllocator& range_allocator() { return m_range_allocator; } private: - PageDirectory(); + explicit PageDirectory(const RangeAllocator* parent_range_allocator); explicit PageDirectory(PhysicalAddress); RangeAllocator m_range_allocator; diff --git a/Kernel/VM/RangeAllocator.cpp b/Kernel/VM/RangeAllocator.cpp index db97cc9d79..f077ff7383 100644 --- a/Kernel/VM/RangeAllocator.cpp +++ b/Kernel/VM/RangeAllocator.cpp @@ -12,6 +12,11 @@ RangeAllocator::RangeAllocator(LinearAddress base, size_t size) #endif } +RangeAllocator::RangeAllocator(const RangeAllocator& parent_allocator) + : m_available_ranges(parent_allocator.m_available_ranges) +{ +} + RangeAllocator::~RangeAllocator() { } diff --git a/Kernel/VM/RangeAllocator.h b/Kernel/VM/RangeAllocator.h index a2f1575bdc..e80e1278ca 100644 --- a/Kernel/VM/RangeAllocator.h +++ b/Kernel/VM/RangeAllocator.h @@ -46,6 +46,7 @@ private: class RangeAllocator { public: RangeAllocator(LinearAddress, size_t); + RangeAllocator(const RangeAllocator&); ~RangeAllocator(); Range allocate_anywhere(size_t); -- cgit v1.2.3