From 0b5a915725f20545cbe44fa94feb2c6c6f08f421 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 9 Mar 2021 11:30:20 +0100 Subject: [PATCH] UserspaceEmulator: Keep the MMU regions list sorted --- Userland/DevTools/UserspaceEmulator/SoftMMU.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Userland/DevTools/UserspaceEmulator/SoftMMU.cpp b/Userland/DevTools/UserspaceEmulator/SoftMMU.cpp index 7d42a8eb24..0d56f73bb0 100644 --- a/Userland/DevTools/UserspaceEmulator/SoftMMU.cpp +++ b/Userland/DevTools/UserspaceEmulator/SoftMMU.cpp @@ -30,6 +30,7 @@ #include "Report.h" #include #include +#include namespace UserspaceEmulator { @@ -49,6 +50,7 @@ void SoftMMU::add_region(NonnullOwnPtr region) } m_regions.append(move(region)); + quick_sort((Vector>&)m_regions, [](auto& a, auto& b) { return a->base() < b->base(); }); } void SoftMMU::remove_region(Region& region) @@ -80,17 +82,27 @@ void SoftMMU::ensure_split_at(X86::LogicalAddress address) // If we get here, we know that the page exists and belongs to a region, that there is // a previous page, and that it belongs to the same region. VERIFY(is(m_page_to_region_map[page_index])); - MmapRegion* old_region = static_cast(m_page_to_region_map[page_index]); + auto* old_region = static_cast(m_page_to_region_map[page_index]); + + //dbgln("splitting at {:p}", address.offset()); + //dbgln(" old region: {:p}-{:p}", old_region->base(), old_region->end() - 1); + NonnullOwnPtr new_region = old_region->split_at(VirtualAddress(offset)); + //dbgln(" new region: {:p}-{:p}", new_region->base(), new_region->end() - 1); + //dbgln(" up old region: {:p}-{:p}", old_region->base(), old_region->end() - 1); size_t first_page_in_region = new_region->base() / PAGE_SIZE; size_t last_page_in_region = (new_region->base() + new_region->size() - 1) / PAGE_SIZE; + + //dbgln(" @ remapping pages {} thru {}", first_page_in_region, last_page_in_region); + for (size_t page = first_page_in_region; page <= last_page_in_region; ++page) { VERIFY(m_page_to_region_map[page] == old_region); m_page_to_region_map[page] = new_region.ptr(); } m_regions.append(move(new_region)); + quick_sort((Vector>&)m_regions, [](auto& a, auto& b) { return a->base() < b->base(); }); } void SoftMMU::set_tls_region(NonnullOwnPtr region)