Skip to content

Instantly share code, notes, and snippets.

@morimolymoly
Created November 17, 2018 08:32
Show Gist options
  • Save morimolymoly/1fe58bc65aaf41cc9c983dfdd0c149b8 to your computer and use it in GitHub Desktop.
Save morimolymoly/1fe58bc65aaf41cc9c983dfdd0c149b8 to your computer and use it in GitHub Desktop.
Compiled https://github.com/Tr4pMafia/bar0 with https://github.com/Tr4pMafia/hypervisor/tree/moly-bar and make quick.
Patch is below.
diff --git a/bfvmm/include/hve/arch/intel_x64/exit_handler.h b/bfvmm/include/hve/arch/intel_x64/exit_handler.h
index 275c5633..287b7a83 100755
--- a/bfvmm/include/hve/arch/intel_x64/exit_handler.h
+++ b/bfvmm/include/hve/arch/intel_x64/exit_handler.h
@@ -54,6 +54,16 @@
#pragma warning(disable : 4251)
#endif
+#include "../../../memory_manager/arch/x64/cr3.h"
+namespace bfvmm::x64
+{
+static cr3::mmap s_mmap;
+gsl::not_null<cr3::mmap *>
+mmap()
+{
+ return &s_mmap;
+}
+}
// -----------------------------------------------------------------------------
// Handler Types
// -----------------------------------------------------------------------------
diff --git a/bfvmm/src/hve/arch/intel_x64/exit_handler.cpp b/bfvmm/src/hve/arch/intel_x64/exit_handler.cpp
index b98638a7..b679c4dc 100755
--- a/bfvmm/src/hve/arch/intel_x64/exit_handler.cpp
+++ b/bfvmm/src/hve/arch/intel_x64/exit_handler.cpp
@@ -50,16 +50,6 @@ extern "C" void exit_handler_entry(void) noexcept;
// Global Variables
// -----------------------------------------------------------------------------
-namespace bfvmm::x64
-{
-gsl::not_null<cr3::mmap *>
-mmap()
-{
- static cr3::mmap s_mmap;
- return &s_mmap;
-}
-}
-
static bfn::once_flag g_once_flag{};
static ::intel_x64::cr0::value_type g_cr0{};
static ::intel_x64::cr3::value_type g_cr3{};
@@ -123,6 +113,7 @@ setup()
if (extended_feature_flags::subleaf0::ebx::smap::is_enabled()) {
g_cr4 |= ::intel_x64::cr4::smap_enable_bit::mask;
}
+ bfdebug_nhex(0, "setup cr3", mmap()->cr3());
}
// -----------------------------------------------------------------------------
This hypervisor outputs CR3 value of static mmap's physical address(m_pml4.phys_addr).
moly@yayoi:~/bar/build$ make dump
[0] DEBUG: setup cr3 0x000000038f415000
[0] DEBUG: mafia vcpu cr3 0x000000038f416000
[0] DEBUG: host os is now in a vm
[1] DEBUG: host os is now in a vm
[2] DEBUG: host os is now in a vm
[3] DEBUG: host os is now in a vm
[4] DEBUG: host os is now in a vm
[5] DEBUG: host os is now in a vm
[6] DEBUG: host os is now in a vm
[7] DEBUG: host os is now in a vm
[8] DEBUG: host os is now in a vm
[9] DEBUG: host os is now in a vm
[10] DEBUG: host os is now in a vm
[11] DEBUG: host os is now in a vm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment