1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:28:12 +00:00

Kernel: Use an IntrusiveRedBlackTree for storing the cr3 mappings

This ensures we don't allocate when intializing the PageDirectory.
This commit is contained in:
Idan Horowitz 2021-09-08 02:40:44 +03:00
parent 0279fb4dd3
commit bee2de4b31
2 changed files with 8 additions and 4 deletions

View file

@ -17,9 +17,9 @@ extern u8 end_of_kernel_image[];
namespace Kernel::Memory {
static Singleton<HashMap<FlatPtr, PageDirectory*>> s_cr3_map;
static Singleton<IntrusiveRedBlackTree<FlatPtr, PageDirectory, RawPtr<PageDirectory>, &PageDirectory::m_tree_node>> s_cr3_map;
static HashMap<FlatPtr, PageDirectory*>& cr3_map()
static IntrusiveRedBlackTree<FlatPtr, PageDirectory, RawPtr<PageDirectory>, &PageDirectory::m_tree_node>& cr3_map()
{
VERIFY_INTERRUPTS_DISABLED();
return *s_cr3_map;
@ -28,7 +28,7 @@ static HashMap<FlatPtr, PageDirectory*>& cr3_map()
RefPtr<PageDirectory> PageDirectory::find_by_cr3(FlatPtr cr3)
{
SpinlockLocker lock(s_mm_lock);
return cr3_map().get(cr3).value_or({});
return cr3_map().find(cr3);
}
UNMAP_AFTER_INIT NonnullRefPtr<PageDirectory> PageDirectory::must_create_kernel_page_directory()
@ -132,7 +132,7 @@ KResultOr<NonnullRefPtr<PageDirectory>> PageDirectory::try_create_for_userspace(
auto* new_pd = MM.quickmap_pd(*directory, 0);
memcpy(new_pd, &buffer, sizeof(PageDirectoryEntry));
cr3_map().set(directory->cr3(), directory.ptr());
cr3_map().insert(directory->cr3(), directory);
return directory;
}