From 2a3ce863fd66643c3b70fb9c3ffa06df425d81b3 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 18 Apr 2017 12:33:53 +0200 Subject: [PATCH] Enable write protect bit to improve safety --- src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 51d0295..847e2bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,6 +46,7 @@ pub extern fn rust_main(multiboot_information_address: usize) { multiboot_end, memory_map_tag.memory_areas()); enable_nxe_bit(); + enable_write_protect_bit(); memory::remap_the_kernel(&mut frame_allocator, boot_info); println!("It did not crash!"); @@ -62,6 +63,12 @@ fn enable_nxe_bit() { } } +fn enable_write_protect_bit() { + use x86_64::registers::control_regs::{cr0, cr0_write, Cr0}; + + unsafe { cr0_write(cr0() | Cr0::WRITE_PROTECT) }; +} + #[lang = "eh_personality"] extern fn eh_personality() {} #[lang = "panic_fmt"]