diff --git a/Kernel/Arch/i386/CPU.h b/Kernel/Arch/i386/CPU.h index d1bed13d9e..d7bf93fcc0 100644 --- a/Kernel/Arch/i386/CPU.h +++ b/Kernel/Arch/i386/CPU.h @@ -1137,22 +1137,4 @@ ALWAYS_INLINE void clac() : "cc"); } -class SmapDisabler { -public: - ALWAYS_INLINE SmapDisabler() - { - m_flags = cpu_flags(); - stac(); - } - - ALWAYS_INLINE ~SmapDisabler() - { - if (!(m_flags & 0x40000)) - clac(); - } - -private: - u32 m_flags; -}; - } diff --git a/Kernel/Arch/x86/SmapDisabler.h b/Kernel/Arch/x86/SmapDisabler.h new file mode 100644 index 0000000000..3574dc733f --- /dev/null +++ b/Kernel/Arch/x86/SmapDisabler.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2018-2021, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include + +namespace Kernel { + +class SmapDisabler { +public: + ALWAYS_INLINE SmapDisabler() + : m_flags(cpu_flags()) + { + stac(); + } + + ALWAYS_INLINE ~SmapDisabler() + { + if (!(m_flags & 0x40000)) + clac(); + } + +private: + const FlatPtr m_flags; +}; + +} diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index c7667644b2..54037845b4 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -13,10 +13,11 @@ set(KERNEL_SOURCES ACPI/MultiProcessorParser.cpp ACPI/Parser.cpp AddressSanitizer.cpp + Arch/PC/BIOS.cpp Arch/i386/CPU.cpp Arch/i386/ProcessorInfo.cpp Arch/i386/SafeMem.cpp - Arch/PC/BIOS.cpp + Arch/x86/SmapDisabler.h CMOS.cpp CommandLine.cpp Console.cpp diff --git a/Kernel/KSyms.cpp b/Kernel/KSyms.cpp index dc77c21550..8bdd475dc0 100644 --- a/Kernel/KSyms.cpp +++ b/Kernel/KSyms.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include diff --git a/Kernel/PerformanceEventBuffer.cpp b/Kernel/PerformanceEventBuffer.cpp index 1f58bfc28d..81b6bbf668 100644 --- a/Kernel/PerformanceEventBuffer.cpp +++ b/Kernel/PerformanceEventBuffer.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include diff --git a/Kernel/StdLib.cpp b/Kernel/StdLib.cpp index 2b6df4871e..00a7010453 100644 --- a/Kernel/StdLib.cpp +++ b/Kernel/StdLib.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include diff --git a/Kernel/Syscalls/sigaction.cpp b/Kernel/Syscalls/sigaction.cpp index 3bd36453bc..f89eb775a1 100644 --- a/Kernel/Syscalls/sigaction.cpp +++ b/Kernel/Syscalls/sigaction.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 51a6a632aa..7040315811 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include diff --git a/Kernel/VM/AnonymousVMObject.cpp b/Kernel/VM/AnonymousVMObject.cpp index 1c99d47b1d..7a8f1f3513 100644 --- a/Kernel/VM/AnonymousVMObject.cpp +++ b/Kernel/VM/AnonymousVMObject.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include