2020-03-01 14:38:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
2023-04-01 00:53:20 +00:00
|
|
|
* Copyright (c) 2023, Timon Kruiper <timonkruiper@gmail.com>
|
2020-03-01 14:38:09 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-01 14:38:09 +00:00
|
|
|
*/
|
|
|
|
|
2023-02-24 18:33:43 +00:00
|
|
|
#include <Kernel/Interrupts/InterruptDisabler.h>
|
2021-08-06 08:45:34 +00:00
|
|
|
#include <Kernel/Memory/MemoryManager.h>
|
2021-09-06 15:22:36 +00:00
|
|
|
#include <Kernel/Memory/ScopedAddressSpaceSwitcher.h>
|
2020-03-01 14:38:09 +00:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-09-06 15:22:36 +00:00
|
|
|
ScopedAddressSpaceSwitcher::ScopedAddressSpaceSwitcher(Process& process)
|
2020-03-01 14:38:09 +00:00
|
|
|
{
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY(Thread::current() != nullptr);
|
2023-04-01 00:53:20 +00:00
|
|
|
m_previous_page_directory = Memory::PageDirectory::find_current();
|
2021-10-02 06:45:15 +00:00
|
|
|
Memory::MemoryManager::enter_process_address_space(process);
|
2020-03-01 14:38:09 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 15:22:36 +00:00
|
|
|
ScopedAddressSpaceSwitcher::~ScopedAddressSpaceSwitcher()
|
2020-03-01 14:38:09 +00:00
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
2023-04-01 00:53:20 +00:00
|
|
|
Memory::activate_page_directory(*m_previous_page_directory, Thread::current());
|
2020-03-01 14:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|