diff --git a/Kernel/Arch/x86/common/PageDirectory.cpp b/Kernel/Arch/x86/common/PageDirectory.cpp index 993dab67ca..1efe016508 100644 --- a/Kernel/Arch/x86/common/PageDirectory.cpp +++ b/Kernel/Arch/x86/common/PageDirectory.cpp @@ -1,43 +1,41 @@ /* - * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2018-2022, Andreas Kling * Copyright (c) 2018-2022, James Mintram * * SPDX-License-Identifier: BSD-2-Clause */ #include - -#include #include #include namespace Kernel::Memory { -// FIXME: This needs real locking: -static Singleton> s_cr3_map; +struct CR3Map { + SpinlockProtected> map { LockRank::None }; +}; -static IntrusiveRedBlackTree<&PageDirectory::m_tree_node>& cr3_map() -{ - VERIFY_INTERRUPTS_DISABLED(); - return *s_cr3_map; -} +static Singleton s_cr3_map; void PageDirectory::register_page_directory(PageDirectory* directory) { - InterruptDisabler disabler; - cr3_map().insert(directory->cr3(), *directory); + s_cr3_map->map.with([&](auto& map) { + map.insert(directory->cr3(), *directory); + }); } void PageDirectory::deregister_page_directory(PageDirectory* directory) { - InterruptDisabler disabler; - cr3_map().remove(directory->cr3()); + s_cr3_map->map.with([&](auto& map) { + map.remove(directory->cr3()); + }); } LockRefPtr PageDirectory::find_current() { - SpinlockLocker lock(s_mm_lock); - return cr3_map().find(read_cr3()); + return s_cr3_map->map.with([&](auto& map) { + return map.find(read_cr3()); + }); } void activate_kernel_page_directory(PageDirectory const& pgd)