mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:37:45 +00:00
Kernel/x86: Protect the CR3->PD map with a spinlock
This can be accessed from multiple CPUs at the same time, so relying on the interrupt flag is clearly insufficient.
This commit is contained in:
parent
6cd3695761
commit
4c081e0479
1 changed files with 14 additions and 16 deletions
|
@ -1,43 +1,41 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
||||||
* Copyright (c) 2018-2022, James Mintram <me@jamesrm.com>
|
* Copyright (c) 2018-2022, James Mintram <me@jamesrm.com>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/Singleton.h>
|
#include <AK/Singleton.h>
|
||||||
|
|
||||||
#include <Kernel/Arch/InterruptDisabler.h>
|
|
||||||
#include <Kernel/Memory/PageDirectory.h>
|
#include <Kernel/Memory/PageDirectory.h>
|
||||||
#include <Kernel/Thread.h>
|
#include <Kernel/Thread.h>
|
||||||
|
|
||||||
namespace Kernel::Memory {
|
namespace Kernel::Memory {
|
||||||
|
|
||||||
// FIXME: This needs real locking:
|
struct CR3Map {
|
||||||
static Singleton<IntrusiveRedBlackTree<&PageDirectory::m_tree_node>> s_cr3_map;
|
SpinlockProtected<IntrusiveRedBlackTree<&PageDirectory::m_tree_node>> map { LockRank::None };
|
||||||
|
};
|
||||||
|
|
||||||
static IntrusiveRedBlackTree<&PageDirectory::m_tree_node>& cr3_map()
|
static Singleton<CR3Map> s_cr3_map;
|
||||||
{
|
|
||||||
VERIFY_INTERRUPTS_DISABLED();
|
|
||||||
return *s_cr3_map;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PageDirectory::register_page_directory(PageDirectory* directory)
|
void PageDirectory::register_page_directory(PageDirectory* directory)
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
s_cr3_map->map.with([&](auto& map) {
|
||||||
cr3_map().insert(directory->cr3(), *directory);
|
map.insert(directory->cr3(), *directory);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageDirectory::deregister_page_directory(PageDirectory* directory)
|
void PageDirectory::deregister_page_directory(PageDirectory* directory)
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
s_cr3_map->map.with([&](auto& map) {
|
||||||
cr3_map().remove(directory->cr3());
|
map.remove(directory->cr3());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
LockRefPtr<PageDirectory> PageDirectory::find_current()
|
LockRefPtr<PageDirectory> PageDirectory::find_current()
|
||||||
{
|
{
|
||||||
SpinlockLocker lock(s_mm_lock);
|
return s_cr3_map->map.with([&](auto& map) {
|
||||||
return cr3_map().find(read_cr3());
|
return map.find(read_cr3());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void activate_kernel_page_directory(PageDirectory const& pgd)
|
void activate_kernel_page_directory(PageDirectory const& pgd)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue