diff options
author | Andreas Kling <kling@serenityos.org> | 2021-02-25 17:25:34 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-25 17:25:34 +0100 |
commit | 8129f3da52eeec0b7cf6c342bdf22580193f8a9b (patch) | |
tree | 34bf9637f8ad27e862ce1804d269f92e45a41a01 /Kernel/Arch | |
parent | 8f70528f301bea948ab8f7a3a0835284dc735dd1 (diff) | |
download | serenity-8129f3da52eeec0b7cf6c342bdf22580193f8a9b.zip |
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.
Diffstat (limited to 'Kernel/Arch')
-rw-r--r-- | Kernel/Arch/i386/CPU.h | 18 | ||||
-rw-r--r-- | Kernel/Arch/x86/SmapDisabler.h | 51 |
2 files changed, 51 insertions, 18 deletions
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 <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; +}; + +} |