summaryrefslogtreecommitdiff
path: root/Kernel/Arch/i386
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-05-20 14:14:02 +0200
committerAndreas Kling <kling@serenityos.org>2020-05-20 14:17:01 +0200
commit81d35c68919a41c4dc97beda19a452a4f9b3ca7b (patch)
treea929a3423bacf90655957906b97a799ec6f27fae /Kernel/Arch/i386
parente10183a6c5f840ba979c94ae4b6e1f7721114d2e (diff)
downloadserenity-81d35c68919a41c4dc97beda19a452a4f9b3ca7b.zip
Kernel: Always inline stac(), clac() and SmapDisabler
Let's not be paying the function call overhead for these tiny ops. Maybe there's an argument for having fewer gadgets in the kernel but for now we're actually seeing stac() in profiles so let's put that above theoretical security issues.
Diffstat (limited to 'Kernel/Arch/i386')
-rw-r--r--Kernel/Arch/i386/CPU.cpp16
-rw-r--r--Kernel/Arch/i386/CPU.h21
2 files changed, 17 insertions, 20 deletions
diff --git a/Kernel/Arch/i386/CPU.cpp b/Kernel/Arch/i386/CPU.cpp
index 11909c4cfb..affd7705d1 100644
--- a/Kernel/Arch/i386/CPU.cpp
+++ b/Kernel/Arch/i386/CPU.cpp
@@ -734,22 +734,6 @@ void cpu_detect()
g_cpu_supports_umip = (extended_features.ecx() & (1 << 2));
}
-void stac()
-{
- if (!g_cpu_supports_smap)
- return;
- asm volatile("stac" ::
- : "cc");
-}
-
-void clac()
-{
- if (!g_cpu_supports_smap)
- return;
- asm volatile("clac" ::
- : "cc");
-}
-
void cpu_setup()
{
cpu_detect();
diff --git a/Kernel/Arch/i386/CPU.h b/Kernel/Arch/i386/CPU.h
index 6cc85461b3..9b6e771be0 100644
--- a/Kernel/Arch/i386/CPU.h
+++ b/Kernel/Arch/i386/CPU.h
@@ -584,18 +584,31 @@ extern bool g_cpu_supports_sse;
extern bool g_cpu_supports_tsc;
extern bool g_cpu_supports_umip;
-void stac();
-void clac();
+ALWAYS_INLINE void stac()
+{
+ if (!g_cpu_supports_smap)
+ return;
+ asm volatile("stac" ::
+ : "cc");
+}
+
+ALWAYS_INLINE void clac()
+{
+ if (!g_cpu_supports_smap)
+ return;
+ asm volatile("clac" ::
+ : "cc");
+}
class SmapDisabler {
public:
- SmapDisabler()
+ ALWAYS_INLINE SmapDisabler()
{
m_flags = cpu_flags();
stac();
}
- ~SmapDisabler()
+ ALWAYS_INLINE ~SmapDisabler()
{
if (!(m_flags & 0x40000))
clac();