summaryrefslogtreecommitdiff
path: root/Kernel/Memory/ScopedAddressSpaceSwitcher.cpp
blob: 5abd6b04b5691ec0e7a4189c05ff4ce33f9c804e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
 * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
 * Copyright (c) 2023, Timon Kruiper <timonkruiper@gmail.com>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <Kernel/InterruptDisabler.h>
#include <Kernel/Memory/MemoryManager.h>
#include <Kernel/Memory/ScopedAddressSpaceSwitcher.h>

namespace Kernel {

ScopedAddressSpaceSwitcher::ScopedAddressSpaceSwitcher(Process& process)
{
    VERIFY(Thread::current() != nullptr);
    m_previous_page_directory = Memory::PageDirectory::find_current();
    Memory::MemoryManager::enter_process_address_space(process);
}

ScopedAddressSpaceSwitcher::~ScopedAddressSpaceSwitcher()
{
    InterruptDisabler disabler;
    Memory::activate_page_directory(*m_previous_page_directory, Thread::current());
}

}