diff options
28 files changed, 58 insertions, 64 deletions
diff --git a/Kernel/Arch/InterruptDisabler.h b/Kernel/Arch/InterruptDisabler.h new file mode 100644 index 0000000000..d4e49bb9b4 --- /dev/null +++ b/Kernel/Arch/InterruptDisabler.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022, Timon Kruiper <timonkruiper@gmail.com> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/Types.h> +#include <Kernel/Arch/Processor.h> + +namespace Kernel { + +class InterruptDisabler { +public: + InterruptDisabler() + : m_interrupts_were_enabled(Processor::are_interrupts_enabled()) + { + Processor::disable_interrupts(); + } + + ~InterruptDisabler() + { + if (m_interrupts_were_enabled) + Processor::enable_interrupts(); + } + +private: + bool m_interrupts_were_enabled; +}; + +} diff --git a/Kernel/Arch/x86/InterruptDisabler.h b/Kernel/Arch/x86/InterruptDisabler.h deleted file mode 100644 index 941ddaab2b..0000000000 --- a/Kernel/Arch/x86/InterruptDisabler.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include <AK/Types.h> - -#include <Kernel/Arch/x86/IO.h> - -#include <Kernel/Arch/x86/ASM_wrapper.h> - -#include <AK/Platform.h> -VALIDATE_IS_X86() - -namespace Kernel { - -class InterruptDisabler { -public: - InterruptDisabler() - { - m_flags = cpu_flags(); - cli(); - } - - ~InterruptDisabler() - { - if ((m_flags & 0x200) != 0) - sti(); - } - -private: - u32 m_flags; -}; - -} diff --git a/Kernel/Arch/x86/common/Processor.cpp b/Kernel/Arch/x86/common/Processor.cpp index 7e2e2800ad..632d24e2b9 100644 --- a/Kernel/Arch/x86/common/Processor.cpp +++ b/Kernel/Arch/x86/common/Processor.cpp @@ -19,12 +19,12 @@ #include <Kernel/StdLib.h> #include <Kernel/Thread.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Arch/Interrupts.h> #include <Kernel/Arch/Processor.h> #include <Kernel/Arch/SafeMem.h> #include <Kernel/Arch/ScopedCritical.h> #include <Kernel/Arch/x86/CPUID.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> #include <Kernel/Arch/x86/MSR.h> #include <Kernel/Arch/x86/ProcessorInfo.h> #include <Kernel/Arch/x86/TrapFrame.h> diff --git a/Kernel/Arch/x86/common/TrapFrame.cpp b/Kernel/Arch/x86/common/TrapFrame.cpp index 9e3054c678..2262840d1c 100644 --- a/Kernel/Arch/x86/common/TrapFrame.cpp +++ b/Kernel/Arch/x86/common/TrapFrame.cpp @@ -4,8 +4,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Arch/Processor.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> #include <Kernel/Arch/x86/TrapFrame.h> namespace Kernel { diff --git a/Kernel/DoubleBuffer.cpp b/Kernel/DoubleBuffer.cpp index 498bf0f538..cc921ef7bb 100644 --- a/Kernel/DoubleBuffer.cpp +++ b/Kernel/DoubleBuffer.cpp @@ -5,7 +5,7 @@ */ #include <AK/StringView.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/DoubleBuffer.h> namespace Kernel { diff --git a/Kernel/FileSystem/FileSystem.cpp b/Kernel/FileSystem/FileSystem.cpp index 368d924425..96d19bef43 100644 --- a/Kernel/FileSystem/FileSystem.cpp +++ b/Kernel/FileSystem/FileSystem.cpp @@ -7,7 +7,7 @@ #include <AK/HashMap.h> #include <AK/Singleton.h> #include <AK/StringView.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/FileSystem/FileSystem.h> #include <Kernel/FileSystem/Inode.h> #include <Kernel/Memory/MemoryManager.h> diff --git a/Kernel/Firmware/ACPI/Parser.cpp b/Kernel/Firmware/ACPI/Parser.cpp index 41ebbecd12..406275bffb 100644 --- a/Kernel/Firmware/ACPI/Parser.cpp +++ b/Kernel/Firmware/ACPI/Parser.cpp @@ -9,8 +9,8 @@ #include <AK/Format.h> #include <AK/StringView.h> #include <AK/Try.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Arch/x86/IO.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> #include <Kernel/Bus/PCI/API.h> #include <Kernel/Debug.h> #include <Kernel/Firmware/ACPI/Parser.h> diff --git a/Kernel/Firmware/Hypervisor/VMWareBackdoor.cpp b/Kernel/Firmware/Hypervisor/VMWareBackdoor.cpp index 5df1b8d61d..b1b78ed585 100644 --- a/Kernel/Firmware/Hypervisor/VMWareBackdoor.cpp +++ b/Kernel/Firmware/Hypervisor/VMWareBackdoor.cpp @@ -7,7 +7,7 @@ #include <AK/OwnPtr.h> #include <AK/Singleton.h> #include <Kernel/API/MousePacket.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/CommandLine.h> #include <Kernel/Debug.h> #include <Kernel/Firmware/Hypervisor/VMWareBackdoor.h> diff --git a/Kernel/GlobalProcessExposed.cpp b/Kernel/GlobalProcessExposed.cpp index 025b3ea8be..91288c4531 100644 --- a/Kernel/GlobalProcessExposed.cpp +++ b/Kernel/GlobalProcessExposed.cpp @@ -8,7 +8,7 @@ #include <AK/JsonObjectSerializer.h> #include <AK/Try.h> #include <AK/UBSanitizer.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Arch/x86/ProcessorInfo.h> #include <Kernel/Bus/PCI/API.h> #include <Kernel/Bus/PCI/Access.h> diff --git a/Kernel/Interrupts/IOAPIC.cpp b/Kernel/Interrupts/IOAPIC.cpp index f17be74382..0b75722bfd 100644 --- a/Kernel/Interrupts/IOAPIC.cpp +++ b/Kernel/Interrupts/IOAPIC.cpp @@ -5,7 +5,7 @@ */ #include <AK/Optional.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Debug.h> #include <Kernel/Interrupts/APIC.h> #include <Kernel/Interrupts/IOAPIC.h> diff --git a/Kernel/Interrupts/IRQHandler.cpp b/Kernel/Interrupts/IRQHandler.cpp index d73ccc94cd..86e53a3404 100644 --- a/Kernel/Interrupts/IRQHandler.cpp +++ b/Kernel/Interrupts/IRQHandler.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Debug.h> #include <Kernel/Interrupts/IRQHandler.h> #include <Kernel/Interrupts/InterruptManagement.h> diff --git a/Kernel/Interrupts/InterruptManagement.cpp b/Kernel/Interrupts/InterruptManagement.cpp index c7570f3f34..a63f90d94b 100644 --- a/Kernel/Interrupts/InterruptManagement.cpp +++ b/Kernel/Interrupts/InterruptManagement.cpp @@ -6,8 +6,8 @@ #include <AK/ByteReader.h> #include <Kernel/API/Syscall.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Arch/Interrupts.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> #include <Kernel/CommandLine.h> #include <Kernel/Firmware/MultiProcessor/Parser.h> #include <Kernel/Interrupts/APIC.h> diff --git a/Kernel/Interrupts/PIC.cpp b/Kernel/Interrupts/PIC.cpp index 906cdc2018..002e6fbbd8 100644 --- a/Kernel/Interrupts/PIC.cpp +++ b/Kernel/Interrupts/PIC.cpp @@ -6,8 +6,8 @@ #include <AK/Assertions.h> #include <AK/Types.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Arch/x86/IO.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> #include <Kernel/Interrupts/GenericInterruptHandler.h> #include <Kernel/Interrupts/PIC.h> #include <Kernel/Sections.h> diff --git a/Kernel/Memory/ScopedAddressSpaceSwitcher.cpp b/Kernel/Memory/ScopedAddressSpaceSwitcher.cpp index f007141a68..146d37b2b9 100644 --- a/Kernel/Memory/ScopedAddressSpaceSwitcher.cpp +++ b/Kernel/Memory/ScopedAddressSpaceSwitcher.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Memory/MemoryManager.h> #include <Kernel/Memory/ScopedAddressSpaceSwitcher.h> diff --git a/Kernel/Net/NetworkAdapter.cpp b/Kernel/Net/NetworkAdapter.cpp index cbc16764a9..c5860813dc 100644 --- a/Kernel/Net/NetworkAdapter.cpp +++ b/Kernel/Net/NetworkAdapter.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Heap/kmalloc.h> #include <Kernel/Net/EtherType.h> #include <Kernel/Net/NetworkAdapter.h> diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 0b60ae622d..e709323821 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -9,7 +9,7 @@ #include <AK/Time.h> #include <AK/Types.h> #include <Kernel/API/Syscall.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Coredump.h> #include <Kernel/Debug.h> #include <Kernel/Devices/DeviceManagement.h> diff --git a/Kernel/ProcessSpecificExposed.cpp b/Kernel/ProcessSpecificExposed.cpp index 653f1c786a..5f9c9399d4 100644 --- a/Kernel/ProcessSpecificExposed.cpp +++ b/Kernel/ProcessSpecificExposed.cpp @@ -7,7 +7,7 @@ #include <AK/JsonArraySerializer.h> #include <AK/JsonObjectSerializer.h> #include <AK/JsonValue.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/FileSystem/Custody.h> #include <Kernel/FileSystem/ProcFS.h> #include <Kernel/KBufferBuilder.h> diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index 9695086004..7159e45fef 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -8,7 +8,7 @@ #include <AK/ScopeGuard.h> #include <AK/Singleton.h> #include <AK/Time.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Arch/x86/TrapFrame.h> #include <Kernel/Debug.h> #include <Kernel/Panic.h> diff --git a/Kernel/Syscalls/kill.cpp b/Kernel/Syscalls/kill.cpp index 66067584e5..58c3409b5d 100644 --- a/Kernel/Syscalls/kill.cpp +++ b/Kernel/Syscalls/kill.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Process.h> namespace Kernel { diff --git a/Kernel/Syscalls/setpgid.cpp b/Kernel/Syscalls/setpgid.cpp index 9d3f58e13d..d2976c9aa5 100644 --- a/Kernel/Syscalls/setpgid.cpp +++ b/Kernel/Syscalls/setpgid.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Process.h> #include <Kernel/TTY/TTY.h> diff --git a/Kernel/Syscalls/sigaction.cpp b/Kernel/Syscalls/sigaction.cpp index 38c5cd19ff..c5a94d27c1 100644 --- a/Kernel/Syscalls/sigaction.cpp +++ b/Kernel/Syscalls/sigaction.cpp @@ -5,8 +5,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Arch/SmapDisabler.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> #include <Kernel/Process.h> namespace Kernel { diff --git a/Kernel/TTY/MasterPTY.cpp b/Kernel/TTY/MasterPTY.cpp index 6c27d348ee..4739e644e7 100644 --- a/Kernel/TTY/MasterPTY.cpp +++ b/Kernel/TTY/MasterPTY.cpp @@ -5,7 +5,7 @@ */ #include <Kernel/API/POSIX/errno.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Debug.h> #include <Kernel/Process.h> #include <Kernel/TTY/MasterPTY.h> diff --git a/Kernel/TTY/TTY.cpp b/Kernel/TTY/TTY.cpp index 77bb9ed645..c8f0b68999 100644 --- a/Kernel/TTY/TTY.cpp +++ b/Kernel/TTY/TTY.cpp @@ -8,7 +8,7 @@ #include <AK/ScopeGuard.h> #include <AK/StringView.h> #include <Kernel/API/POSIX/errno.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Debug.h> #include <Kernel/Process.h> #include <Kernel/TTY/TTY.h> diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index b168ea4c6b..5c1306b477 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -9,8 +9,8 @@ #include <AK/StringBuilder.h> #include <AK/TemporaryChange.h> #include <AK/Time.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Arch/SmapDisabler.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> #include <Kernel/Arch/x86/TrapFrame.h> #include <Kernel/Debug.h> #include <Kernel/Devices/KCOVDevice.h> diff --git a/Kernel/Time/HPETComparator.cpp b/Kernel/Time/HPETComparator.cpp index ce95a93fbf..7cdefd1706 100644 --- a/Kernel/Time/HPETComparator.cpp +++ b/Kernel/Time/HPETComparator.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Assertions.h> #include <Kernel/Debug.h> #include <Kernel/Sections.h> diff --git a/Kernel/Time/PIT.cpp b/Kernel/Time/PIT.cpp index 455a77240e..f435e23b5c 100644 --- a/Kernel/Time/PIT.cpp +++ b/Kernel/Time/PIT.cpp @@ -4,8 +4,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Arch/x86/IO.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> #include <Kernel/Interrupts/GenericInterruptHandler.h> #include <Kernel/Scheduler.h> #include <Kernel/Sections.h> diff --git a/Kernel/Time/RTC.cpp b/Kernel/Time/RTC.cpp index f8b7a690bb..59de79808e 100644 --- a/Kernel/Time/RTC.cpp +++ b/Kernel/Time/RTC.cpp @@ -4,8 +4,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/Arch/x86/IO.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> #include <Kernel/Arch/x86/NonMaskableInterruptDisabler.h> #include <Kernel/CMOS.h> #include <Kernel/Time/RTC.h> diff --git a/Kernel/Time/TimeManagement.cpp b/Kernel/Time/TimeManagement.cpp index 811cd7a4ef..18d42d6d95 100644 --- a/Kernel/Time/TimeManagement.cpp +++ b/Kernel/Time/TimeManagement.cpp @@ -7,7 +7,7 @@ #include <AK/Singleton.h> #include <AK/StdLibExtras.h> #include <AK/Time.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> +#include <Kernel/Arch/InterruptDisabler.h> #include <Kernel/CommandLine.h> #include <Kernel/Firmware/ACPI/Parser.h> #include <Kernel/Interrupts/APIC.h> |