From f16b9a691f382ffb32880cdc3af4f6b87329da52 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 6 Sep 2021 17:22:36 +0200 Subject: [PATCH] Kernel: Rename ProcessPagingScope => ScopedAddressSpaceSwitcher --- Kernel/Arch/x86/common/Processor.cpp | 6 +++--- Kernel/CMakeLists.txt | 2 +- Kernel/Coredump.cpp | 4 ++-- Kernel/Devices/AsyncDeviceRequest.h | 10 +++++----- ...sPagingScope.cpp => ScopedAddressSpaceSwitcher.cpp} | 6 +++--- ...ocessPagingScope.h => ScopedAddressSpaceSwitcher.h} | 8 ++++---- Kernel/Syscalls/ptrace.cpp | 6 +++--- Kernel/Thread.cpp | 6 +++--- 8 files changed, 24 insertions(+), 24 deletions(-) rename Kernel/Memory/{ProcessPagingScope.cpp => ScopedAddressSpaceSwitcher.cpp} (71%) rename Kernel/Memory/{ProcessPagingScope.h => ScopedAddressSpaceSwitcher.h} (50%) diff --git a/Kernel/Arch/x86/common/Processor.cpp b/Kernel/Arch/x86/common/Processor.cpp index c7d29bbda4c..094f3fdc577 100644 --- a/Kernel/Arch/x86/common/Processor.cpp +++ b/Kernel/Arch/x86/common/Processor.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include #include @@ -522,7 +522,7 @@ Vector Processor::capture_stack_trace(Thread& thread, size_t max_frames thread.cpu(), [&]() { dbgln("CPU[{}] getting stack for cpu #{}", Processor::current_id(), proc.id()); - ProcessPagingScope paging_scope(thread.process()); + ScopedAddressSpaceSwitcher switcher(thread.process()); VERIFY(&Processor::current() != &proc); VERIFY(&thread == Processor::current_thread()); // NOTE: Because the other processor is still holding the @@ -548,7 +548,7 @@ Vector Processor::capture_stack_trace(Thread& thread, size_t max_frames // stack. Before switching out of that thread, it switch_context // pushed the callee-saved registers, and the last of them happens // to be ebp. - ProcessPagingScope paging_scope(thread.process()); + ScopedAddressSpaceSwitcher switcher(thread.process()); auto& regs = thread.regs(); auto* stack_top = reinterpret_cast(regs.sp()); if (Memory::is_user_range(VirtualAddress(stack_top), sizeof(FlatPtr))) { diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 4fbfe451090..45d74f98d12 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -152,7 +152,7 @@ set(KERNEL_SOURCES Memory/PhysicalRegion.cpp Memory/PhysicalZone.cpp Memory/PrivateInodeVMObject.cpp - Memory/ProcessPagingScope.cpp + Memory/ScopedAddressSpaceSwitcher.cpp Memory/Region.cpp Memory/RingBuffer.cpp Memory/ScatterGatherList.cpp diff --git a/Kernel/Coredump.cpp b/Kernel/Coredump.cpp index acd044097c7..c20c90df0c2 100644 --- a/Kernel/Coredump.cpp +++ b/Kernel/Coredump.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -343,7 +343,7 @@ KResultOr Coredump::create_notes_segment_data() const KResult Coredump::write() { SpinlockLocker lock(m_process->address_space().get_lock()); - ProcessPagingScope scope(m_process); + ScopedAddressSpaceSwitcher switcher(m_process); auto notes_segment_result = create_notes_segment_data(); if (notes_segment_result.is_error()) diff --git a/Kernel/Devices/AsyncDeviceRequest.h b/Kernel/Devices/AsyncDeviceRequest.h index a67ddcd5016..ef0f86aa52b 100644 --- a/Kernel/Devices/AsyncDeviceRequest.h +++ b/Kernel/Devices/AsyncDeviceRequest.h @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include @@ -85,7 +85,7 @@ public: { if (in_target_context(buffer)) return buffer.write(forward(args)...); - ProcessPagingScope paging_scope(m_process); + ScopedAddressSpaceSwitcher switcher(m_process); return buffer.write(forward(args)...); } @@ -94,7 +94,7 @@ public: { if (in_target_context(buffer)) return buffer.write_buffered(forward(args)...); - ProcessPagingScope paging_scope(m_process); + ScopedAddressSpaceSwitcher switcher(m_process); return buffer.write_buffered(forward(args)...); } @@ -103,7 +103,7 @@ public: { if (in_target_context(buffer)) return buffer.read(forward(args)...); - ProcessPagingScope paging_scope(m_process); + ScopedAddressSpaceSwitcher switcher(m_process); return buffer.read(forward(args)...); } @@ -112,7 +112,7 @@ public: { if (in_target_context(buffer)) return buffer.read_buffered(forward(args)...); - ProcessPagingScope paging_scope(m_process); + ScopedAddressSpaceSwitcher switcher(m_process); return buffer.read_buffered(forward(args)...); } diff --git a/Kernel/Memory/ProcessPagingScope.cpp b/Kernel/Memory/ScopedAddressSpaceSwitcher.cpp similarity index 71% rename from Kernel/Memory/ProcessPagingScope.cpp rename to Kernel/Memory/ScopedAddressSpaceSwitcher.cpp index b8e94fcaa18..622eec26a06 100644 --- a/Kernel/Memory/ProcessPagingScope.cpp +++ b/Kernel/Memory/ScopedAddressSpaceSwitcher.cpp @@ -6,18 +6,18 @@ #include #include -#include +#include namespace Kernel { -ProcessPagingScope::ProcessPagingScope(Process& process) +ScopedAddressSpaceSwitcher::ScopedAddressSpaceSwitcher(Process& process) { VERIFY(Thread::current() != nullptr); m_previous_cr3 = read_cr3(); MM.enter_process_address_space(process); } -ProcessPagingScope::~ProcessPagingScope() +ScopedAddressSpaceSwitcher::~ScopedAddressSpaceSwitcher() { InterruptDisabler disabler; Thread::current()->regs().cr3 = m_previous_cr3; diff --git a/Kernel/Memory/ProcessPagingScope.h b/Kernel/Memory/ScopedAddressSpaceSwitcher.h similarity index 50% rename from Kernel/Memory/ProcessPagingScope.h rename to Kernel/Memory/ScopedAddressSpaceSwitcher.h index c2b88a896b3..d5470729314 100644 --- a/Kernel/Memory/ProcessPagingScope.h +++ b/Kernel/Memory/ScopedAddressSpaceSwitcher.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2020-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -11,10 +11,10 @@ namespace Kernel { -class ProcessPagingScope { +class ScopedAddressSpaceSwitcher { public: - explicit ProcessPagingScope(Process&); - ~ProcessPagingScope(); + explicit ScopedAddressSpaceSwitcher(Process&); + ~ScopedAddressSpaceSwitcher(); private: u32 m_previous_cr3 { 0 }; diff --git a/Kernel/Syscalls/ptrace.cpp b/Kernel/Syscalls/ptrace.cpp index 210bae36c1a..3f698027bb1 100644 --- a/Kernel/Syscalls/ptrace.cpp +++ b/Kernel/Syscalls/ptrace.cpp @@ -8,8 +8,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -168,7 +168,7 @@ KResultOr Process::peek_user_data(Userspace address) { // This function can be called from the context of another // process that called PT_PEEK - ProcessPagingScope scope(*this); + ScopedAddressSpaceSwitcher switcher(*this); uint32_t data; TRY(copy_from_user(&data, address)); return data; @@ -180,7 +180,7 @@ KResult Process::poke_user_data(Userspace address, u32 data) auto* region = address_space().find_region_containing(range); if (!region) return EFAULT; - ProcessPagingScope scope(*this); + ScopedAddressSpaceSwitcher switcher(*this); if (region->is_shared()) { // If the region is shared, we change its vmobject to a PrivateInodeVMObject // to prevent the write operation from changing any shared inode data diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 69d223427b8..8c7125c58c8 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -911,7 +911,7 @@ DispatchSignalResult Thread::dispatch_signal(u8 signal) VERIFY(previous_mode() == PreviousMode::UserMode); VERIFY(current_trap()); - ProcessPagingScope paging_scope(m_process); + ScopedAddressSpaceSwitcher switcher(m_process); u32 old_signal_mask = m_signal_mask; u32 new_signal_mask = action.mask; @@ -1157,7 +1157,7 @@ String Thread::backtrace() auto& process = const_cast(this->process()); auto stack_trace = Processor::capture_stack_trace(*this); VERIFY(!g_scheduler_lock.is_locked_by_current_processor()); - ProcessPagingScope paging_scope(process); + ScopedAddressSpaceSwitcher switcher(process); for (auto& frame : stack_trace) { if (Memory::is_user_range(VirtualAddress(frame), sizeof(FlatPtr) * 2)) { recognized_symbols.append({ frame });