1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:47:45 +00:00

Kernel: Implement ScopedAddressSpaceSwitcher using PageDirectory

This makes the code architecture independent, and thus makes it work for
aarch64.
This commit is contained in:
Timon Kruiper 2023-04-01 02:53:20 +02:00 committed by Idan Horowitz
parent 6a8581855d
commit 7440112cd9
2 changed files with 6 additions and 12 deletions

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2023, Timon Kruiper <timonkruiper@gmail.com>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -13,23 +14,14 @@ namespace Kernel {
ScopedAddressSpaceSwitcher::ScopedAddressSpaceSwitcher(Process& process) ScopedAddressSpaceSwitcher::ScopedAddressSpaceSwitcher(Process& process)
{ {
VERIFY(Thread::current() != nullptr); VERIFY(Thread::current() != nullptr);
#if ARCH(X86_64) m_previous_page_directory = Memory::PageDirectory::find_current();
m_previous_cr3 = read_cr3();
#elif ARCH(AARCH64)
TODO_AARCH64();
#endif
Memory::MemoryManager::enter_process_address_space(process); Memory::MemoryManager::enter_process_address_space(process);
} }
ScopedAddressSpaceSwitcher::~ScopedAddressSpaceSwitcher() ScopedAddressSpaceSwitcher::~ScopedAddressSpaceSwitcher()
{ {
InterruptDisabler disabler; InterruptDisabler disabler;
#if ARCH(X86_64) Memory::activate_page_directory(*m_previous_page_directory, Thread::current());
Thread::current()->regs().cr3 = m_previous_cr3;
write_cr3(m_previous_cr3);
#elif ARCH(AARCH64)
TODO_AARCH64();
#endif
} }
} }

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2023, Timon Kruiper <timonkruiper@gmail.com>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -7,6 +8,7 @@
#pragma once #pragma once
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/Arch/PageDirectory.h>
#include <Kernel/Forward.h> #include <Kernel/Forward.h>
namespace Kernel { namespace Kernel {
@ -17,7 +19,7 @@ public:
~ScopedAddressSpaceSwitcher(); ~ScopedAddressSpaceSwitcher();
private: private:
u32 m_previous_cr3 { 0 }; LockRefPtr<Memory::PageDirectory> m_previous_page_directory;
}; };
} }