From 84b0fe02eefd26462b4c9e258736b8b4ecb35e45 Mon Sep 17 00:00:00 2001
From: "iliya.saroukha" <iliya.saroukhanian@etu.hesge.ch>
Date: Tue, 3 Dec 2024 16:40:21 +0100
Subject: [PATCH] feat: added function for checking MSR's flags

---
 docs/re.md | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/docs/re.md b/docs/re.md
index 1fae61c..0ef0a6e 100644
--- a/docs/re.md
+++ b/docs/re.md
@@ -135,6 +135,26 @@ able to write to this MSR using __wrmsr. What's interesting about this is that
 the tutorial tries to modify this MSR but if we assume that the **lock bit is set**
 that branch **will be a no-op**.
 
+```c
+static bool ia32_feature_control_flags(void) {
+    int msr_value = __rdmsr(IA32_FEATURE_CONTROL_MSR);
+
+    if (!(msr_value & IA32_FEATURE_CONTROL_LOCK_BIT)) {
+        printk(KERN_INFO "Writing to the IA32_FEATURE_CONTROL MSR\n");
+        __wrmsr(IA32_FEATURE_CONTROL_MSR,
+                IA32_FEATURE_CONTROL_LOCK_BIT |
+                    IA32_FEATURE_CONTROL_VMXON_OUTSIDE_SMX,
+                0);
+    }
+
+    if (!(msr_value & IA32_FEATURE_CONTROL_VMXON_OUTSIDE_SMX)) {
+        printk(KERN_INFO "Virtualization isn't available\n");
+        return false;
+    }
+
+    return true;
+}
+```
 
 ## References
 
-- 
GitLab