From 053e167002648170a0396f72269264319c0fc1f1 Mon Sep 17 00:00:00 2001 From: EnderIce2 Date: Thu, 1 Feb 2024 16:27:10 +0200 Subject: [PATCH] Add CheckRegion function --- include/memory/virtual.hpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/memory/virtual.hpp b/include/memory/virtual.hpp index 6061c8e..f766799 100644 --- a/include/memory/virtual.hpp +++ b/include/memory/virtual.hpp @@ -66,6 +66,32 @@ namespace Memory PTFlag Flag = PTFlag::P, MapType Type = MapType::FourKiB); + /** + * @brief Check if the region has the specified flag. + * + * @param VirtualAddress Virtual address of the region. + * @param Length Length of the region. + * @param Flag Flag to check. + * @param Type Type of the page. Check MapType enum. + * @return true if the region has the specified flag, false otherwise. + */ + bool CheckRegion(void *VirtualAddress, + size_t Length, + PTFlag Flag = PTFlag::P, + MapType Type = MapType::FourKiB) + { + for (size_t i = 0; i < Length; i += PAGE_SIZE_4K) + { + if (!this->Check((void *)((uintptr_t)VirtualAddress + i), Flag, Type)) + { + debug("address %#lx for pt %#lx has flag(s) %#lx", + (uintptr_t)VirtualAddress + i, this->pTable, Flag); + return false; + } + } + return true; + } + /** * @brief Get physical address of the page. * @param VirtualAddress Virtual address of the page.