diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-11-04 00:05:57 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-04 00:05:57 +0100 |
commit | 9b2dc362292293394d212e0d7b0ac86579d077e9 (patch) | |
tree | c2edf4ca6ee55d5a2c32c6c76144c8250986f1bb | |
parent | 98b328754ec8bd29bd495c6567343e2422a33fa5 (diff) | |
download | serenity-9b2dc362292293394d212e0d7b0ac86579d077e9.zip |
Kernel: Merge MemoryManager::map_region_at_address() into Region::map()
-rw-r--r-- | Kernel/VM/MemoryManager.cpp | 32 | ||||
-rw-r--r-- | Kernel/VM/MemoryManager.h | 1 | ||||
-rw-r--r-- | Kernel/VM/Region.cpp | 38 |
3 files changed, 32 insertions, 39 deletions
diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index f52e0c7ba5..e007c29b2d 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -682,38 +682,6 @@ void MemoryManager::unquickmap_page() m_quickmap_in_use = false; } -void MemoryManager::map_region_at_address(PageDirectory& page_directory, Region& region, VirtualAddress vaddr) -{ - InterruptDisabler disabler; - region.set_page_directory(page_directory); - auto& vmo = region.vmobject(); -#ifdef MM_DEBUG - dbgprintf("MM: map_region_at_address will map VMO pages %u - %u (VMO page count: %u)\n", region.first_page_index(), region.last_page_index(), vmo.page_count()); -#endif - for (size_t i = 0; i < region.page_count(); ++i) { - auto page_vaddr = vaddr.offset(i * PAGE_SIZE); - auto& pte = ensure_pte(page_directory, page_vaddr); - auto& physical_page = vmo.physical_pages()[region.first_page_index() + i]; - if (physical_page) { - pte.set_physical_page_base(physical_page->paddr().get()); - pte.set_present(true); // FIXME: Maybe we should use the is_readable flag here? - if (region.should_cow(i)) - pte.set_writable(false); - else - pte.set_writable(region.is_writable()); - } else { - pte.set_physical_page_base(0); - pte.set_present(false); - pte.set_writable(region.is_writable()); - } - pte.set_user_allowed(region.is_user_accessible()); - page_directory.flush(page_vaddr); -#ifdef MM_DEBUG - dbgprintf("MM: >> map_region_at_address (PD=%p) '%s' V%p => P%p (@%p)\n", &page_directory, region.name().characters(), page_vaddr, physical_page ? physical_page->paddr().get() : 0, physical_page.ptr()); -#endif - } -} - bool MemoryManager::validate_user_read(const Process& process, VirtualAddress vaddr) const { auto* region = region_from_vaddr(process, vaddr); diff --git a/Kernel/VM/MemoryManager.h b/Kernel/VM/MemoryManager.h index 38ed88ba42..3305674ac8 100644 --- a/Kernel/VM/MemoryManager.h +++ b/Kernel/VM/MemoryManager.h @@ -68,7 +68,6 @@ public: OwnPtr<Region> allocate_kernel_region(size_t, const StringView& name, bool user_accessible = false, bool should_commit = true); OwnPtr<Region> allocate_user_accessible_kernel_region(size_t, const StringView& name); - void map_region_at_address(PageDirectory&, Region&, VirtualAddress); unsigned user_physical_pages() const { return m_user_physical_pages; } unsigned user_physical_pages_used() const { return m_user_physical_pages_used; } diff --git a/Kernel/VM/Region.cpp b/Kernel/VM/Region.cpp index c47d1c8eb4..682f28f55c 100644 --- a/Kernel/VM/Region.cpp +++ b/Kernel/VM/Region.cpp @@ -6,6 +6,8 @@ #include <Kernel/VM/MemoryManager.h> #include <Kernel/VM/Region.h> +//#define MM_DEBUG + Region::Region(const Range& range, const String& name, u8 access) : m_range(range) , m_vmobject(AnonymousVMObject::create_with_size(size())) @@ -190,10 +192,8 @@ void Region::remap_page(size_t index) #ifdef MM_DEBUG dbg() << "MM: >> region.remap_page (PD=" << page_directory()->cr3() << ", PTE=" << (void*)pte.raw() << "{" << &pte << "}) " << name() << " " << page_vaddr << " => " << physical_page->paddr() << " (@" << physical_page.ptr() << ")"; #endif - } - void Region::unmap(ShouldDeallocateVirtualMemoryRange deallocate_range) { InterruptDisabler disabler; @@ -207,8 +207,8 @@ void Region::unmap(ShouldDeallocateVirtualMemoryRange deallocate_range) pte.set_user_allowed(false); page_directory()->flush(vaddr); #ifdef MM_DEBUG - auto& physical_page = region.vmobject().physical_pages()[region.first_page_index() + i]; - dbgprintf("MM: >> Unmapped V%p => P%p <<\n", vaddr, physical_page ? physical_page->paddr().get() : 0); + auto& physical_page = vmobject().physical_pages()[first_page_index() + i]; + dbgprintf("MM: >> Unmapped V%p => P%p <<\n", vaddr.get(), physical_page ? physical_page->paddr().get() : 0); #endif } if (deallocate_range == ShouldDeallocateVirtualMemoryRange::Yes) @@ -218,11 +218,37 @@ void Region::unmap(ShouldDeallocateVirtualMemoryRange deallocate_range) void Region::map(PageDirectory& page_directory) { - MM.map_region_at_address(page_directory, *this, vaddr()); + InterruptDisabler disabler; + set_page_directory(page_directory); +#ifdef MM_DEBUG + dbgprintf("MM: map_region_at_address will map VMO pages %u - %u (VMO page count: %u)\n", first_page_index(), last_page_index(), vmobject().page_count()); +#endif + for (size_t i = 0; i < page_count(); ++i) { + auto page_vaddr = vaddr().offset(i * PAGE_SIZE); + auto& pte = MM.ensure_pte(page_directory, page_vaddr); + auto& physical_page = vmobject().physical_pages()[first_page_index() + i]; + if (physical_page) { + pte.set_physical_page_base(physical_page->paddr().get()); + pte.set_present(true); // FIXME: Maybe we should use the is_readable flag here? + if (should_cow(i)) + pte.set_writable(false); + else + pte.set_writable(is_writable()); + } else { + pte.set_physical_page_base(0); + pte.set_present(false); + pte.set_writable(is_writable()); + } + pte.set_user_allowed(is_user_accessible()); + page_directory.flush(page_vaddr); +#ifdef MM_DEBUG + dbgprintf("MM: >> map_region_at_address (PD=%p) '%s' V%p => P%p (@%p)\n", &page_directory, name().characters(), page_vaddr.get(), physical_page ? physical_page->paddr().get() : 0, physical_page.ptr()); +#endif + } } void Region::remap() { ASSERT(m_page_directory); - MM.map_region_at_address(*m_page_directory, *this, vaddr()); + map(*m_page_directory); } |