summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-01-28 15:02:45 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-28 23:41:18 +0100
commit5092813a45daab9bb44f51b1575603c0521af8c8 (patch)
tree1f0a162808016bd4d753f8c631309567157f7c6b
parent145eeb57ab268ca654077c65032e62a5cf12070a (diff)
downloadserenity-5092813a45daab9bb44f51b1575603c0521af8c8.zip
Kernel: Quickly reject userspace addresses in kernel_region_from_vaddr()
This avoids taking and releasing the MM lock just to reject an address that we can tell from just looking at it that it won't ever be in the kernel regions tree.
-rw-r--r--Kernel/Memory/MemoryManager.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/Kernel/Memory/MemoryManager.cpp b/Kernel/Memory/MemoryManager.cpp
index 07eb097970..d76a802ed0 100644
--- a/Kernel/Memory/MemoryManager.cpp
+++ b/Kernel/Memory/MemoryManager.cpp
@@ -645,6 +645,9 @@ UNMAP_AFTER_INIT void MemoryManager::initialize(u32 cpu)
Region* MemoryManager::kernel_region_from_vaddr(VirtualAddress vaddr)
{
+ if (is_user_address(vaddr))
+ return nullptr;
+
SpinlockLocker lock(s_mm_lock);
auto* region = MM.m_kernel_regions.find_largest_not_above(vaddr.get());
if (!region || !region->contains(vaddr))