From 71fd54f76b60f07bb68e763478c3ca6a334c50fe Mon Sep 17 00:00:00 2001 From: asynts Date: Sat, 10 Oct 2020 18:05:22 +0200 Subject: [PATCH] MemoryManager: Off-by-one error when collecting memory pages. Notice that we ensured that the size is a multiple of the page size and that there is at least one page there, otherwise, this change would be invalid. We create an empty region and then expand it: // First iteration. m_user_physical_regions.append(PhysicalRegion::create(addr, addr)); // Following iterations. region->expand(region->lower(), addr); So if the memory region only has one page, we would end up with an empty region. Thus we need to do one more iteration. --- Kernel/VM/MemoryManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index 8d1e24a7b8..9cebe27a20 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -151,7 +151,7 @@ void MemoryManager::parse_memory_map() klog() << "MM: considering memory at " << String::format("%p", (FlatPtr)mmap->addr) << " - " << String::format("%p", (FlatPtr)(mmap->addr + mmap->len)); #endif - for (size_t page_base = mmap->addr; page_base < (mmap->addr + mmap->len); page_base += PAGE_SIZE) { + for (size_t page_base = mmap->addr; page_base <= (mmap->addr + mmap->len); page_base += PAGE_SIZE) { auto addr = PhysicalAddress(page_base); if (addr.get() < used_range_end.get() && addr.get() >= used_range_start.get())