diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2021-03-08 19:20:09 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-08 22:57:36 +0100 |
commit | 1e857de26354576fbaf46642e7956632bd1f8af9 (patch) | |
tree | a5ceaea5162d22ed40f8ed6a1915adf8de340939 /Userland/DevTools/UserspaceEmulator/SoftMMU.h | |
parent | 45443f24ec6624a46abf7363c9ee962666dc5e5e (diff) | |
download | serenity-1e857de26354576fbaf46642e7956632bd1f8af9.zip |
UserspaceEmulator: Support munmap/mprotect with partial mappings
Fixes #5663.
Diffstat (limited to 'Userland/DevTools/UserspaceEmulator/SoftMMU.h')
-rw-r--r-- | Userland/DevTools/UserspaceEmulator/SoftMMU.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Userland/DevTools/UserspaceEmulator/SoftMMU.h b/Userland/DevTools/UserspaceEmulator/SoftMMU.h index 5ee14c7a47..1fd8207131 100644 --- a/Userland/DevTools/UserspaceEmulator/SoftMMU.h +++ b/Userland/DevTools/UserspaceEmulator/SoftMMU.h @@ -87,6 +87,28 @@ public: } } + template<typename Callback> + void for_regions_in(X86::LogicalAddress address, size_t size, Callback callback) + { + VERIFY(size > 0); + X86::LogicalAddress address_end = address; + address_end.set_offset(address_end.offset() + size); + ensure_split_at(address); + ensure_split_at(address_end); + + size_t first_page = address.offset() / PAGE_SIZE; + size_t last_page = (address_end.offset() - 1) / PAGE_SIZE; + Region* last_reported = nullptr; + for (size_t page = first_page; page <= last_page; ++page) { + Region* current_region = m_page_to_region_map[page]; + if (page != first_page && current_region == last_reported) + continue; + if (callback(current_region) == IterationDecision::Break) + return; + last_reported = current_region; + } + } + private: Emulator& m_emulator; |