1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:07:35 +00:00

UserspaceEmulator: Keep the MMU regions list sorted

This commit is contained in:
Andreas Kling 2021-03-09 11:30:20 +01:00
parent 728d947601
commit 0b5a915725

View file

@ -30,6 +30,7 @@
#include "Report.h"
#include <AK/ByteBuffer.h>
#include <AK/Memory.h>
#include <AK/QuickSort.h>
namespace UserspaceEmulator {
@ -49,6 +50,7 @@ void SoftMMU::add_region(NonnullOwnPtr<Region> region)
}
m_regions.append(move(region));
quick_sort((Vector<OwnPtr<Region>>&)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<MmapRegion>(m_page_to_region_map[page_index]));
MmapRegion* old_region = static_cast<MmapRegion*>(m_page_to_region_map[page_index]);
auto* old_region = static_cast<MmapRegion*>(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<MmapRegion> 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<OwnPtr<Region>>&)m_regions, [](auto& a, auto& b) { return a->base() < b->base(); });
}
void SoftMMU::set_tls_region(NonnullOwnPtr<Region> region)