2020-03-01 17:38:09 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-01 17:38:09 +03:00
|
|
|
*/
|
|
|
|
|
2022-05-16 15:42:49 +03:00
|
|
|
#include <Kernel/Arch/InterruptDisabler.h>
|
2021-08-06 11:45:34 +03:00
|
|
|
#include <Kernel/Memory/MemoryManager.h>
|
2021-09-06 18:22:36 +03:00
|
|
|
#include <Kernel/Memory/ScopedAddressSpaceSwitcher.h>
|
2020-03-01 17:38:09 +03:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-09-06 18:22:36 +03:00
|
|
|
ScopedAddressSpaceSwitcher::ScopedAddressSpaceSwitcher(Process& process)
|
2020-03-01 17:38:09 +03:00
|
|
|
{
|
2021-02-23 22:42:32 +03:00
|
|
|
VERIFY(Thread::current() != nullptr);
|
2020-03-01 17:38:09 +03:00
|
|
|
m_previous_cr3 = read_cr3();
|
2021-10-02 09:45:15 +03:00
|
|
|
Memory::MemoryManager::enter_process_address_space(process);
|
2020-03-01 17:38:09 +03:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:22:36 +03:00
|
|
|
ScopedAddressSpaceSwitcher::~ScopedAddressSpaceSwitcher()
|
2020-03-01 17:38:09 +03:00
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
2021-06-26 20:57:16 +03:00
|
|
|
Thread::current()->regs().cr3 = m_previous_cr3;
|
2020-03-01 17:38:09 +03:00
|
|
|
write_cr3(m_previous_cr3);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|