Kernel: Move SMAP disabler RAII helper to its own file

Added this in a new directory called Kernel/Arch/x86/ where stuff
that applies to both i386 and x86_64 can live.
This commit is contained in:
Andreas Kling 2021-02-25 17:25:34 +01:00
parent 8f70528f30
commit 8129f3da52
9 changed files with 59 additions and 19 deletions

View file

@ -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;
};
}

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* 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 <Kernel/Arch/i386/CPU.h>
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;
};
}

View file

@ -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

View file

@ -26,6 +26,7 @@
#include <AK/Demangle.h>
#include <AK/TemporaryChange.h>
#include <Kernel/Arch/x86/SmapDisabler.h>
#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/KSyms.h>
#include <Kernel/Process.h>

View file

@ -27,6 +27,7 @@
#include <AK/JsonArraySerializer.h>
#include <AK/JsonObject.h>
#include <AK/JsonObjectSerializer.h>
#include <Kernel/Arch/x86/SmapDisabler.h>
#include <Kernel/KBufferBuilder.h>
#include <Kernel/PerformanceEventBuffer.h>
#include <Kernel/Process.h>

View file

@ -29,6 +29,7 @@
#include <AK/String.h>
#include <AK/Types.h>
#include <Kernel/Arch/i386/CPU.h>
#include <Kernel/Arch/x86/SmapDisabler.h>
#include <Kernel/Heap/kmalloc.h>
#include <Kernel/StdLib.h>
#include <Kernel/VM/MemoryManager.h>

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <Kernel/Arch/x86/SmapDisabler.h>
#include <Kernel/Panic.h>
#include <Kernel/Process.h>

View file

@ -29,6 +29,7 @@
#include <AK/StringBuilder.h>
#include <AK/Time.h>
#include <Kernel/Arch/i386/CPU.h>
#include <Kernel/Arch/x86/SmapDisabler.h>
#include <Kernel/Debug.h>
#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/KSyms.h>

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <Kernel/Arch/x86/SmapDisabler.h>
#include <Kernel/Debug.h>
#include <Kernel/Process.h>
#include <Kernel/VM/AnonymousVMObject.h>